MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::interface Namespace Reference

Namespaces

namespace  detail
namespace  kernel
 The kernels that take their width from interleave_rows.

Classes

struct  blas_triangular_call
 The BLAS ?trsm / ?trmm description of the left-side problem A X = B (or B := A B) on dense buffers that may be row-major (#724). More...
struct  interleave_rows
 How many rows Kernel interleaves for accumulator type T. More...
struct  interleave_choice
 A table entry: width[type][kernel], type 0 = double and 1 = float, kernel 0 = gemv, 1 = trmv and 2 = the forward substitution. More...

Concepts

concept  BlasDenseMatrix
 Concept satisfied by dense matrix types eligible for BLAS/LAPACK dispatch.
concept  BlasHermitianMatrix
 Concept satisfied by dense matrix types eligible for complex-Hermitian LAPACK dispatch (cheev/zheev).
concept  ContiguousVector
 True when a vector type's storage is CONTIGUOUS – data()[i] IS element i.
concept  BlasDenseVector
 Concept satisfied by dense vector types eligible for BLAS dispatch.
concept  SimdDenseVector
 Concept satisfied by dense vector types eligible for MTL5's OWN SIMD kernels.
concept  SimdNarrowVector
 Concept satisfied by dense vector types whose element type is not a lane but can be WIDENED into one by a dot-product accumulate – 16-bit integers, as of #451 phase 2.
concept  SimdQuadVector
 Concept satisfied by dense vector types of an 8-bit element that the quad multiply-accumulate can widen into a 32-bit lane (#451 phase 3).
concept  ContiguousMatrixData
 Storage shape only: contiguous data() plus dimensions, with NO constraint on the element type.
concept  SimdDenseMatrix
 Concept satisfied by dense matrix types eligible for MTL5's own SIMD kernels – BlasDenseMatrix widened to every mtl::simd lane type, for the same reason as SimdDenseVector.
concept  ThreadableDenseMatrix
 Concept satisfied by dense matrix types whose OUTPUT ROWS may be partitioned across threads: the storage shape only, with NO constraint on the element type.
concept  ThreadableDenseVector
 Concept satisfied by dense vector types usable as an operand or an output of a row-partitioned kernel.

Typedefs

template<typename M>
using memory_space_t = ::mtl::detail::memory_space_of_t<std::remove_cvref_t<M>>
 The memory space of a container type: M::memory_space where M names one, otherwise memory_space::host, as for expressions, views and user types, which all address host memory.
template<typename M>
using runtime_of_t = ::mtl::detail::runtime_of_space_t<memory_space_t<M>>
 The device runtime M's elements belong to (#1017): R for a container in memory_space::device<R>, shared<R> or pinned<R>; runtime::none for host memory, expressions, views and user types.

Enumerations

enum class  interleave_cpu : unsigned char {
  unknown , alder_lake , ivy_bridge , zen4 ,
  cortex_a78ae , cortex_a78c
}
 The cores the table knows. More...

Functions

template<typename T>
constexpr std::size_t row_grain (std::size_t units_per_row)
 Grain (in output rows) for a kernel that partitions over rows, given the work each row costs in iteration units – num_cols() for a GEMV, N*K for a GEMM.
template<typename MA, typename MB>
blas_triangular_call blas_triangular_describe (bool upper, std::size_t m, std::size_t n)
template<typename M>
constexpr char blas_lower_uplo ()
 For a symmetric operand whose LOWER triangle holds the data: the uplo that names that triangle in the column-major view of its buffer.
template<typename T, typename Kernel>
consteval std::size_t measured_interleave_rows ()
 The measured float/double width for Kernel on this target, before the register cap (see the top of this file).
constexpr std::size_t interleave_cap (std::size_t measured, std::size_t registers)
 A measured width capped at half of registers vector registers: the other half holds the batches of A and x.
template<typename T, typename Kernel>
consteval std::size_t default_interleave_rows ()
 The default width for T and Kernel, before any override (see the top of this file).
template<typename T, typename Kernel>
consteval std::size_t configured_interleave_rows ()
 The width with the -D overrides applied.
template<typename T, typename Kernel>
consteval bool interleave_rows_at_runtime ()
 Whether Kernel picks its width for T at run time (#778): only with MTL5_INTERLEAVE_RUNTIME, on x86-64 or AArch64, for float and double, and only where neither a -D override nor a specialization fixed the width.
template<typename T, typename Kernel>
std::size_t selected_interleave_rows () noexcept
 The width Kernel uses for T in this process: the run-time choice where there is one, else interleave_rows_v.
template<typename T, typename Kernel, typename F>
decltype(auto) with_interleave_rows (F &&f)
 Call f(std::integral_constant<std::size_t, W>{}) with the width Kernel uses for T: interleave_rows_v, or with run-time selection, the width chosen for this CPU, dispatched over runtime_interleave_widths.
constexpr bool is_runtime_interleave_width (std::size_t w) noexcept
 Whether w is one of runtime_interleave_widths.
constexpr const char * to_string (interleave_cpu c) noexcept
constexpr interleave_choice interleave_table (interleave_cpu cpu) noexcept
 The measured widths for cpu under this compiler and build (see the top of this file).
interleave_cpu detect_interleave_cpu () noexcept
 The core this thread's CPU is, as far as the table goes.
interleave_cpu runtime_interleave_cpu () noexcept
 The core detected on first use, cached.
void force_interleave_rows (std::size_t w)
 Make every run-time-selected kernel use width w; 0 goes back to the table.
std::size_t runtime_interleave_width (int type, int kernel) noexcept
 The width run-time selection picks for type (0 = double, 1 = float) and kernel (0 = gemv, 1 = trmv, 2 = the forward substitution): the forced one, else the table's, else 0 for the compile-time default.
constexpr const char * blas_vendor () noexcept
 The BLAS/LAPACK vendor CMake detected: "mkl", "blis", "openblas" or "".
constexpr bool blas_capped_in_region () noexcept
 Whether a vendor call made inside an MTL5 region runs on one thread.
int blas_vendor_threads () noexcept
 The number of threads the detected vendor would use for a call made on this thread now; 0 when no vendor was detected.

Variables

template<typename T>
constexpr bool is_blas_scalar_v
 True for scalar types supported by standard BLAS/LAPACK (float, double).
template<typename T>
constexpr bool is_lapack_complex_v = false
 True for complex scalar types backed by LAPACK (complex<float>, complex<double>).
template<typename T>
constexpr bool is_lapack_complex_v< std::complex< T > > = is_blas_scalar_v<T>
template<typename Accumulator>
constexpr bool accumulator_allows_blas_v = std::is_void_v<Accumulator>
 Whether the requested accumulator policy permits a hardware-fixed BLAS / native-fast path.
template<typename M>
constexpr bool host_resident_v = memory_space_t<M>::host_accessible
 Whether host code, and so every dispatch target in this header, may read M's elements.
template<typename M, typename Space>
constexpr bool in_memory_space_v = std::is_same_v<memory_space_t<M>, Space>
 Whether M's elements live in memory space Space.
template<typename M, typename... Ms>
constexpr bool same_runtime_v
 Whether every operand belongs to one device runtime (#1017).
template<typename R, typename T>
constexpr bool runtime_supports_v
 Whether runtime R's devices can compute in T (#1017): false for double on a device without FP64.
template<typename T>
constexpr std::size_t parallel_chunk_units
 Iteration units that make one parallel chunk worth dispatching, for element type T.
template<typename M>
constexpr bool is_row_major_v
 Check if a matrix type uses row-major orientation.
template<typename M>
constexpr bool is_compressed2D_v = false
 Check if a matrix type is a sparse compressed2D (for sparse solver dispatch).
template<typename Value, typename Params>
constexpr bool is_compressed2D_v< mat::compressed2D< Value, Params > > = true
template<typename M>
constexpr bool is_suitesparse_eligible_v
 True for sparse matrices with BLAS-compatible scalar types (float/double).
template<typename V>
constexpr bool is_dense_vector_double_v = false
 True for vec::dense_vector<double, P>, the only vector type the SuiteSparse bindings (umfpack_solve, cholmod_solve, spqr_solve) take.
template<typename Params>
constexpr bool is_dense_vector_double_v< vec::dense_vector< double, Params > > = true
template<typename M, typename VecX, typename VecB>
constexpr bool suitesparse_solve_dispatches_v
 True when the sparse solve dispatch can call a SuiteSparse binding: compressed2D<double> with dense_vector<double> x and b.
constexpr std::size_t vector_registers
 The vector registers on the target, from the compiler's ISA macros: one floating-point accumulator occupies one, scalar or not.
template<typename T, typename Kernel>
constexpr std::size_t interleave_rows_v
template<typename T, typename Kernel>
constexpr bool interleave_rows_at_runtime_v = interleave_rows_at_runtime<T, Kernel>()
constexpr std::size_t runtime_interleave_widths [] = {2, 4, 6, 8, 12}
 The widths run-time selection compiles each kernel at.

Typedef Documentation

◆ memory_space_t

template<typename M>
using mtl::interface::memory_space_t = ::mtl::detail::memory_space_of_t<std::remove_cvref_t<M>>

The memory space of a container type: M::memory_space where M names one, otherwise memory_space::host, as for expressions, views and user types, which all address host memory.

◆ runtime_of_t

The device runtime M's elements belong to (#1017): R for a container in memory_space::device<R>, shared<R> or pinned<R>; runtime::none for host memory, expressions, views and user types.

Enumeration Type Documentation

◆ interleave_cpu

enum class mtl::interface::interleave_cpu : unsigned char
strong

The cores the table knows.

Enumerator
unknown 
alder_lake 

Intel family 6, model 0x97/0x9A: Golden Cove P-cores (i7-12700K).

ivy_bridge 

Intel family 6, model 0x3A/0x3E (Xeon E5-2420 v2).

zen4 

AMD family 0x19, model 0x60-0x7F: client Zen 4 (Ryzen 7 8845HS, Ryzen 9 8945HS).

cortex_a78ae 

Arm part 0xd42 (Jetson Orin).

cortex_a78c 

Arm part 0xd4b (Arduino Ventuno Q).

Function Documentation

◆ blas_capped_in_region()

bool mtl::interface::blas_capped_in_region ( )
constexprnoexcept

Whether a vendor call made inside an MTL5 region runs on one thread.

◆ blas_lower_uplo()

template<typename M>
char mtl::interface::blas_lower_uplo ( )
constexpr

For a symmetric operand whose LOWER triangle holds the data: the uplo that names that triangle in the column-major view of its buffer.

A row-major buffer is the transpose, whose upper triangle is the matrix's lower one.

◆ blas_triangular_describe()

template<typename MA, typename MB>
blas_triangular_call mtl::interface::blas_triangular_describe ( bool upper,
std::size_t m,
std::size_t n )

◆ blas_vendor()

const char * mtl::interface::blas_vendor ( )
constexprnoexcept

The BLAS/LAPACK vendor CMake detected: "mkl", "blis", "openblas" or "".

◆ blas_vendor_threads()

int mtl::interface::blas_vendor_threads ( )
inlinenoexcept

The number of threads the detected vendor would use for a call made on this thread now; 0 when no vendor was detected.

◆ configured_interleave_rows()

template<typename T, typename Kernel>
std::size_t mtl::interface::configured_interleave_rows ( )
consteval

The width with the -D overrides applied.

◆ default_interleave_rows()

template<typename T, typename Kernel>
std::size_t mtl::interface::default_interleave_rows ( )
consteval

The default width for T and Kernel, before any override (see the top of this file).

◆ detect_interleave_cpu()

interleave_cpu mtl::interface::detect_interleave_cpu ( )
inlinenoexcept

The core this thread's CPU is, as far as the table goes.

◆ force_interleave_rows()

void mtl::interface::force_interleave_rows ( std::size_t w)
inline

Make every run-time-selected kernel use width w; 0 goes back to the table.

◆ interleave_cap()

std::size_t mtl::interface::interleave_cap ( std::size_t measured,
std::size_t registers )
constexpr

A measured width capped at half of registers vector registers: the other half holds the batches of A and x.

A function of the register count, so the rule can be tested for every target on any one (#840).

◆ interleave_rows_at_runtime()

template<typename T, typename Kernel>
bool mtl::interface::interleave_rows_at_runtime ( )
consteval

Whether Kernel picks its width for T at run time (#778): only with MTL5_INTERLEAVE_RUNTIME, on x86-64 or AArch64, for float and double, and only where neither a -D override nor a specialization fixed the width.

◆ interleave_table()

interleave_choice mtl::interface::interleave_table ( interleave_cpu cpu)
constexprnoexcept

The measured widths for cpu under this compiler and build (see the top of this file).

All zero where nothing was measured.

◆ is_runtime_interleave_width()

bool mtl::interface::is_runtime_interleave_width ( std::size_t w)
constexprnoexcept

Whether w is one of runtime_interleave_widths.

◆ measured_interleave_rows()

template<typename T, typename Kernel>
std::size_t mtl::interface::measured_interleave_rows ( )
consteval

The measured float/double width for Kernel on this target, before the register cap (see the top of this file).

◆ row_grain()

template<typename T>
std::size_t mtl::interface::row_grain ( std::size_t units_per_row)
inlineconstexpr

Grain (in output rows) for a kernel that partitions over rows, given the work each row costs in iteration units – num_cols() for a GEMV, N*K for a GEMM.

At least 1, and 1 for a zero-width row (nothing to balance).

◆ runtime_interleave_cpu()

interleave_cpu mtl::interface::runtime_interleave_cpu ( )
inlinenoexcept

The core detected on first use, cached.

◆ runtime_interleave_width()

std::size_t mtl::interface::runtime_interleave_width ( int type,
int kernel )
inlinenoexcept

The width run-time selection picks for type (0 = double, 1 = float) and kernel (0 = gemv, 1 = trmv, 2 = the forward substitution): the forced one, else the table's, else 0 for the compile-time default.

◆ selected_interleave_rows()

template<typename T, typename Kernel>
std::size_t mtl::interface::selected_interleave_rows ( )
noexcept

The width Kernel uses for T in this process: the run-time choice where there is one, else interleave_rows_v.

◆ to_string()

const char * mtl::interface::to_string ( interleave_cpu c)
constexprnoexcept

◆ with_interleave_rows()

template<typename T, typename Kernel, typename F>
decltype(auto) mtl::interface::with_interleave_rows ( F && f)

Call f(std::integral_constant<std::size_t, W>{}) with the width Kernel uses for T: interleave_rows_v, or with run-time selection, the width chosen for this CPU, dispatched over runtime_interleave_widths.

Variable Documentation

◆ accumulator_allows_blas_v

template<typename Accumulator>
bool mtl::interface::accumulator_allows_blas_v = std::is_void_v<Accumulator>
inlineconstexpr

Whether the requested accumulator policy permits a hardware-fixed BLAS / native-fast path.

External BLAS/LAPACK (and the blocked native GEMM) accumulate inner products in a fixed precision and cannot honor a caller-selected accumulator or result type, so ANY non-default accumulator (Accumulator != void) MUST fall to the native (generic) kernel – even for float/double operands (e.g. a double accumulator over float storage). The default void selects today's accelerated dispatch. Operations gate their BLAS path on this predicate.

◆ host_resident_v

template<typename M>
bool mtl::interface::host_resident_v = memory_space_t<M>::host_accessible
inlineconstexpr

Whether host code, and so every dispatch target in this header, may read M's elements.

◆ in_memory_space_v

template<typename M, typename Space>
bool mtl::interface::in_memory_space_v = std::is_same_v<memory_space_t<M>, Space>
inlineconstexpr

Whether M's elements live in memory space Space.

◆ interleave_rows_at_runtime_v

template<typename T, typename Kernel>
bool mtl::interface::interleave_rows_at_runtime_v = interleave_rows_at_runtime<T, Kernel>()
inlineconstexpr

◆ interleave_rows_v

template<typename T, typename Kernel>
std::size_t mtl::interface::interleave_rows_v
inlineconstexpr
Initial value:
= [] {
constexpr std::size_t w = interleave_rows<std::remove_cvref_t<T>, Kernel>::value;
static_assert(w >= 1 && w <= 64, "interleave_rows must be between 1 and 64");
return w;
}()
How many rows Kernel interleaves for accumulator type T.
Definition interleave_rows.hpp:154

◆ is_blas_scalar_v

template<typename T>
bool mtl::interface::is_blas_scalar_v
inlineconstexpr
Initial value:
=
std::is_same_v<T, float> || std::is_same_v<T, double>

True for scalar types supported by standard BLAS/LAPACK (float, double).

◆ is_compressed2D_v

template<typename M>
bool mtl::interface::is_compressed2D_v = false
inlineconstexpr

Check if a matrix type is a sparse compressed2D (for sparse solver dispatch).

◆ is_compressed2D_v< mat::compressed2D< Value, Params > >

template<typename Value, typename Params>
bool mtl::interface::is_compressed2D_v< mat::compressed2D< Value, Params > > = true
inlineconstexpr

◆ is_dense_vector_double_v

template<typename V>
bool mtl::interface::is_dense_vector_double_v = false
inlineconstexpr

True for vec::dense_vector<double, P>, the only vector type the SuiteSparse bindings (umfpack_solve, cholmod_solve, spqr_solve) take.

◆ is_dense_vector_double_v< vec::dense_vector< double, Params > >

template<typename Params>
bool mtl::interface::is_dense_vector_double_v< vec::dense_vector< double, Params > > = true
inlineconstexpr

◆ is_lapack_complex_v

template<typename T>
bool mtl::interface::is_lapack_complex_v = false
inlineconstexpr

True for complex scalar types backed by LAPACK (complex<float>, complex<double>).

These route Hermitian eigensolves to cheev/zheev.

◆ is_lapack_complex_v< std::complex< T > >

template<typename T>
bool mtl::interface::is_lapack_complex_v< std::complex< T > > = is_blas_scalar_v<T>
inlineconstexpr

◆ is_row_major_v

template<typename M>
bool mtl::interface::is_row_major_v
inlineconstexpr
Initial value:
=
std::is_same_v<typename M::orientation, tag::row_major>

Check if a matrix type uses row-major orientation.

◆ is_suitesparse_eligible_v

template<typename M>
bool mtl::interface::is_suitesparse_eligible_v
inlineconstexpr
Initial value:
=
constexpr bool is_compressed2D_v
Check if a matrix type is a sparse compressed2D (for sparse solver dispatch).
Definition dispatch_traits.hpp:353
constexpr bool is_blas_scalar_v
True for scalar types supported by standard BLAS/LAPACK (float, double).
Definition dispatch_traits.hpp:19

True for sparse matrices with BLAS-compatible scalar types (float/double).

These can be dispatched to SuiteSparse external solvers.

◆ parallel_chunk_units

template<typename T>
std::size_t mtl::interface::parallel_chunk_units
inlineconstexpr
Initial value:
=
std::is_arithmetic_v<T> ? std::size_t{65536} : std::size_t{1024}

Iteration units that make one parallel chunk worth dispatching, for element type T.

A chunk must hold enough work to amortize the pool's condition-variable handoff, and "enough" is a WALL-CLOCK quantity, so counting operations only works if you know what an operation costs. 65536 is the budget the native paths have always used, and it is right for a type whose multiply-add is one instruction.

A class-type scalar is not that type. Its multiply-add is at minimum a non-inlined call, and for the software-emulated formats this predicate exists to serve it measures 100x-6000x a double flop (#446). Charging them the same 65536 units per chunk asks for hundreds of times more wall-clock per chunk than the handoff needs, and the cost is paid in PARALLELISM, not overhead: parallel_for caps the team at n / grain chunks, so a posit GEMM at n=64 (4096 units per output row -> grain 16) would form 4 chunks and leave half of an 8-way pool idle on a problem that already takes a second. 1024 units keeps the chunk far above the handoff cost for any emulated format while letting the small-n case fill the pool.

std::is_arithmetic_v is the split because it is exactly the line between "the hardware does this" and "software does this". std::complex<double> is class-typed and lands on the smaller budget – a few times too small rather than orders of magnitude too large, which is the safe side to miss on.

◆ runtime_interleave_widths

std::size_t mtl::interface::runtime_interleave_widths[] = {2, 4, 6, 8, 12}
inlineconstexpr

The widths run-time selection compiles each kernel at.

◆ runtime_supports_v

template<typename R, typename T>
bool mtl::interface::runtime_supports_v
inlineconstexpr
Initial value:
= [] {
if constexpr (::mtl::DeviceRuntime<R>) return static_cast<bool>(R::template supports<T>);
else return false;
}()

Whether runtime R's devices can compute in T (#1017): false for double on a device without FP64.

False for runtime::none, which has no devices.

◆ same_runtime_v

template<typename M, typename... Ms>
bool mtl::interface::same_runtime_v
inlineconstexpr
Initial value:
=
!std::is_same_v<runtime_of_t<M>, ::mtl::runtime::none>
&& (std::is_same_v<runtime_of_t<M>, runtime_of_t<Ms>> && ...)
::mtl::detail::runtime_of_space_t< memory_space_t< M > > runtime_of_t
The device runtime M's elements belong to (#1017): R for a container in memory_space::device<R>,...
Definition dispatch_traits.hpp:70
No device runtime: host memory, and runtime::preferred in a build that enables no accelerator.
Definition runtime.hpp:24

Whether every operand belongs to one device runtime (#1017).

Host operands (runtime::none) do not count as a runtime: a device backend's concept requires this, and device accessibility, so an operand of one runtime never reaches another runtime's library.

◆ suitesparse_solve_dispatches_v

template<typename M, typename VecX, typename VecB>
bool mtl::interface::suitesparse_solve_dispatches_v
inlineconstexpr
Initial value:
=
&& std::is_same_v<typename std::remove_cvref_t<M>::value_type, double>
constexpr bool host_resident_v
Whether host code, and so every dispatch target in this header, may read M's elements.
Definition dispatch_traits.hpp:60
constexpr bool is_dense_vector_double_v
True for vec::dense_vector<double, P>, the only vector type the SuiteSparse bindings (umfpack_solve,...
Definition dispatch_traits.hpp:367

True when the sparse solve dispatch can call a SuiteSparse binding: compressed2D<double> with dense_vector<double> x and b.

Every other operand (float, or another vector type) takes the native sparse solver (#850); the bindings take only double.

◆ vector_registers

std::size_t mtl::interface::vector_registers
inlineconstexpr
Initial value:
=
8

The vector registers on the target, from the compiler's ISA macros: one floating-point accumulator occupies one, scalar or not.

Unknown targets get the 32-bit x86 count, which keeps the default at its pre-#772 width of 4.