LAK
LAK is a small personal linear algebra crate with BLAS-like kernels over contiguous Rust slices. Its goal was to see whether a safe, contiguous-only Rust library can stay minimal and elegant without sacrificing much performance. Benchmarks are available here. The current blocking constants and chunk sizes are tuned for ARMv8/Apple Silicon. If you test LAK on another architecture and find better parameters, tuning contributions are welcome.
The API is organized around BLAS levels:
lak::l1: vector-vector routines likedot,axpy,scal, andnrm2lak::l2: matrix-vector routines likegemv,ger,trmv, andtrsvlak::l3: matrix-matrix routines likegemm
Matrices are column-major. The safe API uses MatRef, MatMut, VecRef, and
VecMut view types from lak::types. All Level-1 and Level-2 routines are generic
over f32/f64. Level-3 gemm is also generic, but direct sgemm and dgemm
functions exist for maximum performance.
LAK also provides lak::blas, a thin wrapper around the historical BLAS API for
both LP64 and ILP64 callers. Though since LAK is contiguous-only, strides are asserted
to be 1.
The only Level-3 routine implemented right now is gemm.
use gemm;
use ;
// column-major 2 x 3 matrix:
// [1 3 5]
// [2 4 6]
let a = ;
// column-major 3 x 2 matrix:
// [ 7 10]
// [ 8 11]
// [ 9 12]
let b = ;
let mut c = ;
let alpha = 1.0;
let beta = 0.0;
let a = new;
let b = new;
let mut c = new;
// c.reborrow() used to allow c.as_slice() afterwards.
gemm;
// C = A * B
// [ 76 103]
// [100 136]
assert_eq!;
This crate currently targets nightly Rust because it uses portable_simd.
Informal notes on LAK’s design, implementation challenges, and lessons learned are available here.