|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
#include <algorithm>#include <cstddef>#include <type_traits>#include <utility>#include <mtl/interface/dispatch_traits.hpp>#include <mtl/tag/orientation.hpp>Namespaces | |
| namespace | mtl |
| namespace | mtl::detail |
| mat*vec multiply into pre-allocated y: y = A * x. | |
Macros | |
| #define | MTL5_NO_LOOP_VECTORIZE |
| GCC's loop vectorizer off for one function, the SLP vectorizer on (#884, #898). | |
Functions | |
| template<std::size_t C, typename T> | |
| constexpr bool | mtl::detail::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 | 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. | |
| 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. | |
| 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. | |
Variables | |
| template<typename M> | |
| constexpr bool | mtl::detail::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 | mtl::detail::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 | mtl::detail::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 | mtl::detail::column_sweep_columns = 8 |
| Columns per pass over a strip (#884). | |
| constexpr std::size_t | mtl::detail::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 | mtl::detail::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 | mtl::detail::column_sweep_trmv_row_kernel_n = 64 |
| constexpr std::size_t | mtl::detail::column_sweep_trsv_row_kernel_n = 64 |
| template<typename Acc, typename M> | |
| constexpr bool | mtl::detail::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 | mtl::detail::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 | mtl::detail::column_sweep_fixed_rows = 16 |
| Strips of at most this many rows take sweep_fixed_rows (#884). | |
| #define MTL5_NO_LOOP_VECTORIZE |
GCC's loop vectorizer off for one function, the SLP vectorizer on (#884, #898).
In the fixed-row strip (and so in the row kernels on a column-major A under GCC on x86-64, row_kernel_fixed_rows_v), the R accumulators are R independent chains over the columns. GCC's SLP vectorizer packs them into registers, which is what these loops want. With AVX its loop vectorizer can instead vectorize the column loop itself, as an in-order reduction: R x 4 columns loaded, then each chain rebuilt with shuffles and scalar merges. Which one it picks depends on the calling context, so the same instantiation ran at 0.35 us in one binary and 2.2 us in another (64 x 64 f64 gemv, i7-12700K, -O3 -march=native). Clang and MSVC don't do it.