|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
Customization point for a scheme's fused mat-vec kernel. More...
#include <block_matrix_view.hpp>
Customization point for a scheme's fused mat-vec kernel.
The primary template is empty, and then mult() decodes row by row. A scheme that has a faster route (integer dots on the encoded blocks, say, with simd::reduce_dot_block_scaled) specializes it:
template <> struct mtl::block_kernels<my_scheme> {
// y = A x. `scratch` holds at least scratch_bytes(A.num_cols())
// bytes, aligned to scratch_alignment.
static void gemv(const mtl::mat::block_matrix_view<my_scheme>& A,
const float* x, float* y, std::span<std::byte> scratch);
// Optional: working memory per call (default 0) and its alignment
// (default alignof(std::max_align_t), a power of two).
static std::size_t scratch_bytes(std::size_t cols);
static constexpr std::size_t scratch_alignment = 64;
};
The scratch is for what a fused kernel builds from x before it touches A, typically x quantized per block to the integer format the dots consume. It is the caller's memory, not the kernel's: mult(A, x, y, scratch) passes it through, so a runtime that sizes its buffers up front never allocates in the mat-vec. mult(A, x, y) allocates it for the one call.
mult() calls the kernel for float input and output vectors with contiguous storage and no explicit Accumulator. The kernel owns its accuracy contract. The decode-then-dot path stays the reference it is measured against.