Thermite SIMD: Melt Your CPU

Thermite is a portable SIMD library for Rust with a singular goal: you write a
numeric kernel once, generic over a small trait hierarchy, and that one
function compiles to high-performance code for every instruction set at every vector
width. Unchanged, it also computes its own derivatives (Dual), runs in
double-double precision (Compensated), or evaluates over the complex plane
(Complex).
It ships a full, policy-tunable vectorized math library, from the ordinary
transcendentals through special functions, works on stable Rust, and is no_std
by default.
This repository is the Cargo workspace for Thermite and its companion crates.
Example
The function below is written once, against traits. Nothing in it names an
instruction set, a lane count, or an element type. The type you instantiate it
with decides whether you get plain SIMD, a gradient, or 106 bits of
significand.
use thermite::prelude::*;
use thermite::math::TranscendentalMath;
use thermite_dual::AutoDiff;
use thermite_compensated::Compensated;
// `#[dispatch]` is what makes this fast. It isn't optional. See below.
#[thermite::dispatch(V)]
fn gaussian<V: FloatVector + TranscendentalMath>(x: V) -> V {
(-(x * x)).exp()
}
let xs: Vec<f32> = (0..4096).map(|i| i as f32 * 0.001 - 2.0).collect();
let mut ys = vec![0.0f32; xs.len()];
let mut dydx = vec![0.0f32; xs.len()];
// `dispatch_dyn!` takes its parameters by value, so hand it slices.
let (xs, ys, dydx) = (xs.as_slice(), ys.as_mut_slice(), dydx.as_mut_slice());
thermite::dispatch_dyn!(|xs: &[f32], ys: &mut [f32], dydx: &mut [f32]| {
// `f32xN` is the widest native f32 vector of whichever ISA this CPU turned
// out to have, chosen once at runtime: 8 lanes on AVX2, 4 on SSE2 or NEON.
let n = f32xN::lanes();
for ((x, y), d) in xs.chunks_exact(n)
.zip(ys.chunks_exact_mut(n))
.zip(dydx.chunks_exact_mut(n))
{
let x = f32xN::from_slice(x);
// Plain SIMD. `n` values through the kernel at once.
gaussian(x).copy_to_slice(y);
// The same function, differentiated. Value and gradient in one pass,
// still `n` at a time.
gaussian.ad([x]).dual[0].copy_to_slice(d);
// The same function again, evaluated to a ~106-bit significand.
let precise = gaussian(Compensated::new(x));
let _ = (precise.value(), precise.error());
}
});
Three meanings, one function body, no edits between them.
History & Motivation
Thermite was originally conceived while working on the Raygon renderer, when it
was decided we needed a state of the art high-performance SIMD library focused
on SoA algorithms. Libraries at the time (and even now) were either too
low-level, lacking in features, or not optimized for modern hardware. The goal
was to let developers write efficient SIMD code without having to worry about
the underlying hardware details.
However, my first prototype was flawed. Too many leaky abstractions, and back in
2020 the Rust language and compiler were themselves too limited to support the
abstractions this needs. In 2025 I felt renewed interest in the project, and
with mature const generics, a better trait solver, edition 2024, and much wider
stable intrinsics coverage, I was able to redesign it from the ground up. Rust
is powerful enough to express all of this safely on stable, but it took me ten
years of writing it (and one failed prototype) to figure out how.
Melting your CPU is just a fun tagline, obviously. The real goal is to get as
much useful work out of one as it can physically do, and every design decision
follows from that. Estimating-FMA defaults, so no port waits on a scalar
fallback. Static dispatch, so no call boundary silently drops you to baseline
code. Precision policies, so you never pay for accuracy you didn't ask for.