Skip to content

trnsci

Scientific computing libraries for AWS Trainium — the reference implementation for the post-FP64 era.

NVIDIA CUDA programmers reach for cuFFT, cuBLAS, cuRAND, cuSOLVER, cuSPARSE, and cuTENSOR when they need fast numerical primitives. The AWS Neuron SDK ships none of these. trnsci is six libraries that fill the gap:

trnsci NVIDIA analog Scope Latest
trnfft cuFFT FFT, complex tensors, STFT, spherical harmonic transforms, complex NN layers 0.30.0
trnblas cuBLAS BLAS Levels 1–3, batched GEMM, DF-MP2 energy 0.15.0
trnrand cuRAND Threefry/Philox PRNG, Sobol/Halton QMC 0.15.0
trnsolver cuSOLVER Cholesky/LU/QR/SVD, Jacobi eigh, CG/GMRES and block CG, SCF eigensolvers 0.24.0
trnsparse cuSPARSE BSR-128 SpMM, Schwarz screening, block-sparse attention, fused kernel-matrix operator 0.18.0
trntensor cuTENSOR Einstein summation with path planning, CP/Tucker/TT, streamed DF integrals, multi-chip sharding 0.27.0

What is this for

Two things at once.

Practically: workloads that depend on the CUDA cu* libraries — signal processing, quantum chemistry, Monte Carlo, sparse linear systems, tensor contractions — and need to run on Trainium without per-project rewrites.

Architecturally: every major silicon roadmap from 2022 onward has converged on tensor-native cores with FP32 accumulate on BF16/FP8/FP4 inputs and FP64 either halved, emulated, or absent. On H100 the FP64:BF16 throughput ratio is already 1:14.8; on B200 it is 1:61; cuBLAS in CUDA 13 now emulates FP64 DGEMM via the Ozaki scheme on FP8 tensor cores. Trainium was designed without an FP64 legacy to protect — it codified this architecture in 2020. trnsci is the library that treats the mixed-precision numerical-analysis literature (Carson–Higham iterative refinement, Ozaki-scheme FP64 emulation, stochastic rounding, randomized NLA) as the default API rather than an exotic overlay on an FP64-centric BLAS stack.

See why trnsci exists for the full argument.

Why Trainium specifically

The post-FP64 argument applies to every accelerator vendor. What makes Trainium the right target for a library built on that argument is that every feature the mixed-precision numerical-analysis community has spent a decade asking for is already present — and exposed to the programmer:

  • PSUM is a named, addressable FP32 accumulator. The 128×128 systolic array always writes its K-reduction result into PSUM in FP32, and every other engine (Vector, Scalar, GpSimd) can read and write PSUM. On NVIDIA tensor cores, the FP32 accumulator is hidden inside the WMMA abstraction. On Trainium it is named, sized, and programmable. This is what makes error-free transformations at systolic scale practical rather than theoretical.
  • Stochastic rounding is in the hardware. Every NeuronCore from v2 on can round stochastically (NeuronCore-v3: "programmable rounding mode (RNE & Stochastic-rounding)"). Connolly–Higham–Mary (2021) proved SR replaces the worst-case K·u Krylov error bound with a mean-zero √K·u probabilistic bound — which is what makes BF16 iterative solvers converge rather than stagnate. On NKI 0.7 (Neuron SDK 2.33) it is a process-wide runtime setting rather than a per-instruction one, and results with it on are not bitwise reproducible, so it is for narrow (BF16) accumulations, not a default (precision and platform limits).
  • Determinism is structural. The compiler statically schedules all instructions and DMAs. The suite's kernels give bitwise-identical output run to run given a fixed seed, and trnrand and trnsparse stay bitwise identical across core counts — not as a ReproBLAS-style overlay, but as a default. The known exception is device aten reductions, which can differ between LNC=1 and LNC=2 (trnsolver#128).
  • The compiler is open-source. NKI's MLIR backend (Apache 2.0) is public. Formal error bounds require inspecting the reduction order; on Trainium it is documented and stable.
  • Trainium3 adds per-block microscaling (MXFP8/MXFP4). These are the hardware realization of the per-block precision assumptions that mixed-precision HODLR, BLR-LU, and progressive-precision multigrid have been writing theorems about for years.

Other accelerators have some of these. Recent GPUs, for example, have stochastic-rounding conversion instructions. What Trainium adds is having them together, under one kernel language that names the accumulator and the on-chip memory. Trainium is not missing FP64; it is the architecture the post-FP64 literature has been designing algorithms for. trnsci is the library that makes that concrete.

Who is this for

  • CUDA programmers migrating scientific workloads to Trainium. The CUDA → trnsci Rosetta stone maps cu* symbols to their trnsci counterparts.
  • HPC and computational-science researchers who need certified accuracy at stated forward-error tolerances rather than a precision knob and a prayer.
  • Trainium programmers who want a scientific-computing library stack that exploits the hardware's architectural strengths — PSUM as a free FP32 accumulator, stochastic rounding in the ISA, deterministic dataflow — rather than working around them.

Get started

pip install "trnsci[all]"

On Trainium, see installation for the Neuron extras.

Try the cross-library integration demo (composes trnrand, trnsparse, trnsolver, trnblas and trntensor into an end-to-end closed-shell DF-MP2 energy evaluation on synthetic inputs, checked against a float64 reference; trnblas's own PySCF examples carry the real-molecule validation):

git clone git@github.com:trnsci/trnsci.git
cd trnsci
make install-dev
python examples/quantum_chemistry/df_mp2_synthetic.py --demo

Status

Phase 1 has landed across all six libraries, and every Phase 1 tracker is closed. NKI paths are exercised in CI via the NKI CPU simulator on every PR, and every library runs a conformance suite against independent references. All six libraries ship native TorchNeuron dispatch on Trn2/Trn3 (Neuron SDK 2.33); their current releases are validated on Trn2 (validation status), and the PyTorch/XLA path on Trn1 is in maintenance. On the native device, auto dispatch uses an NKI kernel only where it measured faster than aten: the fused kernels (DF-MP2 pair energy, AO→MO, DF J/K, BSR SpMM, the GP kernel operator, block-sparse attention, the SHT Legendre stage) win, most dense GEMM goes to aten, and trnfft is the only FFT on the device. float64 follows one suite policy: the device has no float64 arithmetic, so auto computes it on the host.

The workload-level results — a 10⁶-point Gaussian process, spherical harmonic transforms, DF-RHF/MP2 to 3508 basis functions and DeepVariant call_variants, each on one Trn2 chip — are on exemplars.

PyTorch fallback works end-to-end on any machine, with or without Neuron hardware.

Read more:

Follow the blog for technical deep-dives from the sub-project libraries.