MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::simd::batch< T > Class Template Reference

#include <batch.hpp>

Public Types

using value_type = T

Public Member Functions

 batch ()=default
 batch (T x)
void store_aligned (T *p) const
void store_unaligned (T *p) const

Static Public Member Functions

static batch load_aligned (const T *p)
static batch load_unaligned (const T *p)
template<typename Src>
static batch load_widen (const Src *p)
 Load one narrower value and widen to T (scalar fallback of the SIMD widening load; see the Highway variant).
template<typename I>
requires (std::is_same_v<T, float> && (std::is_same_v<I, std::int32_t> || std::is_same_v<I, std::uint32_t>))
static batch convert (batch< I > v)
 Integer -> float lane conversion – scalar fallback; see the Highway variant.
template<typename Narrow>
static void widen_dot_accumulate (const Narrow *a, const Narrow *b, batch &sum0, batch &sum1)
 Widening dot accumulate – scalar fallback of the SIMD primitive; see the Highway variant for the contract.
template<typename NA, typename NB>
static void quad_dot_accumulate (const NA *a, const NB *b, batch &sum)
 Quad-widening dot accumulate – scalar fallback; see the Highway variant.
template<typename NA, typename NB>
static void quad_dot_broadcast_accumulate (const NA *a4, const NB *b, batch &sum)
 Quad multiply-accumulate with a broadcast left operand – scalar fallback; see the Highway variant for the contract.

Static Public Attributes

static constexpr std::size_t size = 1
static constexpr std::size_t widen_step = 2
 Narrow values consumed per widen_dot_accumulate call.
static constexpr std::size_t quad_step = 4
 Narrow values consumed per quad_dot_accumulate call – four, matching the instruction's four-products-per-lane shape rather than the lane count.

Friends

template<typename>
class batch
struct detail::batch_access
batch operator+ (batch a, batch b)
batch operator- (batch a, batch b)
batch operator* (batch a, batch b)
batch operator/ (batch a, batch b)
 Lane-wise division – floating lanes only; see the Highway variant for why.
batch fma (batch a, batch b, batch c)
 Fused multiply-add: a*b + c (the single FMA decision point).
batch min (batch a, batch b)
 Lane-wise minimum and maximum, as std::min and std::max; see the Highway variant.
batch max (batch a, batch b)
T reduce_add (batch a)
T reduce_min (batch a)
T reduce_max (batch a)

Member Typedef Documentation

◆ value_type

template<typename T>
using mtl::simd::batch< T >::value_type = T

Constructor & Destructor Documentation

◆ batch() [1/2]

template<typename T>
mtl::simd::batch< T >::batch ( )
default

◆ batch() [2/2]

template<typename T>
mtl::simd::batch< T >::batch ( T x)
inlineexplicit

Member Function Documentation

◆ convert()

template<typename T>
template<typename I>
requires (std::is_same_v<T, float> && (std::is_same_v<I, std::int32_t> || std::is_same_v<I, std::uint32_t>))
batch mtl::simd::batch< T >::convert ( batch< I > v)
inlinestatic

Integer -> float lane conversion – scalar fallback; see the Highway variant.

static_cast rounds to nearest, as the SIMD instruction does.

◆ load_aligned()

template<typename T>
batch mtl::simd::batch< T >::load_aligned ( const T * p)
inlinestatic

◆ load_unaligned()

template<typename T>
batch mtl::simd::batch< T >::load_unaligned ( const T * p)
inlinestatic

◆ load_widen()

template<typename T>
template<typename Src>
batch mtl::simd::batch< T >::load_widen ( const Src * p)
inlinestatic

Load one narrower value and widen to T (scalar fallback of the SIMD widening load; see the Highway variant).

◆ quad_dot_accumulate()

template<typename T>
template<typename NA, typename NB>
void mtl::simd::batch< T >::quad_dot_accumulate ( const NA * a,
const NB * b,
batch< T > & sum )
inlinestatic

Quad-widening dot accumulate – scalar fallback; see the Highway variant.

Four products into the single accumulator, which is exactly what the instruction does to one lane.

◆ quad_dot_broadcast_accumulate()

template<typename T>
template<typename NA, typename NB>
void mtl::simd::batch< T >::quad_dot_broadcast_accumulate ( const NA * a4,
const NB * b,
batch< T > & sum )
inlinestatic

Quad multiply-accumulate with a broadcast left operand – scalar fallback; see the Highway variant for the contract.

With one lane the broadcast is a no-op, so this is the same four products as quad_dot_accumulate – which is the definition the SIMD path has to reproduce lane by lane, and the reference the tests compare against.

◆ store_aligned()

template<typename T>
void mtl::simd::batch< T >::store_aligned ( T * p) const
inline

◆ store_unaligned()

template<typename T>
void mtl::simd::batch< T >::store_unaligned ( T * p) const
inline

◆ widen_dot_accumulate()

template<typename T>
template<typename Narrow>
void mtl::simd::batch< T >::widen_dot_accumulate ( const Narrow * a,
const Narrow * b,
batch< T > & sum0,
batch< T > & sum1 )
inlinestatic

Widening dot accumulate – scalar fallback of the SIMD primitive; see the Highway variant for the contract.

Splitting the two products across the two accumulators reproduces the "unspecified lane assignment, defined total" behaviour rather than papering over it.

◆ batch

template<typename T>
template<typename>
friend class batch
friend

◆ detail::batch_access

template<typename T>
friend struct detail::batch_access
friend

◆ fma

template<typename T>
batch fma ( batch< T > a,
batch< T > b,
batch< T > c )
friend

Fused multiply-add: a*b + c (the single FMA decision point).

std::fma is a floating-point function, so the integer case is the plain wrapping multiply-add – which is exact mod 2^32 and therefore matches the Highway backend's MulAdd lane for lane.

◆ max

template<typename T>
batch max ( batch< T > a,
batch< T > b )
friend

◆ min

template<typename T>
batch min ( batch< T > a,
batch< T > b )
friend

Lane-wise minimum and maximum, as std::min and std::max; see the Highway variant.

◆ operator*

template<typename T>
batch operator* ( batch< T > a,
batch< T > b )
friend

◆ operator+

template<typename T>
batch operator+ ( batch< T > a,
batch< T > b )
friend

◆ operator-

template<typename T>
batch operator- ( batch< T > a,
batch< T > b )
friend

◆ operator/

template<typename T>
batch operator/ ( batch< T > a,
batch< T > b )
friend

Lane-wise division – floating lanes only; see the Highway variant for why.

◆ reduce_add

template<typename T>
T reduce_add ( batch< T > a)
friend

◆ reduce_max

template<typename T>
T reduce_max ( batch< T > a)
friend

◆ reduce_min

template<typename T>
T reduce_min ( batch< T > a)
friend

Member Data Documentation

◆ quad_step

template<typename T>
std::size_t mtl::simd::batch< T >::quad_step = 4
staticconstexpr

Narrow values consumed per quad_dot_accumulate call – four, matching the instruction's four-products-per-lane shape rather than the lane count.

◆ size

template<typename T>
std::size_t mtl::simd::batch< T >::size = 1
staticconstexpr

◆ widen_step

template<typename T>
std::size_t mtl::simd::batch< T >::widen_step = 2
staticconstexpr

Narrow values consumed per widen_dot_accumulate call.

Two rather than one, so the fallback drives BOTH accumulators and the loop in reduce_dot_widen is the same shape on either backend – which also means the fallback exercises the sum1 path that Highway may or may not use.


The documentation for this class was generated from the following file:
  • /home/runner/work/mtl5/mtl5/include/mtl/simd/batch.hpp