mdarray_linalg_tblis
TBLIS backend for [mdarray_linalg].
This crate provides the [Tblis] struct that implements matrix multiplication and
tensor contraction traits from [mdarray_linalg], delegating to the high-performance
C library TBLIS. TBLIS is specifically designed for dense tensor contractions
and shines on large, high-rank tensors where BLAS-based backends would need costly
transpositions.
Backend implementation modules are private. Use [Tblis] together with the
operation traits from mdarray_linalg::prelude::*.
Scope
The TBLIS backend covers:
- Matrix multiplication —
matmul - Tensor contraction —
contract_all,contract_n,contract_pairs,contract(einsum)
For vector operations, decompositions, or solving, use another backend
([mdarray_linalg_blas], [mdarray_linalg_faer], etc.).
Setup
This crate binds to TBLIS but does not choose which native TBLIS library to link against. This is left to the user. For example, to link against an installed TBLIS library:
In one of your Rust crates, reference the provider so its link directives are included:
extern crate tblis_src as _;
If TBLIS is installed outside standard linker paths, set TBLIS_DIR,
LD_LIBRARY_PATH, or equivalent linker/runtime configuration. If you need
to install TBLIS from source, see the
upstream build guide.
You may also provide equivalent link flags from your application build.rs.
Example
All operations are accessed through the [Tblis] backend:
# extern crate tblis_src as _;
use array;
use *;
use Tblis;
// ----- Matrix multiplication -----
let a = array!;
let b = array!;
let c = Tblis.matmul.eval;
assert_eq!;
// ----- Tensor contraction: contract last n axes -----
let t1 = array!.into_dyn;
let t2 = array!.into_dyn;
// Full contraction (contract_all) → scalar
let scalar = Tblis.contract_all;
assert_eq!; // 1·5 + 2·6 + 3·7 + 4·8
// ----- Outer product (contract_n with n=0) -----
let x = array!.into_dyn;
let y = array!.into_dyn;
let outer = Tblis.contract_n.eval;
assert_eq!;
// ----- Einsum-style contraction -----
// ij,jk->ik (matrix multiplication)
let result = Tblis
.contract
.eval;
assert_eq!;
// ij,ij-> (full contraction)
let result = Tblis
.contract
.eval;
assert_eq!;
// ij,jk->ki (matmul with transposed output)
let result = Tblis
.contract
.eval;
assert_eq!;
// i,j->ij (outer product via einsum)
let result = Tblis
.contract
.eval;
assert_eq!;
// ----- Scaled addition: C = α·A·B + β·C -----
let mut c = array!;
Tblis.matmul.add_to_scaled;
// C = A·B + 2·C = [[19,22],[43,50]] + 2·[[1,1],[1,1]]
Supported types
f32, f64, Complex<f32>, Complex<f64>.
Troubleshooting
Linking errors usually mean that the native TBLIS library was not linked
into the final binary, or that it is not in the linker/runtime search path.
Add tblis-src, reference it from Rust code, or provide equivalent link
flags from your application build.rs.