Bit-Exact Triton Kernels Make Our Reactor Solver 12× Faster on H100
Fused Triton kernels sped up the transport calculation for our 3D reactor training data by 36.1× and the eight-sample solver by 12× on one H100. The bit-exact configuration matched the original outputs for all 256 samples in each of three eight-GPU runs.
We generate 3D simulations of how chemicals move and react inside a reactor to train and test scientific AI. When we tried speeding up the transport calculation with default torch.compile settings, about 22% of its output values changed by tiny amounts. We wrote custom Triton kernels that combined GPU operations, speeding up that calculation by 36.1× and the solver by 12× on one H100. On eight GPUs, the exact-match configuration reproduced the saved trajectories, flow across interfaces, and metadata byte for byte for all 256 samples in each of three runs.
Research preprint What Bitwise Reproduction Misses in a GPU Reactor Data Pipeline.
- 36.1× Transport stencil · 47.387 to 1.314 ms
- 7.0× Reaction update · 10.71 to 1.53 ms
- 64.6% Lower peak memory · 13.883 to 4.914 GB
Why exact outputs matter
We generate synthetic stirred-tank reactor trajectories to train and evaluate our physics tokenizer, which encodes evolving fields for downstream models. The solver advances eight transported fields on a 128³ grid: three reactants, the desired product, two byproducts, temperature, and residence time.
Transport, heat, a reaction network, and an analytic velocity and pressure closure run on the GPU. The solver advances the state in FP64 to preserve the arithmetic of the NumPy reference through repeated updates, then stores the fields in FP32.
The acceptance contract compares raw trajectories, interface flux, and metadata by sample ID. The full-node test exposed a difference in one reduction diagnostic that a field-only comparison would have missed.
Where the time went
The original solver already batched samples on the GPU in eager PyTorch. Advection and diffusion ran as a chain of full-array operations, repeatedly writing and reading neighbour values, masks, gradients, and intermediates. Transport alone accounted for 64.3% of the profiled step.
Where the reactor step spent its time
H100 · 128³ grid · eight samples per batch · selected sections of the July profiles
Milliseconds per step
The original stencil timer includes the state stack. The Triton timer measures the fused call. Both save timings come from synchronized profiles with different save harnesses.
The stencil kernel
We packed the state into a single [field, batch, z, y, x] buffer. One Triton program handles a contiguous run of 128 x cells for one row and one field-sample pair. It loads the centre and six neighbours, accumulates upwind advection and the Laplacian, and writes the transport result once.
The seven field values in a stencil update
A program selects one field, sample, z plane and y row, then processes a contiguous x tile.
Offsets in parentheses count elements relative to the centre address in the contiguous field buffer. The stencil uses the centre value for any out-of-bounds or inactive neighbour.
The grid bounds control which neighbour addresses may be read. For each direction, the kernel loads the neighbour and its active-cell flag, and substitutes the centre value when the neighbour is outside the grid or inactive, matching the reference's no-flux rule. It then takes the upwind difference selected by the sign of the local velocity for advection, and accumulates the Laplacian for diffusion in the reference's exact operation order. The y and z passes follow the same pattern with element offsets of ±X and ±(Y × X).
At production shape, each launch covers 16,384 rows for each of the 64 field-sample pairs, with 128-cell blocks and four warps per program. A separate kernel fuses reaction rates, source terms, and state updates, replacing about 60 pointwise launches with one.
Matching every bit
Controlled rounding
A fused multiply-add rounds once. The eager multiply and add sequence rounds twice. We disable floating-point fusion in the Triton compile and preserve the reference operation order, including the order of the two Laplacian additions. NVIDIA floating-point guide
Matched division
On the tested H100 PyTorch CUDA path, division by a Python scalar used multiplication by its reciprocal. Triton receives the same precomputed reciprocals of the grid spacing and its square as FP64 values on the device, so both paths perform identical arithmetic.
Bitwise testing
At the stencil level, outputs are compared as raw 64-bit patterns against the eager GPU output, so a difference in even one bit fails the test. The validation also covered full 640-step reaction and update rollouts and the stored FP32 output against NumPy at 32³, 48³, and 128³. The pipeline comparison checks a separate, downstream contract by matching per-sample trajectory, flux, and metadata digests.
Benchmarking against torch.compile
We used archived stencil functions on one H100 with a 128³ grid, eight samples, eight FP64 fields, and identical synthetic inputs. The reported latency is the median of nine rounds after warmup.
| Stencil implementation | Median ms/call | vs. eager | Bit-exact |
|---|---|---|---|
| Eager PyTorch | 47.387 | 1.0× | Reference |
| torch.compile, default | 1.343 | 35.3× | No |
| torch.compile, precision emulation | 1.404 | 33.8× | Yes |
| Handwritten Triton | 1.314 | 36.1× | Yes |
Default Inductor differed on 29,434,441 of 134,217,728 FP64 stencil values, with a maximum absolute error of 2.84 × 10−14. With precision-cast emulation enabled, Inductor matched eager bit for bit, within 7% of the handwritten kernel, which makes it a strong option for new stencils. We wrote the Triton kernel before testing that mode; it had the lowest measured latency, and its timing benefits slightly from writing into a preallocated output buffer. torch.compile · Triton
Reading and writing the eight FP64 fields for eight samples accounts for 2.15 GB per call. Dividing by 1.314 ms gives 1.63 TB/s of effective field I/O.
Scaling to eight H100s
Each GPU runs its own campaign. The optimized pipeline packs ten snapshot arrays into one device-to-host copy on a side stream, using a reusable pinned host buffer. The GPU accumulates reaction-check failures and the runner checks them at save boundaries and before completion.
Overlapping CPU packing, audit, and writes can keep two sub-batches live per campaign. The first eight-campaign attempt exceeded the 256 GB host-memory allocation. We then ran the original GPU pipeline and both Triton chunk sizes on a single node under the same resource requirements, with a different configuration order in each of three rounds.
Chunk 4 matched all 256 trajectory and flux digests in each round, with 215 of 256 metadata digests matching. In round 1, the reaction-extent diagnostic accounted for all 41 metadata differences. Of those values, 34 differed by one unit in the last place (ULP) and seven by two.
The full-pipeline result
Chunk 8 retained asynchronous snapshots, used serial sub-batch output processing, and ran two flux workers per campaign. We used it for the bit-exact comparison because its trajectory, flux, and metadata digests matched for all 256 samples in each round.
Eight-GPU pipeline elapsed time
Three rounds on the same H100 node · 256 samples per configuration · common time scale
Round 1
Round 2
Round 3
| Round | Original | Chunk 4 time | Chunk 8 time | Chunk 4 throughput | Chunk 8 throughput |
|---|---|---|---|---|---|
| 1 | 1,954.93 s | 524.32 s | 785.38 s | 3.73× | 2.49× |
| 2 | 1,902.53 s | 820.89 s | 3,030.17 s | 2.32× | 0.63× |
| 3 | 1,557.71 s | 649.07 s | 1,164.08 s | 2.40× | 1.34× |
| Median paired throughput | 2.40× | 1.34× | |||
Chunk 4 ran at 2.32–3.73× original throughput across the three rounds, with a median of 2.40× and 41 metadata digest mismatches per round. Bit-exact chunk 8 ranged from 0.63× to 2.49×, with a median of 1.34×. It ran slower than the original in round 2.
Host-side packing, flux calculation, auditing, and writes made up about 80% of the optimized 111 s single-GPU pipeline. On eight GPUs, chunk 4 overlaps output work across sub-batches. Chunk 8 preserves the original eight-sample reduction shape and processes sub-batch output serially to fit the 256 GB host-memory budget. That puts host processing and storage on its critical path.
In the saved chunk-8 campaign logs, the interval covering simulation, snapshots, and raw output writes took 2,943–3,012 s per campaign in round 2, up from 731–770 s in round 1. The timing combines GPU and host stages, so the contribution of host or storage contention to the slowdown remains unresolved.
Results
| Workload | Original | Triton | Change | Scope |
|---|---|---|---|---|
| Transport stencil, batch 8 | 47.387 ms | 1.314 ms | 36.1× | Bit-exact |
| Reaction + update, per step | 10.71 ms | 1.53 ms | 7.0× | Archived profiles |
| Peak GPU allocated memory | 13.883 GB | 4.914 GB | −64.6% | Same-GPU solver run |
| Solver execution, 8 samples | 269.27 s | 22.46 s | 12.0× | Same-GPU solver run |
| Single-GPU pipeline, 8 samples | 428 s | 111 s | 3.9× | 8/8 digests match |
What made it work
Fusing transport and reaction updates reduced solver time. The full-node tests exposed a separate trade-off between overlapping output work and keeping the original FP64 diagnostic reduction grouping. Checking metadata alongside the fields made that trade-off visible.
How we measured
Reproduction. A pinned reproduction checkpoint holds the archived GPU runners and solvers, source hashes, replay scripts, and campaign manifests. Because the original runs did not record shared-helper hashes, the helpers are pinned to a July repository snapshot; the staged helpers reproduced all eight archived campaign configurations.
Isolated measurements. The stencil test used an H100 80 GB SXM with PyTorch 2.10.0+cu128 and Triton 3.6.0. CUDA events timed nine rounds of eight calls after warmup. The reaction-update comparison comes from archived section profiles. Both pinned solvers ran on the same H100 with a 128³ grid, eight samples in one chunk, 640 steps, and snapshots every 40 steps. Peak memory is PyTorch's maximum allocated device memory.
Eight-H100 verification. Three configurations × three rounds = nine runs on the same node. Each run launched eight concurrent campaigns of 32 samples, with 64 requested CPUs and 256 GB of requested host memory. Launcher wall time ends when the final campaign process exits. We joined the saved manifest rows by sample ID and compared SHA-256 digests for packed trajectories, interface fluxes, and metadata. Round 1 chunk-4 ULP counts come from direct comparison of the saved FP64 diagnostic values.
References: NVIDIA CUDA floating-point guide · Triton documentation · PyTorch torch.compile documentation