Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
clustering::math::GemmPlan< T, Backend > Class Template Reference

Reusable GEMM plan: packs B once at construction, amortizes the packing cost across repeated execute calls with varying A. More...

#include <clustering/math/gemm_plan.h>

Public Member Functions

template<Layout LB>
 GemmPlan (const NDArray< T, 2, LB > &B, Pool pool)
 Construct the plan and fully pre-pack B into m_Bp.
template<Layout LA>
void execute (const NDArray< T, 2, LA > &A, NDArray< T, 2 > &C, T alpha=T{1}, T beta=T{0}) const noexcept
 Execute the plan: compute C := alpha * A * B + beta * C against the pre-packed B captured at construction.
std::size_t kDim () const noexcept
 Inner dimension captured at construction (B.rows).
std::size_t nDim () const noexcept
 Column count captured at construction (B.cols).
const T * debugBpData () const noexcept
 Debug accessor exposing the packed B pointer so tests can pin alignment.
std::size_t debugScratchSize () const noexcept
 Debug accessor exposing the scratch capacity so tests can pin the sizing formula.
 GemmPlan (const GemmPlan &)=delete
GemmPlanoperator= (const GemmPlan &)=delete
 GemmPlan (GemmPlan &&) noexcept=default
 Defaulted move constructor; transfers the packed B panel and scratch.
GemmPlanoperator= (GemmPlan &&) noexcept=default
 Defaulted move assignment; transfers the packed B panel and scratch.
 ~GemmPlan ()=default

Detailed Description

template<class T, class Backend = detail::ReferenceGemm>
class clustering::math::GemmPlan< T, Backend >

Reusable GEMM plan: packs B once at construction, amortizes the packing cost across repeated execute calls with varying A.

Ownership model:

  • m_Bp holds a packB-shaped copy of B covering every (jcIdx, pcIdx) block; the source B may be destroyed after construction.
  • m_scratch holds per-worker A-packing arenas sized workerCount * kMc * kKc.
  • m_pool is captured by value at construction. execute uses it unchanged.

Concurrency: execute is const with respect to the plan's observable shape but mutates m_scratch via pointer aliasing into the per-worker slice. Two concurrent execute calls on the same plan alias the same scratch; callers that pipeline across application threads construct one plan per thread.

Lifetime: move-only. m_Bp and m_scratch are std::vector; move is noexcept.

Template Parameters
TElement type (float or double).
BackendBackend tag; defaulted to detail::ReferenceGemm. GemmPlan does NOT route through the backend – it calls gemmRunPrepacked directly with its owned m_Bp. The template parameter exists so GemmPlan is selected at the same <T, Backend> call site as the one-shot gemm entry.

Definition at line 40 of file gemm_plan.h.

Constructor & Destructor Documentation

◆ GemmPlan() [1/3]

template<class T, class Backend = detail::ReferenceGemm>
template<Layout LB>
clustering::math::GemmPlan< T, Backend >::GemmPlan ( const NDArray< T, 2, LB > & B,
Pool pool )
inline

Construct the plan and fully pre-pack B into m_Bp.

Template Parameters
LBLayout tag of B (Contig or MaybeStrided).
Parameters
BSource matrix (K x N); contents are copied into m_Bp, the source may outlive the plan or vice versa without coupling.
poolPool captured by value for use by execute; pool.workerCount() determines m_scratch size and is fixed for the plan's lifetime.

Definition at line 55 of file gemm_plan.h.

◆ GemmPlan() [2/3]

template<class T, class Backend = detail::ReferenceGemm>
clustering::math::GemmPlan< T, Backend >::GemmPlan ( const GemmPlan< T, Backend > & )
delete

◆ GemmPlan() [3/3]

template<class T, class Backend = detail::ReferenceGemm>
clustering::math::GemmPlan< T, Backend >::GemmPlan ( GemmPlan< T, Backend > && )
defaultnoexcept

Defaulted move constructor; transfers the packed B panel and scratch.

◆ ~GemmPlan()

template<class T, class Backend = detail::ReferenceGemm>
clustering::math::GemmPlan< T, Backend >::~GemmPlan ( )
default

Member Function Documentation

◆ debugBpData()

template<class T, class Backend = detail::ReferenceGemm>
const T * clustering::math::GemmPlan< T, Backend >::debugBpData ( ) const
inlinenodiscardnoexcept

Debug accessor exposing the packed B pointer so tests can pin alignment.

Not part of the stable API.

Definition at line 131 of file gemm_plan.h.

◆ debugScratchSize()

template<class T, class Backend = detail::ReferenceGemm>
std::size_t clustering::math::GemmPlan< T, Backend >::debugScratchSize ( ) const
inlinenodiscardnoexcept

Debug accessor exposing the scratch capacity so tests can pin the sizing formula.

Not part of the stable API.

Definition at line 135 of file gemm_plan.h.

◆ execute()

template<class T, class Backend = detail::ReferenceGemm>
template<Layout LA>
void clustering::math::GemmPlan< T, Backend >::execute ( const NDArray< T, 2, LA > & A,
NDArray< T, 2 > & C,
T alpha = T{1},
T beta = T{0} ) const
inlinenoexcept

Execute the plan: compute C := alpha * A * B + beta * C against the pre-packed B captured at construction.

Template Parameters
LALayout tag of A.
Parameters
AInput matrix (M x kDim()).
COutput matrix (M x nDim()); must be mutable.
alphaScalar multiplier on A*B; defaults to 1.
betaScalar multiplier on the prior C; defaults to 0.

Definition at line 109 of file gemm_plan.h.

◆ kDim()

template<class T, class Backend = detail::ReferenceGemm>
std::size_t clustering::math::GemmPlan< T, Backend >::kDim ( ) const
inlinenodiscardnoexcept

Inner dimension captured at construction (B.rows).

Definition at line 124 of file gemm_plan.h.

◆ nDim()

template<class T, class Backend = detail::ReferenceGemm>
std::size_t clustering::math::GemmPlan< T, Backend >::nDim ( ) const
inlinenodiscardnoexcept

Column count captured at construction (B.cols).

Definition at line 127 of file gemm_plan.h.

◆ operator=() [1/2]

template<class T, class Backend = detail::ReferenceGemm>
GemmPlan & clustering::math::GemmPlan< T, Backend >::operator= ( const GemmPlan< T, Backend > & )
delete

◆ operator=() [2/2]

template<class T, class Backend = detail::ReferenceGemm>
GemmPlan & clustering::math::GemmPlan< T, Backend >::operator= ( GemmPlan< T, Backend > && )
defaultnoexcept

Defaulted move assignment; transfers the packed B panel and scratch.


The documentation for this class was generated from the following file: