MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mult.hpp File Reference
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <limits>
#include <type_traits>
#include <utility>
#include <mtl/concepts/matrix.hpp>
#include <mtl/concepts/vector.hpp>
#include <mtl/math/identity.hpp>
#include <mtl/math/accumulator_traits.hpp>
#include <mtl/detail/same_object.hpp>
#include <mtl/detail/wrapping_arithmetic.hpp>
#include <mtl/detail/scalar_chain.hpp>
#include <mtl/detail/column_sweep.hpp>
#include <mtl/interface/dispatch_traits.hpp>
#include <mtl/traits/is_expression.hpp>
#include <mtl/mat/dense2D.hpp>
#include <mtl/interface/interleave_rows.hpp>
#include <mtl/mat/compressed2D.hpp>
#include <mtl/mat/view/transposed_view.hpp>
#include <mtl/vec/dense_vector.hpp>
#include <mtl/detail/thread_pool.hpp>
#include <mtl/detail/dispatch_trace.hpp>
#include <vector>
#include <mtl/interface/device_dispatch.hpp>

Namespaces

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

Functions

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).
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).
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).
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.
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.
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.
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.
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).
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>.
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).
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.
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.
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.
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).
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.
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.
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.
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).
template<typename Accumulator = void, typename V, typename P, Vector VIn, Vector VOut>
void mtl::mult (const mat::view::transposed_view< mat::compressed2D< V, P > > &At, const VIn &x, VOut &y)
 y = A^T x for a transposed compressed2D.
template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mtl::mult (const M &A, const VIn &x, VOut &y)
 y = A x.
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).
template<typename T>
constexpr bool mtl::detail::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 > 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.
template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mtl::mult (const MA &A, const MB &B, MC &C)
 mat*mat multiply into pre-allocated C: C = A * B.
template<typename Accumulator, Matrix MA, Matrix MB, Matrix MC>
void mtl::mult_quad (const MA &A, const MB &B, MC &C)
 C = A * B through the QUAD MULTIPLY-ACCUMULATE micro-kernel – VNNI vpdpbusd on x86, SDOT/UDOT on NEON (#451 phase 5).

Variables

template<typename Accumulator, typename MA, typename MB>
constexpr bool mtl::detail::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 mtl::detail::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 mtl::detail::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 mtl::detail::holds_expression_v = holds_expression<std::remove_cvref_t<T>>()
template<typename MC>
constexpr bool mtl::detail::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.