Skip to main content

Crate onemkl

Crate onemkl 

Source
Expand description

Safe, idiomatic Rust wrapper over Intel oneAPI Math Kernel Library (oneMKL).

For the raw FFI surface, see onemkl-sys.

§Quick orientation by use case

  • Dense linear algebra — see blas (Level 1/2/3, batched, pack/compute, JIT, mixed-precision, compact) and lapack (solvers, factorizations, eigenvalue / SVD, auxiliary routines).
  • Sparse linear algebra — see sparse (CSR/COO/CSC/BSR matrices, mv/mm/trsv, format conversion, sparse arithmetic), pardiso / dss (direct solvers), iss (CG / FGMRES), preconditioners (ILU0 / ILUT).
  • FFT and signal processing — see fft (1D/2D/3D/N-D complex and real-input transforms with configurable scaling), pde (DCT / DST trigonometric transforms), rng::convolution (1D conv / corr).
  • Statistics and random numbers — see rng (RNG streams, distributions) and rng::summary_stats (mean / variance / min / max / sum).
  • Mixed-precision ML kernels — see blas::mixed_precision for bf16 / fp16 / FP8 / int8 GEMMs and blas::jit for runtime-specialized small kernels.
  • Eigensolvers — see lapack for general drivers and feast for contour-integration solvers (find all eigenvalues in an interval).
  • Optimization — see optim for trust-region nonlinear least squares.
  • Spline / data fitting — see data_fitting for cubic splines (natural / Bessel / Akima / Hermite).
  • MKL service / runtime — see service (threading, verbose mode, version).

Anything not yet wrapped is reachable through the raw bindings re-exported as sys.

§A minimal example

use onemkl::prelude::*;
use onemkl::blas::level3::gemm;

// Compute C = A * B + 0 * C for two 2×2 matrices.
let a_data = vec![1.0_f64, 2.0, 3.0, 4.0];
let b_data = vec![5.0_f64, 6.0, 7.0, 8.0];
let mut c_data = vec![0.0_f64; 4];
let a = MatrixRef::new(&a_data, 2, 2, Layout::RowMajor).unwrap();
let b = MatrixRef::new(&b_data, 2, 2, Layout::RowMajor).unwrap();
let mut c = MatrixMut::new(&mut c_data, 2, 2, Layout::RowMajor).unwrap();
gemm(
    Transpose::NoTrans, Transpose::NoTrans,
    1.0, &a, &b, 0.0, &mut c,
).unwrap();
// c_data ≈ [19, 22, 43, 50].

§Per-domain features

Each major oneMKL domain is gated by a Cargo feature so users can opt out of unused parts. All domain features are enabled by default. Foundation modules (error, enums, matrix, scalar, and service) are always built.

FeatureModuleWhat’s inside
blasblasLevel 1/2/3, batched (strided + pointer-array), pack/compute, JIT, mixed precision (bf16/f16/FP8/int8), compact
data-fittingdata_fittingCubic splines (natural / Bessel / Akima / Hermite)
dssdssDirect sparse solver with statistics readout
feastfeastContour-integration eigensolver (dense, CSR, banded, generalized)
fftfftDFTI 1D / 2D / 3D / N-D, complex and real-input, configurable scaling
ississCG / FGMRES with closure or step-by-step session API
lapacklapackSolvers, factorizations, eigenvalue / SVD, auxiliary (lacpy / lange / gecon / laswp / larfg)
optimoptimTrust-region nonlinear least squares
pardisopardisoStateful direct sparse solver, pardiso_64, pivot callback
pdepdeTrigonometric transforms (DCT / DST) for spectral PDE solvers
preconditionerspreconditionersILU0 / ILUT and apply_ilu
rngrngVSL streams, distributions, 1-D conv/corr, summary statistics
sparsesparseInspector-Executor sparse: CSR/COO/CSC/BSR, mv/mm/trsv, copy/convert, add/spmm/spmmd
vmvmElement-wise vector math

For a minimal build:

onemkl = { version = "...", default-features = false, features = [
    "lp64", "threading-sequential", "link-dynamic",  # required
    "blas", "lapack",                                # whatever you need
] }

Until a domain has a safe wrapper, the raw bindings are accessible via sys.

§Building against MKL

The build script in onemkl-sys searches in this order:

  1. MKLROOT environment variable.
  2. ONEMKL_SYS_INCLUDE_DIR / ONEMKL_SYS_LIB_DIR overrides.
  3. ONEAPI_ROOT/mkl/latest.
  4. Platform-standard install paths (C:\Program Files (x86)\Intel\oneAPI on Windows, /opt/intel/oneapi on Linux/macOS).

At runtime MKL’s bin/ (or lib/) directory must be on the loader search path so that the dynamic libraries can be found.

Re-exports§

pub use enums::Diag;
pub use enums::Layout;
pub use enums::Side;
pub use enums::Transpose;
pub use enums::UpLo;
pub use error::Error;
pub use error::Result;
pub use error::SparseStatus;
pub use matrix::MatrixMut;
pub use matrix::MatrixRef;
pub use scalar::ComplexScalar;
pub use scalar::RealScalar;
pub use scalar::Scalar;
pub use onemkl_sys as sys;

Modules§

blas
Basic Linear Algebra Subprograms (BLAS).
data_fitting
Data fitting — 1-D spline interpolation and integration.
dss
Direct Sparse Solver (DSS) — alternative interface to oneMKL PARDISO with a slightly more verbose but cleaner API.
enums
BLAS / LAPACK enumeration types.
error
Unified error types for the safe oneMKL wrapper.
feast
Extended Eigensolver — the FEAST contour-integration eigensolver.
fft
Discrete Fourier Transform (DFT) — fast Fourier transform via the oneMKL DFTI interface.
iss
Iterative sparse solvers — Conjugate Gradient (CG) and Flexible GMRES (FGMRES) via oneMKL’s RCI (reverse-communication interface).
lapack
LAPACK linear algebra routines.
matrix
Strided matrix views.
optim
Nonlinear optimization — trust-region nonlinear least-squares (TRNLS) and bound-constrained variant (TRNLSPBC).
pardiso
Intel oneMKL PARDISO direct sparse solver.
pde
PDE support — trigonometric transforms (DCT / DST) used in spectral PDE solvers and signal processing.
preconditioners
Preconditioners for iterative sparse solvers — Incomplete LU factorization (ILU0 and ILUT).
prelude
Convenience prelude exporting the items most numerical Rust code will reach for: foundation enums (Layout, Transpose, UpLo, Side, Diag), the Error / Result types, matrix views, and the per-domain scalar traits when their feature is enabled.
rng
Random number generation via the Vector Statistical Library (VSL).
scalar
Scalar type abstractions used throughout oneMKL.
service
Service routines: version info, threading control, memory tracking, verbose mode, and overall library lifecycle.
sparse
Inspector-Executor Sparse BLAS — sparse linear algebra with reusable handles.
vm
Vector Mathematical Functions (VM).