Tensorium
Loading...
Searching...
No Matches
tensorium::MatrixKernel< K > Class Template Reference

MatrixKernel provides specialized SIMD-accelerated matrix multiplication routines for statically-sized square matrices. More...

#include <MatrixKernel.hpp>

Inheritance diagram for tensorium::MatrixKernel< K >:
Collaboration diagram for tensorium::MatrixKernel< K >:

Public Types

using Simd = simd::SimdTraits<K, DefaultISA>
 
using reg = typename Simd::reg
 
- Public Types inherited from tensorium::Matrix< K, true >
using Simd
 
using reg
 

Public Member Functions

 MatrixKernel (const Matrix< K, true > &m)
 Construct a MatrixKernel from a column-major matrix.
 
 MatrixKernel (const Matrix< K, false > &m)
 Construct a MatrixKernel from a row-major matrix by copying elements.
 
 MatrixKernel (size_t r, size_t c)
 Construct an empty column-major matrix kernel of size (r × c).
 
Matrix< Kmul_mat2x2 (const MatrixKernel< K > &B) const
 Multiply two 2×2 matrices using SIMD.
 
Matrix< Kmul_mat3x3 (const MatrixKernel< K > &B) const
 Multiply two 3×3 matrices using SIMD.
 
Matrix< Kmul_mat4x4 (const MatrixKernel< K > &B) const
 Multiply two 4×4 matrices using SIMD.
 
Matrix< Kmul_mat8x8 (const MatrixKernel< K > &B) const
 Multiply two 8×8 matrices using SIMD.
 
Matrix< Kmul_mat16x16 (const MatrixKernel< K > &B) const
 Multiply two 16×16 matrices using SIMD with FMADD accumulation. This function splits each row into two registers (low/high).
 
Matrix< Kmul_mat32x32 (const MatrixKernel< K > &B) const
 Multiply two 32×32 matrices using SIMD. Each row is split into two registers (16 elements each).
 
Matrix< Kmul_mat64x64 (const MatrixKernel< K > &B) const
 Multiply two 64×64 matrices using SIMD. Each row is split into 4 SIMD registers (4×16 elements). Vectorized FMADD chaining is used for performance.
 
- Public Member Functions inherited from tensorium::Matrix< K, true >
 Matrix (size_t r, size_t c)
 Construct a matrix of size r × c, initialized with zeros.
 
size_t index (size_t i, size_t j) const
 
size_t size () const
 Return the total number of elements.
 
Koperator() (size_t i, size_t j)
 Element access (mutable)
 
const Koperator() (size_t i, size_t j) const
 
void print () const
 Print the matrix to stdout.
 
void swap_rows (size_t i, size_t j)
 Swap two rows of the matrix.
 
Vector< Toperator* (const Vector< T > &v) const
 Multiply matrix by a vector (naïve fallback)
 
void add (const Matrix &m)
 In-place matrix addition: this += m.
 
void sub (const Matrix &m)
 In-place matrix subtraction: this -= m.
 
void scl (K a)
 In-place scalar multiplication: this *= a.
 
void lerp (const Matrix< K > &A, const Matrix< K > &B, K alpha)
 Linearly interpolate between two matrices: this = (1 - α) * A + α * B.
 
Matrix _mul_mat (const Matrix< K > &mat) const
 Multiply matrix by another matrix using optimized SIMD path.
 
Vector< Tmul_vec (const Vector< T > &x) const
 Multiply matrix by a vector using SIMD.
 
Matrix< Ktranspose () const
 Returns the transpose \( A^T \) of the matrix (column-major layout)
 
Matrix< Ktrace () const
 Returns the trace of a square matrix as a 1×1 matrix.
 
Matrix< Kinverse () const
 Compute the inverse of the matrix using Gauss–Jordan elimination.
 
K det () const
 Compute the determinant using Gaussian elimination.
 
size_t rank (K eps=K(1e-6)) const
 Compute the numerical rank of the matrix.
 

Additional Inherited Members

- Public Attributes inherited from tensorium::Matrix< K, true >
size_t rows
 
size_t cols
 
aligned_vector< Kdata
 
size_t block_size
 
bool iscolumn
 
size_t simd_width
 

Detailed Description

template<typename K>
class tensorium::MatrixKernel< K >

MatrixKernel provides specialized SIMD-accelerated matrix multiplication routines for statically-sized square matrices.

This class inherits from a column-major Matrix<K, true> and offers optimized kernels for specific square sizes (2x2, 3x3, ..., 64x64), using AVX/SIMD intrinsics for high performance. The kernels exploit register-level blocking and FMADD chaining.

Template Parameters
KScalar type (float, double, etc.)

Member Typedef Documentation

◆ reg

template<typename K >
using tensorium::MatrixKernel< K >::reg = typename Simd::reg

◆ Simd

Constructor & Destructor Documentation

◆ MatrixKernel() [1/3]

template<typename K >
tensorium::MatrixKernel< K >::MatrixKernel ( const Matrix< K, true > & m)
inline

Construct a MatrixKernel from a column-major matrix.

Parameters
mSource matrix.

◆ MatrixKernel() [2/3]

template<typename K >
tensorium::MatrixKernel< K >::MatrixKernel ( const Matrix< K, false > & m)
inline

Construct a MatrixKernel from a row-major matrix by copying elements.

Parameters
mSource matrix.

References tensorium::Matrix< K, RowMajor >::cols, and tensorium::Matrix< K, RowMajor >::rows.

◆ MatrixKernel() [3/3]

template<typename K >
tensorium::MatrixKernel< K >::MatrixKernel ( size_t r,
size_t c )
inline

Construct an empty column-major matrix kernel of size (r × c).

Member Function Documentation

◆ mul_mat16x16()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat16x16 ( const MatrixKernel< K > & B) const
inline

Multiply two 16×16 matrices using SIMD with FMADD accumulation. This function splits each row into two registers (low/high).

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

References tensorium::Matrix< K, true >::data, and tensorium::Matrix< K, RowMajor >::data.

◆ mul_mat2x2()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat2x2 ( const MatrixKernel< K > & B) const
inline

Multiply two 2×2 matrices using SIMD.

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

References tensorium::Matrix< K, RowMajor >::data.

◆ mul_mat32x32()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat32x32 ( const MatrixKernel< K > & B) const
inline

Multiply two 32×32 matrices using SIMD. Each row is split into two registers (16 elements each).

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

References tensorium::Matrix< K, true >::data, and tensorium::Matrix< K, RowMajor >::data.

◆ mul_mat3x3()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat3x3 ( const MatrixKernel< K > & B) const
inline

Multiply two 3×3 matrices using SIMD.

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

◆ mul_mat4x4()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat4x4 ( const MatrixKernel< K > & B) const
inline

Multiply two 4×4 matrices using SIMD.

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

References tensorium::Matrix< K, true >::data, and tensorium::Matrix< K, RowMajor >::data.

◆ mul_mat64x64()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat64x64 ( const MatrixKernel< K > & B) const
inline

Multiply two 64×64 matrices using SIMD. Each row is split into 4 SIMD registers (4×16 elements). Vectorized FMADD chaining is used for performance.

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

References tensorium::Matrix< K, true >::data, and tensorium::Matrix< K, RowMajor >::data.

◆ mul_mat8x8()

template<typename K >
Matrix< K > tensorium::MatrixKernel< K >::mul_mat8x8 ( const MatrixKernel< K > & B) const
inline

Multiply two 8×8 matrices using SIMD.

Parameters
BRight-hand matrix.
Returns
Result of multiplication.

References tensorium::Matrix< K, true >::data, and tensorium::Matrix< K, RowMajor >::data.


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