MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::math::accumulator_traits< Acc, Value > Struct Template Reference

Accumulator policy for accumulating products of Values into an Acc. More...

#include <accumulator_traits.hpp>

Static Public Member Functions

static void clear (Acc &a)
 Reset the accumulator to zero.
static void assign (Acc &a, const Value &v)
 Set the accumulator to a single value.
template<typename Result = Value>
static Result value (const Acc &a)
 Round the accumulator out to Result (default: the element type Value), once, at the point the accumulated entry is consumed – giving single-rounding ("exact dot product") semantics when Acc is exact, and fusing the accumulate->output conversion when Result differs from Acc.
static void add_product (Acc &a, const Value &m, const Value &v)
 a += m * v : the canonical accumulate-a-product primitive (a dot product / quire is a sum of products).
static void merge (Acc &a, const Acc &b)
 a += b : combine two partial accumulators of the same reduction, e.g.

Detailed Description

template<typename Acc, typename Value>
struct mtl::math::accumulator_traits< Acc, Value >

Accumulator policy for accumulating products of Values into an Acc.

Configuration 1 (plain acc += product): the primary template. The product is formed in Acc, so Acc wider than Value accumulates more accurately.

Member Function Documentation

◆ add_product()

template<typename Acc, typename Value>
void mtl::math::accumulator_traits< Acc, Value >::add_product ( Acc & a,
const Value & m,
const Value & v )
inlinestatic

a += m * v : the canonical accumulate-a-product primitive (a dot product / quire is a sum of products).

Callers pass a negated multiplier for a subtraction (e.g. the LU elimination update). The product is formed in the accumulator precision Acc, so a wider Acc than Value (e.g. fp32 accumulate over bf16 elements) gains accuracy out of the box; this is a no-op cast and byte-identical when Acc == Value.

◆ assign()

template<typename Acc, typename Value>
void mtl::math::accumulator_traits< Acc, Value >::assign ( Acc & a,
const Value & v )
inlinestatic

Set the accumulator to a single value.

◆ clear()

template<typename Acc, typename Value>
void mtl::math::accumulator_traits< Acc, Value >::clear ( Acc & a)
inlinestatic

Reset the accumulator to zero.

math::zero<Acc>(), i.e. Acc{0}, NOT a value-initialized Acc{}. The two agree for the built-in types but not in general: a logarithmic number system encodes 2^0 in its all-zero bit pattern, so Universal's lns{} is 1.0. With Acc{} here, every sum of products over an lns accumulator started at 1 – which, once householder() routed its default-path sum of squares through this function (#537), broke QR/LQ for lns outright.

◆ merge()

template<typename Acc, typename Value>
void mtl::math::accumulator_traits< Acc, Value >::merge ( Acc & a,
const Acc & b )
inlinestatic

a += b : combine two partial accumulators of the same reduction, e.g.

the per-thread or per-process partials of a parallel dot product. For this configuration it is an ordinary add, one rounding; for an exact super-accumulator it is exact, which is what makes a parallel reduction independent of how the terms were partitioned. Offered only when Acc has a +=, so mergeable_accumulator is an accurate test.

◆ value()

template<typename Acc, typename Value>
template<typename Result = Value>
Result mtl::math::accumulator_traits< Acc, Value >::value ( const Acc & a)
inlinestatic

Round the accumulator out to Result (default: the element type Value), once, at the point the accumulated entry is consumed – giving single-rounding ("exact dot product") semantics when Acc is exact, and fusing the accumulate->output conversion when Result differs from Acc.


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