BLAS operations for AWS Trainium via NKI
Project description
trnblas
BLAS operations for AWS Trainium via NKI (Neuron Kernel Interface).
Trainium ships no BLAS library. trnblas provides Level 1-3 BLAS operations with NKI kernel acceleration on the Tensor Engine, targeting scientific computing workloads that are GEMM-dominated.
Part of the trnsci scientific computing suite (github.com/trnsci).
Current phase
trnblas follows the trnsci 5-phase roadmap. Active work is tracked in phase-labeled GitHub issues:
- Phase 1 — correctness: complete as of v0.4.0 (GEMM, SYRK, MP2 energy reduction kernels hardware-validated on trn1; end-to-end DF-MP2 validated against PySCF at nanohartree tolerance).
- Phase 2 — precision (next): double-double FP64 GEMM for chemistry workloads. Unblocks trnsolver#27 and trntensor#28.
- Phase 3 — perf: tile sweeps, fused DF-MP2 kernels, true 3D batched GEMM, NEFF cache reuse.
- Phase 4 — multi-chip: tensor-parallel GEMM across NeuronCores.
- Phase 5 — generation: trn2 FP16-accumulate GEMM path.
Suite-wide tracker: trnsci/trnsci#1.
Why
NVIDIA has cuBLAS with 152 optimized routines. Trainium has torch.matmul. That's fine for ML training but insufficient for scientific computing codes that need TRSM, SYRK, SYMM, and batched GEMM with specific transpose/scaling semantics.
trnblas closes this gap — same BLAS API surface, NKI-accelerated GEMM on Trainium, PyTorch fallback everywhere else.
Install
pip install trnblas
# With Neuron hardware support
pip install trnblas[neuron]
Usage
import torch
import trnblas
# Level 3 — Matrix multiply (the hot path)
C = trnblas.gemm(alpha=1.0, A=A, B=B, beta=0.5, C=C_init, transA=True)
# Batched GEMM (DF-MP2 tensor contractions)
C = trnblas.batched_gemm(1.0, A_batch, B_batch)
# Symmetric matrix multiply (Fock builds)
F = trnblas.symm(1.0, density, H_core, side="left")
# Triangular solve (Cholesky-based density fitting)
X = trnblas.trsm(1.0, L, B, uplo="lower")
# Symmetric rank-k update (metric construction)
J = trnblas.syrk(1.0, integrals, trans=True)
# Level 2 — Matrix-vector
y = trnblas.gemv(1.0, A, x, beta=1.0, y=y)
# Level 1 — Vector operations
y = trnblas.axpy(alpha, x, y)
d = trnblas.dot(x, y)
n = trnblas.nrm2(x)
DF-MP2 Example
# Run the density-fitted MP2 example
python examples/df_mp2.py --demo
python examples/df_mp2.py --nbasis 100 --nocc 20
The example demonstrates all core BLAS operations in a realistic quantum chemistry workflow: Cholesky factorization, triangular solve, half-transform GEMMs, metric contraction, and energy evaluation.
Real-molecule validation (via PySCF)
pip install trnblas[pyscf]
python examples/df_mp2_pyscf.py # H2O / STO-3G
python examples/df_mp2_pyscf.py --mol ch4 --basis cc-pvdz
Runs SCF + density fitting via PySCF, feeds the integrals through trnblas, and compares to PySCF's own DF-MP2 reference energy. Matches to < 10⁻⁷ Hartree on H2O, CH4, NH3 at cc-pvdz.
Operations
| Level | Operation | Description |
|---|---|---|
| 1 | axpy |
y = αx + y |
| 1 | dot |
x^T y |
| 1 | nrm2 |
‖x‖₂ |
| 1 | scal |
x = αx |
| 1 | asum |
Σ|xᵢ| |
| 1 | iamax |
argmax |xᵢ| |
| 2 | gemv |
y = α op(A) x + βy |
| 2 | symv |
y = α A x + βy (A symmetric) |
| 2 | trmv |
x = op(A) x (A triangular) |
| 2 | ger |
A = α x yᵀ + A |
| 3 | gemm |
C = α op(A) op(B) + βC |
| 3 | batched_gemm |
Batched GEMM |
| 3 | symm |
C = α A B + βC (A symmetric) |
| 3 | syrk |
C = α A Aᵀ + βC |
| 3 | trsm |
Solve op(A) X = αB |
| 3 | trmm |
B = α op(A) B |
Status
- Level 1-3 BLAS with PyTorch backend
- GEMM with NKI dispatch stub
- DF-MP2 example
- NKI GEMM kernel validation on trn1/trn2
- NKI GEMM with stationary tile reuse
- Batched GEMM NKI kernel
- Double-double FP64 emulation
- Benchmarks vs cuBLAS
Related Projects
| Project | What |
|---|---|
| trnfft | FFT + complex ops for Trainium |
| trnrand | Random number generation (Philox/Sobol) for Trainium |
| trnsolver | Linear solvers and eigendecomposition |
License
Apache 2.0 — Copyright 2026 Scott Friedman
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trnblas-0.4.3.tar.gz.
File metadata
- Download URL: trnblas-0.4.3.tar.gz
- Upload date:
- Size: 65.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47cf6b1569e878f3320a864a58827f1c0dfe4a44131d388f756e12e2dbb1c6c1
|
|
| MD5 |
ce4d14ec8a18e2c875b05d1dbbdaf542
|
|
| BLAKE2b-256 |
759d8b6e9f3b069846a0bb33fabbd8ea33b162a4ab8de2c5c46f52c9bbb61dce
|
Provenance
The following attestation bundles were made for trnblas-0.4.3.tar.gz:
Publisher:
publish.yml on trnsci/trnblas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trnblas-0.4.3.tar.gz -
Subject digest:
47cf6b1569e878f3320a864a58827f1c0dfe4a44131d388f756e12e2dbb1c6c1 - Sigstore transparency entry: 1288935345
- Sigstore integration time:
-
Permalink:
trnsci/trnblas@6cc5a4cba7c91c321d8bb4467fe80dab3728bb98 -
Branch / Tag:
refs/tags/v0.4.3 - Owner: https://github.com/trnsci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6cc5a4cba7c91c321d8bb4467fe80dab3728bb98 -
Trigger Event:
release
-
Statement type:
File details
Details for the file trnblas-0.4.3-py3-none-any.whl.
File metadata
- Download URL: trnblas-0.4.3-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afc8edd130879979aaa980ff8b16211f98ef01562d26aeb9272fa17ccc787bae
|
|
| MD5 |
60653a54e05863e1cd6a79717a0c65d7
|
|
| BLAKE2b-256 |
60737c042e8a067fa68de150f2dbc916b12646e4138ac5896e0d551a2bdf2e15
|
Provenance
The following attestation bundles were made for trnblas-0.4.3-py3-none-any.whl:
Publisher:
publish.yml on trnsci/trnblas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trnblas-0.4.3-py3-none-any.whl -
Subject digest:
afc8edd130879979aaa980ff8b16211f98ef01562d26aeb9272fa17ccc787bae - Sigstore transparency entry: 1288935465
- Sigstore integration time:
-
Permalink:
trnsci/trnblas@6cc5a4cba7c91c321d8bb4467fe80dab3728bb98 -
Branch / Tag:
refs/tags/v0.4.3 - Owner: https://github.com/trnsci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6cc5a4cba7c91c321d8bb4467fe80dab3728bb98 -
Trigger Event:
release
-
Statement type: