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

mat*vec multiply into pre-allocated y: y = A * x. More...

Namespaces

namespace  magnitude_adl
namespace  expm_impl
namespace  expm_multiply_impl
namespace  frechet_impl
namespace  logm_impl
namespace  normest1_impl
namespace  norms_adl
 The default two_norm and frobenius_norm sum the squares unscaled, which overflows for elements above about sqrt(max) and loses everything below about sqrt(min) (#690).
namespace  sqrtm_impl
namespace  classify_adl

Classes

class  aligned_allocator
 C++ Allocator that hands out Align-byte-aligned storage. More...
struct  complex_qr_options
class  contiguous_memory_block
 Contiguous memory block with compile-time stack/heap selection. More...
struct  lanv2_constants
 Constants for lanv2(): the relative precision and the power-of-two scale window of LAPACK's dlanv2. More...
struct  francis_options
 Options for francis_qr(). More...
struct  gemm_grid
 The threaded nest's shape decision: the ic block size and the ic x jc thread grid. More...
struct  batch_tile
 The jc block size this nest will step by, under model (#479's harness arm). More...
struct  vla_tile
struct  gemm_plan
 Everything the threaded nest decides for one call: the ic step it will actually use, the block counts that follow, and the thread grid. More...
class  gemm_barrier
 Reusable sense-reversing barrier for a fixed party count. More...
struct  c_index
 0-based index (C/C++ convention) – default More...
struct  f_index
 1-based index (Fortran convention). More...
struct  nc_model_inputs
 Everything a model needs. More...
struct  alias_target
 The storage an assignment writes: the target object and its elements' bytes. More...
struct  alias_elementwise_binary
struct  alias_elementwise_binary<::mtl::mat::expr::mat_mat_op_expr< E1, E2, SF > >
struct  alias_elementwise_unary
struct  alias_elementwise_unary<::mtl::mat::expr::mat_negate_expr< E > >
struct  alias_elementwise_unary<::mtl::mat::expr::mat_scal_op_expr< S, M, SF > >
struct  alias_elementwise_unary<::mtl::mat::expr::mat_rscal_op_expr< M, S, SF > >
struct  alias_product
struct  alias_product<::mtl::mat::expr::mat_mat_times_expr< E1, E2 > >
struct  rebind_space
 Parameters with their memory space replaced by Space, for copy_to. More...
struct  rebind_space< vec::parameters< O, D, St, Sz, Sp >, Space >
struct  rebind_space< mat::parameters< O, I, D, St, Sz, Sp >, Space >
struct  runtime_device_handle
 The handle a runtime names memory of one kind by: its device_handle<T>, shared_handle<T> (DeviceRuntime, optional), or T* when it declares none. More...
struct  runtime_device_handle< R, T >
struct  runtime_shared_handle
struct  runtime_shared_handle< R, T >
struct  space_handle
 The handle space S names T storage by: S::handle_type<T>, or T* for a space that declares none (#1017). More...
struct  space_handle< S, T >
struct  handle_traits
 How space S names T storage, with one interface for pointers and for the handles that are not (#1017, following std::mdspan's accessor policy): handle_type S::handle_type<T>, or T* const_handle_type const T* for a pointer; the handle itself otherwise (as for mdspan, constness is the accessor's business) is_pointer whether handle_type is T* offset(h, i) the handle of element i: h + i, or S::offset(h, i) address(h) the host address of the first element, in a host-accessible space: h, or S::address(h) same(a, b) whether two handles name the same storage, where that can be told: equal pointers, or equal handles of a type with ==; false for a handle without == is_null(h) whether h names no storage (nullptr, or a value-initialized handle of a type with ==). More...
struct  memory_space_of
 The memory space a type names (T::memory_space), or memory_space::host for a type that names none: a parameter bundle written before #223, an expression, a view or a user type, all of which address host memory. More...
struct  memory_space_of< T >
struct  runtime_of_space
 The runtime a memory space belongs to: S::runtime for a device memory kind, runtime::none for host memory and for a space that names no runtime. More...
struct  runtime_of_space< S >
class  space_allocator
struct  space_vector_impl
struct  space_vector_impl< T, ::mtl::memory_space::host >
struct  gemmt_strided
 A dense operand as a base pointer and strides: X(i, j) == p[i*rs + j*cs]. More...
struct  kron_value
 kron's element type: the common type of the operands' value types, as in dot, axpy and the other mixed-type operations (#694). More...
struct  kron_value< TA, TB, std::void_t< std::common_type_t< TA, TB > > >
struct  bk_interchange
 One interchange of the factorization: rows r1 < r2, made at step k (so it applies to the L columns p < k in the one-row-order convention). More...
struct  sat_traits
 The integer types saturating_cast clamps: the integral types, and __int128 / unsigned __int128 where the compiler has them. More...
struct  sat_unsigned
struct  sylvester_limits
 The range limits of a Sylvester solve, from numeric_limits: More...

Concepts

concept  contiguous_storage
 A collection whose elements are laid out from a host address: dense vectors and matrices, strided references, and views over a caller's buffer.
concept  minor_array_storage
 A compressed matrix's index arrays (compressed2D's ref_minor() and ref_major()): a writable output over them would corrupt the indices the kernel is still reading.
concept  major_array_storage
concept  value_array_storage
 A sparse matrix whose values are one array (compressed2D's and ell_matrix's ref_data()).
concept  entry_array_storage
 A matrix whose entries are one array of (row, col, value) triplets (coordinate2D's ref_entries()).
concept  block_list_storage
 A matrix made of separately stored blocks (block_diagonal2D): its storage is every block's.
concept  encoded_byte_storage
 A matrix over encoded bytes (block_matrix_view's bytes()).
concept  view_of_storage
 A view over another collection (transposed_view, the triangular and banded views, ...): its storage is its base's.
concept  declares_scratch_bytes
concept  declares_scratch_alignment
concept  alias_view
concept  alias_contiguous_leaf
concept  alias_known_storage
 A leaf whose element storage for_each_storage_range can list.
concept  converts_to_double
 T has an explicit or implicit conversion to double.

Typedefs

template<typename T>
using expr_store_t
 Given the deduced forwarding-reference type T:
template<typename T>
using expr_raw_t = std::remove_cvref_t<T>
 Strip reference and cv to get the underlying type for member access.
template<typename T>
using packed_buffer = std::vector<T, aligned_allocator<T>>
 SIMD-aligned scratch buffer for packed panels (reused across the nest).
using thread_pool = mtl::parallel::thread_pool
template<typename T>
using wrap_op_t = std::common_type_t<std::make_unsigned_t<T>, unsigned int>
 The type the modular arithmetic is actually performed in: the unsigned counterpart of T, or unsigned int when that is narrower than int.
template<typename Storage, typename Space>
using rebound_storage_t
template<typename Params, typename Space>
using rebind_space_t = typename rebind_space<Params, Space>::type
template<typename S, typename T>
using space_handle_t = typename space_handle<S, T>::type
template<typename T>
using memory_space_of_t = typename memory_space_of<T>::type
template<typename S>
using runtime_of_space_t = typename runtime_of_space<S>::type
template<typename T, typename Space>
using space_vector = typename space_vector_impl<T, Space>::type
 A growable array in memory space Space: std::vector<T> for host memory.
template<typename MC>
using congruence_temp_t
 The intermediate T of a congruence: dense, C's element type and orientation.

Enumerations

enum class  memory_category { own , external , view }
 Ownership mode for heap-allocated memory. More...
enum class  francis_output { eigenvalues , schur_form }
 What francis_qr() computes. More...
enum class  gemm_kernel { widening , quad }
 Which micro-kernel the blocked nest drives. More...
enum class  nc_model {
  m0_default , m1_balanced , m2_detected , m3_per_team ,
  m4_per_sharer , m5_exact , m6_guarded , m7_sharer_gated
}
 Candidate models for sizing nc. See the file header for why each exists. More...

Functions

template<typename Acc, typename Value, bool Threadable, typename MapFn>
Acc accumulate (std::size_t n, std::size_t grain, MapFn &&map)
 Accumulate map(acc, begin, end) over [0, n) into a cleared Acc.
template<typename T>
T * allocate_aligned (std::size_t n)
 Allocate and value-initialize n elements of T on an over-aligned heap block (block_alignment<T>).
template<typename T>
void deallocate_aligned (T *p, std::size_t n) noexcept
 Destroy n elements and free a block from allocate_aligned. No-op on nullptr.
template<std::size_t C, typename T>
constexpr bool column_sweep_unrolled (std::size_t ld)
 Whether a sweep with C columns per pass over columns ld elements of T apart takes the unrolled path (strip_columns<C>) rather than sweep_columns<1>.
template<std::size_t C, typename Acc, typename T, typename XAt, typename Op>
void sweep_columns (Acc *acc, const T *a, std::size_t ld, std::size_t r0, std::size_t rr, std::size_t cb, std::size_t ce, const XAt &x_at, const Op &op)
 Columns [cb, ce) of the column-major a (leading dimension ld) into the strip's accumulators: acc[l] = op(acc[l], a[c * ld + r0 + l], x(c)) for l < rr and c ascending.
template<std::size_t R, typename Acc, typename T, typename XAt, typename Op>
MTL5_NO_LOOP_VECTORIZE void sweep_fixed_rows (Acc *acc, const T *a, std::size_t ld, std::size_t r0, std::size_t cb, std::size_t ce, const XAt &x_at, const Op &op)
 sweep_columns for a strip of exactly R rows, R known at compile time: the R accumulators are indexed only by a pack, so they stay in registers across all the columns, where the run-time strip loads and stores them every pass.
template<std::size_t C, typename Acc, typename T, typename XAt, typename Op>
void strip_columns (Acc *acc, const T *a, std::size_t ld, std::size_t r0, std::size_t rr, std::size_t cb, std::size_t ce, const XAt &x_at, const Op &op)
 Columns [cb, ce) into a strip of rr rows: sweep_fixed_rows for a short strip, sweep_columns<C> otherwise.
template<typename R>
R cabs1 (const std::complex< R > &z)
 |re z| + |im z|: LAPACK's CABS1, the cheap norm zlahqr's tests use.
template<typename R>
R cmod (const std::complex< R > &z)
 |z|, without overflow in the squares (dlapy2).
template<typename R>
R lapy3 (R x, R y, R z)
 sqrt(x^2 + y^2 + z^2) without overflow in the squares (dlapy3).
template<typename R>
std::complex< R > ladiv (const std::complex< R > &x, const std::complex< R > &y)
 x / y by Smith's algorithm, which divides by the larger of y's parts and so does not overflow in |y|^2 (zladiv).
template<typename R>
std::complex< R > csqrt (const std::complex< R > &z)
 The principal square root of z: the root with a non-negative real part.
template<typename R>
std::complex< R > larfg2 (std::complex< R > &alpha, std::complex< R > &x, const R &safmin)
 zlarfg for n = 2: the reflector G = I - tau [1; v] [1; v]^H with G^H [alpha; x] = [beta; 0], beta real.
template<typename R>
void complex_qr (mat::dense2D< std::complex< R > > &H, mat::dense2D< std::complex< R > > &Z, const complex_qr_options< R > &opt)
 zlahqr with wantt and wantz on the whole matrix: H upper Hessenberg on entry, upper triangular on return, and every transformation applied to Z from the right.
template<typename R>
complex_qr_options< R > make_complex_qr_options (std::size_t n, const char *who)
 The options for R: the deflation floor and larfg2's rescaling use R's numeric_limits minimum only when it is a safe minimum in LAPACK's sense, below the epsilon, which excludes fixed point (as schur() does for reals).
template<typename R>
int scale_to_unit_binade (mat::dense2D< std::complex< R > > &W)
 Scale W by a power of two so that its largest real or imaginary part is in [1/2, 1], as scale_to_unit_binade does for a real matrix; returns the exponent k of the factor 2^-k applied.
template<typename Body>
void parallel_ewise (std::size_t n, std::size_t work_per_elem, Body &&body)
 Run body(i) for every i in [0, n) across the pool, partitioned into contiguous chunks.
template<typename Body>
void parallel_ewise_2d (std::size_t rows, std::size_t cols, std::size_t work_per_elem, Body &&body)
 Run body(r, c) for every element of a rows x cols index space, in row-major order, across the pool.
template<typename E>
void throw_or_abort (E &&e)
 Throw e; with exceptions disabled, abort instead.
void contract_abort (const char *what) noexcept
 A broken contract on a path that cannot throw (a noexcept move): print the message and abort, in every build.
template<typename T>
lanv2_constants< T > make_lanv2_constants ()
template<typename T>
T lapy2 (T x, T y)
 sqrt(x^2 + y^2) without avoidable overflow or underflow.
template<typename T>
T with_sign_of (T a, T b)
 |a| with the sign of b, where b == 0 counts as positive.
template<typename T>
void lanv2 (T &a, T &b, T &c, T &d, T &rt1r, T &rt1i, T &rt2r, T &rt2i, T &cs, T &sn, const lanv2_constants< T > &k)
 The Schur factorization of a real 2x2 block in standard form,.
template<francis_output Output, typename T>
void francis_qr (mat::dense2D< T > &H, mat::dense2D< T > *Z, vec::dense_vector< T > &wr, vec::dense_vector< T > &wi, const francis_options< T > &opt)
 Francis implicit double-shift QR on the upper Hessenberg H (EISPACK hqr / hqr2).
template<typename T>
int scale_to_unit_binade (mat::dense2D< T > &W)
 Scales W by a power of two so max |w_ij| lies in [1/2, 1], and returns the exponent k that undoes it: W_in = W_out * 2^k (0 if W is zero or already in range).
constexpr std::size_t critical_panels (std::size_t m, std::size_t mc, unsigned ic_nt, std::size_t mr) noexcept
 Default GEMM thread count: the persistent pool's size (env MTL5_NUM_THREADS, clamped to hardware concurrency; 1 when unset/invalid).
std::size_t balanced_mc (std::size_t m, std::size_t mc_max, unsigned ic_nt, std::size_t mr=1)
 Choose the ic-block size for the threaded m-partition (#408, #458).
constexpr double grid_imbalance (std::size_t blocks, unsigned workers) noexcept
 How much of a round-robin partition's capacity the most-loaded worker wastes: ceil(blocks / workers) * workers / blocks, which is 1.0 exactly when the blocks divide evenly and grows as the remainder does.
constexpr std::size_t packed_b_bytes (unsigned jc_nt, std::size_t kc, std::size_t nc, std::size_t nr, std::size_t elem_bytes, std::size_t k_group=1) noexcept
 Bytes of packed B held simultaneously: one panel per jc-team, as the packer actually lays it out.
constexpr std::size_t c_strip_mc_cap (std::size_t l2_bytes, std::size_t kc, std::size_t n, std::size_t nc, std::size_t sdata, bool charge_a=true)
 The largest mc for which the packed A block AND the strip of C it accumulates both fit in L2.
constexpr gemm_grid plan_gemm_grid (std::size_t m, std::size_t n, std::size_t mc_cache, std::size_t nc, std::size_t mr, unsigned budget, std::size_t mc_extra_cap=0)
 Choose mc and the grid for an m x n problem on budget threads.
unsigned gemm_default_threads ()
template<typename TC, typename TA, typename TB, bool Quad, typename F>
decltype(auto) with_gemm_tile (F &&f)
 Run f(tile) with the tile the GEMM uses for (TC, TA, TB, Kern) on this machine: on a scalable target, for a same-type float or double GEMM, the vla_tile whose lane count the hardware has; otherwise batch_tile.
template<typename TC>
simd::blocking_params gemm_blocking ()
 The register tile and compile-time blocks a same-type TC GEMM runs with on this machine: simd::default_blocking<TC>, except on a scalable target, where it is the vla_tile's (#427).
template<typename TC>
const simd::blocking_params & gemm_runtime_blocking ()
 The detected-cache blocks of that tile: simd::runtime_blocking<TC>() except on a scalable target (#427).
template<typename TC, typename TB = TC, std::size_t KGroup = 1, typename Tile = batch_tile<TC>>
std::size_t nc_for_plan (std::size_t m, std::size_t n, unsigned budget, nc_model model)
template<typename TC, typename TB, std::size_t KGroup, typename Tile>
gemm_plan gemm_plan_for_tiled (std::size_t m, std::size_t n, unsigned nthreads, nc_model model)
 The plan gemm_blocked<TC> will follow for an m x n problem on nthreads.
template<typename TC, typename TB = TC, std::size_t KGroup = 1>
gemm_plan gemm_plan_for (std::size_t m, std::size_t n, unsigned nthreads, nc_model model=nc_model_selection())
 The plan gemm_blocked runs for a same-type GEMM (TC, operand type TB) on this machine: on a scalable target, the vla_tile the hardware's lane count selects (#427), so what is reported is what the nest steps.
template<typename TC, typename TA, typename TB, gemm_kernel Kern, typename Tile>
requires (mtl::Scalar<TC> && mtl::Scalar<TA> && mtl::Scalar<TB>)
void gemm_blocked_tiled (std::size_t m, std::size_t n, std::size_t k, TC alpha, const TA *A, std::ptrdiff_t a_rs, std::ptrdiff_t a_cs, const TB *B, std::ptrdiff_t b_rs, std::ptrdiff_t b_cs, TC beta, TC *C, std::size_t ldc, unsigned nthreads, nc_model model)
 C[m x n] (row-major, leading dim ldc) := beta*C + alpha * A[m x k] * B[k x n].
template<typename TC, typename TA = TC, typename TB = TA, gemm_kernel Kern = gemm_kernel::widening>
requires (mtl::Scalar<TC> && mtl::Scalar<TA> && mtl::Scalar<TB>)
void gemm_blocked (std::size_t m, std::size_t n, std::size_t k, TC alpha, const TA *A, std::ptrdiff_t a_rs, std::ptrdiff_t a_cs, const TB *B, std::ptrdiff_t b_rs, std::ptrdiff_t b_cs, TC beta, TC *C, std::size_t ldc, unsigned nthreads=1, nc_model model=nc_model_selection())
 The blocked GEMM, on the tile this machine runs (see gemm_blocked_tiled for the contract).
template<typename TC, typename TAB, std::size_t MR, std::size_t NR>
void gemm_microkernel (std::size_t kc, const TAB *Ap, const TAB *Bp, TC *C, std::size_t ldc)
constexpr std::size_t packed_A_size (std::size_t m, std::size_t k, std::size_t MR)
 Elements needed to pack an m x k A block into MR-row panels (rows padded to MR).
constexpr std::size_t packed_B_size (std::size_t k, std::size_t n, std::size_t NR)
 Elements needed to pack a k x n B block into NR-col panels (cols padded to NR).
template<typename T, std::size_t MR>
requires mtl::Scalar<T>
void pack_A (const T *A, std::ptrdiff_t rs, std::ptrdiff_t cs, std::size_t m, std::size_t k, T *Ap)
 Pack an m x k block of A into MR-row, column-major micro-panels.
template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void pack_B_panels (const T *B, std::ptrdiff_t rs, std::ptrdiff_t cs, std::size_t k, std::size_t n, T *Bp, std::size_t q0, std::size_t q1)
 Pack a k x n block of B into NR-col, row-major micro-panels.
template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void pack_B (const T *B, std::ptrdiff_t rs, std::ptrdiff_t cs, std::size_t k, std::size_t n, T *Bp)
template<typename TC, typename TA, typename TB>
constexpr bool is_quad_gemm ()
 Does the (accumulator, A operand, B operand) triple ADMIT the quad kernel?
template<typename TC, typename TA, typename TB, std::size_t MR, std::size_t NR>
void gemm_quad_microkernel (std::size_t kp, const TA *Ap, const TB *Bp, TC *C, std::size_t ldc, TC alpha)
 Accumulate an MR x NR tile of C from quad-interleaved packed panels:
constexpr std::size_t quad_depth (std::size_t k)
 k rounded up to a whole number of 4-value groups – the depth the quad layout actually stores, and the depth the micro-kernel steps.
constexpr std::size_t packed_A_quad_size (std::size_t m, std::size_t k, std::size_t MR)
 Elements needed to pack an m x k A block into quad-interleaved MR-row panels.
constexpr std::size_t packed_B_quad_size (std::size_t k, std::size_t n, std::size_t NR)
 Elements needed to pack a k x n B block into quad-interleaved NR-col panels.
template<bool Quad>
constexpr std::size_t packed_A_size_for (std::size_t m, std::size_t k, std::size_t MR)
 The A-panel size for whichever layout the (accumulator, operand) pair selects.
template<bool Quad>
constexpr std::size_t packed_B_size_for (std::size_t k, std::size_t n, std::size_t NR)
 The B-panel size for whichever layout the pair selects; see packed_A_size_for.
template<typename T, std::size_t MR>
requires mtl::Scalar<T>
void pack_A_quad (const T *A, std::ptrdiff_t rs, std::ptrdiff_t cs, std::size_t m, std::size_t k, T *Ap)
 Pack an m x k block of A into quad-interleaved MR-row micro-panels.
template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void pack_B_quad_panels (const T *B, std::ptrdiff_t rs, std::ptrdiff_t cs, std::size_t k, std::size_t n, T *Bp, std::size_t q0, std::size_t q1)
 Pack panels [q0, q1) of a k x n B block into quad-interleaved NR-col micro-panels, each written at the offset it would occupy in a whole pack:
template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void pack_B_quad (const T *B, std::ptrdiff_t rs, std::ptrdiff_t cs, std::size_t k, std::size_t n, T *Bp)
template<typename T>
requires mtl::Scalar<T>
void gemv_rowmajor (std::size_t m, std::size_t n, const T *A, std::size_t lda, const T *x, T *y)
 y[m] := A[m x n] * x[n], A row-major (rows contiguous, lda = n).
template<typename T>
requires mtl::Scalar<T>
void gemv_colmajor (std::size_t m, std::size_t n, const T *A, std::size_t lda, const T *x, T *y)
 y[m] := A[m x n] * x[n], A col-major (columns contiguous, lda = m).
template<typename T>
requires mtl::Scalar<T>
void gemv_panel (bool row_major, std::size_t ld, const T *A, std::size_t r0, std::size_t c0, std::size_t m, std::size_t k, const T *x, T *t)
 t[m] := A(r0 : r0+m, c0 : c0+k) * x[k] for a sub-panel of an n-column (row-major) or n-row (column-major) dense matrix at A: the off-diagonal panel of the blocked trmv and trsv (#747).
template<typename M>
void require_finite (const M &A, std::string_view who)
 Throws std::invalid_argument unless every entry of A is finite.
template<typename M>
void require_square (const M &A, std::string_view who)
 Throws std::invalid_argument unless A is square.
template<typename M>
void require_square_finite (const M &A, std::string_view who)
 Throws std::invalid_argument unless A is square and every entry finite.
std::size_t balanced_nc (std::size_t n, std::size_t nc_max, unsigned jc_nt, std::size_t nr=1)
 Choose the jc-block size that balances the threaded n-partition – the jc-side counterpart of balanced_mc (#479, feeding #429).
constexpr std::size_t nc_from_budget (std::size_t budget_bytes, std::size_t kc, std::size_t sdata, std::size_t nr) noexcept
 The capacity-only part: nc such that the packed B panel kc x nc fills the budget, rounded down to a whole number of nr-column panels.
std::size_t nc_for_model (nc_model model, const nc_model_inputs &in) noexcept
 nc under one model.
constexpr bool nc_guard_declines (std::size_t packed_b_new, std::size_t packed_b_old, std::size_t l3_bytes) noexcept
 M6's rule, as a named predicate: decline the balanced nc when it would BOTH grow the resident packed-B set AND push it past L3 (#429, measured in #479).
constexpr const char * nc_model_name (nc_model m) noexcept
 Short stable token for CSV columns and command lines.
nc_model nc_model_from_name (const char *s, bool &ok) noexcept
 Parse a model name; ok reports whether it was recognised.
nc_model nc_model_selection ()
 The model this process runs, from MTL5_NC_MODEL; M7 when unset (#492).
template<typename T>
constexpr bool pivot_unusable (const T &p)
 True when p is zero or NaN: not a pivot a factorization can divide by.
template<typename T, typename U>
constexpr bool same_object (const T &a, const U &b) noexcept
 True when a and b are the same object (#696).
template<typename T>
auto first_element_address (const T &t)
 The host address of a collection's first element: data() where that is the elements' address, and otherwise begin(), for a container in a host-accessible space whose handle is not an element pointer (#1017).
template<contiguous_storage T>
std::pair< const unsigned char *, const unsigned char * > storage_bytes (const T &t)
 The bytes from t's first element to its last.
template<typename A>
std::pair< const unsigned char *, const unsigned char * > array_bytes (const A &v)
 The bytes of a std::vector-like array's elements; empty when it is.
template<typename T, typename F>
void for_each_storage_range (const T &t, F &&f)
 Calls f(lo, hi) for each byte range a collection's elements live in, looking through views: a contiguous collection's elements; a compressed or ELL matrix's value array; a coordinate matrix's triplets; each block of a block-diagonal matrix; a block matrix view's encoded bytes; a view's base.
template<typename T, typename U>
bool storage_overlaps (const T &a, const U &b) noexcept
 Whether a and b may share storage (#840, #855): the same object, or element storage whose byte ranges overlap – a vector over part of another's buffer, as zero-copy views make easy; a vector over a sparse matrix's values or triplets, a block's elements or a block view's bytes; the matrix behind a transposed view.
template<typename M>
constexpr bool keep_scalar_row_major ()
 Whether M is a row-major matrix type.
template<bool Enable, typename T>
void keep_scalar (T &v)
 An empty asm that keeps v in a scalar register of its own, when Enable.
template<typename T>
constexpr magnitude_t< T > cabs1 (const T &z)
 LAPACK's CABS1: |Re z| + |Im z|.
template<typename Mag>
requires std::numeric_limits<Mag>::is_specialized
constexpr Mag structure_tol (std::size_t n, Mag scale)
 Threshold separating "this matrix has this structure" from "rounding noise", scaled by the size of the problem and the magnitude of the data.
template<typename T>
void transpose_copy (const T *in, std::size_t rows, std::size_t cols, T *out)
 out[c * rows + r] = in[r * cols + c] for every r < rows, c < cols: copies the row-major rows x cols array in into out as the column-major one, which is the same as writing in^T row-major.
template<typename Real>
requires std::numeric_limits<Real>::is_specialized
Real machine_epsilon ()
 The machine epsilon of Real: the spacing of Real's values at 1, from std::numeric_limits.
template<typename Real>
Real unit_roundoff ()
 The unit roundoff u of Real, the bound on the relative error of one rounding: fl(x) = x (1 + d), |d| <= u.
template<typename T>
MTL5_WRAPS_ON_PURPOSE constexpr T wrap_add (T a, T b) noexcept
template<typename T>
MTL5_WRAPS_ON_PURPOSE constexpr T wrap_sub (T a, T b) noexcept
template<typename T>
MTL5_WRAPS_ON_PURPOSE constexpr T wrap_mul (T a, T b) noexcept
template<typename Result, typename A, typename B>
constexpr Result generic_fma (Result acc, const A &a, const B &b)
 acc + a * b for the generic element-wise loops: wrapping when the result type is integral, the plain expression otherwise.
template<typename Result, typename A>
constexpr Result generic_add (Result acc, const A &a)
 acc + a for the generic element-wise loops: wrapping when the result type is integral, the plain expression otherwise (#461).
template<typename T>
constexpr auto generic_abs (const T &a)
 |a|, wrapping, for the norm accumulations (#461).
template<typename Result, typename A, typename B>
constexpr Result generic_mul (const A &a, const B &b)
 a * b delivered in Result: wrapping when Result is integral, the plain expression otherwise (#461).
template<typename S>
constexpr std::size_t block_scratch_alignment () noexcept
template<typename Accumulator, typename S, typename VIn, typename VOut>
void block_mult_rows (const mat::block_matrix_view< S > &A, const VIn &x, VOut &y, std::size_t rb, std::size_t re, std::vector< float > &buf)
 y[rb, re) = A x for a block matrix: decode one row into buf, then dot it with x.
template<typename Accumulator, typename S, typename VIn, typename VOut>
void block_mult_decode (const mat::block_matrix_view< S > &A, const VIn &x, VOut &y)
 y = A x by decode-then-dot, rows partitioned across the thread pool.
template<typename T>
bool alias_storage_overlaps (const T &m, const alias_target &t)
 Whether a known-storage leaf is the target or any of its storage overlaps the target's elements.
template<typename T>
bool alias_overlaps (const T &m, const alias_target &t)
 Whether the leaf's contiguous storage overlaps the target's.
template<typename E>
bool alias_reaches_target (const E &e, const alias_target &t)
 Whether evaluating e reads the target's storage at all.
template<typename E>
bool alias_reads_target_elsewhere (const E &e, const alias_target &t)
 Whether evaluating e element by element into the target can read an element of the target other than the one being written.
template<typename T, typename H>
auto transport_target (H h)
 A handle as a runtime's copy_bytes receives it: a T* as void*, any other handle as itself (#1017).
template<typename T, typename H>
auto transport_source (H h)
template<typename SrcSpace, typename DstSpace, typename T>
void copy_between_spaces (typename handle_traits< SrcSpace, T >::const_handle_type src, typename handle_traits< DstSpace, T >::handle_type dst, std::size_t n)
 Copy n elements of trivially copyable T between two memory spaces, through the runtime that owns the device side (see the header comment).
template<typename Ordering, typename M>
int cholesky_factor_generic (M &A)
 The generic (non-LAPACK) A = L*L^T loop, in either summation order (#556).
template<typename Accumulator, typename M>
int cholesky_factor_acc (M &A)
 The accumulator A = L*L^H loop (#585): each entry is assign(A(i,j)), then add_product(-L(i,k), conj(L(j,k))) for k < j, rounded once.
template<typename Accumulator, bool Conj, typename M, typename VecX, typename VecB>
void cholesky_solve_acc (const M &L, VecX &x, const VecB &b)
 The two substitutions of an L*L^H (Conj = true) or L*L^T (false) solve, with each row's b(i) - sum of products formed in Accumulator and rounded once.
template<typename T>
std::vector< std::complex< T > > quasi_triangular_eigenvector (const mat::dense2D< T > &R, std::size_t k, std::complex< T > lambda, T smin, T limit)
 A right eigenvector y of the real quasi-upper-triangular T (a real Schur form, 2x2 blocks in standard form) for its eigenvalue lambda at index k: (T - lambda I) y = 0, with y zero below lambda's block.
template<typename Real>
bool tridiagonal_negligible (const Real &e, const Real &d0, const Real &d1, const Real &tol)
 Deflation test of the implicit tridiagonal QR: is the subdiagonal entry e, between diagonal entries d0 and d1, negligible?
template<typename Real>
Real default_eigen_tolerance ()
 Default tolerance of the symmetric eigensolvers: the machine epsilon of the eigenvalue type.
template<typename Dest, typename Expr>
bool fused_reads_dest_elsewhere (const Dest &dest, const Expr &expr)
 Whether writing expr into dest element by element could read an element of dest other than the one being written (issue 887): the test dense2D's operator= makes (#824).
template<typename Dest, typename Expr>
mat::dense2D< typename Dest::value_type > fused_evaluate (const Expr &expr)
 expr evaluated into a dense matrix of Dest's value type.
template<typename MC>
void mirror_triangle (MC &C, uplo t)
 Copy the t triangle of the n x n matrix C across the diagonal.
template<typename Accumulator, typename Value, typename S, typename MC, typename Terms>
void gemmt_triangle (const S &alpha, const S &beta, MC &C, uplo t, Terms terms)
 The generic triangle loop.
template<typename M>
auto gemmt_describe (const M &X)
template<typename M>
auto gemmt_describe_mut (M &X)
template<typename Accumulator = void, typename S, typename MT, typename MA, typename MC>
void congruence_second (const S &alpha, const MT &T, const MA &A, const S &beta, MC &C)
 The second product of a congruence, C = alpha * T*A^T + beta*C, lower triangle mirrored.
template<typename Accumulator, bool Conj, typename M>
int ldlt_factor_acc (M &A)
 The accumulator loop of ldlt_factor (Conj = false, A = L D L^T) and ldlt_h_factor (Conj = true, A = L D L^H, D real).
template<typename Accumulator, bool Conj, typename M, typename VecX, typename VecB>
void ldlt_solve_acc (const M &A, VecX &x, const VecB &b, const char *who)
 The three phases of an LDL^T (Conj = false) or LDL^H (true) solve, with each row's b(i) - sum of products formed in Accumulator and rounded once.
std::vector< bk_interchange > bk_interchanges (const std::vector< int > &ipiv)
 The interchanges ipiv records, in the order the factorization made them.
template<typename Accumulator, typename M>
int ldlt_bk_factor_acc (M &A, bk_pivot_info &pivots)
 ldlt_bk_factor's accumulator path: left-looking Bunch-Kaufman (top of file).
template<typename Accumulator, typename M, typename VecX, typename VecB>
void ldlt_bk_solve_acc (const M &A, const bk_pivot_info &pivots, VecX &x, const VecB &b)
 ldlt_bk_solve's accumulator path (top of file).
template<std::size_t W, typename M, typename VecX, typename VecB>
void lower_trisolve_rows (const M &L, VecX &x, const VecB &b, bool unit_diag, typename M::size_type i=0)
 The default-accumulator forward substitution on rows [i, n), W rows per block (#749, #772).
template<std::size_t S, std::size_t C = column_sweep_columns, typename M, typename VecX, typename VecB>
void lower_trisolve_column_sweep (const M &L, VecX &x, const VecB &b, bool unit_diag)
 The default-accumulator forward substitution on a contiguous column-major L, S rows per strip, top-down (#777; see detail/column_sweep.hpp).
template<typename Accumulator, typename M>
int lu_factor_acc (M &A, std::vector< typename M::size_type > &pivot)
 lu_factor's accumulator path: left-looking LU with partial pivoting.
template<typename M, typename F>
bool all_stored (const M &A, F &&f)
 Calls f(r, c, v) for each stored entry of a compressed2D, row by row.
template<Matrix M>
magnitude_t< typename M::value_type > product_tol (const M &A, magnitude_t< typename M::value_type > tol)
template<std::size_t W, typename M, typename VIn, typename VOut>
void mult_rows_interleaved (const M &A, const VIn &x, VOut &y, std::size_t rb, std::size_t re)
 The default-accumulator mat*vec rows [rb, re), W rows per pass over x, one accumulator each (#749, #772).
template<std::size_t S, std::size_t C = column_sweep_columns, typename M, typename VIn, typename VOut>
void mult_rows_column_sweep (const M &A, const VIn &x, VOut &y, std::size_t rb, std::size_t re)
 The default-accumulator mat*vec rows [rb, re) on a contiguous column-major A, S rows per strip (#777; see detail/column_sweep.hpp).
template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mult_generic_rows (const M &A, const VIn &x, VOut &y, std::size_t rb, std::size_t re)
 Generic mat*vec over the OUTPUT ROW RANGE [rb, re): the loop body of mult_generic below, split out so a threaded caller can hand one contiguous band of rows to each worker (#446).
template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mult_generic (const M &A, const VIn &x, VOut &y)
 Generic mat*vec: y = A * x.
template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mult_sparse_csr_rows (const mat::compressed2D< V, P > &A, const VIn &x, VOut &y, std::size_t rb, std::size_t re)
 Sparse CSR mat*vec over the OUTPUT ROW RANGE [rb, re): the loop body of mult_sparse_csr below, split out for the threaded caller exactly as the dense kernels are.
template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mult_sparse_csr (const mat::compressed2D< V, P > &A, const VIn &x, VOut &y)
 Sparse CSR mat*vec: y = A * x, iterating only stored nonzeros.
template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mult_sparse_csr_par (const mat::compressed2D< V, P > &A, const VIn &x, VOut &y)
 Sparse CSR mat*vec with the output rows spread over the pool.
template<typename V, typename P, typename MB, typename MC>
void mult_sparse_csr_dense_rows (const mat::compressed2D< V, P > &A, const MB &B, MC &C, std::size_t rb, std::size_t re)
 Sparse (CSR) x dense mat*mat over the OUTPUT ROW RANGE [rb, re) of C (#550): C.row(r) = sum over A's stored entries (k, v) of row r, in ascending k, of v * B.row(k).
template<typename Accumulator, typename V, typename P, typename MB, typename MC>
void mult_sparse_csr_any (const mat::compressed2D< V, P > &A, const MB &B, MC &C)
 Sparse (CSR) A times any B into any dense C (issue 886): column-major dense B or C, a compressed B, and mult<Accumulator>.
template<typename V, typename P, typename MB, typename MC>
void mult_sparse_csr_dense_par (const mat::compressed2D< V, P > &A, const MB &B, MC &C)
 mult_sparse_csr_dense_rows over all rows, threaded over row bands like mult_sparse_csr_par (each output row is one band's, so the result does not depend on the thread count).
template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mult_generic_rows (const MA &A, const MB &B, MC &C, std::size_t rb, std::size_t re)
 Generic mat*mat over the OUTPUT ROW RANGE [rb, re) of C – the mat*mat counterpart of mult_generic_rows above, with the same bit-identity argument: C(r, c) is written by whichever band owns row r, out of an inner k loop that does not depend on the band.
template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mult_generic (const MA &A, const MB &B, MC &C)
 Generic mat*mat: C = A * B.
template<std::size_t W, std::size_t Nr, typename Accumulator, typename AT, typename Value, typename MA, typename MC>
void mult_acc_panel_row (const MA &A, MC &C, std::size_t r, std::size_t j0, std::size_t kdim, const Value *panel)
 One row of C, columns [j0, j0 + W), against a packed panel of W columns of B.
template<typename Accumulator, Matrix MA, Matrix MB, Matrix MC>
void mult_acc_panel_rows (const MA &A, const MB &B, MC &C, std::size_t rb, std::size_t re)
 Accumulator-typed mat*mat over the OUTPUT ROW RANGE [rb, re) of C, through a packed panel of B (#587).
template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mult_generic_par (const M &A, const VIn &x, VOut &y)
 mat*vec: y = A * x, output rows partitioned across the pool when A, x and y are plain dense storage and there is more than one chunk's worth of work.
template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mult_generic_par (const MA &A, const MB &B, MC &C)
 mat*mat: C = A * B, output rows of C partitioned across the pool when A, B and C are plain dense storage and there is more than one chunk's worth of work.
template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mult_sparse_csr_transposed (const mat::view::transposed_view< mat::compressed2D< V, P > > &At, const VIn &x, VOut &y)
 Transposed sparse CSR mat*vec: y = A^T * x, O(nnz), scatter into y.
template<typename VOut, typename F>
void mult_via_temporary (VOut &y, F &&compute)
 y = op(x) through a temporary, then copied into y element by element, so a y that is a view keeps writing its buffer (#833).
template<typename MC, typename F>
void mult_mat_via_temporary (MC &C, F &&compute)
 C = op(A, B) through a temporary of C's own type, then copy-assigned into C, which writes a non-owning C's buffer in place (#833).
template<typename T>
constexpr bool holds_expression ()
 Whether an operand is, or views, a lazy expression: an expression type, or a view (anything with base(): trans, hermitian, the triangular and banded views) whose base is one.
template<typename M>
mat::dense2D< typename M::value_type > dense_copy (const M &A)
 An owning dense copy of a matrix operand, in its own element type: what an expression operand is evaluated into before a kernel that writes C runs.
template<typename Mag>
bool sum_squares_needs_rescan (const Mag &ss)
template<typename Mag>
void max_propagating_nan (Mag &result, const Mag &a)
 result = max(result, a), but a NaN a makes the result NaN and keeps it there (#690).
template<typename M, typename F>
void for_each_entry (const M &m, F &&f)
 Calls f(r, c, a) for every element a = m(r, c) that can be nonzero, in an order that suits the storage: a compressed2D's stored entries row by row (its operator() is a binary search, so the full m x n loop was O(m n log nnz) for an O(nnz) answer); a column-major matrix column by column; any other matrix row by row.
template<typename A, typename B>
constexpr bool int_less (A a, B b) noexcept
 a < b by value, for integral types of any signedness and width.
template<typename Target, typename Value>
Target saturating_cast (Value v)
 Convert a value to Target, clamping to [min, max] for integer types to prevent undefined behavior from signed integer overflow.
std::mt19937_64 random_engine ()
 A std::mt19937_64 seeded from std::random_device, for the calls without a seed.
double random_unit (std::mt19937_64 &gen)
 Uniform on [0, 1): the top 53 bits of one 64-bit draw.
template<typename T>
void check_random_bounds (const T &lo, const T &hi, const char *who)
 Throws unless lo and hi are finite and lo <= hi.
template<typename T>
T random_uniform (std::mt19937_64 &gen, const T &lo, const T &hi)
 One value uniform on [lo, hi), or lo when lo == hi. Bounds already checked.
template<typename M>
auto schur_complex (const M &A)
 The in-house complex Schur form: Hessenberg reduction, its unitary Q, and the complex QR iteration, on A scaled to the unit binade.
template<typename T>
constexpr T signum_scalar (const T &x)
 +1, 0 or -1; an unsigned type has no -1, so 1 or 0 (T{-1} narrowed and did not compile, issue 887).
template<Matrix M>
std::vector< magnitude_t< typename M::value_type > > singular_values (const M &A)
template<typename Accumulator, typename V1, typename P1, typename V2, typename P2>
auto spgemm_acc (const mat::compressed2D< V1, P1 > &A, const mat::compressed2D< V2, P2 > &B)
 spgemm with an accumulator: one per touched column of the current row, rounded once at the gather (see the header note).
template<typename T>
void vec_sum (std::vector< T > &p)
 VecSum (Algorithm 4.3): p_i, p_{i-1} = TwoSum(p_i, p_{i-1}) for i = 2..n.
template<typename T>
T sum_k_inplace (std::vector< T > &p, int K)
 SumK (Algorithm 4.8) on a vector it may overwrite: K - 1 VecSum passes, then fl(sum_{i<n} p_i + p_n).
template<typename Accumulator, typename value_type, typename Size, typename Term>
value_type svd_dot (Size len, Term term)
 sum_i a(i) * b(i) for i < len, where term(i) returns {a(i), b(i)}: a plain value_type sum for void, else one accumulator rounded once.
template<typename Accumulator, typename value_type, typename Size, typename Load>
void svd_pair_sums (Size len, Load load, value_type &alpha, value_type &betac, value_type &gamma)
 alpha = ||p||^2, betac = ||q||^2, gamma = p .
template<typename Accumulator = void, typename value_type>
void one_sided_jacobi (mat::dense2D< value_type > &B, mat::dense2D< value_type > &V, std::vector< value_type > &sigma_s, value_type tol)
 One-sided Jacobi core shared by every svd overload.
template<typename Accumulator = void, typename value_type>
void complete_orthonormal (mat::dense2D< value_type > &U, typename mat::dense2D< value_type >::size_type filled)
 Completes the columns [filled, ncol) of U (m x ncol, m >= ncol) to an orthonormal set, given that columns [0, filled) are already orthonormal.
template<typename T>
bool sylvester_representable (const T &x)
 Whether a solution entry is representable: finite, and below the largest value of the real type (a posit saturates there rather than overflowing).
template<typename M>
std::vector< std::size_t > quasi_triangular_blocks (const M &T, const char *who, const char *name)
 The diagonal blocks of an upper quasi-triangular square matrix, as their starting indices followed by n.
template<typename R>
sylvester_limits< R > make_sylvester_limits (std::size_t m, std::size_t n, const R &eps)
template<typename R>
R scale_down_to_one (R x)
 The largest power of two f <= 1 with x * f <= 1, for x > 1.
template<typename Value>
Value sylvester_scale_pow2 (const Value &x, int k)
 x * 2^k, part by part for a complex type: exact in a binary type unless the result overflows or becomes subnormal.
template<typename T>
T block_quotient (const T &x, const T &y)
 Solve the p*q unknowns of a p x p block a and a q x q block b (p, q <= 2),.
template<typename T, typename R>
bool solve_sylvester_block (const T(&a)[2][2], int p, const T(&b)[2][2], int q, const T &sgn, T(&rhs)[2][2], const R &smin, const sylvester_limits< R > &lim, bool scaled, R &scaloc)
template<typename Accumulator, typename MA, typename MB, typename MC>
sylvester_scaled_result< typename MC::value_type > sylvester_triangular_inhouse (const MA &A, const MB &B, const MC &C, sylvester_sign sign, const std::vector< std::size_t > &ablocks, const std::vector< std::size_t > &bblocks, bool scaled)
 The in-house solve behind sylvester_triangular (scaled == false: no scaling, scale stays 1) and sylvester_triangular_scaled (scaled == true).
template<typename Accumulator, typename MA, typename MB, typename MC>
sylvester_scaled_result< typename MC::value_type > sylvester_triangular_solve (const MA &A, const MB &B, const MC &C, sylvester_sign sign, bool scaled)
 Validate, dispatch and solve, for sylvester_triangular (scaled == false) and sylvester_triangular_scaled (scaled == true).
template<typename Value>
magnitude_t< Value > sylvester_max_part (const mat::dense2D< Value > &X)
 The largest |x| over X's entries; for a complex type the largest |part|, as in sylvester_representable.
template<typename R>
int sylvester_downscale_exponent (const R &p, const R &bound)
 The k >= 0 for which p * 2^-k <= bound: 0 when p <= bound already, and otherwise the smallest k the binary exponents of p and bound guarantee.
template<std::size_t R, typename Acc, typename TA, typename TX>
void symv_strip_scatter (std::size_t len, const TA *const *p, const TX *xr, Acc *acc)
 acc[j] += p[0][j] x[0] + p[1][j] x[1] + ... in row order, for j < len: R rows' contributions to the entries left of the strip.
template<std::size_t R, typename Acc, typename TA, typename X>
MTL5_NO_LOOP_VECTORIZE void symv_strip_gather (std::size_t len, const TA *const *p, Acc *s, const X &x, std::size_t j0)
 s[r] += p[r][j] x[j] in ascending j, for j < len: each row's own sum, R independent chains sharing each x[j] (see MTL5_NO_LOOP_VECTORIZE).
template<typename S, typename MA, typename MB>
void trmm_rows (const S &alpha, const MA &A, MB &B, bool upper, bool unit_diag, typename MA::size_type b0, typename MA::size_type b1)
 The generic product on a row-major B, a whole row of B at a time (#724).
template<typename S, typename MA, typename MB>
void trmm_rows (const S &alpha, const MA &A, MB &B, bool upper, bool unit_diag)
template<std::size_t W, typename M, typename VX>
void trmv_upper_rows (const M &A, VX &x, typename M::size_type i, bool unit_diag)
 The generic upper trmv on rows [i, n), W rows per block, top-down (#749, #772).
template<std::size_t W, typename M, typename VX>
void trmv_lower_rows (const M &A, VX &x, typename M::size_type ii, bool unit_diag)
 The generic lower trmv on rows [0, ii), W rows per block, bottom-up: the mirror image of trmv_upper_rows.
template<std::size_t S, std::size_t C = column_sweep_columns, typename M, typename VX>
void trmv_column_sweep (const M &A, VX &x, bool upper, bool unit_diag)
 The generic trmv on a contiguous column-major A, S rows per strip (#777; see detail/column_sweep.hpp).
template<typename S, typename MA, typename MB>
void trsm_rows (const S &alpha, const MA &A, MB &B, bool upper, bool unit_diag, typename MA::size_type b0, typename MA::size_type b1)
 The generic solve on a row-major B, a whole row of B at a time (#724).
template<typename S, typename MA, typename MB>
void trsm_rows (const S &alpha, const MA &A, MB &B, bool upper, bool unit_diag)
template<typename T>
bool scalar_is_finite (const T &x)
template<typename T>
bool scalar_is_nan (const T &x)
template<typename T>
bool scalar_is_inf (const T &x)
template<typename Mag, typename ForEachAbs>
Mag rescaled_two_norm (ForEachAbs &&for_each_abs)
 sqrt(sum a^2) over the magnitudes that for_each_abs(f) passes to f, computed with a power-of-two scale so that neither the squares nor their sum overflow or underflow.

Variables

template<typename Acc, typename Value>
constexpr std::size_t accumulate_chunk_units
 Iteration units per chunk for a reduction of Value terms into Acc: the smaller of the two types' budgets, since either a software-emulated element or a software accumulator makes each term cost a call rather than a flop.
constexpr std::size_t default_alignment = 64
 Default over-alignment: 64 bytes covers a typical cache line and the widest common SIMD register (AVX-512).
template<typename T>
constexpr std::size_t block_alignment
 Alignment used for a block of T: at least default_alignment, but never less than T's natural alignment.
template<typename M>
constexpr bool col_major_contiguous_v
 Whether M is a dense matrix whose data() is column-major with leading dimension num_rows(): element (i, j) at data()[j * num_rows() + i].
template<typename Acc, typename M>
constexpr bool column_sweep_v
 Whether the generic row kernels take the column sweep for an accumulator of type Acc over a matrix of type M.
template<typename T>
constexpr std::size_t column_strip_rows = std::max<std::size_t>(1, 16384 / sizeof(T))
 Rows per strip: 16 KB of accumulators, at least one.
constexpr std::size_t column_sweep_columns = 8
 Columns per pass over a strip (#884).
constexpr std::size_t column_sweep_unrolled_stride = 8192
 A run-time strip goes one column per pass when A's columns are this many bytes apart or more (#884): eight columns per pass then read eight streams that far apart, and on the Jetson Orin and the Ventuno that ran at 0.46-0.75 of one column per pass at n = 2048-4096 (8 KB and up), as on the Xeon at.
constexpr std::size_t column_sweep_gemv_row_kernel_rows = 2
 The shapes the row kernels take although A is column-major (#884): where the sweep's per-strip fixed cost isn't amortized.
constexpr std::size_t column_sweep_trmv_row_kernel_n = 64
constexpr std::size_t column_sweep_trsv_row_kernel_n = 64
template<typename Acc, typename M>
constexpr bool row_kernel_fixed_rows_v
 Whether the row kernels (mult_rows_interleaved, trmv_upper_rows, trmv_lower_rows) run a block's column loop as sweep_fixed_rows<W> on a contiguous column-major A (#898): GCC on x86-64 only.
constexpr std::size_t row_kernel_fixed_rows_min_columns = 16
 ... and only over at least this many columns: below it the call costs more than the loop (2 x 2 and 4 x 4 ran at 0.46-0.83 through it).
constexpr std::size_t column_sweep_fixed_rows = 16
 Strips of at most this many rows take sweep_fixed_rows (#884).
constexpr std::size_t gemv_colmajor_columns = 2
 Columns the col-major gemv takes per pass over a strip of y (#804): four where the target has a fused multiply-add, two where fma is a separate multiply and add.
template<typename T>
constexpr std::size_t gemv_colmajor_strip_rows
 Rows per strip of the col-major gemv: 64 KB of y, a whole number of batches (at least one).
constexpr nc_model all_nc_models []
constexpr std::size_t nc_model_count
 How many models there are.
template<typename T>
constexpr bool data_is_element_address
 Whether t.data() is the address of t's elements.
template<typename T, typename M, std::size_t W>
constexpr bool keep_scalar_v
 Whether the W accumulators of type T over a matrix of type M need keep_scalar (see the top of this file).
template<typename T, typename M, std::size_t W>
constexpr bool keep_scalar_triangular_v
 The same, for the trmv and forward-substitution kernels: as keep_scalar_v on x86-64, never on AArch64, where it made them 5.6-7.2x slower (#795).
constexpr std::size_t transpose_tile = 32
 Tile edge of transpose_copy, chosen by measurement on an Apple M2 and an x86-64 host (issue 1040): 32 beat 8, 16 and 64 for float and double.
template<typename T>
constexpr bool is_wrapping_integer_v
 Integral types these helpers wrap.
template<typename M>
constexpr bool row_major_contiguous_v
 Row-major storage with contiguous rows: data() and a row-major orientation.
constexpr std::size_t triangular_block = 64
 Row block of the blocked trsm and trmm on the native-fast path (#724): the diagonal blocks run in the row loop, everything else in the blocked GEMM, so the row loop's share of the flops is about triangular_block / m.
template<typename Accumulator, typename S, typename VIn, typename VOut>
constexpr bool block_fused_gemv_v
 Does mult(A, x, y) on these types run the scheme's fused kernel?
template<typename P1, typename P2>
constexpr bool mat_params_differ_only_in_space_v
 True when two matrix parameter bundles agree in every axis but the memory space (#1012): a dense2D of one may be built from, and assigned, a dense2D of the other.
template<typename T>
constexpr bool zero_fill_is_value_init_v = ::mtl::zero_fill_is_value_init<std::remove_cv_t<T>>::value
template<typename M>
constexpr bool is_transposed_view_v = false
template<typename M>
constexpr bool is_transposed_view_v< mat::view::transposed_view< M > > = true
template<typename M>
constexpr bool is_transposed_csr_v = false
template<typename V, typename P>
constexpr bool is_transposed_csr_v< mat::view::transposed_view< mat::compressed2D< V, P > > > = true
template<typename Accumulator, typename MA, typename MB, typename MC>
constexpr bool gemmt_dispatches_blas_v
 Whether gemmt<Accumulator>(alpha, A, B, beta, C) calls ?gemmt (for sizes that fit an int; with OpenBLAS, only for n <= gemmt_block – see gemmt_uses_blocked_v).
constexpr std::size_t gemmt_block = 64
 Rows of the diagonal blocks of the blocked gemmt (#744).
template<typename M>
constexpr bool gemmt_strided_dense_v
 Dense float/double with contiguous storage and an orientation: the operands the blocked gemmt describes by strides.
template<typename M>
constexpr bool gemmt_strided_operand_v
template<typename Accumulator, typename MA, typename MB, typename MC>
constexpr bool gemmt_uses_blocked_v
 Whether gemmt<Accumulator>(alpha, A, B, beta, C) takes the blocked path for n > gemmt_block (#744): wherever ?gemmt is not called, and with OpenBLAS in place of its dgemmt.
template<typename Accumulator, typename S, typename M, typename VX, typename VY>
constexpr bool ger_dispatches_blas_v
 Whether ger<Accumulator>(alpha, x, y, A) calls ?ger (for sizes that fit an int).
template<typename Accumulator, typename MA, typename MB>
constexpr bool acc_panel_gemm_v
 Whether mult<Acc> takes the packed-panel kernel below (#587): hardware arithmetic operands and an accumulator of at most 32 bytes.
template<typename Accumulator>
constexpr std::size_t acc_panel_width = sizeof(Accumulator) <= 8 ? 8 : 4
 Columns of C an accumulator GEMM computes per pass over a row of A (#587).
template<typename Accumulator, typename MA, typename MB, typename MC>
constexpr bool gemm_dispatches_blas_v
 Whether mult<Accumulator>(A, B, C), mat*mat, calls ?gemm: dense float or double operands of one element type under the default accumulator, in any mix of orientations (#849; before, only A, B and C of one orientation did).
template<typename T>
constexpr bool holds_expression_v = holds_expression<std::remove_cvref_t<T>>()
template<typename MC>
constexpr bool mult_mat_temporary_ok_v
 Whether mult can route an aliased C through mult_mat_via_temporary: C's type can be made at C's size and copy-assigned.
template<typename Mag>
constexpr bool rescalable_sum_squares_v = norms_adl::rescalable_sum_squares<Mag>
template<typename M>
constexpr bool norm_col_major_v
 The loop order of a matrix norm follows the storage (issue 886): one_norm walked a row-major 6000^2 dense2D by columns, 6x slower than infinity_norm, and the other two were the mirror image on column-major.
template<typename M>
constexpr bool norm_row_major_v
template<typename T>
constexpr bool is_sat_int_v = sat_traits<T>::is_int
template<typename T>
constexpr bool sat_signed_v = sat_traits<T>::is_signed
template<typename Accumulator, typename MA, typename MB, typename MC>
constexpr bool symm_dispatches_blas_v
 Whether symm<Accumulator>(alpha, A, B, beta, C) calls ?symm (for sizes that fit an int).
template<typename MA, typename MB, typename MC>
constexpr bool symm_uses_blocked_v
 Whether symm<void> on this build expands A and calls the native blocked GEMM (#724): MTL5_NATIVE_FAST_GEMM, float or double, dense A and B, row-major C.
template<typename MB>
constexpr bool symm_uses_row_loop_v = row_major_contiguous_v<MB>
 Whether the generic symm<void> forms C row by row over a row-major B (#724).
template<typename Accumulator, typename M, typename VX, typename VY>
constexpr bool symv_dispatches_blas_v
 Whether symv<Accumulator>(alpha, A, x, beta, y) calls ?symv (for sizes that fit an int).
template<typename M>
constexpr bool symv_uses_row_loop_v = row_major_contiguous_v<M>
 Whether the generic symv<void> makes one row-wise pass over a row-major A's lower triangle (#724).
constexpr std::size_t symv_strip_rows = 8
 Rows per strip of the row-major symv (#236), and columns per block of a strip's pass over the columns left of it: 8 rows of 256 doubles are 16 KB, in L1 for the second of the two loops below.
constexpr std::size_t symv_strip_block = 256
constexpr std::size_t symv_strip_min_n = 128
template<typename Accumulator, typename MA, typename MB, typename MC>
constexpr bool syr2k_dispatches_blas_v
 Whether syr2k<Accumulator>(alpha, A, B, beta, C) calls ?syr2k (for sizes that fit an int).
template<typename MA, typename MB>
constexpr bool syr2k_uses_row_loop_v = row_major_contiguous_v<MA> && row_major_contiguous_v<MB>
 Whether the generic syr2k<void> forms C's lower triangle row by row over transposed copies of row-major A and B (#724).
template<typename Accumulator, typename S, typename MA, typename MB, typename MC>
constexpr bool syr2k_uses_gemmt_v
 Whether syr2k<Accumulator>(alpha, A, B, beta, C) is two gemmt calls, C = alpha A B^T + beta C and then C += alpha B A^T, above detail::gemmt_block rows (#236): the MTL5_NATIVE_FAST_GEMM build without BLAS, where gemmt takes its blocked path over gemm_blocked.
template<typename Accumulator, typename MA, typename MC>
constexpr bool syrk_dispatches_blas_v
 Whether syrk<Accumulator>(alpha, A, beta, C) calls ?syrk (for sizes that fit an int).
template<typename MA>
constexpr bool syrk_uses_row_loop_v = row_major_contiguous_v<MA>
 Whether the generic syrk<void> forms C's lower triangle row by row over a transposed copy of a row-major A (#724).
template<typename Accumulator, typename S, typename MA, typename MC>
constexpr bool syrk_uses_gemmt_v
 Whether syrk<Accumulator>(alpha, A, beta, C) is gemmt(alpha, A, trans(A), beta, C) above detail::gemmt_block rows (#236): the MTL5_NATIVE_FAST_GEMM build without BLAS, where gemmt takes its blocked path over gemm_blocked.
template<typename Accumulator, typename MA, typename MB>
constexpr bool trmm_dispatches_blas_v
 Whether trmm<Accumulator>(alpha, A, B, ...) calls ?trmm (for sizes that fit an int and a nonzero alpha).
template<typename MB>
constexpr bool trmm_uses_row_loop_v = row_major_contiguous_v<MB>
 Whether the generic trmm<void> forms a row-major B row by row (#724).
template<typename MA, typename MB>
constexpr bool trmm_uses_blocked_v
 Whether trmm<void> on this build takes the blocked product over the native GEMM (#724): as trsm_uses_blocked_v.
template<typename Accumulator, typename M, typename VX>
constexpr bool trmv_dispatches_blas_v
 Whether trmv<Accumulator>(A, x, ...) calls ?trmv (for n that fits an int).
template<typename Accumulator, typename M, typename VX>
constexpr bool trmv_uses_blocked_v
 Whether trmv<Accumulator>(A, x, ...) takes the blocked SIMD path for n > triangular_block (#747): native-fast, no BLAS, float/double.
template<typename Accumulator, typename MA, typename MB>
constexpr bool trsm_dispatches_blas_v
 Whether trsm<Accumulator>(alpha, A, B, ...) calls ?trsm (for sizes that fit an int).
template<typename MB>
constexpr bool trsm_uses_row_loop_v = row_major_contiguous_v<MB>
 Whether the generic trsm<void> solves a row-major B row by row (#724).
template<typename MA, typename MB>
constexpr bool trsm_uses_blocked_v
 Whether trsm<void> on this build takes the blocked solve over the native GEMM (#724): MTL5_NATIVE_FAST_GEMM, float or double, dense A, row-major B.
template<typename Accumulator, typename M, typename VX>
constexpr bool trsv_dispatches_blas_v
 Whether trsv<Accumulator>(A, x, ...) calls ?trsv (for n that fits an int).
template<typename Accumulator, typename M, typename VX>
constexpr bool trsv_uses_blocked_v
 Whether trsv<Accumulator>(A, x, ...) takes the blocked SIMD path for n > triangular_block (#747): native-fast, no BLAS, float/double.
template<typename P1, typename P2>
constexpr bool vec_params_differ_only_in_space_v
 True when two vector parameter bundles agree in every axis but the memory space (#1012): a dense_vector of one may be built from, and assigned, a dense_vector of the other.

Detailed Description

mat*vec multiply into pre-allocated y: y = A * x.

Mixed precision: pass an explicit Accumulator to sum each y element in a precision distinct from the operand element type; the result is rounded out to y's element type. Default Accumulator = void keeps the BLAS / native-fast / generic dispatch unchanged. mat*vec multiply for a transposed sparse view: y = A^T * x, O(nnz). Mirrors mat::operator*(transposed_view<compressed2D>, dense_vector) but adds Accumulator support for mixed-precision / quire accumulation.

Vectors only: a matrix B (trans(S) * B through mat::operator*) takes the matrix-matrix mult below (#824).

Typedef Documentation

◆ congruence_temp_t

template<typename MC>
using mtl::detail::congruence_temp_t
Initial value:
mat::dense2D<typename MC::value_type,
Dense row/column-major matrix with configurable dimensions and storage.
Definition dense2D.hpp:52
Parameter bundle for matrix types.
Definition parameter.hpp:23

The intermediate T of a congruence: dense, C's element type and orientation.

◆ expr_raw_t

template<typename T>
using mtl::detail::expr_raw_t = std::remove_cvref_t<T>

Strip reference and cv to get the underlying type for member access.

◆ expr_store_t

template<typename T>
using mtl::detail::expr_store_t
Initial value:
std::conditional_t<
std::is_lvalue_reference_v<T>,
const std::remove_reference_t<T>&,
std::remove_cvref_t<T>
>

Given the deduced forwarding-reference type T:

  • if T is an lvalue reference (X& or const X&), store as const X&
  • if T is a non-reference (rvalue), store as X (by value)

◆ memory_space_of_t

template<typename T>
using mtl::detail::memory_space_of_t = typename memory_space_of<T>::type

◆ packed_buffer

template<typename T>
using mtl::detail::packed_buffer = std::vector<T, aligned_allocator<T>>

SIMD-aligned scratch buffer for packed panels (reused across the nest).

◆ rebind_space_t

template<typename Params, typename Space>
using mtl::detail::rebind_space_t = typename rebind_space<Params, Space>::type

◆ rebound_storage_t

template<typename Storage, typename Space>
using mtl::detail::rebound_storage_t
Initial value:
std::conditional_t<
std::is_same_v<Storage, tag::read_only>
|| (std::is_same_v<Storage, tag::on_stack> && !std::is_same_v<Space, memory_space::host>),
tag::on_heap, Storage>
Definition storage.hpp:6

◆ runtime_of_space_t

template<typename S>
using mtl::detail::runtime_of_space_t = typename runtime_of_space<S>::type

◆ space_handle_t

template<typename S, typename T>
using mtl::detail::space_handle_t = typename space_handle<S, T>::type

◆ space_vector

template<typename T, typename Space>
using mtl::detail::space_vector = typename space_vector_impl<T, Space>::type

A growable array in memory space Space: std::vector<T> for host memory.

◆ thread_pool

◆ wrap_op_t

template<typename T>
using mtl::detail::wrap_op_t = std::common_type_t<std::make_unsigned_t<T>, unsigned int>

The type the modular arithmetic is actually performed in: the unsigned counterpart of T, or unsigned int when that is narrower than int.

This width promise is the whole correctness argument, and casting to make_unsigned_t<T> alone does NOT deliver it. Integral promotion runs before any arithmetic operator, and it promotes any type narrower than int to signed int – so for T = int16_t, static_cast<uint16_t>(-1) * static_cast<uint16_t>(-1) is 65535 * 65535 evaluated in int, which overflows and is undefined. The unsigned cast meant to prevent UB reintroduced it for every type narrower than int. Multiplying in common_type_t<U, unsigned> keeps the operation unsigned, where overflow is defined as reduction, and the result is then narrowed back to U.

Enumeration Type Documentation

◆ francis_output

enum class mtl::detail::francis_output
strong

What francis_qr() computes.

Enumerator
eigenvalues 

eigenvalues only (EISPACK hqr); H is left as working storage

schur_form 

the real Schur form T, and its Schur vectors when asked (EISPACK hqr2)

◆ gemm_kernel

enum class mtl::detail::gemm_kernel
strong

Which micro-kernel the blocked nest drives.

An EXPLICIT choice, never inferred from the element types, because an (i8, i8) pair is valid input to both and inference would silently replace the widen-on-load path the moment this kernel existed. Both are correct; they differ only in speed, and which one a build measured is not recoverable from a timing afterwards. So the caller says which, and the default is the one that was already there.

Enumerator
widening 

same-type, or narrow operands widened on load: one k value per multiply-add

quad 

the hardware quad multiply-accumulate: four k values per instruction

◆ memory_category

enum class mtl::detail::memory_category
strong

Ownership mode for heap-allocated memory.

Enumerator
own 
external 
view 

◆ nc_model

enum class mtl::detail::nc_model
strong

Candidate models for sizing nc. See the file header for why each exists.

Enumerator
m0_default 

pre-#429: compile-time L3, no balancing. The baseline.

m1_balanced 

M0 + balanced_nc.

m2_detected 

detected L3 + balanced_nc – FALSIFIED, see below

m3_per_team 

(detected L3 / jc_nt) + balanced – rejected on #426, measured anyway

m4_per_sharer 

(detected L3 / L3 sharing cores) + balanced

m5_exact 

pick nc so njb == jc_nt exactly, where n allows

m6_guarded 

M1, declined where the packed-B set would grow past L3.

The default for #429; superseded by M7 (#492).

m7_sharer_gated 

M4, but ONLY where the grid is jc-parallel.

THE DEFAULT since #492. See the case below.

Function Documentation

◆ accumulate()

template<typename Acc, typename Value, bool Threadable, typename MapFn>
Acc mtl::detail::accumulate ( std::size_t n,
std::size_t grain,
MapFn && map )

Accumulate map(acc, begin, end) over [0, n) into a cleared Acc.

Threaded across the pool, grain units per chunk at least, when Threadable (the operands are plain dense storage, safe to read concurrently) and the accumulator can merge. Otherwise one serial pass, as before #582.

◆ alias_overlaps()

template<typename T>
bool mtl::detail::alias_overlaps ( const T & m,
const alias_target & t )

Whether the leaf's contiguous storage overlaps the target's.

Its span is rows * cols elements from data(): the only leaf with data() and a leading dimension is dense2D, whose leading dimension is always its column count (row-major) or row count (column-major), with no padding, so there is no tail beyond rows * cols for an overlap to hide in (#857).

A leaf in a memory space whose handle is not a pointer (#1017) is read through its host address, begin(); one without a host address may hold the target, so the answer is yes and the assignment goes through a temporary.

◆ alias_reaches_target()

template<typename E>
bool mtl::detail::alias_reaches_target ( const E & e,
const alias_target & t )

Whether evaluating e reads the target's storage at all.

◆ alias_reads_target_elsewhere()

template<typename E>
bool mtl::detail::alias_reads_target_elsewhere ( const E & e,
const alias_target & t )

Whether evaluating e element by element into the target can read an element of the target other than the one being written.

◆ alias_storage_overlaps()

template<typename T>
bool mtl::detail::alias_storage_overlaps ( const T & m,
const alias_target & t )

Whether a known-storage leaf is the target or any of its storage overlaps the target's elements.

◆ all_stored()

template<typename M, typename F>
bool mtl::detail::all_stored ( const M & A,
F && f )

Calls f(r, c, v) for each stored entry of a compressed2D, row by row.

The predicates below loop over every (i, j) through operator(), which on a compressed2D is a binary search: O(m n log nnz) for an answer the stored entries decide in O(nnz) – is_diagonal on a 5000 x 5000 diagonal matrix took 37 ms (issue 886). An entry that isn't stored is zero, and every predicate below holds for a zero wherever it sits.

◆ allocate_aligned()

template<typename T>
T * mtl::detail::allocate_aligned ( std::size_t n)
nodiscard

Allocate and value-initialize n elements of T on an over-aligned heap block (block_alignment<T>).

Returns nullptr for n == 0. Works for cv- qualified T (e.g. ndarray's const double views) by constructing/freeing through the unqualified type.

◆ array_bytes()

template<typename A>
std::pair< const unsigned char *, const unsigned char * > mtl::detail::array_bytes ( const A & v)

The bytes of a std::vector-like array's elements; empty when it is.

◆ balanced_mc()

std::size_t mtl::detail::balanced_mc ( std::size_t m,
std::size_t mc_max,
unsigned ic_nt,
std::size_t mr = 1 )
inline

Choose the ic-block size for the threaded m-partition (#408, #458).

mc_max is an UPPER bound set by the L2 budget – any smaller value is still cache-legal – so we are free to trade a little block size for a shorter critical path. The threaded nest hands ic-blocks to the ic_nt members round-robin, so the most-loaded thread gets ceil(nib / ic_nt) blocks.

THE CRITICAL PATH IS COUNTED IN MICRO-PANELS, NOT BLOCKS (#458). This used to round nib up to a multiple of ic_nt and stop there, which is right about the block count and blind to what a block costs: ceil(mc / mr) panels, whole or not. At the shipped threaded mc = 32 with mr = 6, every block is 5.33 panels and runs as 6, a ragged panel in EVERY block – something the serial path, which rounds mc to whole panels, never does. That is the T=1-vs-T=6 divergence #458 measured: the two thread counts were not running the same blocks. Against the Xeon E5-2420 v2 curve that issue reported (2048^3, T=6), the busiest thread's panel count correlates with throughput at r = +0.83 (kc = 512) and +0.74 (kc = 256); the block-count balance this function used to optimise correlates at +0.23 and 0.00. (It did not reliably reach that balance either: ceil(m / ceil(m / nib)) is not nib.)

So the even partition below is now the INCUMBENT, and a block size in [ceil(mc_max / 2), mc_max] replaces it only when it gives the busiest thread strictly fewer panels. Ties keep the incumbent, so a plan that was already panel-optimal – #408's mc = 64 at m = 1024 on 8 threads, and the i7-12700K's shipped plans at T = 8 – does not move.

THE WINDOW IS THE GUARD AGAINST SMALL BLOCKS. Counted in panels alone, a single-panel block is always optimal, and it is not: every ic block costs a pass over the shared packed B panel. On an i7-12700K at kc = 1024, mc = 6 ran at x0.61-0.87 of mc = 16 on eight threads. Searching no lower than half the cache bound limits that to at most twice the blocks.

Why this is needed at all: mc used to be rounded down to a multiple of mr in derive_blocking, which coupled the L2 block size to the register tile. The #382 tile change (mr 4 -> 6) therefore moved mc 64 -> 60, turning nib = 16 at m = 1024 (exactly 2.00 blocks per thread on 8 threads) into nib = 18 (2.25, a 1.41x critical path). That converted a +21.5% single-thread win into a -7.4% eight-thread REGRESSION. The rounding is gone and the balance is chosen here, where m and the thread count are actually known.

IT NEVER RETURNS A BLOCK SHORTER THAN ONE REGISTER TILE (#488). Balancing works by RAISING the block count, which lowers mc, and pushed far enough that lands below mr – at which point every ic block is a ragged tile and takes the micro-kernel's edge path, through a zeroed mr x nr temporary with a copy in and a copy out. Not just the trailing block, which is the case the edge path was written for: EVERY block.

plan_gemm_grid already floors mc at mr for exactly this reason ("a block shorter than mr would waste the micro-kernel") and this function used to undo that floor a moment later: balanced_mc(m=18, mc_max=6, ic_nt=2, mr=6) returned 5, because nib = ceil(18/6) = 3 rounds up to 4 and ceil(18/4) = 5. Measured on the #479 timing runs, where a re-plan moved ic_nt 3 -> 2 and mc 6 -> 5, throughput fell to x0.818-0.950 against a 4.3-5.5% noise floor. That is #408's own repair damaging the thing #408 protects.

WHEN THE EVEN PARTITION IS SUB-TILE, THERE IS NO OTHER EVEN ONE. The balanced candidates are the multiples of ic_nt at or above nib_min, and mc DECREASES as that count grows – so if the smallest such multiple is already sub-tile, every larger one is too. Balance cannot be traded here, only abandoned; the fallback takes the least-imbalanced block that is still a whole tile, preferring the larger block on a tie.

Returns mc_max unchanged for the serial case, where there is nothing to balance and the largest cache-legal block is best.

◆ balanced_nc()

std::size_t mtl::detail::balanced_nc ( std::size_t n,
std::size_t nc_max,
unsigned jc_nt,
std::size_t nr = 1 )
inline

Choose the jc-block size that balances the threaded n-partition – the jc-side counterpart of balanced_mc (#479, feeding #429).

nc_max is an UPPER bound set by the L3 budget, so any smaller value is still cache-legal and we are free to trade block size for a partition that divides evenly across the teams. The threaded nest hands jc-blocks to the jc_nt teams round-robin, so the most-loaded team gets ceil(njb / jc_nt) blocks and the critical path is minimised when njb is a MULTIPLE of jc_nt. This picks the largest nc <= nc_max achieving that.

WHY THE ic SIDE GOT THIS FIRST. balanced_mc exists because #408 measured what its absence costs: an mc that moved 64 -> 60 took nib from 16 (exactly 2.00 blocks per thread on 8 threads) to 18 (2.25), a 1.41x critical path that turned a +21.5% single-thread win into a -7.4% eight-thread regression. The jc loop has the same arithmetic and went without the repair for longer; this is that repair, default since #429/#490 as m6_guarded.

IT DOES NOT LET THE DETECTED L3 BACK IN, and the reason is worth stating because the old version of this comment implied the opposite. nc was withheld from cache detection on the theory that an unbalanced partition was the only hazard. #479 measured the pairing: detected L3 WITH balancing (M2) still loses up to 45%, 37 regressions. Balancing does not rescue it, so the theory was wrong rather than merely untested – and with_detected_caches keeps pinning nc to the compile-time derivation. See blocking.hpp.

IT LIVES HERE, NOT IN gemm_blocked.hpp, because it exists FOR the models below: every one of M1..M6 is "some capacity budget, then this". Keeping it beside them also breaks the include cycle the harness arm would otherwise need – gemm_blocked now includes this header to reach nc_for_model, so this header can no longer include gemm_blocked.

Returns nc_max unchanged for the serial case, where there is nothing to balance.

IT DOES NOT ROUND THE BALANCED nc TO A MULTIPLE OF nr, and that omission is the whole lesson of #408 restated on this axis. Rounding nc after balancing changes njb again and destroys the property just established: the first draft of this function did round, and the pre-registered control in test_nc_models caught it – m4_per_sharer at n = 276681, jc_nt = 4 went from a perfectly even partition to 1.0038, i.e. the balancing step made the imbalance WORSE. That is #408's defect exactly: a register-tile quantity perturbing a partition quantity.

balanced_mc takes the same position for the same reason – it rounds to whole mr panels only on the SERIAL path, where there is no partition to perturb. A multiple of nr is an optimisation, not a requirement: the nest computes npanels = ceil(nci / NR) and the micro-kernel's edge path already handles a ragged final panel, since n is not a multiple of nc in general.

◆ bk_interchanges()

std::vector< bk_interchange > mtl::detail::bk_interchanges ( const std::vector< int > & ipiv)
inline

The interchanges ipiv records, in the order the factorization made them.

◆ block_mult_decode()

template<typename Accumulator, typename S, typename VIn, typename VOut>
void mtl::detail::block_mult_decode ( const mat::block_matrix_view< S > & A,
const VIn & x,
VOut & y )

y = A x by decode-then-dot, rows partitioned across the thread pool.

◆ block_mult_rows()

template<typename Accumulator, typename S, typename VIn, typename VOut>
void mtl::detail::block_mult_rows ( const mat::block_matrix_view< S > & A,
const VIn & x,
VOut & y,
std::size_t rb,
std::size_t re,
std::vector< float > & buf )

y[rb, re) = A x for a block matrix: decode one row into buf, then dot it with x.

The row is decoded once whatever x is; the dot is SIMD when x is contiguous float, and the generic fused loop otherwise.

◆ block_quotient()

template<typename T>
T mtl::detail::block_quotient ( const T & x,
const T & y )

Solve the p*q unknowns of a p x p block a and a q x q block b (p, q <= 2),.

a y + sgn y b = scaloc * rhs,

written as the Kronecker system (I_q (x) a + sgn b^T (x) I_p) vec(y) = vec(rhs), by Gaussian elimination with complete pivoting, as LAPACK's dlasy2 does. A pivot no larger in magnitude than smin is replaced by smin; the return value says whether that happened. On return rhs holds y.

scaloc is 1 unless scaled and a division in the back substitution would exceed lim.bignum. Then the right-hand side, and the part of y already computed, are scaled by a power of two that brings the dividend to at most 1, as LAPACK's 1x1 case does with 1 / |dividend|; scaloc is the product of those factors. x / y, by Smith's algorithm for a complex T: a standard library may divide a std::complex naively, through |y|^2, which overflows for y near (0.8 max, 0.8 max) and gave 0 on MSVC's (review of #990).

◆ block_scratch_alignment()

template<typename S>
std::size_t mtl::detail::block_scratch_alignment ( )
constexprnoexcept

◆ c_strip_mc_cap()

std::size_t mtl::detail::c_strip_mc_cap ( std::size_t l2_bytes,
std::size_t kc,
std::size_t n,
std::size_t nc,
std::size_t sdata,
bool charge_a = true )
constexpr

The largest mc for which the packed A block AND the strip of C it accumulates both fit in L2.

Returns 0 for "no bound" on degenerate input.

WHY THIS IS A RUNTIME BOUND AND NOT PART OF THE MODEL (#453). derive_blocking sizes mc so the A block mc x kc fills about half of L2 and counts nothing else, while the same cache simultaneously holds the C strip the ic block is accumulating into. The obvious repair – add the C term to the compile-time model – is FALSIFIED by its own calibration point: the strip there has to be mc x nc, since n is unknown, and reproducing the shipped mc = 64 then needs

mc * (kc + nc) * sizeof <= 8.5 * L2

which is not a residency statement at all, and a different family of hardware needs 2.5 rather than 8.5. The model cannot be fixed with a constant.

The reason is that the strip is mc x min(n, nc), not mc x nc – and n is known exactly HERE, at the call, which is already where mc is capped for the thread budget. On an i7 (L2 = 1.25 MB, kc = 256) this yields 128 at n = 1024, where the shipped mc = 64 is untouched, and 37 at n = 4096, where the measurements preferred a smaller mc than the model chose (#430: the 4096^2 single-thread point was the one place a smaller-mc arm WON, at 1.029). charge_a decides whether the packed A block is charged against the same budget. MEASURED, not assumed (Xeon E5-2420, 6 cores, 6 rounds):

shape      T   default mc   A+C      C alone   fits L2?   ccap ratio
2048^2     6      32        640K      512K       NO         1.151
4096^2     6      32        640K      512K       NO         1.158
1024^2     6      29        348K      232K       yes        0.854
96x4096    6      16        320K      256K       yes        0.832

Charging A+C fires whenever the pair exceeds L2 – but every WIN is a shape where C ALONE exceeds it, and every LOSS is a shape where C already fitted and the bound only shrank mc for nothing. So A does not belong in the budget: it is streamed into the packed buffer and consumed once per jc block, while C is read-modify-written across the whole kc loop and is the operand that has to stay resident.

◆ cabs1() [1/2]

template<typename R>
R mtl::detail::cabs1 ( const std::complex< R > & z)

|re z| + |im z|: LAPACK's CABS1, the cheap norm zlahqr's tests use.

◆ cabs1() [2/2]

template<typename T>
magnitude_t< T > mtl::detail::cabs1 ( const T & z)
constexpr

LAPACK's CABS1: |Re z| + |Im z|.

Within a factor of sqrt(2) of |z| and free of the sqrt/hypot that abs() would cost – which is what a structural noise threshold wants, since the threshold itself is only order-of-magnitude. The prepass is O(n^2) against an O(n^3/3) factorization, so avoiding a hypot per entry matters at small n.

◆ check_random_bounds()

template<typename T>
void mtl::detail::check_random_bounds ( const T & lo,
const T & hi,
const char * who )

Throws unless lo and hi are finite and lo <= hi.

x - x is 0 only for a finite x (inf - inf and NaN - NaN are NaN), which works for any number type.

◆ cholesky_factor_acc()

template<typename Accumulator, typename M>
int mtl::detail::cholesky_factor_acc ( M & A)

The accumulator A = L*L^H loop (#585): each entry is assign(A(i,j)), then add_product(-L(i,k), conj(L(j,k))) for k < j, rounded once.

For a real element type conj is the identity and this is A = L*L^T. The pivot is the real part of its round-out, tested for positivity before the square root. Rows i > j are split over the pool as on the void path, bit-identically.

◆ cholesky_factor_generic()

template<typename Ordering, typename M>
int mtl::detail::cholesky_factor_generic ( M & A)

The generic (non-LAPACK) A = L*L^T loop, in either summation order (#556).

tag::subtract_sum L(i,j) = (A(i,j) - sum_k L(i,k) L(j,k)) / L(j,j) tag::subtract_term_by_term s = A(i,j); s = s - L(i,k) L(j,k), k = 0..j-1; L(i,j) = s / L(j,j)

and the same two forms for the pivot. The products and the order of k are the same in both; only where the matrix entry enters the sum differs, so the two round differently and neither is more accurate across the board (docs/numerical/summation-order-in-cholesky.md).

◆ cholesky_solve_acc()

template<typename Accumulator, bool Conj, typename M, typename VecX, typename VecB>
void mtl::detail::cholesky_solve_acc ( const M & L,
VecX & x,
const VecB & b )

The two substitutions of an L*L^H (Conj = true) or L*L^T (false) solve, with each row's b(i) - sum of products formed in Accumulator and rounded once.

◆ cmod()

template<typename R>
R mtl::detail::cmod ( const std::complex< R > & z)

|z|, without overflow in the squares (dlapy2).

◆ column_sweep_unrolled()

template<std::size_t C, typename T>
bool mtl::detail::column_sweep_unrolled ( std::size_t ld)
constexpr

Whether a sweep with C columns per pass over columns ld elements of T apart takes the unrolled path (strip_columns<C>) rather than sweep_columns<1>.

◆ complete_orthonormal()

template<typename Accumulator = void, typename value_type>
void mtl::detail::complete_orthonormal ( mat::dense2D< value_type > & U,
typename mat::dense2D< value_type >::size_type filled )

Completes the columns [filled, ncol) of U (m x ncol, m >= ncol) to an orthonormal set, given that columns [0, filled) are already orthonormal.

Used for the left singular vectors that one-sided Jacobi does not determine: those of zero singular values and, for the full U, the columns beyond rank n.

◆ complex_qr()

template<typename R>
void mtl::detail::complex_qr ( mat::dense2D< std::complex< R > > & H,
mat::dense2D< std::complex< R > > & Z,
const complex_qr_options< R > & opt )

zlahqr with wantt and wantz on the whole matrix: H upper Hessenberg on entry, upper triangular on return, and every transformation applied to Z from the right.

Throws std::runtime_error if the iteration does not converge in 30 max(10, n) iterations per eigenvalue, as zlahqr's info > 0.

◆ congruence_second()

template<typename Accumulator = void, typename S, typename MT, typename MA, typename MC>
void mtl::detail::congruence_second ( const S & alpha,
const MT & T,
const MA & A,
const S & beta,
MC & C )

The second product of a congruence, C = alpha * T*A^T + beta*C, lower triangle mirrored.

A CSR A goes to gemmt as trans(A), which walks its rows. So does a dense A that ?gemmt takes, through its transb argument, and one the blocked path takes above gemmt_block rows, by its strides (#744). Any other dense A is copied out as A^T first: an O(mn) copy that lets a row-major C take gemmt's i-k-j form, where trans(A) would walk a column of A per entry. The entries summed, and their order, are the same either way.

◆ contract_abort()

void mtl::detail::contract_abort ( const char * what)
inlinenoexcept

A broken contract on a path that cannot throw (a noexcept move): print the message and abort, in every build.

For the cases that used to be an assert and, under NDEBUG, carried on doing something wrong (#856).

◆ copy_between_spaces()

template<typename SrcSpace, typename DstSpace, typename T>
void mtl::detail::copy_between_spaces ( typename handle_traits< SrcSpace, T >::const_handle_type src,
typename handle_traits< DstSpace, T >::handle_type dst,
std::size_t n )

Copy n elements of trivially copyable T between two memory spaces, through the runtime that owns the device side (see the header comment).

Each side is named by its space's handle (#1017): a pointer, or an object such as a Metal buffer and offset, which the runtime's copy_bytes accepts as it is.

◆ critical_panels()

std::size_t mtl::detail::critical_panels ( std::size_t m,
std::size_t mc,
unsigned ic_nt,
std::size_t mr )
constexprnoexcept

Default GEMM thread count: the persistent pool's size (env MTL5_NUM_THREADS, clamped to hardware concurrency; 1 when unset/invalid).

Using the pool as the single source of truth guarantees the GEMM's team never exceeds the pool. Micro-panels on the busiest thread of a round-robin ic partition: blocks of mc rows handed to ic_nt threads in turn, each block costing ceil(rows / mr) panels because the micro-kernel computes whole mr-row tiles. This, not the block count, is the threaded nest's critical path (#458).

Closed form, so the planner allocates nothing: thread 0 always holds the most blocks, ceil(nib / ic_nt) of them, and the only block shorter than mc is the last, which lands on a thread holding that many. The busiest thread is shortened by it only when it is the ONLY thread holding that many.

◆ csqrt()

template<typename R>
std::complex< R > mtl::detail::csqrt ( const std::complex< R > & z)

The principal square root of z: the root with a non-negative real part.

t = sqrt((|x| + |z|) / 2) is formed as sqrt(|x| + |z|) sqrt(1/2), so that halving a subnormal |x| + |z| cannot round it to zero and leave t = 0 to divide by (review of #990). Where |x| + |z| overflows, the halves are added instead, which is safe there. A part above a quarter of the largest finite value would overflow |z| itself, so z is then scaled by 1/4, exactly, and the root by 2 (review of #992). That is one step, not a recursion: an infinite part stays infinite under scaling, and gives a non-finite root.

◆ deallocate_aligned()

template<typename T>
void mtl::detail::deallocate_aligned ( T * p,
std::size_t n )
noexcept

Destroy n elements and free a block from allocate_aligned. No-op on nullptr.

◆ default_eigen_tolerance()

template<typename Real>
Real mtl::detail::default_eigen_tolerance ( )

Default tolerance of the symmetric eigensolvers: the machine epsilon of the eigenvalue type.

A custom scalar without a std::numeric_limits specialization gets epsilon() == Real{}, i.e. zero, and a zero tolerance only deflates subdiagonal entries that are exactly zero – the iteration can then run out of max_iter (which throws, #853). For such a type machine_epsilon measures the epsilon instead (detail/unit_roundoff.hpp).

◆ dense_copy()

template<typename M>
mat::dense2D< typename M::value_type > mtl::detail::dense_copy ( const M & A)

An owning dense copy of a matrix operand, in its own element type: what an expression operand is evaluated into before a kernel that writes C runs.

A sparse expression is densified too: mult(S + S, B, C) or mult(2.0 * S, B, C) with a compressed2D S allocates an m x k dense2D, where the operand was once read lazily. That is the chosen trade (issue 909, option a): the copy is what lets storage_overlaps see the operand's storage, so that mult(S, C + C, C) cannot read C while writing it (issue 886). A caller with a large sparse expression forms the sparse matrix itself first (there is no expression-to-compressed2D evaluation): a copy of S with its values scaled for 2.0 * S, or an inserter for a sum. A compressed2D operand is not copied.

◆ first_element_address()

template<typename T>
auto mtl::detail::first_element_address ( const T & t)

The host address of a collection's first element: data() where that is the elements' address, and otherwise begin(), for a container in a host-accessible space whose handle is not an element pointer (#1017).

◆ for_each_entry()

template<typename M, typename F>
void mtl::detail::for_each_entry ( const M & m,
F && f )

Calls f(r, c, a) for every element a = m(r, c) that can be nonzero, in an order that suits the storage: a compressed2D's stored entries row by row (its operator() is a binary search, so the full m x n loop was O(m n log nnz) for an O(nnz) answer); a column-major matrix column by column; any other matrix row by row.

Within a row (column) the order is by column (row), as the m x n loop has it.

◆ for_each_storage_range()

template<typename T, typename F>
void mtl::detail::for_each_storage_range ( const T & t,
F && f )

Calls f(lo, hi) for each byte range a collection's elements live in, looking through views: a contiguous collection's elements; a compressed or ELL matrix's value array; a coordinate matrix's triplets; each block of a block-diagonal matrix; a block matrix view's encoded bytes; a view's base.

Nothing for a type with none of these (an expression).

◆ francis_qr()

template<francis_output Output, typename T>
void mtl::detail::francis_qr ( mat::dense2D< T > & H,
mat::dense2D< T > * Z,
vec::dense_vector< T > & wr,
vec::dense_vector< T > & wi,
const francis_options< T > & opt )

Francis implicit double-shift QR on the upper Hessenberg H (EISPACK hqr / hqr2).

Fills wr, wi (size n) with the eigenvalues.

francis_output::eigenvalues: eigenvalues only. Each sweep touches only the active block, and H is left as working storage. This is the loop eigenvalue() has always run, operation for operation.

francis_output::schur_form: H is reduced to the real Schur form T. Every transformation is applied to the whole of T and, when Z != nullptr, accumulated into Z's columns, so A = Z T Z^T holds for the Z and H that came in as A = Z H Z^T. Each 2x2 block is put into standard form by lanv2(), the exceptional shift is added back to the diagonal as each block converges, and an exceptional shift is taken every ten sweeps. Entries below the subdiagonal are left for the caller to clear.

Throws std::runtime_error when an eigenvalue takes more than max_its sweeps.

◆ fused_evaluate()

template<typename Dest, typename Expr>
mat::dense2D< typename Dest::value_type > mtl::detail::fused_evaluate ( const Expr & expr)

expr evaluated into a dense matrix of Dest's value type.

◆ fused_reads_dest_elsewhere()

template<typename Dest, typename Expr>
bool mtl::detail::fused_reads_dest_elsewhere ( const Dest & dest,
const Expr & expr )

Whether writing expr into dest element by element could read an element of dest other than the one being written (issue 887): the test dense2D's operator= makes (#824).

A target whose element storage can't be seen is assumed to be read.

◆ gemm_blocked()

template<typename TC, typename TA = TC, typename TB = TA, gemm_kernel Kern = gemm_kernel::widening>
requires (mtl::Scalar<TC> && mtl::Scalar<TA> && mtl::Scalar<TB>)
void mtl::detail::gemm_blocked ( std::size_t m,
std::size_t n,
std::size_t k,
TC alpha,
const TA * A,
std::ptrdiff_t a_rs,
std::ptrdiff_t a_cs,
const TB * B,
std::ptrdiff_t b_rs,
std::ptrdiff_t b_cs,
TC beta,
TC * C,
std::size_t ldc,
unsigned nthreads = 1,
nc_model model = nc_model_selection() )

The blocked GEMM, on the tile this machine runs (see gemm_blocked_tiled for the contract).

On a scalable SIMD target a same-type float or double GEMM takes the vla_tile matching the hardware's lane count and the scalable micro-kernel (#427); everything else, batch's tile and micro-kernel.

◆ gemm_blocked_tiled()

template<typename TC, typename TA, typename TB, gemm_kernel Kern, typename Tile>
requires (mtl::Scalar<TC> && mtl::Scalar<TA> && mtl::Scalar<TB>)
void mtl::detail::gemm_blocked_tiled ( std::size_t m,
std::size_t n,
std::size_t k,
TC alpha,
const TA * A,
std::ptrdiff_t a_rs,
std::ptrdiff_t a_cs,
const TB * B,
std::ptrdiff_t b_rs,
std::ptrdiff_t b_cs,
TC beta,
TC * C,
std::size_t ldc,
unsigned nthreads,
nc_model model )

C[m x n] (row-major, leading dim ldc) := beta*C + alpha * A[m x k] * B[k x n].

A,B addressed by generic strides (see file header). ldc must be >= n.

◆ gemm_blocking()

template<typename TC>
simd::blocking_params mtl::detail::gemm_blocking ( )
inline

The register tile and compile-time blocks a same-type TC GEMM runs with on this machine: simd::default_blocking<TC>, except on a scalable target, where it is the vla_tile's (#427).

What gemm_plan_for is consistent with.

◆ gemm_default_threads()

unsigned mtl::detail::gemm_default_threads ( )
inline

◆ gemm_microkernel()

template<typename TC, typename TAB, std::size_t MR, std::size_t NR>
void mtl::detail::gemm_microkernel ( std::size_t kc,
const TAB * Ap,
const TAB * Bp,
TC * C,
std::size_t ldc )

◆ gemm_plan_for()

template<typename TC, typename TB = TC, std::size_t KGroup = 1>
gemm_plan mtl::detail::gemm_plan_for ( std::size_t m,
std::size_t n,
unsigned nthreads,
nc_model model = nc_model_selection() )
inline

The plan gemm_blocked runs for a same-type GEMM (TC, operand type TB) on this machine: on a scalable target, the vla_tile the hardware's lane count selects (#427), so what is reported is what the nest steps.

◆ gemm_plan_for_tiled()

template<typename TC, typename TB, std::size_t KGroup, typename Tile>
gemm_plan mtl::detail::gemm_plan_for_tiled ( std::size_t m,
std::size_t n,
unsigned nthreads,
nc_model model )
inline

The plan gemm_blocked<TC> will follow for an m x n problem on nthreads.

Reads its parameters from exactly the places the nest reads them, so a caller that records this records what ran.

model defaults to the process selection rather than to M0 so that a caller which records the plan records the plan that will RUN. Defaulting to M0 here would give a benchmark harness a recording function that silently disagreed with the nest the moment MTL5_NC_MODEL was set – which is the whole point of the variable – and the CSV would carry the baseline's blocking against the model's timings.

◆ gemm_quad_microkernel()

template<typename TC, typename TA, typename TB, std::size_t MR, std::size_t NR>
void mtl::detail::gemm_quad_microkernel ( std::size_t kp,
const TA * Ap,
const TB * Bp,
TC * C,
std::size_t ldc,
TC alpha )

Accumulate an MR x NR tile of C from quad-interleaved packed panels:

C(i, j) += alpha * sum_{p < kp} A(i, p) * B(p, j)

kp is the panel depth, a multiple of four (quad_depth(kc)); the packing zero-pads the k tail up to it, and a zero operand contributes a zero product, so no size check reaches the inner loop. Ap and Bp are laid out by pack_A_quad / pack_B_quad. C is row-major with leading dimension ldc, and this is the ACCUMULATE form – the caller zeroes or pre-scales it.

ALPHA IS APPLIED HERE, on the way out, and not folded into the packed A panel the way the pairwise nest does it. Folding is wrong for this kernel by construction: the panel holds 8-bit operands, so alpha * A would be truncated back into a byte before it ever reached the accumulator. Scaling the int32 tile instead is exact (mod 2^32, like everything here) and costs one multiply per C element per kc block, which is O(1/kc) of the work.

◆ gemm_runtime_blocking()

template<typename TC>
const simd::blocking_params & mtl::detail::gemm_runtime_blocking ( )
inline

The detected-cache blocks of that tile: simd::runtime_blocking<TC>() except on a scalable target (#427).

◆ gemmt_describe()

template<typename M>
auto mtl::detail::gemmt_describe ( const M & X)

◆ gemmt_describe_mut()

template<typename M>
auto mtl::detail::gemmt_describe_mut ( M & X)

◆ gemmt_triangle()

template<typename Accumulator, typename Value, typename S, typename MC, typename Terms>
void mtl::detail::gemmt_triangle ( const S & alpha,
const S & beta,
MC & C,
uplo t,
Terms terms )

The generic triangle loop.

terms(i, j, f) calls f(a, b) for each product of entry (i, j) in ascending k; this function owns the summation, the accumulator and the alpha/beta combine.

◆ gemv_colmajor()

template<typename T>
requires mtl::Scalar<T>
void mtl::detail::gemv_colmajor ( std::size_t m,
std::size_t n,
const T * A,
std::size_t lda,
const T * x,
T * y )

y[m] := A[m x n] * x[n], A col-major (columns contiguous, lda = m).

The rows are swept in STRIPS of S rows (64 KB of y), and each strip walks down the columns, reading S contiguous elements of each, a few columns per pass (#804). The kernel before it held only 4 batches of y in registers (16 rows of f64 under AVX2) and swept all n columns for them, so every load came from a different column: at n = 4096 each strip touched 4096 cache lines on 4096 pages, and native-fast ran 2.2-5x slower than the generic build's column sweep (#777).

The strip is 64 KB, not the 16 KB that keeps it in L1, because the length of each contiguous run down a column matters more than where y lives: on a Cortex-A78 (Jetson Orin) f64 at n = 4096 took 23.5 ms with 16 KB strips and 17.2 ms with 64 KB ones, and no machine measured got slower. Columns per pass: gemv_colmajor_columns.

Each y[i] sees the same FMA chain, in ascending column order from zero, as the register-strip kernel gave it, so the result is independent of how the caller partitions the rows across threads. That includes the last m mod W rows, which run one at a time through simd::scalar_fma, the batch's own fma on one lane (#840). They used a separate multiply and add, so a row's rounding depended on whether it fell in the SIMD part or the tail.

◆ gemv_panel()

template<typename T>
requires mtl::Scalar<T>
void mtl::detail::gemv_panel ( bool row_major,
std::size_t ld,
const T * A,
std::size_t r0,
std::size_t c0,
std::size_t m,
std::size_t k,
const T * x,
T * t )

t[m] := A(r0 : r0+m, c0 : c0+k) * x[k] for a sub-panel of an n-column (row-major) or n-row (column-major) dense matrix at A: the off-diagonal panel of the blocked trmv and trsv (#747).

k may be 0 (t is then zero).

◆ gemv_rowmajor()

template<typename T>
requires mtl::Scalar<T>
void mtl::detail::gemv_rowmajor ( std::size_t m,
std::size_t n,
const T * A,
std::size_t lda,
const T * x,
T * y )

y[m] := A[m x n] * x[n], A row-major (rows contiguous, lda = n).

◆ generic_abs()

template<typename T>
auto mtl::detail::generic_abs ( const T & a)
constexpr

|a|, wrapping, for the norm accumulations (#461).

std::abs IS UB at the minimum of a signed type – there is no positive -2^(N-1) to return – so one_norm(dense_vector<int32_t>) over full-range data is undefined before any accumulation happens. That is a separate defect from the += this pass is fixing, and it is reached by exactly the test the fix requires: full-range operands include the minimum.

The wrapping answer is the minimum itself, since 2^(N-1) reduced mod 2^N is -2^(N-1). Expressed as wrap_sub(0, a) so the narrow types get the same promotion handling as everywhere else in this header – writing the unsigned negation inline would reintroduce the int-promotion trap for int8/int16.

Non-integral types keep using std::abs; abs(a), so the ADL-found abs of a custom number type is still what gets called.

◆ generic_add()

template<typename Result, typename A>
Result mtl::detail::generic_add ( Result acc,
const A & a )
constexpr

acc + a for the generic element-wise loops: wrapping when the result type is integral, the plain expression otherwise (#461).

generic_fma for the loops that accumulate a term they did not form by multiplying – one_norm's acc += abs(v(i)), the column and row sums in the matrix norms, and the scatter in the transposed sparse matvec, where the product was computed at a different point from the addition.

The same operand rule as generic_fma, for the same reason: A is tested with std::is_integral_v, which admits bool, because converting a bool to an integral Result is exact and excluding it would push the expression onto the plain branch and reinstate the UB.

◆ generic_fma()

template<typename Result, typename A, typename B>
Result mtl::detail::generic_fma ( Result acc,
const A & a,
const B & b )
constexpr

acc + a * b for the generic element-wise loops: wrapping when the result type is integral, the plain expression otherwise.

The generic path is where an integer mult lands whenever the native kernel is not selected – which is the DEFAULT build, since MTL5_NATIVE_FAST_GEMM is off – and where a non-contiguous integer vector lands in dot. Both must agree with the SIMD path bit for bit, and neither may be undefined.

The operands are converted to Result BEFORE multiplying, which is what makes the integer case exact mod 2^N rather than merely defined: it is the product that overflows first, not the sum. Narrowing first loses nothing, because reduction mod 2^N is a ring homomorphism – (a mod 2^N)(b mod 2^N) and (a b) mod 2^N agree.

The OPERANDS must be integral too, not just Result. Converting them first is only lossless between integers: with a floating-point operand and an integral result – mult(dense2D<double>, dense_vector<double>, dense_vector<int>) – it would truncate each factor before multiplying and turn 2.5 * 2.5 into 2 * 2, where the plain expression accumulates in the result type and rounds each term once. Those mixed cases keep the original expression.

The operand test is std::is_integral_v, NOT is_wrapping_integer_v. The difference is bool, and it matters in the direction that is easy to get backwards: bool must be excluded as a RESULT type, because std::make_unsigned_t<bool> is ill-formed, but it must be INCLUDED as an operand, because converting it to an integral Result is exact (0 or 1) and excluding it would push the whole expression onto the plain branch – reinstating the signed-overflow UB this helper exists to remove. dot(dense_vector<bool>, dense_vector<int32_t>) is that case.

◆ generic_mul()

template<typename Result, typename A, typename B>
Result mtl::detail::generic_mul ( const A & a,
const B & b )
constexpr

a * b delivered in Result: wrapping when Result is integral, the plain expression otherwise (#461).

The multiply-only counterpart, for scale's *it *= alpha.

NOTE the difference from generic_fma, which deliberately does NOT convert on its non-integral branch: here the conversion is already part of the operation being replaced. *it *= alpha is *it = static_cast<T>(*it * alpha) by the definition of compound assignment, so returning Result preserves the existing rounding rather than adding one.

◆ grid_imbalance()

double mtl::detail::grid_imbalance ( std::size_t blocks,
unsigned workers )
constexprnoexcept

How much of a round-robin partition's capacity the most-loaded worker wastes: ceil(blocks / workers) * workers / blocks, which is 1.0 exactly when the blocks divide evenly and grows as the remainder does.

This is the MEDIATOR #479 turns on. Recording throughput alone can say a model was faster; recording this alongside it is what says the model was faster BECAUSE it balanced the partition. Without it the experiment picks a winner it cannot explain, and the next hardware change starts from zero.

◆ holds_expression()

template<typename T>
bool mtl::detail::holds_expression ( )
constexpr

Whether an operand is, or views, a lazy expression: an expression type, or a view (anything with base(): trans, hermitian, the triangular and banded views) whose base is one.

storage_overlaps finds no storage behind an expression, so such an operand that reads C is not seen to alias it (issue 886): auto E = C + C; gemmt(1, S, trans(E), 0, C).

◆ int_less()

template<typename A, typename B>
bool mtl::detail::int_less ( A a,
B b )
constexprnoexcept

a < b by value, for integral types of any signedness and width.

With the same signedness the usual conversions widen both to the wider type, which preserves values; otherwise the signed side is tested for a negative value first and compared, as unsigned, only when it is not.

◆ is_quad_gemm()

template<typename TC, typename TA, typename TB>
bool mtl::detail::is_quad_gemm ( )
constexpr

Does the (accumulator, A operand, B operand) triple ADMIT the quad kernel?

Necessary for gemm_kernel::quad, never sufficient to select it – see above.

A function rather than a variable template because quad_accumulator_t is undefined for a rejected pairing – notably (int8, uint8), which is absent on purpose so that a caller holding it is told to swap rather than handed the emulated path silently. Naming the trait unconditionally would turn that deliberate absence into an "incomplete type" error at every use site.

◆ keep_scalar()

template<bool Enable, typename T>
void mtl::detail::keep_scalar ( T & v)
inline

An empty asm that keeps v in a scalar register of its own, when Enable.

◆ keep_scalar_row_major()

template<typename M>
bool mtl::detail::keep_scalar_row_major ( )
constexpr

Whether M is a row-major matrix type.

◆ ladiv()

template<typename R>
std::complex< R > mtl::detail::ladiv ( const std::complex< R > & x,
const std::complex< R > & y )

x / y by Smith's algorithm, which divides by the larger of y's parts and so does not overflow in |y|^2 (zladiv).

Its sums reach twice the larger part of the numerator or the denominator: a + b e and c + d e with |e| <= 1. So x and y are each scaled by 1/4 when a part is above max/4, and the quotient by the net factor after; that last step overflows only when the quotient does (review of #990).

◆ lanv2()

template<typename T>
void mtl::detail::lanv2 ( T & a,
T & b,
T & c,
T & d,
T & rt1r,
T & rt1i,
T & rt2r,
T & rt2i,
T & cs,
T & sn,
const lanv2_constants< T > & k )

The Schur factorization of a real 2x2 block in standard form,.

[a b] [cs -sn] [aa bb] [ cs sn] [c d] = [sn cs] [cc dd] [-sn cs]

where cs and sn are the cosine and sine of a plane rotation. On return (a, b, c, d) holds (aa, bb, cc, dd), in one of two forms:

  • cc == 0: the block is upper triangular, and its real eigenvalues are aa and dd.
  • aa == dd and bb*cc < 0: the eigenvalues are the complex pair aa +- i sqrt(-bb*cc).

That is the form LAPACK's gees returns for each 2x2 block, and the form Higham's real square root (sqrtm) relies on.

The eigenvalues are returned as roots of the block's characteristic polynomial, under LAPACK's names: rt1r and rt1i are the real and imaginary parts of root 1, and rt2r and rt2i those of root 2. For a complex pair, rt1i > 0 and rt2i = -rt1i.

Name and origin. This is a port of LAPACK's dlanv2. In LAPACK's naming, the first letter is the arithmetic: s for float, d for double, and c or z for the complex types. "la" marks an auxiliary routine. LAPACK does not expand the remaining letters; the routine handles the nonsymmetric 2x2 case. Here the arithmetic is the template parameter T instead of a letter, so the routine is named lanv2: lanv2<float> is slanv2, lanv2<double> is dlanv2, and lanv2<posit<32,2>> is the same algorithm in posit arithmetic. The local names follow dlanv2 so the two can be compared line by line. They are explained where they are defined.

One change from dlanv2: the scale window comes from lanv2_constants, so a type without numeric_limits skips the rescaling. Fortran's SIGN is with_sign_of().

◆ lapy2()

template<typename T>
T mtl::detail::lapy2 ( T x,
T y )

sqrt(x^2 + y^2) without avoidable overflow or underflow.

This is LAPACK's dlapy2: "la" marks a LAPACK auxiliary routine, "py" Pythagoras, and "2" the two arguments (dlapy3 takes three). std::hypot computes the same thing but only for the built-in floating-point types, so this generic version is used for user-defined types too.

◆ lapy3()

template<typename R>
R mtl::detail::lapy3 ( R x,
R y,
R z )

sqrt(x^2 + y^2 + z^2) without overflow in the squares (dlapy3).

◆ larfg2()

template<typename R>
std::complex< R > mtl::detail::larfg2 ( std::complex< R > & alpha,
std::complex< R > & x,
const R & safmin )

zlarfg for n = 2: the reflector G = I - tau [1; v] [1; v]^H with G^H [alpha; x] = [beta; 0], beta real.

On return alpha is beta and x is v; tau is returned. safmin > 0 enables LAPACK's rescaling of a beta below it (zlarfg's safmin / eps); 0 disables it, for a type without such a minimum.

◆ ldlt_bk_factor_acc()

template<typename Accumulator, typename M>
int mtl::detail::ldlt_bk_factor_acc ( M & A,
bk_pivot_info & pivots )

ldlt_bk_factor's accumulator path: left-looking Bunch-Kaufman (top of file).

◆ ldlt_bk_solve_acc()

template<typename Accumulator, typename M, typename VecX, typename VecB>
void mtl::detail::ldlt_bk_solve_acc ( const M & A,
const bk_pivot_info & pivots,
VecX & x,
const VecB & b )

ldlt_bk_solve's accumulator path (top of file).

◆ ldlt_factor_acc()

template<typename Accumulator, bool Conj, typename M>
int mtl::detail::ldlt_factor_acc ( M & A)

The accumulator loop of ldlt_factor (Conj = false, A = L D L^T) and ldlt_h_factor (Conj = true, A = L D L^H, D real).

Column j first forms v(k) = conj?(L(j,k)) * D(k), once, in the element type; then

D(j) = A(j,j) - sum_k L(j,k) v(k) (real part when Conj) L(i,j) = (A(i,j) - sum_k L(i,k) v(k)) / D(j)

each one accumulator, assigned the matrix entry and rounded once.

◆ ldlt_solve_acc()

template<typename Accumulator, bool Conj, typename M, typename VecX, typename VecB>
void mtl::detail::ldlt_solve_acc ( const M & A,
VecX & x,
const VecB & b,
const char * who )

The three phases of an LDL^T (Conj = false) or LDL^H (true) solve, with each row's b(i) - sum of products formed in Accumulator and rounded once.

◆ lower_trisolve_column_sweep()

template<std::size_t S, std::size_t C = column_sweep_columns, typename M, typename VecX, typename VecB>
void mtl::detail::lower_trisolve_column_sweep ( const M & L,
VecX & x,
const VecB & b,
bool unit_diag )

The default-accumulator forward substitution on a contiguous column-major L, S rows per strip, top-down (#777; see detail/column_sweep.hpp).

A strip of rows [r0, r1) first adds the columns j < r0, which are already solved, one column at a time down the strip. Then its diagonal block goes column by column: row j is solved, and its x(j) is added to the strip's rows below it. Every row still sums L(i, j) x(j) in ascending j with the same expressions as the one-row loop, so x is bit-identical to it. The in-place overload passes x as b: b(j) is read when row j is solved, before anything writes x(j).

The solved columns j < r0, and the diagonal block's columns below each group of C, go C at a time (#884, see column_sweep_columns); C = 1 is the sweep as #777 wrote it.

◆ lower_trisolve_rows()

template<std::size_t W, typename M, typename VecX, typename VecB>
void mtl::detail::lower_trisolve_rows ( const M & L,
VecX & x,
const VecB & b,
bool unit_diag,
typename M::size_type i = 0 )

The default-accumulator forward substitution on rows [i, n), W rows per block (#749, #772).

Rows i0..i0+W-1 sum their shared columns j < i0, which are already solved, together: W independent chains instead of one serial reduction, which hides the add latency. Then the W x W diagonal block finishes in order: row i0 completes, row i0+1 adds its term in x(i0) and completes, and so on. Every row still sums the same terms in ascending j with the same expressions, so x is bit-identical to the one-row loop for every W. The in-place overload passes x as b: x(i) is read before row i writes it, as before. The rows left over go to W / 2, down to W = 1, which is the one-row loop.

◆ lu_factor_acc()

template<typename Accumulator, typename M>
int mtl::detail::lu_factor_acc ( M & A,
std::vector< typename M::size_type > & pivot )

lu_factor's accumulator path: left-looking LU with partial pivoting.

At step k it forms column k of the Schur complement (rows i >= k), pivots on it, forms row k of U (columns j > k), then scales column k into L. Every entry is one accumulator: assign the matrix entry, add each -L(i,p) * U(p,j), round once – the form the sparse LU uses (#530).

The entries of a column, and of a row, are independent, so each loop is split over the pool; the result is bit-identical to serial.

◆ machine_epsilon()

template<typename Real>
requires std::numeric_limits<Real>::is_specialized
Real mtl::detail::machine_epsilon ( )

The machine epsilon of Real: the spacing of Real's values at 1, from std::numeric_limits.

Every MTL5 element type has a specialization (#838); a measured fallback for types without one was removed with that rule.

◆ make_complex_qr_options()

template<typename R>
complex_qr_options< R > mtl::detail::make_complex_qr_options ( std::size_t n,
const char * who )

The options for R: the deflation floor and larfg2's rescaling use R's numeric_limits minimum only when it is a safe minimum in LAPACK's sense, below the epsilon, which excludes fixed point (as schur() does for reals).

◆ make_lanv2_constants()

template<typename T>
lanv2_constants< T > mtl::detail::make_lanv2_constants ( )

◆ make_sylvester_limits()

template<typename R>
sylvester_limits< R > mtl::detail::make_sylvester_limits ( std::size_t m,
std::size_t n,
const R & eps )

◆ max_propagating_nan()

template<typename Mag>
void mtl::detail::max_propagating_nan ( Mag & result,
const Mag & a )

result = max(result, a), but a NaN a makes the result NaN and keeps it there (#690).

A plain a > result skips a NaN, so infinity_norm({1, NaN, 2}) gave 2 while one_norm gave NaN. For an integer a != a is always false. A magnitude type without != keeps the plain maximum.

◆ mirror_triangle()

template<typename MC>
void mtl::detail::mirror_triangle ( MC & C,
uplo t )

Copy the t triangle of the n x n matrix C across the diagonal.

In 8 x 8 tiles, so that the side read along a row and the side written down a column stay in cache together (#744). A plain double loop writes one cache line per element on the column side, and when the leading dimension is a power of two those lines all fall in the same few L1 sets: at n = 1024 it took 1.4 ms, against 0.25 ms at n = 1000, more than a tenth of a blocked gemmt. Small tiles cut that by a third at n = 512 and 1024 and lose little elsewhere; larger ones did worse at powers of two. The entries copied are the same.

◆ mult_acc_panel_row()

template<std::size_t W, std::size_t Nr, typename Accumulator, typename AT, typename Value, typename MA, typename MC>
void mtl::detail::mult_acc_panel_row ( const MA & A,
MC & C,
std::size_t r,
std::size_t j0,
std::size_t kdim,
const Value * panel )

One row of C, columns [j0, j0 + W), against a packed panel of W columns of B.

panel[k * Nr + jj] holds B(k, j0 + jj) in the operands' common type.

◆ mult_acc_panel_rows()

template<typename Accumulator, Matrix MA, Matrix MB, Matrix MC>
void mtl::detail::mult_acc_panel_rows ( const MA & A,
const MB & B,
MC & C,
std::size_t rb,
std::size_t re )

Accumulator-typed mat*mat over the OUTPUT ROW RANGE [rb, re) of C, through a packed panel of B (#587).

This is what mult<Acc> runs on dense operands when acc_panel_gemm_v holds.

The dot-product form in mult_generic_rows reads B(k, c) down a column for every C(r, c). Once B leaves cache every term of a row-major B misses, and at n = 1024 that bound mult<double> at 546 MMAC/s against 7447 for the default i-k-j kernel. Here a panel of acc_panel_width columns of B is copied once, k-major and already converted to Value, and every row of the band sweeps it with one accumulator per column: the k loop is unit-stride, and the columns' accumulators are independent chains the core overlaps.

BIT-IDENTICAL to mult_generic_rows, by construction rather than by luck: each C(r, c) still gets clear, then add_product(A(r,k), B(k,c)) for k = 0, 1, ..., K-1 in ascending order, then one value<Result>. Only the interleaving between DIFFERENT entries changes, and no entry reads another's accumulator. The packed value is static_cast<Value>(B(k, c)), the same conversion the reference applies per term. So every accumulator, rounding ones included, gives the same C, at every thread count (#446, #584).

Packing costs O(K * N) per row band against O(band * K * N) work. The panel holds K * min(nr, N) values: a ragged last panel is packed at its own width, so a narrow C (one column, long K) does not reserve nr columns it never uses.

◆ mult_generic() [1/2]

template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mtl::detail::mult_generic ( const M & A,
const VIn & x,
VOut & y )

Generic mat*vec: y = A * x.

With an explicit Accumulator, each y element is summed in that precision and rounded out (fused convert) to y's element type.

Stays SERIAL by name: two GEMM tests use this as the naive reference kernel a fast path is compared against, and a reference that silently threads is no longer a reference. mult_generic_par is the threading entry point.

◆ mult_generic() [2/2]

template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mtl::detail::mult_generic ( const MA & A,
const MB & B,
MC & C )

Generic mat*mat: C = A * B.

With Accumulator = void (default) each C element is summed in C's own value type (unchanged). With an explicit Accumulator, the inner product is summed in that precision via mtl::math::accumulator_traits and the result is rounded out (fused convert) to C's element type on store – the Element -> Accumulate -> Result model, with the result type inferred from C.

Serial, for the same reason as the mat*vec overload: this is the naive triple loop tests compare a fast path against.

◆ mult_generic_par() [1/2]

template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mtl::detail::mult_generic_par ( const M & A,
const VIn & x,
VOut & y )

mat*vec: y = A * x, output rows partitioned across the pool when A, x and y are plain dense storage and there is more than one chunk's worth of work.

Bit-identical to mult_generic in every case.

◆ mult_generic_par() [2/2]

template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mtl::detail::mult_generic_par ( const MA & A,
const MB & B,
MC & C )

mat*mat: C = A * B, output rows of C partitioned across the pool when A, B and C are plain dense storage and there is more than one chunk's worth of work.

Bit-identical to mult_generic in every case.

◆ mult_generic_rows() [1/2]

template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mtl::detail::mult_generic_rows ( const M & A,
const VIn & x,
VOut & y,
std::size_t rb,
std::size_t re )

Generic mat*vec over the OUTPUT ROW RANGE [rb, re): the loop body of mult_generic below, split out so a threaded caller can hand one contiguous band of rows to each worker (#446).

Each y(r) is an independent dot product read out of A and x and written nowhere else, so a partition of [0, num_rows()) into bands computes exactly the values the whole-range call would, in exactly the same summation order – the result is bit-identical to the serial loop, not merely close to it. Preconditions the serial call already had: y must not alias A or x.

The dimension assertions are mult's, restated. They are not redundant paperwork: with assertions live they are also the only place the optimizer learns that these extents agree, and losing them across the extra call layer this refactor introduced measured as a 1.8x slowdown of the serial kernel on a class-typed scalar (-O2 without NDEBUG; every optimized CMake config defines NDEBUG and was unaffected). A row band is a band of the SAME matrices, so every equality still holds inside it.

◆ mult_generic_rows() [2/2]

template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mtl::detail::mult_generic_rows ( const MA & A,
const MB & B,
MC & C,
std::size_t rb,
std::size_t re )

Generic mat*mat over the OUTPUT ROW RANGE [rb, re) of C – the mat*mat counterpart of mult_generic_rows above, with the same bit-identity argument: C(r, c) is written by whichever band owns row r, out of an inner k loop that does not depend on the band.

C must not alias A or B. The assertions are mult's, restated here for the reason given on the mat*vec overload above.

◆ mult_mat_via_temporary()

template<typename MC, typename F>
void mtl::detail::mult_mat_via_temporary ( MC & C,
F && compute )

C = op(A, B) through a temporary of C's own type, then copy-assigned into C, which writes a non-owning C's buffer in place (#833).

For a C that shares storage with an input: the kernels write C while they still read A and B.

◆ mult_rows_column_sweep()

template<std::size_t S, std::size_t C = column_sweep_columns, typename M, typename VIn, typename VOut>
void mtl::detail::mult_rows_column_sweep ( const M & A,
const VIn & x,
VOut & y,
std::size_t rb,
std::size_t re )

The default-accumulator mat*vec rows [rb, re) on a contiguous column-major A, S rows per strip (#777; see detail/column_sweep.hpp).

Row r sums generic_fma<Result>(acc, A(r, c), x(c)) for c ascending from zero, as the one-row loop does, so y is bit-identical to it.

C columns per pass (#884, see column_sweep_columns), and a strip of at most column_sweep_fixed_rows rows in registers (strip_columns). C = 1 is the sweep as #777 wrote it, kept for bench_column_sweep: one column per pass, every strip at run time. The bits are the same for any C.

◆ mult_rows_interleaved()

template<std::size_t W, typename M, typename VIn, typename VOut>
void mtl::detail::mult_rows_interleaved ( const M & A,
const VIn & x,
VOut & y,
std::size_t rb,
std::size_t re )

The default-accumulator mat*vec rows [rb, re), W rows per pass over x, one accumulator each (#749, #772).

W independent chains instead of one serial reduction hide the add latency a single row is bound by. Each row sums the same terms in ascending c with the same expression as the one-row loop, so y is bit-identical for every W; W only sets the speed. The rows left over go to W / 2, and so on down to W = 1, which is the one-row loop.

The accumulators are an array indexed only by the pack K, never by a run-time index, so the compiler keeps each one in a register.

◆ mult_sparse_csr()

template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mtl::detail::mult_sparse_csr ( const mat::compressed2D< V, P > & A,
const VIn & x,
VOut & y )

Sparse CSR mat*vec: y = A * x, iterating only stored nonzeros.

Mirrors mat::operator*(compressed2D, dense_vector)'s traversal but adds Accumulator support (accumulator_traits), so mixed-precision / quire accumulation works on sparse matrices too, not just dense ones.

Serial; mult_sparse_csr_par is the threading entry point.

THIS LOOP IS DUPLICATED from mult_sparse_csr_rows above, deliberately, and the duplication is worth more than it costs. Expressing it as a whole-range call to the row-range kernel – the shape the dense path uses – measured 6.5% SLOWER here (0.004396s -> 0.004681s, n=200000 nnz=2.4M, min of 5): starting the loop at a parameter rather than a literal 0 costs the optimizer something on the starts[r] / starts[r+1] pair the CSR traversal indexes with, and the restated assertions that recovered the dense case did not recover this one. That 6.5% lands on dense_vector<double> SpMV at MTL5_NUM_THREADS=1, which is the default and is the inner loop of every Krylov iteration in itl/ – the one place in this file where a few percent is not a rounding error. The threaded path has no such constraint: it is already paying for a pool handoff.

Keep the two bodies in step. They are the same arithmetic, and a test asserts they agree exactly.

◆ mult_sparse_csr_any()

template<typename Accumulator, typename V, typename P, typename MB, typename MC>
void mtl::detail::mult_sparse_csr_any ( const mat::compressed2D< V, P > & A,
const MB & B,
MC & C )

Sparse (CSR) A times any B into any dense C (issue 886): column-major dense B or C, a compressed B, and mult<Accumulator>.

For each C(r, c), the stored entries (k, v) of A's row r in ascending k, so the terms and their order are mult_generic_rows' with A's unstored zeros left out (exactly the dense result when those terms are exact zeros, as for mult_sparse_csr_dense_rows). mult_generic_rows read A(r, k) by binary search for every (r, c, k): O(m n K log nnz).

◆ mult_sparse_csr_dense_par()

template<typename V, typename P, typename MB, typename MC>
void mtl::detail::mult_sparse_csr_dense_par ( const mat::compressed2D< V, P > & A,
const MB & B,
MC & C )

mult_sparse_csr_dense_rows over all rows, threaded over row bands like mult_sparse_csr_par (each output row is one band's, so the result does not depend on the thread count).

◆ mult_sparse_csr_dense_rows()

template<typename V, typename P, typename MB, typename MC>
void mtl::detail::mult_sparse_csr_dense_rows ( const mat::compressed2D< V, P > & A,
const MB & B,
MC & C,
std::size_t rb,
std::size_t re )

Sparse (CSR) x dense mat*mat over the OUTPUT ROW RANGE [rb, re) of C (#550): C.row(r) = sum over A's stored entries (k, v) of row r, in ascending k, of v * B.row(k).

Each C(r, c) is zero + v_k0*B(k0,c) + v_k1*B(k1,c) + ... – the dense product's order with A's unstored (zero) terms left out, so it equals the dense result whenever those terms are exact zeros. B and C row-major dense; C must not alias B.

◆ mult_sparse_csr_par()

template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mtl::detail::mult_sparse_csr_par ( const mat::compressed2D< V, P > & A,
const VIn & x,
VOut & y )

Sparse CSR mat*vec with the output rows spread over the pool.

mat::operator*(compressed2D, dense_vector) has threaded this same traversal for any value type since #221; this is the accumulator-aware entry point catching up, so mult(compressed2D, x, y) and A * x no longer disagree about whether a sparse matvec uses the machine.

GRAIN IS AVERAGED, and for a sparse matrix that is an approximation rather than a measurement: a row's cost is its own nnz, so contiguous bands sized off nnz/nrows balance well for a banded or roughly regular matrix and badly for a power-law one, where a handful of dense rows can dominate a band. Averaging is what the operator* path already does, and the alternative – partitioning on the prefix sum of starts so each band holds equal nnz – changes which rows land together without changing any result, so it is a pure scheduling improvement that belongs behind a measurement rather than in this change.

◆ mult_sparse_csr_rows()

template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mtl::detail::mult_sparse_csr_rows ( const mat::compressed2D< V, P > & A,
const VIn & x,
VOut & y,
std::size_t rb,
std::size_t re )

Sparse CSR mat*vec over the OUTPUT ROW RANGE [rb, re): the loop body of mult_sparse_csr below, split out for the threaded caller exactly as the dense kernels are.

Each y(r) reads only row r's slice of the CSR arrays and writes only y(r), so a partition into row bands is bit-identical to the serial loop. The GATHER from x is what makes this safe to parallelize and its transpose not: reads of x(indices[k]) may collide across bands, and concurrent reads are not a race. y must not alias x.

The assertions are mult's, restated – see mult_generic_rows for why that matters beyond documentation.

◆ mult_sparse_csr_transposed()

template<typename Accumulator = void, typename V, typename P, typename VIn, typename VOut>
void mtl::detail::mult_sparse_csr_transposed ( const mat::view::transposed_view< mat::compressed2D< V, P > > & At,
const VIn & x,
VOut & y )

Transposed sparse CSR mat*vec: y = A^T * x, O(nnz), scatter into y.

Mirrors mat::operator*(transposed_view<compressed2D>, dense_vector) but adds Accumulator support so mixed-precision / quire accumulation works on transposed sparse matvecs too. Scatter pattern means each y(j) receives contributions from multiple rows r, so accumulation is done per-output-element rather than per-row.

STAYS SERIAL, and the scatter is exactly why (#446 follow-up). The forward kernel above threads because a row band owns its output elements outright; here row r contributes to y(indices[k]) for every stored column, so two bands racing to update the same y(j) is the normal case, not an edge one. The fixes both cost something this kernel is not willing to pay: atomics do not exist for a custom number type and would not be deterministic if they did, and per-thread privatization needs O(threads * y.size()) accumulators – already the expensive part here, since a configuration-3 super-accumulator is one to two orders of magnitude larger per element than the value type – and changes the summation grouping, which forfeits the bit-identity every other threaded path in this file guarantees. Threading this wants a different algorithm (a CSC view, or a symbolic split of the output range), not a partition of this loop.

◆ mult_via_temporary()

template<typename VOut, typename F>
void mtl::detail::mult_via_temporary ( VOut & y,
F && compute )

y = op(x) through a temporary, then copied into y element by element, so a y that is a view keeps writing its buffer (#833).

For a y that shares storage with an input, which the kernels would overwrite while reading.

◆ nc_for_model()

std::size_t mtl::detail::nc_for_model ( nc_model model,
const nc_model_inputs & in )
inlinenoexcept

nc under one model.

Pure, so the offline sweep and the benchmark arm cannot disagree about what a model means.

A model that would need a figure the machine did not report FALLS BACK to the compile-time L3 rather than to zero. An undetectable machine must behave exactly as M0 does, not produce a degenerate block size – the same rule with_detected_caches follows field by field.

◆ nc_for_plan()

template<typename TC, typename TB = TC, std::size_t KGroup = 1, typename Tile = batch_tile<TC>>
std::size_t mtl::detail::nc_for_plan ( std::size_t m,
std::size_t n,
unsigned budget,
nc_model model )
inline

◆ nc_from_budget()

std::size_t mtl::detail::nc_from_budget ( std::size_t budget_bytes,
std::size_t kc,
std::size_t sdata,
std::size_t nr )
constexprnoexcept

The capacity-only part: nc such that the packed B panel kc x nc fills the budget, rounded down to a whole number of nr-column panels.

This is derive_blocking's own formula, factored out so every model shares it.

◆ nc_guard_declines()

bool mtl::detail::nc_guard_declines ( std::size_t packed_b_new,
std::size_t packed_b_old,
std::size_t l3_bytes )
constexprnoexcept

M6's rule, as a named predicate: decline the balanced nc when it would BOTH grow the resident packed-B set AND push it past L3 (#429, measured in #479).

BOTH TERMS ARE LOAD-BEARING, and the measurement says so rather than the argument. Over 44 arms on four microarchitectures and two dtypes:

grew fires 4 – catches both regressions, declines 2 GAINS exceeds L3 fires 35 – catches both, declines 33 gains grew AND exceeds L3 fires 2 – catches both, declines nothing else

The mechanism it encodes: balanced_nc lowers nc, which raises njb, which can let plan_gemm_grid re-factor the grid and take jc_nt 2 -> 4. Each team holds its own kc x nc packed-B panel, so the resident set moves 16 MB -> 24 MB. An i7-12700K (25 MB L3) absorbs that and gains x1.02; a Ryzen 9 8945HS (16 MB) does not and loses to x0.82 – reproduced at 0.8181 / 0.8181 / 0.8203 across three independent sessions, the last with a pinned governor.

A set that merely EXCEEDS L3 is not the problem: where the set shrank, the same Ryzen gained x1.06-1.74 whether it overflowed or not. It is the growth across the boundary that costs.

◆ nc_model_from_name()

nc_model mtl::detail::nc_model_from_name ( const char * s,
bool & ok )
inlinenoexcept

Parse a model name; ok reports whether it was recognised.

UNRECOGNISED NAMES ARE NOT SILENTLY M0. A typo'd MTL5_NC_MODEL=m1_balnced that quietly ran the baseline would produce a CSV whose model column says m1 and whose numbers are m0 – the two-arms-that-are-secretly-one-arm failure that #470 shipped with the quad kernel, where gemm_i8_i32 and gemm_i8_i32_quad benchmarked identically because inference had made them the same kernel. It cost a benchmark round to notice. So the caller is told, and nc_model_selection refuses to start.

◆ nc_model_name()

const char * mtl::detail::nc_model_name ( nc_model m)
constexprnoexcept

Short stable token for CSV columns and command lines.

◆ nc_model_selection()

nc_model mtl::detail::nc_model_selection ( )
inline

The model this process runs, from MTL5_NC_MODEL; M7 when unset (#492).

Read ONCE into a function-local static: the value is baked into the plan every GEMM makes, so a mid-run change would split one CSV row's timings across two models. Thread-safe by C++11 static initialisation.

An unset variable is the shipped configuration and the overwhelmingly common case, so it costs one relaxed load after the first call. An unrecognised value ABORTS rather than falling back – see nc_model_from_name. This is a benchmark selector; there is no production caller to keep running, and a silent fallback here forges the provenance of every row that follows.

◆ one_sided_jacobi()

template<typename Accumulator = void, typename value_type>
void mtl::detail::one_sided_jacobi ( mat::dense2D< value_type > & B,
mat::dense2D< value_type > & V,
std::vector< value_type > & sigma_s,
value_type tol )

One-sided Jacobi core shared by every svd overload.

On entry B (m x n) holds the matrix to decompose and V (n x n) the identity. It rotates B's columns until each pair is orthogonal to tol (machine epsilon if tol <= 0), accumulating the rotations into V, so that B_in * V = B_out. It then sorts the column norms – the singular values – in descending order into sigma_s (length n) and permutes the columns of B and V to match, so on return B's column j is sigma_s[j] times the j-th left singular vector.

◆ pack_A()

template<typename T, std::size_t MR>
requires mtl::Scalar<T>
void mtl::detail::pack_A ( const T * A,
std::ptrdiff_t rs,
std::ptrdiff_t cs,
std::size_t m,
std::size_t k,
T * Ap )

Pack an m x k block of A into MR-row, column-major micro-panels.

Layout: panels are laid out contiguously by row-block; within panel q (rows [q*MR, q*MR+MR)), storage is column-major over the kc dimension – Ap[q*MR*k + p*MR + i] = (q*MR+i < m) ? A(q*MR+i, p) : 0 for p in [0,k), i in [0,MR). This is exactly what gemm_microkernel reads as Ap[p*MR + i]. Ap must hold packed_A_size(m,k,MR) elements.

◆ pack_A_quad()

template<typename T, std::size_t MR>
requires mtl::Scalar<T>
void mtl::detail::pack_A_quad ( const T * A,
std::ptrdiff_t rs,
std::ptrdiff_t cs,
std::size_t m,
std::size_t k,
T * Ap )

Pack an m x k block of A into quad-interleaved MR-row micro-panels.

Ap[q*MR*KP + g*MR*4 + i*4 + t] = (q*MR+i < m && 4g+t < k) ? A(q*MR+i, 4g+t) : 0

for g in [0, KP/4), i in [0,MR), t in [0,4), KP = quad_depth(k). Ap must hold packed_A_quad_size(m,k,MR) elements. The i*4 + t run is the 4-byte unit gemm_quad_microkernel broadcasts.

◆ pack_B()

template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void mtl::detail::pack_B ( const T * B,
std::ptrdiff_t rs,
std::ptrdiff_t cs,
std::size_t k,
std::size_t n,
T * Bp )

◆ pack_B_panels()

template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void mtl::detail::pack_B_panels ( const T * B,
std::ptrdiff_t rs,
std::ptrdiff_t cs,
std::size_t k,
std::size_t n,
T * Bp,
std::size_t q0,
std::size_t q1 )

Pack a k x n block of B into NR-col, row-major micro-panels.

Layout: panels are laid out contiguously by column-block; within panel q (cols [q*NR, q*NR+NR)), storage is row-major over the kc dimension – Bp[q*NR*k + p*NR + j] = (q*NR+j < n) ? B(p, q*NR+j) : 0 for p in [0,k), j in [0,NR). This is exactly what gemm_microkernel reads as Bp[p*NR + j]. Bp must hold packed_B_size(k,n,NR) elements. Pack only panels [q0, q1) of the same layout, writing each to the offset it would occupy in a whole-panel pack: panel q owns Bp[q*NR*k, (q+1)*NR*k).

Panels are independent and their destinations are disjoint and computable, so a team of threads can pack one B block cooperatively by taking disjoint panel ranges. Packing is pure data movement – no arithmetic – so the packed bytes are identical however the range is split, and any GEMM consuming the result stays bit-identical. That is what lets the threaded pack in gemm_blocked.hpp preserve the bit-exactness guarantee (#110).

◆ pack_B_quad()

template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void mtl::detail::pack_B_quad ( const T * B,
std::ptrdiff_t rs,
std::ptrdiff_t cs,
std::size_t k,
std::size_t n,
T * Bp )

◆ pack_B_quad_panels()

template<typename T, std::size_t NR>
requires mtl::Scalar<T>
void mtl::detail::pack_B_quad_panels ( const T * B,
std::ptrdiff_t rs,
std::ptrdiff_t cs,
std::size_t k,
std::size_t n,
T * Bp,
std::size_t q0,
std::size_t q1 )

Pack panels [q0, q1) of a k x n B block into quad-interleaved NR-col micro-panels, each written at the offset it would occupy in a whole pack:

Bp[q*NR*KP + g*NR*4 + j*4 + t] = (q*NR+j < n && 4g+t < k) ? B(4g+t, q*NR+j) : 0

Bp must hold packed_B_quad_size(k,n,NR) elements. Panel destinations are disjoint and computable, and packing is pure data movement, so a cooperative split across a thread team produces byte-identical output – which is what keeps the threaded quad GEMM bit-identical to the serial one.

◆ packed_A_quad_size()

std::size_t mtl::detail::packed_A_quad_size ( std::size_t m,
std::size_t k,
std::size_t MR )
constexpr

Elements needed to pack an m x k A block into quad-interleaved MR-row panels.

◆ packed_A_size()

std::size_t mtl::detail::packed_A_size ( std::size_t m,
std::size_t k,
std::size_t MR )
constexpr

Elements needed to pack an m x k A block into MR-row panels (rows padded to MR).

◆ packed_A_size_for()

template<bool Quad>
std::size_t mtl::detail::packed_A_size_for ( std::size_t m,
std::size_t k,
std::size_t MR )
constexpr

The A-panel size for whichever layout the (accumulator, operand) pair selects.

A single call site in the nest then covers both kernels.

◆ packed_b_bytes()

std::size_t mtl::detail::packed_b_bytes ( unsigned jc_nt,
std::size_t kc,
std::size_t nc,
std::size_t nr,
std::size_t elem_bytes,
std::size_t k_group = 1 )
constexprnoexcept

Bytes of packed B held simultaneously: one panel per jc-team, as the packer actually lays it out.

Tests the capacity story that models M3 and M4 rest on – that nc should be divided by the team count or the sharer count – directly, against the L3 the machine actually reports, rather than by inference from a throughput change. It is also the left-hand side of M6's guard, so it has to be true rather than approximately true.

THREE THINGS THIS USED TO GET WRONG, all of them making it report a panel the nest does not build (#486):

elem_bytes IS THE OPERAND TYPE, NOT THE ACCUMULATOR. The panel is a packed_buffer<TB>; blocking is chosen for TC because the C microtile maps to TC registers, and callers inherited sizeof(TC) from that. For a mixed pair the two differ: 2x for float operands into an fp64 accumulator (#176), 4x for i8 into i32 (#451).

n IS PADDED TO A WHOLE nr PANEL. packed_B_size reserves ceil(n/NR)*NR*k, and balanced_nc deliberately does NOT round nc to a multiple of nr on the threaded path – rounding after balancing would undo the balance – so a ragged nc is the normal case, not an edge one.

k IS PADDED TO A WHOLE QUAD GROUP when the quad kernel runs, because packed_B_quad_size reserves quad_depth(k). Pass k_group = 4 there.

WHY THIS DOES NOT CHANGE nc ITSELF, which is the question #486 really raises. Correcting the same sizeof inside nc_from_budget would ENLARGE nc by 2-4x for the mixed pairs – and #479 measured that direction and falsified it: M2 enlarged nc about 1.9x by applying the detected L3 and lost up to 45% (x0.548, 37 regressions), with balanced_nc already included so balancing did not rescue it. A bigger panel is not a faster one. So the ACCOUNTING is corrected here, and the BUDGET POLICY stays where the measurement left it. See nc_from_budget in nc_model.hpp.

◆ packed_B_quad_size()

std::size_t mtl::detail::packed_B_quad_size ( std::size_t k,
std::size_t n,
std::size_t NR )
constexpr

Elements needed to pack a k x n B block into quad-interleaved NR-col panels.

◆ packed_B_size()

std::size_t mtl::detail::packed_B_size ( std::size_t k,
std::size_t n,
std::size_t NR )
constexpr

Elements needed to pack a k x n B block into NR-col panels (cols padded to NR).

◆ packed_B_size_for()

template<bool Quad>
std::size_t mtl::detail::packed_B_size_for ( std::size_t k,
std::size_t n,
std::size_t NR )
constexpr

The B-panel size for whichever layout the pair selects; see packed_A_size_for.

◆ parallel_ewise()

template<typename Body>
void mtl::detail::parallel_ewise ( std::size_t n,
std::size_t work_per_elem,
Body && body )
inline

Run body(i) for every i in [0, n) across the pool, partitioned into contiguous chunks.

work_per_elem (>= 1 effectively) estimates the per-index cost so the grain targets ~64K work units per chunk; a deeper expression tree (more flops per element) => smaller grain. Bit-identical across thread counts.

◆ parallel_ewise_2d()

template<typename Body>
void mtl::detail::parallel_ewise_2d ( std::size_t rows,
std::size_t cols,
std::size_t work_per_elem,
Body && body )
inline

Run body(r, c) for every element of a rows x cols index space, in row-major order, across the pool.

The 2D space is FLATTENED to a linear element index [0, rows*cols) before chunking, so the work splits on the element count rather than the row count: a wide/short expression (1 x N) parallelizes exactly like a tall one (N x 1), which a row-per-unit decomposition cannot do (#313).

work_per_elem estimates the per-ELEMENT cost (1 for an ordinary element-wise expression), so the grain targets ~64K work units per chunk – the same chunk size in elements the row-per-unit form produced for tall matrices.

Each chunk walks (r, c) incrementally from one division at its start, so the per-element cost is an increment and a compare, not a div/mod. The visit order within a chunk is the serial nested loop's, every element is produced by exactly one chunk, and the per-element computation does not depend on which thread runs it – so the result is BIT-IDENTICAL to the serial loop and to any other thread count. At MTL5_NUM_THREADS=1 the whole space is one chunk on the calling thread – no parallel dispatch – with body still invoked per element.

◆ pivot_unusable()

template<typename T>
bool mtl::detail::pivot_unusable ( const T & p)
constexpr

True when p is zero or NaN: not a pivot a factorization can divide by.

abs is found by ADL, so a custom number type's own is used.

◆ plan_gemm_grid()

gemm_grid mtl::detail::plan_gemm_grid ( std::size_t m,
std::size_t n,
std::size_t mc_cache,
std::size_t nc,
std::size_t mr,
unsigned budget,
std::size_t mc_extra_cap = 0 )
constexpr

Choose mc and the grid for an m x n problem on budget threads.

Two defects this fixes, both found by measuring three machines (#430) and both costing whole cores rather than percentages:

  1. mc WAS THE CACHE BOUND ONLY, so nib = ceil(m/mc) could be smaller than the budget and cap ic_nt permanently – with njb == 1 (square problems, where n <= nc) there is no jc parallelism to make up the difference and the machine simply idles. Measured: an i7-12700K at 1024^3 ran 5 of 8 threads (ratio 0.551 against the smaller-mc arm) and a Zen 4 ran 4 of 8 (0.590). mc is therefore also bounded by ceil(m/budget) – enough blocks to hand every thread one – floored at a single register tile. This only ever LOWERS mc, so the L2 bound is still respected, and it binds ONLY when the partition would otherwise starve: at the shipped mc = 64 with m = 1024 and 8 threads the cap is 128 and nothing changes.
  2. THE FACTORIZATION WAS GREEDY: fill ic first, then give jc the integer quotient. That throws the remainder away – at budget 6 with nib = 4 it picked 4 x 1 = 4 and left two cores idle, while 3 x 2 and 2 x 3 were both legal. Measured on a Jetson Orin Nano: 0.760 where the grid was the only difference. The search below is exhaustive over ic (a handful of values) and maximises ic_nt * jc_nt, preferring the larger ic_nt on ties because a wider ic team keeps the shared packed-B panel resident.

mc_extra_cap is an additional upper bound on mc (0 = none), used for the C-strip bound above. It is applied BEFORE the budget cap, so both can bind and the smaller wins; like the budget cap it only ever LOWERS mc.

◆ product_tol()

template<Matrix M>
magnitude_t< typename M::value_type > mtl::detail::product_tol ( const M & A,
magnitude_t< typename M::value_type > tol )

◆ quad_depth()

std::size_t mtl::detail::quad_depth ( std::size_t k)
constexpr

k rounded up to a whole number of 4-value groups – the depth the quad layout actually stores, and the depth the micro-kernel steps.

◆ quasi_triangular_blocks()

template<typename M>
std::vector< std::size_t > mtl::detail::quasi_triangular_blocks ( const M & T,
const char * who,
const char * name )

The diagonal blocks of an upper quasi-triangular square matrix, as their starting indices followed by n.

A 2x2 block starts at k when T(k+1, k) != 0. Throws std::invalid_argument when T is not square or not quasi-triangular: a nonzero below the subdiagonal, or two adjacent nonzero subdiagonals.

◆ quasi_triangular_eigenvector()

template<typename T>
std::vector< std::complex< T > > mtl::detail::quasi_triangular_eigenvector ( const mat::dense2D< T > & R,
std::size_t k,
std::complex< T > lambda,
T smin,
T limit )

A right eigenvector y of the real quasi-upper-triangular T (a real Schur form, 2x2 blocks in standard form) for its eigenvalue lambda at index k: (T - lambda I) y = 0, with y zero below lambda's block.

Back-substitution over T's diagonal blocks in complex arithmetic, the recurrence of LAPACK's dtrevc. A diagonal block whose shifted value or determinant is below smin (the determinant: below smin times the block's largest entry) – the same eigenvalue again – is perturbed to that floor, and y is rescaled when an entry passes limit. O(n^2) per eigenvector.

◆ random_engine()

std::mt19937_64 mtl::detail::random_engine ( )
inline

A std::mt19937_64 seeded from std::random_device, for the calls without a seed.

◆ random_uniform()

template<typename T>
T mtl::detail::random_uniform ( std::mt19937_64 & gen,
const T & lo,
const T & hi )

One value uniform on [lo, hi), or lo when lo == hi. Bounds already checked.

◆ random_unit()

double mtl::detail::random_unit ( std::mt19937_64 & gen)
inline

Uniform on [0, 1): the top 53 bits of one 64-bit draw.

◆ require_finite()

template<typename M>
void mtl::detail::require_finite ( const M & A,
std::string_view who )

Throws std::invalid_argument unless every entry of A is finite.

◆ require_square()

template<typename M>
void mtl::detail::require_square ( const M & A,
std::string_view who )

Throws std::invalid_argument unless A is square.

◆ require_square_finite()

template<typename M>
void mtl::detail::require_square_finite ( const M & A,
std::string_view who )

Throws std::invalid_argument unless A is square and every entry finite.

◆ rescaled_two_norm()

template<typename Mag, typename ForEachAbs>
Mag mtl::detail::norms_adl::rescaled_two_norm ( ForEachAbs && for_each_abs)

sqrt(sum a^2) over the magnitudes that for_each_abs(f) passes to f, computed with a power-of-two scale so that neither the squares nor their sum overflow or underflow.

In a binary floating-point type the scaling is exact; in a tapered type it also keeps the squares near 1, where the type is most precise.

◆ same_object()

template<typename T, typename U>
bool mtl::detail::same_object ( const T & a,
const U & b )
constexprnoexcept

True when a and b are the same object (#696).

An operation that overwrites its output while still reading its inputs, such as mult, asserts that the output is not one of them. The test compares addresses only, so it does not see a view of the output, such as mult(trans(C), B, C).

◆ saturating_cast()

template<typename Target, typename Value>
Target mtl::detail::saturating_cast ( Value v)

Convert a value to Target, clamping to [min, max] for integer types to prevent undefined behavior from signed integer overflow.

Floating-point targets pass through without clamping.

Any non-integer source with numeric_limits is clamped, NaN to 0: a bfloat16 or posit source was cast unclamped, because only std::is_floating_point sources were (issue 887).

◆ scalar_is_finite()

template<typename T>
bool mtl::detail::scalar_is_finite ( const T & x)

◆ scalar_is_inf()

template<typename T>
bool mtl::detail::scalar_is_inf ( const T & x)

◆ scalar_is_nan()

template<typename T>
bool mtl::detail::scalar_is_nan ( const T & x)

◆ scale_down_to_one()

template<typename R>
R mtl::detail::scale_down_to_one ( R x)

The largest power of two f <= 1 with x * f <= 1, for x > 1.

◆ scale_to_unit_binade() [1/2]

template<typename R>
int mtl::detail::scale_to_unit_binade ( mat::dense2D< std::complex< R > > & W)

Scale W by a power of two so that its largest real or imaginary part is in [1/2, 1], as scale_to_unit_binade does for a real matrix; returns the exponent k of the factor 2^-k applied.

Exact in a binary floating-point R.

◆ scale_to_unit_binade() [2/2]

template<typename T>
int mtl::detail::scale_to_unit_binade ( mat::dense2D< T > & W)

Scales W by a power of two so max |w_ij| lies in [1/2, 1], and returns the exponent k that undoes it: W_in = W_out * 2^k (0 if W is zero or already in range).

The Francis iteration forms products of two entries, which overflow or underflow for an IEEE matrix with entries near 1e200 or 1e-200; scaled, they cannot, and in a binary floating-point type the scaling is exact. For a posit, whose precision is greatest near 1, it also keeps the deflation test reachable. schur() has scaled this way since #650; eigenvalue() and eigen() do too since #853.

The exponent, not the factor 2^k, is returned, and the entries are scaled by math::pow2_scaling: for a 1x1 [max()] the factor 2^1024 overflows, and for [denorm_min()] the factor 2^1075 does (#853 review). k is the power of two the earlier halve-or-double loop reached, so results are unchanged.

◆ schur_complex()

template<typename M>
auto mtl::detail::schur_complex ( const M & A)

The in-house complex Schur form: Hessenberg reduction, its unitary Q, and the complex QR iteration, on A scaled to the unit binade.

The reduction runs with the default accumulation. householder_reflector() accumulates the reflector's norm in the accumulator over the real magnitude type, and the reflector's application over the complex element type, so no one Accumulator type serves both for a complex matrix.

◆ signum_scalar()

template<typename T>
T mtl::detail::signum_scalar ( const T & x)
constexpr

+1, 0 or -1; an unsigned type has no -1, so 1 or 0 (T{-1} narrowed and did not compile, issue 887).

◆ singular_values()

template<Matrix M>
std::vector< magnitude_t< typename M::value_type > > mtl::detail::singular_values ( const M & A)

◆ solve_sylvester_block()

template<typename T, typename R>
bool mtl::detail::solve_sylvester_block ( const T(&) a[2][2],
int p,
const T(&) b[2][2],
int q,
const T & sgn,
T(&) rhs[2][2],
const R & smin,
const sylvester_limits< R > & lim,
bool scaled,
R & scaloc )

◆ spgemm_acc()

template<typename Accumulator, typename V1, typename P1, typename V2, typename P2>
auto mtl::detail::spgemm_acc ( const mat::compressed2D< V1, P1 > & A,
const mat::compressed2D< V2, P2 > & B )

spgemm with an accumulator: one per touched column of the current row, rounded once at the gather (see the header note).

◆ storage_bytes()

template<contiguous_storage T>
std::pair< const unsigned char *, const unsigned char * > mtl::detail::storage_bytes ( const T & t)

The bytes from t's first element to its last.

◆ storage_overlaps()

template<typename T, typename U>
bool mtl::detail::storage_overlaps ( const T & a,
const U & b )
noexcept

Whether a and b may share storage (#840, #855): the same object, or element storage whose byte ranges overlap – a vector over part of another's buffer, as zero-copy views make easy; a vector over a sparse matrix's values or triplets, a block's elements or a block view's bytes; the matrix behind a transposed view.

A type with no visible storage (an expression) is seen only as the same object.

◆ strip_columns()

template<std::size_t C, typename Acc, typename T, typename XAt, typename Op>
void mtl::detail::strip_columns ( Acc * acc,
const T * a,
std::size_t ld,
std::size_t r0,
std::size_t rr,
std::size_t cb,
std::size_t ce,
const XAt & x_at,
const Op & op )

Columns [cb, ce) into a strip of rr rows: sweep_fixed_rows for a short strip, sweep_columns<C> otherwise.

Bit-identical either way. The callers take sweep_columns<1> themselves at a wide column stride (column_sweep_unrolled<T>): behind this extra call, the same one-column loop measured 25-35% slower than called directly (#884).

◆ structure_tol()

template<typename Mag>
requires std::numeric_limits<Mag>::is_specialized
Mag mtl::detail::structure_tol ( std::size_t n,
Mag scale )
constexpr

Threshold separating "this matrix has this structure" from "rounding noise", scaled by the size of the problem and the magnitude of the data.

Every MTL5 element type has a std::numeric_limits specialization (#838), so epsilon() is the type's own. Before that rule, a type without one got an epsilon of 0 and an exact test, and the ldlt/cholesky symmetry guards rejected a matrix symmetric only to rounding.

◆ sum_k_inplace()

template<typename T>
T mtl::detail::sum_k_inplace ( std::vector< T > & p,
int K )

SumK (Algorithm 4.8) on a vector it may overwrite: K - 1 VecSum passes, then fl(sum_{i<n} p_i + p_n).

◆ sum_squares_needs_rescan()

template<typename Mag>
bool mtl::detail::sum_squares_needs_rescan ( const Mag & ss)

◆ svd_dot()

template<typename Accumulator, typename value_type, typename Size, typename Term>
value_type mtl::detail::svd_dot ( Size len,
Term term )

sum_i a(i) * b(i) for i < len, where term(i) returns {a(i), b(i)}: a plain value_type sum for void, else one accumulator rounded once.

◆ svd_pair_sums()

template<typename Accumulator, typename value_type, typename Size, typename Load>
void mtl::detail::svd_pair_sums ( Size len,
Load load,
value_type & alpha,
value_type & betac,
value_type & gamma )

alpha = ||p||^2, betac = ||q||^2, gamma = p .

q in one pass over the pair, load(i) returning {p(i), q(i)}: plain value_type sums for void, else three accumulators, each rounded once.

◆ sweep_columns()

template<std::size_t C, typename Acc, typename T, typename XAt, typename Op>
void mtl::detail::sweep_columns ( Acc * acc,
const T * a,
std::size_t ld,
std::size_t r0,
std::size_t rr,
std::size_t cb,
std::size_t ce,
const XAt & x_at,
const Op & op )

Columns [cb, ce) of the column-major a (leading dimension ld) into the strip's accumulators: acc[l] = op(acc[l], a[c * ld + r0 + l], x(c)) for l < rr and c ascending.

C columns per pass, then 4, then 1 for the rest. Every accumulator takes the same terms in the same order with the same expression as one column per pass, so the result is bit-identical to it (and so to the one-row loop the sweep matches).

◆ sweep_fixed_rows()

template<std::size_t R, typename Acc, typename T, typename XAt, typename Op>
MTL5_NO_LOOP_VECTORIZE void mtl::detail::sweep_fixed_rows ( Acc * acc,
const T * a,
std::size_t ld,
std::size_t r0,
std::size_t cb,
std::size_t ce,
const XAt & x_at,
const Op & op )

sweep_columns for a strip of exactly R rows, R known at compile time: the R accumulators are indexed only by a pack, so they stay in registers across all the columns, where the run-time strip loads and stores them every pass.

On a 4-row strip that measured 1.5-4.8x faster than the run-time strip (i7-12700K, GCC and Clang, generic and -march=native). The same terms in the same order, so the same bits.

GCC's loop vectorizer is off for it: with AVX it vectorized the column loop, eight columns per iteration put back together with shuffles, where the SLP form (the R accumulators in one register, x broadcast per column) is what this loop wants. On a Xeon E5-2420 v2 the f32 4-row strip ran at half the speed of one column per pass (#884). The SLP vectorizer stays on.

◆ sylvester_downscale_exponent()

template<typename R>
int mtl::detail::sylvester_downscale_exponent ( const R & p,
const R & bound )

The k >= 0 for which p * 2^-k <= bound: 0 when p <= bound already, and otherwise the smallest k the binary exponents of p and bound guarantee.

p and bound are positive and finite.

◆ sylvester_max_part()

template<typename Value>
magnitude_t< Value > mtl::detail::sylvester_max_part ( const mat::dense2D< Value > & X)

The largest |x| over X's entries; for a complex type the largest |part|, as in sylvester_representable.

◆ sylvester_representable()

template<typename T>
bool mtl::detail::sylvester_representable ( const T & x)

Whether a solution entry is representable: finite, and below the largest value of the real type (a posit saturates there rather than overflowing).

A complex entry is checked part by part: (0.8 max, 0.8 max) is representable although its modulus is not (review of #990).

◆ sylvester_scale_pow2()

template<typename Value>
Value mtl::detail::sylvester_scale_pow2 ( const Value & x,
int k )

x * 2^k, part by part for a complex type: exact in a binary type unless the result overflows or becomes subnormal.

◆ sylvester_triangular_inhouse()

template<typename Accumulator, typename MA, typename MB, typename MC>
sylvester_scaled_result< typename MC::value_type > mtl::detail::sylvester_triangular_inhouse ( const MA & A,
const MB & B,
const MC & C,
sylvester_sign sign,
const std::vector< std::size_t > & ablocks,
const std::vector< std::size_t > & bblocks,
bool scaled )

The in-house solve behind sylvester_triangular (scaled == false: no scaling, scale stays 1) and sylvester_triangular_scaled (scaled == true).

A, B and C are validated by the caller.

◆ sylvester_triangular_solve()

template<typename Accumulator, typename MA, typename MB, typename MC>
sylvester_scaled_result< typename MC::value_type > mtl::detail::sylvester_triangular_solve ( const MA & A,
const MB & B,
const MC & C,
sylvester_sign sign,
bool scaled )

Validate, dispatch and solve, for sylvester_triangular (scaled == false) and sylvester_triangular_scaled (scaled == true).

◆ symv_strip_gather()

template<std::size_t R, typename Acc, typename TA, typename X>
MTL5_NO_LOOP_VECTORIZE void mtl::detail::symv_strip_gather ( std::size_t len,
const TA *const * p,
Acc * s,
const X & x,
std::size_t j0 )
inline

s[r] += p[r][j] x[j] in ascending j, for j < len: each row's own sum, R independent chains sharing each x[j] (see MTL5_NO_LOOP_VECTORIZE).

◆ symv_strip_scatter()

template<std::size_t R, typename Acc, typename TA, typename TX>
void mtl::detail::symv_strip_scatter ( std::size_t len,
const TA *const * p,
const TX * xr,
Acc * acc )
inline

acc[j] += p[0][j] x[0] + p[1][j] x[1] + ... in row order, for j < len: R rows' contributions to the entries left of the strip.

Each acc[j] gets its terms one at a time, in the row loop's order; the j's are independent, so the loop vectorizes over j.

◆ throw_or_abort()

template<typename E>
void mtl::detail::throw_or_abort ( E && e)
inline

Throw e; with exceptions disabled, abort instead.

◆ transport_source()

template<typename T, typename H>
auto mtl::detail::transport_source ( H h)

◆ transport_target()

template<typename T, typename H>
auto mtl::detail::transport_target ( H h)

A handle as a runtime's copy_bytes receives it: a T* as void*, any other handle as itself (#1017).

Only T* is erased: a handle that is a pointer to something else (an opaque buffer token) is not a host address, and must not reach a copy_bytes(void*, const void*, ...) overload as one.

◆ transpose_copy()

template<typename T>
void mtl::detail::transpose_copy ( const T * in,
std::size_t rows,
std::size_t cols,
T * out )

out[c * rows + r] = in[r * cols + c] for every r < rows, c < cols: copies the row-major rows x cols array in into out as the column-major one, which is the same as writing in^T row-major.

in and out must not overlap.

The LAPACK paths of lu_factor and qr_factor use it to move a row-major matrix into the column-major scratch LAPACK works on, and back. A plain double loop walks one of the two arrays with a stride of a full row or column, a cache miss per element for large matrices. This walks tile by tile, and inside a tile writes each of out's columns contiguously while reading in with the stride. The other order inside the tile (contiguous reads, strided writes) is up to five times slower when the stride is a power of two: at n = 2048, f32 took 12.7 ms on the M2 against 2.5 ms here, as the strided writes all land in the same cache sets. Every element is copied, never computed, so the result is identical to the plain loop's.

◆ tridiagonal_negligible()

template<typename Real>
bool mtl::detail::tridiagonal_negligible ( const Real & e,
const Real & d0,
const Real & d1,
const Real & tol )

Deflation test of the implicit tridiagonal QR: is the subdiagonal entry e, between diagonal entries d0 and d1, negligible?

This is LAPACK dsteqr's test, |e| <= tol * sqrt(|d0|) * sqrt(|d1|), i.e. e^2 <= tol^2 * |d0 * d1| with the product split so it cannot overflow or underflow.

The earlier test, |e| <= tol * (|d0| + |d1|), scaled with the LARGER of the two diagonal entries, so an entry coupling a small eigenvalue to a large one was dropped while still big enough to perturb the small eigenvalue (#565). The geometric mean scales with the small one. An exactly zero diagonal entry only deflates once e is exactly zero, which the cubically convergent Wilkinson-shifted iteration reaches in a few steps (as in dsteqr).

◆ trmm_rows() [1/2]

template<typename S, typename MA, typename MB>
void mtl::detail::trmm_rows ( const S & alpha,
const MA & A,
MB & B,
bool upper,
bool unit_diag )

◆ trmm_rows() [2/2]

template<typename S, typename MA, typename MB>
void mtl::detail::trmm_rows ( const S & alpha,
const MA & A,
MB & B,
bool upper,
bool unit_diag,
typename MA::size_type b0,
typename MA::size_type b1 )

The generic product on a row-major B, a whole row of B at a time (#724).

The column-by-column loop reads B(j, c) down a column. This form builds row i of the result as (A(i, i) or 1) * B.row(i) plus A(i, j) * B.row(j) for each j in the triangle, in ascending j: contiguous inner loops. Rows are formed in the order that leaves every B.row(j) still unwritten when it is read (ascending i for upper, descending for lower), as the column loop does, and each entry is the same expression in the same type, so the result is bit-identical (contraction aside: see trsm_rows).

[b0, b1) restricts the product to one diagonal block, as for trsm_rows.

◆ trmv_column_sweep()

template<std::size_t S, std::size_t C = column_sweep_columns, typename M, typename VX>
void mtl::detail::trmv_column_sweep ( const M & A,
VX & x,
bool upper,
bool unit_diag )

The generic trmv on a contiguous column-major A, S rows per strip (#777; see detail/column_sweep.hpp).

Each row r starts from its diagonal term and adds A(r, j) x(j) for the other j of its triangle in ascending j, exactly as the one-row loop does, so x is bit-identical to it. A strip reads x before it writes any of its entries, and the strips go in the overwrite-safe order (top-down for upper, bottom-up for lower), so every x(j) read still holds its original value.

The columns go C at a time (#884, see column_sweep_columns), the diagonal block's too: a group of C columns feeds the strip rows that take all of them unrolled, and the few rows inside the group term by term. Each row still adds its terms in ascending j. C = 1 is the sweep as #777 wrote it.

◆ trmv_lower_rows()

template<std::size_t W, typename M, typename VX>
void mtl::detail::trmv_lower_rows ( const M & A,
VX & x,
typename M::size_type ii,
bool unit_diag )

The generic lower trmv on rows [0, ii), W rows per block, bottom-up: the mirror image of trmv_upper_rows.

A block's rows first add the columns j < r0 they share, then each its own terms inside the diagonal block.

◆ trmv_upper_rows()

template<std::size_t W, typename M, typename VX>
void mtl::detail::trmv_upper_rows ( const M & A,
VX & x,
typename M::size_type i,
bool unit_diag )

The generic upper trmv on rows [i, n), W rows per block, top-down (#749, #772).

Row r sums its diagonal term, then A(r, j) x(j) for j > r in ascending j, exactly as the one-row loop does, so x is bit-identical for every W. A block's rows first add their terms inside the W x W diagonal block, each in its own order, then the columns j >= i0 + W they share, as W independent chains. A block reads x before it writes any of its entries, and the rows below it are not overwritten yet. The rows left over go to W / 2, down to W = 1, which is the one-row loop.

"Bit-identical" assumes the compiler contracts a product and its add the same way in both forms, as -ffp-contract=off guarantees (the tests build with it). With contraction on, a compiler may fuse in one form and not the other, and x can differ from the one-row loop in the last bit (#849).

◆ trsm_rows() [1/2]

template<typename S, typename MA, typename MB>
void mtl::detail::trsm_rows ( const S & alpha,
const MA & A,
MB & B,
bool upper,
bool unit_diag )

◆ trsm_rows() [2/2]

template<typename S, typename MA, typename MB>
void mtl::detail::trsm_rows ( const S & alpha,
const MA & A,
MB & B,
bool upper,
bool unit_diag,
typename MA::size_type b0,
typename MA::size_type b1 )

The generic solve on a row-major B, a whole row of B at a time (#724).

The column-by-column loop reads B(j, c) down a column, a stride of n per access. This form subtracts A(i, j) * B.row(j) from row i for each solved j: a contiguous, independent inner loop the compiler vectorizes. Every X(i, c) is still alpha*B(i, c), minus A(i, j)*X(j, c) in ascending j, then divided by A(i, i), with the same expressions in the same types (row holds what the column loop's s held), so the result is bit-identical – unless the compiler contracts across statements (GCC's -ffp-contract=fast with an FMA), which may fuse a different product in each form: same order, an ulp apart. That caveat applies to every row loop here, as to mult's.

[b0, b1) restricts the solve to one diagonal block: rows b0..b1-1, using only A's columns in the same range. The default is the whole matrix; the blocked solve below calls it per block, after GEMM has removed the rest.

◆ unit_roundoff()

template<typename Real>
Real mtl::detail::unit_roundoff ( )

The unit roundoff u of Real, the bound on the relative error of one rounding: fl(x) = x (1 + d), |d| <= u.

Under round-to-nearest this is half the machine epsilon, which is what error analyses (and tables derived from them, such as the Pade degree tables of expm) mean by u: 2^-53 for double.

◆ vec_sum()

template<typename T>
void mtl::detail::vec_sum ( std::vector< T > & p)

VecSum (Algorithm 4.3): p_i, p_{i-1} = TwoSum(p_i, p_{i-1}) for i = 2..n.

◆ with_gemm_tile()

template<typename TC, typename TA, typename TB, bool Quad, typename F>
decltype(auto) mtl::detail::with_gemm_tile ( F && f)

Run f(tile) with the tile the GEMM uses for (TC, TA, TB, Kern) on this machine: on a scalable target, for a same-type float or double GEMM, the vla_tile whose lane count the hardware has; otherwise batch_tile.

◆ with_sign_of()

template<typename T>
T mtl::detail::with_sign_of ( T a,
T b )

|a| with the sign of b, where b == 0 counts as positive.

This is Fortran's intrinsic SIGN(a, b), which the EISPACK and LAPACK code ported here uses. It is not std::copysign. That function exists only for the built-in floating-point types, and it gives -0.0 its negative sign: copysign(1, -0.0) is -1, while with_sign_of(1, -0.0) is 1. eigenvalue() has always treated zero as positive, and keeping that keeps its results bit-identical.

◆ wrap_add()

template<typename T>
MTL5_WRAPS_ON_PURPOSE constexpr T mtl::detail::wrap_add ( T a,
T b )
constexprnoexcept

◆ wrap_mul()

template<typename T>
MTL5_WRAPS_ON_PURPOSE constexpr T mtl::detail::wrap_mul ( T a,
T b )
constexprnoexcept

◆ wrap_sub()

template<typename T>
MTL5_WRAPS_ON_PURPOSE constexpr T mtl::detail::wrap_sub ( T a,
T b )
constexprnoexcept

Variable Documentation

◆ acc_panel_gemm_v

template<typename Accumulator, typename MA, typename MB>
bool mtl::detail::acc_panel_gemm_v
inlineconstexpr
Initial value:
= [] {
if constexpr (std::is_void_v<Accumulator>)
return false;
else
return std::is_arithmetic_v<std::common_type_t<typename MA::value_type,
typename MB::value_type>> &&
sizeof(Accumulator) <= 32;
}()

Whether mult<Acc> takes the packed-panel kernel below (#587): hardware arithmetic operands and an accumulator of at most 32 bytes.

The column walk only costs a kernel that is waiting on memory. A software element type such as a posit, or a large accumulator such as a quire, is compute-bound, so packing has nothing to win there. Measured at n = 128, one thread: posit<32,2> plain and fma moved within 1%, and quire<double> ran 5% slower packed. (Identical posit code also swung +-5% between builds with code placement alone, so differences that small need an aligned rebuild before they mean anything.) Those keep the dot-product loop. False for Accumulator = void, which has its own kernels.

◆ acc_panel_width

template<typename Accumulator>
std::size_t mtl::detail::acc_panel_width = sizeof(Accumulator) <= 8 ? 8 : 4
inlineconstexpr

Columns of C an accumulator GEMM computes per pass over a row of A (#587).

Eight independent accumulators hide the add latency of a cheap one; wider ones get four, since eight x87 long doubles already spill the register stack.

◆ accumulate_chunk_units

template<typename Acc, typename Value>
std::size_t mtl::detail::accumulate_chunk_units
inlineconstexpr
Initial value:
=
constexpr std::size_t parallel_chunk_units
Iteration units that make one parallel chunk worth dispatching, for element type T.
Definition dispatch_traits.hpp:304

Iteration units per chunk for a reduction of Value terms into Acc: the smaller of the two types' budgets, since either a software-emulated element or a software accumulator makes each term cost a call rather than a flop.

◆ all_nc_models

nc_model mtl::detail::all_nc_models[]
inlineconstexpr
Initial value:
= {
}
@ m1_balanced
M0 + balanced_nc.
Definition nc_model.hpp:130
@ m6_guarded
M1, declined where the packed-B set would grow past L3.
Definition nc_model.hpp:135
@ m7_sharer_gated
M4, but ONLY where the grid is jc-parallel.
Definition nc_model.hpp:137
@ m0_default
pre-#429: compile-time L3, no balancing. The baseline.
Definition nc_model.hpp:129
@ m3_per_team
(detected L3 / jc_nt) + balanced – rejected on #426, measured anyway
Definition nc_model.hpp:132
@ m4_per_sharer
(detected L3 / L3 sharing cores) + balanced
Definition nc_model.hpp:133
@ m5_exact
pick nc so njb == jc_nt exactly, where n allows
Definition nc_model.hpp:134
@ m2_detected
detected L3 + balanced_nc – FALSIFIED, see below
Definition nc_model.hpp:131

◆ block_alignment

template<typename T>
std::size_t mtl::detail::block_alignment
inlineconstexpr
Initial value:
=
alignof(T) > default_alignment ? alignof(T) : default_alignment
constexpr std::size_t default_alignment
Default over-alignment: 64 bytes covers a typical cache line and the widest common SIMD register (AVX...
Definition aligned_allocator.hpp:22

Alignment used for a block of T: at least default_alignment, but never less than T's natural alignment.

◆ block_fused_gemv_v

template<typename Accumulator, typename S, typename VIn, typename VOut>
bool mtl::detail::block_fused_gemv_v
inlineconstexpr
Initial value:
=
std::is_void_v<Accumulator> && BlockGemvScheme<S> &&
std::is_same_v<typename VIn::value_type, float> &&
std::is_same_v<typename VOut::value_type, float>
Does the scheme supply a fused gemv?
Definition block_matrix_view.hpp:198
Concept satisfied by dense vector types eligible for MTL5's OWN SIMD kernels.
Definition dispatch_traits.hpp:164

Does mult(A, x, y) on these types run the scheme's fused kernel?

◆ col_major_contiguous_v

template<typename M>
bool mtl::detail::col_major_contiguous_v
inlineconstexpr
Initial value:
= [] {
if constexpr (interface::ContiguousMatrixData<M> && requires { typename M::orientation; })
return std::is_same_v<typename M::orientation, tag::col_major>;
else
return false;
}()
Storage shape only: contiguous data() plus dimensions, with NO constraint on the element type.
Definition dispatch_traits.hpp:214

Whether M is a dense matrix whose data() is column-major with leading dimension num_rows(): element (i, j) at data()[j * num_rows() + i].

◆ column_strip_rows

template<typename T>
std::size_t mtl::detail::column_strip_rows = std::max<std::size_t>(1, 16384 / sizeof(T))
inlineconstexpr

Rows per strip: 16 KB of accumulators, at least one.

◆ column_sweep_columns

std::size_t mtl::detail::column_sweep_columns = 8
inlineconstexpr

Columns per pass over a strip (#884).

One column per pass loads and stores every accumulator of the strip for each column, so on a short strip the loop is bound by that traffic, not by A: a 4 x 1000 gemv ran at half the row kernel's speed. Eight columns per pass keep each accumulator in a register across eight terms.

Measured with bench_column_sweep on five machines (i7-12700K, Xeon E5-2420 v2, Ryzen 7 8845HS, Jetson Orin, Arduino Ventuno Q), GCC and Clang, generic and native: gemv 1.15-2.2x faster than one column per pass in geometric mean over the shapes. MSVC is the exception: its code for the eight-column pass ran at 0.23-0.89 of the one-column loop from 48 rows up, so under MSVC the sweep stays as #777 wrote it.

◆ column_sweep_fixed_rows

std::size_t mtl::detail::column_sweep_fixed_rows = 16
inlineconstexpr

Strips of at most this many rows take sweep_fixed_rows (#884).

◆ column_sweep_gemv_row_kernel_rows

std::size_t mtl::detail::column_sweep_gemv_row_kernel_rows = 2
inlineconstexpr

The shapes the row kernels take although A is column-major (#884): where the sweep's per-strip fixed cost isn't amortized.

Measured across the five machines above, a size up to these minimized the geometric mean of the time over the best of the sweep and the row kernel. #884 set gemv m <= 2 and trmv n <= 32, held there by GCC's code for the row kernels on a column-major A on x86 (1.3-3.3x slower native than generic); with that fixed (#898, row_kernel_fixed_rows_v) the same simulation gives trmv n <= 64: 1.046 -> 1.013 of the best, the worst case 2.0 -> 1.5. It also suggested gemv m <= 4, but m = 3 then ran 2x slower than in the sweep (a 2-row and a 1-row block, where the sweep takes one 3-row strip) on every build measured, so gemv stays at m <= 2.

◆ column_sweep_trmv_row_kernel_n

std::size_t mtl::detail::column_sweep_trmv_row_kernel_n = 64
inlineconstexpr

◆ column_sweep_trsv_row_kernel_n

std::size_t mtl::detail::column_sweep_trsv_row_kernel_n = 64
inlineconstexpr

◆ column_sweep_unrolled_stride

std::size_t mtl::detail::column_sweep_unrolled_stride = 8192
inlineconstexpr

A run-time strip goes one column per pass when A's columns are this many bytes apart or more (#884): eight columns per pass then read eight streams that far apart, and on the Jetson Orin and the Ventuno that ran at 0.46-0.75 of one column per pass at n = 2048-4096 (8 KB and up), as on the Xeon at.

  1. Below it the eight-column pass won on every machine.

◆ column_sweep_v

template<typename Acc, typename M>
bool mtl::detail::column_sweep_v
inlineconstexpr
Initial value:
=
col_major_contiguous_v<M> && std::is_arithmetic_v<std::remove_cvref_t<Acc>> &&
std::is_arithmetic_v<typename M::value_type>
constexpr bool col_major_contiguous_v
Whether M is a dense matrix whose data() is column-major with leading dimension num_rows(): element (...
Definition column_sweep.hpp:67

Whether the generic row kernels take the column sweep for an accumulator of type Acc over a matrix of type M.

◆ data_is_element_address

template<typename T>
bool mtl::detail::data_is_element_address
inlineconstexpr
Initial value:
= [] {
using D = decltype(std::declval<const T&>().data());
if constexpr (!std::is_pointer_v<D>) {
return false;
} else if constexpr (requires { typename T::handle_type; typename T::value_type; }) {
return std::is_same_v<std::remove_cv_t<std::remove_pointer_t<D>>,
std::remove_cv_t<typename T::value_type>>;
} else {
return true;
}
}()

Whether t.data() is the address of t's elements.

A container that names its storage by a memory space's handle (#1017) says so with handle_type: its data() is an element address only when the handle is a pointer to its value_type, not when it is an object or a pointer to an opaque token. Any other pointer-returning data() is taken as the elements' address.

◆ default_alignment

std::size_t mtl::detail::default_alignment = 64
inlineconstexpr

Default over-alignment: 64 bytes covers a typical cache line and the widest common SIMD register (AVX-512).

Types with a larger natural alignment keep it.

◆ gemm_dispatches_blas_v

template<typename Accumulator, typename MA, typename MB, typename MC>
bool mtl::detail::gemm_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether mult<Accumulator>(A, B, C), mat*mat, calls ?gemm: dense float or double operands of one element type under the default accumulator, in any mix of orientations (#849; before, only A, B and C of one orientation did).

Nested conditions, not one conjunction: && in a constant expression still instantiates every operand it names, and the value types are only looked at once the operands are known dense.

◆ gemmt_block

std::size_t mtl::detail::gemmt_block = 64
inlineconstexpr

Rows of the diagonal blocks of the blocked gemmt (#744).

Each is formed as a full square GEMM, so about n * gemmt_block * k flops go to entries that are thrown away, against n^2 k for the triangle itself: an eighth at n = 512. Measured with OpenBLAS at n = 256 to 1024, 32 and 64 are within 3% of each other and 128 and 256 are slower: the smaller GEMMs lose about what the saved work gains.

◆ gemmt_dispatches_blas_v

template<typename Accumulator, typename MA, typename MB, typename MC>
bool mtl::detail::gemmt_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether gemmt<Accumulator>(alpha, A, B, beta, C) calls ?gemmt (for sizes that fit an int; with OpenBLAS, only for n <= gemmt_block – see gemmt_uses_blocked_v).

◆ gemmt_strided_dense_v

template<typename M>
bool mtl::detail::gemmt_strided_dense_v
inlineconstexpr
Initial value:
= [] {
return requires { typename M::orientation; };
else
return false;
}()
Concept satisfied by dense matrix types eligible for BLAS/LAPACK dispatch.
Definition dispatch_traits.hpp:93

Dense float/double with contiguous storage and an orientation: the operands the blocked gemmt describes by strides.

◆ gemmt_strided_operand_v

template<typename M>
bool mtl::detail::gemmt_strided_operand_v
inlineconstexpr
Initial value:
= [] {
if constexpr (is_transposed_view_v<M>)
return gemmt_strided_dense_v<std::remove_cvref_t<decltype(std::declval<const M&>().base())>>;
else
}()
constexpr bool is_transposed_view_v
Definition gemmt.hpp:91
constexpr bool gemmt_strided_dense_v
Dense float/double with contiguous storage and an orientation: the operands the blocked gemmt describ...
Definition gemmt.hpp:261

◆ gemmt_uses_blocked_v

template<typename Accumulator, typename MA, typename MB, typename MC>
bool mtl::detail::gemmt_uses_blocked_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether gemmt<Accumulator>(alpha, A, B, beta, C) takes the blocked path for n > gemmt_block (#744): wherever ?gemmt is not called, and with OpenBLAS in place of its dgemmt.

◆ gemv_colmajor_columns

std::size_t mtl::detail::gemv_colmajor_columns = 2
inlineconstexpr

Columns the col-major gemv takes per pass over a strip of y (#804): four where the target has a fused multiply-add, two where fma is a separate multiply and add.

A tuning choice only – either grouping gives each y[i] the same chain of operations, so the result does not depend on it. Read from the compiler's macros, not Highway's HWY_NATIVE_FMA (see scalar_fma in simd/batch.hpp for why that one is not trusted). MSVC defines no FMA; its /arch:AVX2 enables FMA3, so AVX2 stands in for it there.

◆ gemv_colmajor_strip_rows

template<typename T>
std::size_t mtl::detail::gemv_colmajor_strip_rows
inlineconstexpr
Initial value:
=
(65536 / sizeof(T)) / simd::batch<T>::size * simd::batch<T>::size > 0
? (65536 / sizeof(T)) / simd::batch<T>::size * simd::batch<T>::size
static constexpr std::size_t size
Definition batch.hpp:470

Rows per strip of the col-major gemv: 64 KB of y, a whole number of batches (at least one).

◆ ger_dispatches_blas_v

template<typename Accumulator, typename S, typename M, typename VX, typename VY>
bool mtl::detail::ger_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether ger<Accumulator>(alpha, x, y, A) calls ?ger (for sizes that fit an int).

Either orientation of A qualifies: a row-major A is the column-major A^T, updated by ?ger with x and y swapped (#849).

?ger takes alpha in A's element type T, so the scalar S must not be wider than T: common_type_t<S, T> is T. An int or a float alpha with double A converts as the generic expression would convert it; a double alpha with float A would be rounded to float first (2^-150 becomes 0, and ?ger then returns without an update), so it takes the generic path, which forms alpha x(i) y(j) in double.

◆ holds_expression_v

template<typename T>
bool mtl::detail::holds_expression_v = holds_expression<std::remove_cvref_t<T>>()
inlineconstexpr

◆ is_sat_int_v

template<typename T>
bool mtl::detail::is_sat_int_v = sat_traits<T>::is_int
inlineconstexpr

◆ is_transposed_csr_v

template<typename M>
bool mtl::detail::is_transposed_csr_v = false
inlineconstexpr

◆ is_transposed_csr_v< mat::view::transposed_view< mat::compressed2D< V, P > > >

template<typename V, typename P>
bool mtl::detail::is_transposed_csr_v< mat::view::transposed_view< mat::compressed2D< V, P > > > = true
inlineconstexpr

◆ is_transposed_view_v

template<typename M>
bool mtl::detail::is_transposed_view_v = false
inlineconstexpr

◆ is_transposed_view_v< mat::view::transposed_view< M > >

template<typename M>
bool mtl::detail::is_transposed_view_v< mat::view::transposed_view< M > > = true
inlineconstexpr

◆ is_wrapping_integer_v

template<typename T>
bool mtl::detail::is_wrapping_integer_v
inlineconstexpr
Initial value:
=
std::is_integral_v<T> && !std::is_same_v<T, bool>

Integral types these helpers wrap.

bool is excluded: std::make_unsigned_t<bool> is ill-formed, and boolean arithmetic promotes to int and cannot overflow, so it belongs on the plain branch rather than in a modular one.

◆ keep_scalar_triangular_v

template<typename T, typename M, std::size_t W>
bool mtl::detail::keep_scalar_triangular_v
inlineconstexpr
Initial value:
=
constexpr bool keep_scalar_v
Whether the W accumulators of type T over a matrix of type M need keep_scalar (see the top of this fi...
Definition scalar_chain.hpp:77

The same, for the trmv and forward-substitution kernels: as keep_scalar_v on x86-64, never on AArch64, where it made them 5.6-7.2x slower (#795).

◆ keep_scalar_v

template<typename T, typename M, std::size_t W>
bool mtl::detail::keep_scalar_v
inlineconstexpr
Initial value:
=
false

Whether the W accumulators of type T over a matrix of type M need keep_scalar (see the top of this file).

◆ mat_params_differ_only_in_space_v

template<typename P1, typename P2>
bool mtl::detail::mat_params_differ_only_in_space_v
inlineconstexpr
Initial value:
=
std::is_same_v<typename P1::orientation, typename P2::orientation>
&& std::is_same_v<typename P1::index_type, typename P2::index_type>
&& std::is_same_v<typename P1::dimensions_type, typename P2::dimensions_type>
&& std::is_same_v<typename P1::storage, typename P2::storage>
&& std::is_same_v<typename P1::size_type, typename P2::size_type>
&& !std::is_same_v<memory_space_of_t<P1>, memory_space_of_t<P2>>
typename memory_space_of< T >::type memory_space_of_t
Definition memory_space.hpp:313

True when two matrix parameter bundles agree in every axis but the memory space (#1012): a dense2D of one may be built from, and assigned, a dense2D of the other.

A change of orientation, index base, dimensions, storage or size type is a change of layout or kind, not of where the elements live.

◆ mult_mat_temporary_ok_v

template<typename MC>
bool mtl::detail::mult_mat_temporary_ok_v
inlineconstexpr
Initial value:
=
std::is_constructible_v<MC, typename MC::size_type, typename MC::size_type> &&
std::is_copy_assignable_v<MC>

Whether mult can route an aliased C through mult_mat_via_temporary: C's type can be made at C's size and copy-assigned.

Every matrix mult writes can (dense2D, compressed2D).

◆ nc_model_count

std::size_t mtl::detail::nc_model_count
inlineconstexpr
Initial value:
=
sizeof(all_nc_models) / sizeof(all_nc_models[0])
constexpr nc_model all_nc_models[]
Definition nc_model.hpp:303

How many models there are.

Derived, because a hardcoded copy of this number silently EXCLUDED a model once: bench_nc_models and sweep_nc_models both carried a literal 6, and when M6 was added in #429 neither tool measured it – the shipped default was the one arm missing from the harness that exists to check the default. Nothing failed; the CSVs just had six rows per shape instead of seven.

◆ norm_col_major_v

template<typename M>
bool mtl::detail::norm_col_major_v
inlineconstexpr
Initial value:
= [] {
if constexpr (requires { typename M::orientation; })
return std::is_same_v<typename M::orientation, tag::col_major>;
else
return false;
}()

The loop order of a matrix norm follows the storage (issue 886): one_norm walked a row-major 6000^2 dense2D by columns, 6x slower than infinity_norm, and the other two were the mirror image on column-major.

◆ norm_row_major_v

template<typename M>
bool mtl::detail::norm_row_major_v
inlineconstexpr
Initial value:
= [] {
if constexpr (requires { typename M::orientation; })
return std::is_same_v<typename M::orientation, tag::row_major>;
else
return false;
}()

◆ rescalable_sum_squares_v

template<typename Mag>
bool mtl::detail::rescalable_sum_squares_v = norms_adl::rescalable_sum_squares<Mag>
inlineconstexpr

◆ row_kernel_fixed_rows_min_columns

std::size_t mtl::detail::row_kernel_fixed_rows_min_columns = 16
inlineconstexpr

... and only over at least this many columns: below it the call costs more than the loop (2 x 2 and 4 x 4 ran at 0.46-0.83 through it).

◆ row_kernel_fixed_rows_v

template<typename Acc, typename M>
bool mtl::detail::row_kernel_fixed_rows_v
inlineconstexpr
Initial value:
=
false

Whether the row kernels (mult_rows_interleaved, trmv_upper_rows, trmv_lower_rows) run a block's column loop as sweep_fixed_rows<W> on a contiguous column-major A (#898): GCC on x86-64 only.

There GCC's loop vectorizer could turn the loop into an in-order reduction across the columns, which on the i7-12700K and the Xeon E5-2420 v2 ran gemv 2.0-4.0x and trmv 1.6-2.4x slower than sweep_fixed_rows (geometric mean over the shapes up to 256, generic and -march=native). Elsewhere the row kernel's own loop measured as fast or faster: GCC on the Jetson and the Ventuno, Clang and MSVC lost up to 2x on trmv through sweep_fixed_rows. A row-major A always keeps its loop.

◆ row_major_contiguous_v

template<typename M>
bool mtl::detail::row_major_contiguous_v
inlineconstexpr
Initial value:
= [] {
if constexpr (interface::ContiguousMatrixData<M> && requires { typename M::orientation; })
else
return false;
}()
constexpr bool is_row_major_v
Check if a matrix type uses row-major orientation.
Definition dispatch_traits.hpp:318

Row-major storage with contiguous rows: data() and a row-major orientation.

False (not an error) for views without an orientation.

◆ sat_signed_v

template<typename T>
bool mtl::detail::sat_signed_v = sat_traits<T>::is_signed
inlineconstexpr

◆ symm_dispatches_blas_v

template<typename Accumulator, typename MA, typename MB, typename MC>
bool mtl::detail::symm_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether symm<Accumulator>(alpha, A, B, beta, C) calls ?symm (for sizes that fit an int).

B and C must share an orientation; A's may be either.

◆ symm_uses_blocked_v

template<typename MA, typename MB, typename MC>
bool mtl::detail::symm_uses_blocked_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether symm<void> on this build expands A and calls the native blocked GEMM (#724): MTL5_NATIVE_FAST_GEMM, float or double, dense A and B, row-major C.

◆ symm_uses_row_loop_v

template<typename MB>
bool mtl::detail::symm_uses_row_loop_v = row_major_contiguous_v<MB>
inlineconstexpr

Whether the generic symm<void> forms C row by row over a row-major B (#724).

◆ symv_dispatches_blas_v

template<typename Accumulator, typename M, typename VX, typename VY>
bool mtl::detail::symv_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether symv<Accumulator>(alpha, A, x, beta, y) calls ?symv (for sizes that fit an int).

Either orientation of A: a symmetric matrix's row-major buffer holds its lower triangle where the column-major view has the upper one (#724).

◆ symv_strip_block

std::size_t mtl::detail::symv_strip_block = 256
inlineconstexpr

◆ symv_strip_min_n

std::size_t mtl::detail::symv_strip_min_n = 128
inlineconstexpr

◆ symv_strip_rows

std::size_t mtl::detail::symv_strip_rows = 8
inlineconstexpr

Rows per strip of the row-major symv (#236), and columns per block of a strip's pass over the columns left of it: 8 rows of 256 doubles are 16 KB, in L1 for the second of the two loops below.

Below symv_strip_min_n the row loop is as fast.

◆ symv_uses_row_loop_v

template<typename M>
bool mtl::detail::symv_uses_row_loop_v = row_major_contiguous_v<M>
inlineconstexpr

Whether the generic symv<void> makes one row-wise pass over a row-major A's lower triangle (#724).

◆ syr2k_dispatches_blas_v

template<typename Accumulator, typename MA, typename MB, typename MC>
bool mtl::detail::syr2k_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether syr2k<Accumulator>(alpha, A, B, beta, C) calls ?syr2k (for sizes that fit an int).

A and B must share an orientation; C's may be either (#724).

◆ syr2k_uses_gemmt_v

template<typename Accumulator, typename S, typename MA, typename MB, typename MC>
bool mtl::detail::syr2k_uses_gemmt_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether syr2k<Accumulator>(alpha, A, B, beta, C) is two gemmt calls, C = alpha A B^T + beta C and then C += alpha B A^T, above detail::gemmt_block rows (#236): the MTL5_NATIVE_FAST_GEMM build without BLAS, where gemmt takes its blocked path over gemm_blocked.

A BLAS build calls ?syr2k instead. alpha and beta must be of C's element type, as in syrk_uses_gemmt_v.

◆ syr2k_uses_row_loop_v

template<typename MA, typename MB>
bool mtl::detail::syr2k_uses_row_loop_v = row_major_contiguous_v<MA> && row_major_contiguous_v<MB>
inlineconstexpr

Whether the generic syr2k<void> forms C's lower triangle row by row over transposed copies of row-major A and B (#724).

◆ syrk_dispatches_blas_v

template<typename Accumulator, typename MA, typename MC>
bool mtl::detail::syrk_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether syrk<Accumulator>(alpha, A, beta, C) calls ?syrk (for sizes that fit an int).

Every orientation of A and C (#724).

◆ syrk_uses_gemmt_v

template<typename Accumulator, typename S, typename MA, typename MC>
bool mtl::detail::syrk_uses_gemmt_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether syrk<Accumulator>(alpha, A, beta, C) is gemmt(alpha, A, trans(A), beta, C) above detail::gemmt_block rows (#236): the MTL5_NATIVE_FAST_GEMM build without BLAS, where gemmt takes its blocked path over gemm_blocked.

A BLAS build calls ?syrk instead. alpha and beta must be of C's element type: gemmt converts them to it, so a double beta of 1e-50 on float matrices became 0 and C was not read, where syrk's loops scale C in double.

◆ syrk_uses_row_loop_v

template<typename MA>
bool mtl::detail::syrk_uses_row_loop_v = row_major_contiguous_v<MA>
inlineconstexpr

Whether the generic syrk<void> forms C's lower triangle row by row over a transposed copy of a row-major A (#724).

◆ transpose_tile

std::size_t mtl::detail::transpose_tile = 32
inlineconstexpr

Tile edge of transpose_copy, chosen by measurement on an Apple M2 and an x86-64 host (issue 1040): 32 beat 8, 16 and 64 for float and double.

◆ triangular_block

std::size_t mtl::detail::triangular_block = 64
inlineconstexpr

Row block of the blocked trsm and trmm on the native-fast path (#724): the diagonal blocks run in the row loop, everything else in the blocked GEMM, so the row loop's share of the flops is about triangular_block / m.

◆ trmm_dispatches_blas_v

template<typename Accumulator, typename MA, typename MB>
bool mtl::detail::trmm_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trmm<Accumulator>(alpha, A, B, ...) calls ?trmm (for sizes that fit an int and a nonzero alpha).

Every orientation of A and B qualifies.

◆ trmm_uses_blocked_v

template<typename MA, typename MB>
bool mtl::detail::trmm_uses_blocked_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trmm<void> on this build takes the blocked product over the native GEMM (#724): as trsm_uses_blocked_v.

◆ trmm_uses_row_loop_v

template<typename MB>
bool mtl::detail::trmm_uses_row_loop_v = row_major_contiguous_v<MB>
inlineconstexpr

Whether the generic trmm<void> forms a row-major B row by row (#724).

◆ trmv_dispatches_blas_v

template<typename Accumulator, typename M, typename VX>
bool mtl::detail::trmv_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trmv<Accumulator>(A, x, ...) calls ?trmv (for n that fits an int).

◆ trmv_uses_blocked_v

template<typename Accumulator, typename M, typename VX>
bool mtl::detail::trmv_uses_blocked_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trmv<Accumulator>(A, x, ...) takes the blocked SIMD path for n > triangular_block (#747): native-fast, no BLAS, float/double.

◆ trsm_dispatches_blas_v

template<typename Accumulator, typename MA, typename MB>
bool mtl::detail::trsm_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trsm<Accumulator>(alpha, A, B, ...) calls ?trsm (for sizes that fit an int).

Every orientation of A and B qualifies.

◆ trsm_uses_blocked_v

template<typename MA, typename MB>
bool mtl::detail::trsm_uses_blocked_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trsm<void> on this build takes the blocked solve over the native GEMM (#724): MTL5_NATIVE_FAST_GEMM, float or double, dense A, row-major B.

◆ trsm_uses_row_loop_v

template<typename MB>
bool mtl::detail::trsm_uses_row_loop_v = row_major_contiguous_v<MB>
inlineconstexpr

Whether the generic trsm<void> solves a row-major B row by row (#724).

◆ trsv_dispatches_blas_v

template<typename Accumulator, typename M, typename VX>
bool mtl::detail::trsv_dispatches_blas_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trsv<Accumulator>(A, x, ...) calls ?trsv (for n that fits an int).

◆ trsv_uses_blocked_v

template<typename Accumulator, typename M, typename VX>
bool mtl::detail::trsv_uses_blocked_v
inlineconstexpr
Initial value:
= [] {
return false;
}()

Whether trsv<Accumulator>(A, x, ...) takes the blocked SIMD path for n > triangular_block (#747): native-fast, no BLAS, float/double.

◆ vec_params_differ_only_in_space_v

template<typename P1, typename P2>
bool mtl::detail::vec_params_differ_only_in_space_v
inlineconstexpr
Initial value:
=
std::is_same_v<typename P1::orientation, typename P2::orientation>
&& std::is_same_v<typename P1::dimensions_type, typename P2::dimensions_type>
&& std::is_same_v<typename P1::storage, typename P2::storage>
&& std::is_same_v<typename P1::size_type, typename P2::size_type>
&& !std::is_same_v<memory_space_of_t<P1>, memory_space_of_t<P2>>

True when two vector parameter bundles agree in every axis but the memory space (#1012): a dense_vector of one may be built from, and assigned, a dense_vector of the other.

A change of orientation, dimensions, storage or size type is a change of shape or kind, not of where the elements live.

◆ zero_fill_is_value_init_v

template<typename T>
bool mtl::detail::zero_fill_is_value_init_v = ::mtl::zero_fill_is_value_init<std::remove_cv_t<T>>::value
inlineconstexpr