numr
numr is the foundation library for numerical code in Rust. Tensors are generic over a Runtime.
Switching from CPU to CUDA or WebGPU changes the runtime type. Generic functions keep their body, and gain new backends when numr adds them.
Backends
| Runtime | Hardware | Feature | Needs | Dtypes |
|---|---|---|---|---|
CpuRuntime |
x86-64 and ARM64 CPUs | None, always built | Nothing | All 15. F16 and BF16 need f16. FP8 types need fp8 |
CudaRuntime |
NVIDIA GPUs, compute capability 7.5 (Turing) or newer | cuda |
CUDA toolkit 12.8 or newer, with nvcc on PATH or CUDA_PATH set |
Same as CPU |
WgpuRuntime |
Vulkan, Metal, and DX12 GPUs | wgpu |
Platform GPU driver | F32 for computation. cast runs on the GPU among F32, I32, U32, and I64. Other dtypes return Error::UnsupportedDType |
- Kernels: SIMD on CPU (AVX-512, AVX2, NEON), native CUDA kernels, and WGSL compute shaders. No cuBLAS, MKL, or other vendor library.
- ROCm: not implemented.
- Dtype coverage: the table lists what a backend holds. Check the operation before you rely on a dtype.
- CUDA binaries: a build targets the GPUs on the build host. Set
NUMR_CUDA_ARCH=allfor a binary that runs on another machine. - Details: the dtype table, SIMD, graph capture, and every
NUMR_CUDA_ARCHvalue are in docs/backends.md. The CUDA build steps are in CUDA Build.
Installation
Needs Rust 1.95 or newer.
Other feature flags:
| Feature | Description | Default |
|---|---|---|
rayon |
Multi-threaded CPU through Rayon | ✓ |
f16 |
F16 and BF16 types | ✗ |
fp8 |
FP8 types (E4M3, E5M2) | ✗ |
sparse |
Sparse tensors (CSR, CSC, COO) and sparse linear algebra | ✗ |
nccl |
Multi-GPU collectives through NCCL (implies cuda) |
✗ |
distributed |
Multi-machine communication through nexar | ✗ |
distributed-gpu |
NCCL within a node, nexar between nodes (implies distributed and nccl) |
✗ |
What numr Is
numr provides:
- Tensors: N-dimensional arrays
- Linear algebra: decompositions and solvers
- FFT, statistics, and random distributions
- Autograd
numr is not a deep learning framework, a high-level ML API, or domain-specific.
| You need | Use |
|---|---|
| Optimization, ODE solvers, interpolation, signal processing | solvr |
| Attention, model architectures, quantization, training | boostr |
Quick Start
CPU
use *;
use ;
Backend-Generic Code
Write functions over R: Runtime. The same function runs on any backend.
use *;
GPU (CUDA)
use RandomOps;
use *;
use ;
The module docs cover the rest of the API:
- Linear algebra, FFT, and statistics: Algorithms and Operations
- Gradients: Autograd
Operations
numr provides tensor operations as traits in numr::ops. The same traits cover CPU, CUDA, and WebGPU.
The full list is in docs/operations.md:
- Core arithmetic: unary, binary, scalar, type conversion, utility
- Shape and data movement:
cat,stack,gather,scatter,sort,topk, and more - Reductions, cumulative operations, comparisons, and logic
- Activations, normalization, convolution, einsum, and matmul with fused bias and activation
- Linear algebra and complex operations
- Statistics, random distributions, and quasi-random sequences
- Distance metrics on tensors and on plain slices
The algorithm modules are in docs/algorithms.md:
- Linear algebra decompositions, matrix functions, and solvers
- FFT and real FFT
- Special functions and polynomials
- Iterative solvers and preconditioners
- Sparse tensors (CSR, CSC, COO) and sparse linear algebra
Documentation
| Page | Contents |
|---|---|
| docs/operations.md | Tensor operation traits and distance metrics |
| docs/algorithms.md | Decompositions, FFT, special functions, solvers, sparse |
| docs/autograd.md | Reverse-mode and forward-mode autodiff, checkpointing |
| docs/backends.md | Backends, dtypes, SIMD, graph capture, CUDA build |
| docs/distributed.md | Communicators and parallel groups |
| docs/extending-numr.md | Custom kernels and new operations |
| docs/ARCHITECTURE_GUIDE.md | Internal architecture for contributors |
Building from Source
Contributing
Contributions are welcome. See CONTRIBUTING.md for conventions and checks.
Questions and design discussion happen on Discord.
License
Licensed under Apache-2.0. See LICENSE.