Expand description
Linear algebra extension operations for tenferro.
This crate owns the graph-facing linalg op payloads and runtime
registration. Tensor-facing operations are exposed through extension traits.
CPU backend kernels live in this crate behind the linalg backend trait.
A CPU backend paired by tenferro_gpu::apple::AppleContext additionally supports
guarded rank-2 Cholesky on matching Apple managed F32, F64, C32, and
C64 tensors. This is an explicit CPU selection and is not a general
managed-memory fallback for other linalg operations.
§Examples
use tenferro_linalg::TracedTensorLinalgExt;
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{GraphCompiler, Runtime, TracedTensor};
let a = TracedTensor::from_vec_col_major(
vec![2, 2],
vec![4.0_f64, 2.0, 2.0, 3.0],
)
.unwrap();
let l = a.cholesky().unwrap();
let mut compiler = GraphCompiler::new();
let program = compiler.compile(&l).unwrap();
let backend = CpuBackend::new();
let engine_id = tenferro_cpu::runtime_engine_id().unwrap();
let mut builder = Runtime::builder();
builder
.register_engine(tenferro_cpu::runtime_engine_registration(&backend).unwrap())
.unwrap();
builder
.install_extension_module(tenferro_linalg::extension_module::<CpuBackend>(engine_id).unwrap())
.unwrap();
let runtime = builder.build().unwrap();
let out = runtime.run_compiled(&program, &[]).unwrap().pop().unwrap();
assert_eq!(out.shape(), &[2, 2]);§Cargo features
| Feature | Enables |
|---|---|
cpu-faer (default) and the other CPU provider features | Forwarded to tenferro-cpu; see its documentation. |
autodiff | The eager surface (EagerSessionLinalgExt, EagerTensorLinalgExt) and AD rules. Adds the tenferro-ad dependency. |
cuda | CUDA execution through tenferro-gpu. |
webgpu | WebGPU/Metal execution through tenferro-gpu (a subset of operations). |
rocm | Placeholder; HIP/ROCm is not implemented. |
autodiff is not a heavy dependency switch: tenferro-ad is the crate that
owns EagerSession/EagerTensor, so an eager linalg surface without it
would save nothing and would only produce eager tensors whose linalg ops
fail on backward (#1972). For inference without AD, call the same
operations on concrete tensors inside a backend session through
TensorLinalgExt / TypedTensorLinalgExt, which need no autodiff:
use tenferro_cpu::CpuBackend;
use tenferro_linalg::TypedTensorLinalgExt;
use tenferro_tensor::{BackendSessionHost, TypedTensor};
let mut backend = CpuBackend::new();
// Lower-triangular [[2, 0], [1, 1]] (column-major) and right-hand side.
let l = TypedTensor::<f64>::from_vec_col_major(vec![2, 2], vec![2.0, 1.0, 0.0, 1.0])?;
let b = TypedTensor::<f64>::from_vec_col_major(vec![2, 1], vec![4.0, 5.0])?;
let x = backend.with_backend_session(|session| {
// left_side, lower, transpose_a, unit_diagonal
l.triangular_solve(&b, true, true, false, false, session)
})??;
assert_eq!(x.host_data()?, &[2.0, 3.0]);Re-exports§
pub use backend::LinalgBackend;pub use error::Error;pub use error::Result;
Modules§
- backend
- cpu_
kernels - Injectable CPU linear-algebra kernels.
- error
- Domain errors owned by the linear-algebra extension.
- prelude
- Linear algebra extension traits and their method-resolution types.
Structs§
- Eigh
Options - Options for Hermitian eigenvalue decomposition.
- Householder
Qr - Opaque compact Householder QR state.
- Linalg
AdMode Support - User-visible AD support for one mode.
- Linalg
AdOutput Support - AD support status for one output of a linalg operation.
- Linalg
AdSupport - AD support manifest entry for one linalg operation.
- QrOptions
- Options for QR decomposition.
- Rank
Revealing QrOptions - Options for column-pivoted rank-revealing QR.
- Rank
Revealing QrResult - Four fixed-shape outputs of a rank-revealing QR factorization.
- SvdOptions
- Options for singular value decomposition.
Enums§
- Eigh
Driver - cuSOLVER Hermitian eigensolver selection used by
EighOptionson the CUDA backend. - Eigh
Gauge - Eigenvector gauge convention used by
EighOptions. - Linalg
AdOp Kind - Operation keys covered by the linalg AD support manifest.
- Linalg
AdRoute - Implementation route used for a user-visible AD mode.
- Linalg
AdRule Support - AD rule support status for a linalg operation or output.
- QrGauge
- QR factor gauge convention used by
QrOptions. - SvdDriver
- cuSOLVER SVD routine selection used by
SvdOptionson the CUDA backend. - SvdGauge
- Singular-vector gauge convention used by
SvdOptions.
Constants§
- DEFAULT_
DECOMPOSITION_ DERIVATIVE_ EPS - Default derivative regularization used by decomposition AD rules.
- LINALG_
EXTENSION_ FAMILY_ ID
Traits§
- Eager
Session Linalg Ext - Linear algebra operations on a runtime-bound borrowed eager session.
- Eager
Tensor Linalg Ext - Tensor-owned linear solve. Other eager linear-algebra operations use
EagerSessionLinalgExtinsidetenferro_ad::EagerRuntime::with_eager_session. - Linalg
Scalar - Scalar types supported by statically typed linear algebra methods.
- Tensor
Linalg Ext - Linear algebra methods for dtype-erased owned tensors.
- Tensor
Read Linalg Ext - Linear algebra methods for borrowed tensor reads.
- Traced
Tensor Linalg Ext - Linear algebra extension methods for
TracedTensor. - Typed
Tensor Linalg Ext - Linear algebra methods with statically typed inputs and outputs.
Functions§
- all_
linalg_ ad_ support - Return the complete linalg AD support manifest.
- extension_
module - Build this extension module for one runtime engine.
- linalg_
ad_ support - Return the support manifest entry for one linalg operation kind.
- semantic_
ad_ rules - Return the linalg semantic-program AD rule set.
Type Aliases§
- Typed
Eig - Fixed typed output tuple for general eigendecomposition.
- Typed
Full PivLu - Fixed typed output tuple for complete-pivot LU decomposition.
- TypedLu
- Fixed typed output tuple for LU decomposition.
- Typed
Rank Revealing QrResult - Fixed typed output for rank-revealing QR.
- Typed
Svd - Fixed typed output tuple for singular value decomposition.