TF32 Saved 7% Runtime and Tripled Our Flow Velocity
We traced a persistent momentum bias to TF32 rounding in a lattice Boltzmann solver, checked it against FP64, and recovered GPU throughput with a fused Pallas kernel.
When we use fluid simulations to train AI for engineering, small errors in the calculations can change what the model learns. In our tests, a default GPU shortcut saved 7% of simulation time, but by the end the fluid was flowing about three times as fast and had nearly ten times as much energy from its motion as in a more precise run. We traced the difference to how the GPU rounded its numbers and wrote new GPU code that ran the simulation 9.1× faster than the original at comparable accuracy.
On NVIDIA GPUs, JAX can lower eligible FP32 dot and einsum contractions to TF32 by default. Tensor Cores round the operands to 10 fraction bits, down from FP32’s 23, before accumulating in FP32. Setting JAX’s default matmul precision to “highest” when compiling the solver requests full FP32 precision for those contractions. JAX matmul precision
In our H100 replay, default TF32 saved 7% of simulation time (3.34 vs. 3.59 s/sample), while final mean axial velocity was 3.13× and kinetic energy was 9.85× the FP64 result. FP32 highest and fused Pallas each had about 0.016% pooled axial-velocity nRMSE and 0.16% final mean-velocity error against FP64. TF32 had 20.5% pooled error and 212.6% endpoint error. Pallas ran the FP32 simulation 9.10× faster than the precision-matched original.
Checking a solver for this takes one comparison: compile the same rollout once at default and once at highest matmul precision, run both from the same initial state, and compare the outputs.
The same flow, at four precision settings
D3Q19 lattice Boltzmann represents the fluid at each 3D grid cell with 19 populations, one for each discrete velocity. Their sum gives density, and their signed first moment gives momentum. We replayed the coupled non-Newtonian and particulate case on a 128³ grid for 1,600 steps with matched initial conditions. The FP64 control used FP64 state and weights. A second FP64 run promoted the archived FP32 weights, testing the effect of their representation.
TF32 leaves a faster axial flow
128³ lattice · matched initial state · 1,600 coupled steps
Mean axial velocity (mm/s)
- Original JAX · default TF32
- 2.289651 mm/s
- Original JAX · FP64
- 0.732359 mm/s
- Original JAX · FP32 highest
- 0.733525 mm/s
- Fused Pallas · FP32
- 0.73353 mm/s
FP32 velocity difference from FP64 (µm/s)
- Original JAX · FP32 highest
- 1.166288 µm/s
- Fused Pallas · FP32
- 1.171469 µm/s
Where the extra momentum came from
For a low-Mach flow, each moving population sits near a positive D3Q19 weight, typically 1/18 or 1/36. Opposite populations have the same weight and opposite signs in the axial moment. Their small flow perturbations therefore enter the signed sum after the two larger populations have rounded. Near each weight, the exponent and quantization spacing stay nearly fixed. Opposing perturbations can cross rounding thresholds at different points, producing a signed residual. The rounding uses nearest with ties away from zero. NVIDIA PTX instruction set
On the 16 TF32 trajectory states at steps 0, 100, …, 1,500, summed rounding error averaged +2.44×10−6 for forward populations and −1.76×10−6 for backward populations per fluid cell. Their difference matched the measured device-dot bias of +4.19×10−6 and was positive at 15 of 16 states. The corresponding bias on FP32-highest trajectory states changed sign. In the full TF32 rollout, the mean collision impulse was 4.27×10−6 per step versus 6.00×10−7 in FP64, with excess impulse on 1,579 of 1,600 steps.
| FP32 contraction ablation | TF32 trajectory states | FP64 trajectory states |
|---|---|---|
| All three at default | +3.56×10−6 | −8.61×10−8 |
| Momentum only at default | +4.00×10−6 | −7.22×10−8 |
| Equilibrium only at default | −5.40×10−10 | −1.58×10−9 |
| Stress/shear only at default | +9.93×10−13 | +3.92×10−13 |
| Momentum highest, others default | −5.41×10−10 | −1.58×10−9 |
A weight offset suppresses the bias
Lehmann et al. studied this loss of precision in lattice Boltzmann and describe subtracting the lattice weights before storing or computing with populations. The weights contribute zero net momentum by symmetry, so we tested the default-precision moment on f − w using the same 16 frozen states and an FP64 contraction of the original populations as the reference. The offset reduced signed bias from +4.19×10−6 to +1.08×10−8 (390×) and per-cell RMS error from 1.81×10−5 to 8.75×10−7 (20.7×). This test isolates the momentum contraction. Lehmann et al., Phys. Rev. E 106, 015308 (2022)
Tracking the excess momentum through the rollout
Fluid-cell means from the instrumented 128³ solver · all 1,600 steps
Collision impulse above applied force (×10⁻⁶)
- Original JAX · default TF32
- 3.500763 ×10⁻⁶
- Original JAX · FP32 highest
- 0.003394 ×10⁻⁶
- Original JAX · FP64
- 0 ×10⁻⁶
Post-stream axial momentum vs FP64 (×10⁻³)
- Original JAX · default TF32
- 1.553118 ×10⁻³
- Original JAX · FP32 highest
- 0.001167 ×10⁻³
- Original JAX · FP64
- 0 ×10⁻³
Post-stream mass vs FP64 (×10⁻⁶)
- Original JAX · default TF32
- -93.070343 ×10⁻⁶
- Original JAX · FP32 highest
- 0.449543 ×10⁻⁶
- Original JAX · FP64
- 0 ×10⁻⁶
Normal stress σₓₓ vs FP64 (×10⁻⁶)
- Original JAX · default TF32
- 0.011188 ×10⁻⁶
- Original JAX · FP32 highest
- 0.003006 ×10⁻⁶
- Original JAX · FP64
- 0 ×10⁻⁶
Accuracy against FP64
| Solver | Axial velocity nRMSE | Final mean velocity error | Shear nRMSE | Stress xx / zz nRMSE |
|---|---|---|---|---|
| Original JAX, default TF32 | 20.4677% | 212.64% | 20.9564% | 67.5546% / 101.7141% |
| Original JAX, FP32 highest | 0.0158% | 0.1593% | 0.0160% | 0.1891% / 0.4206% |
| Fused Pallas, FP32 | 0.0159% | 0.1600% | 0.0162% | 0.2950% / 0.6680% |
| FP64, promoted FP32 weights | 0.0001% | 0.00007% | 0.0005% | 0.0495% / 0.1883% |
Pallas matches the channel-major FP32 JAX rewrite bit for bit in the tested frames. Its small stress differences from the original JAX solver are consistent with different summation order and multiply-add contraction in the local stress update.
The 64³ check used the step-1,600 fluid-mean axial velocity against the 64³ FP64 run. The endpoint error was 0.0267% for FP32 highest and 246.16% for default TF32. This second grid tests precision sensitivity.
Speed at matched precision
| Implementation | Two runs, s/sample | Mean s/sample | GLUPS |
|---|---|---|---|
| Original JAX, default TF32 | 3.3356, 3.3363 | 3.3359 | 1.006 |
| Original JAX, FP32 highest | 3.5913, 3.5911 | 3.5912 | 0.934 |
| Fused Pallas, FP32 | 0.3945, 0.3950 | 0.3948 | 8.500 |
The uniquely addressed FP32 data per step, including halo accesses and counting the wall mask once per batch, is 182.5 B/update for the fused fluid kernel and 25.7 B/update for particle transport. At 0.395 s/sample this implies 1.77 TB/s effective bandwidth, or 52.8% of the H100 SXM’s 3.35 TB/s peak. Hardware HBM performance counters were restricted in the container environment, so bandwidth is reported from the source-derived unique-address traffic model. NVIDIA H100 specifications
What the fused Pallas kernel does
The original JAX loop launched 17 kernels and one buffer copy per step. A gather-and-transpose kernel took 62.5% of simulation time. The Pallas rewrite lays out each direction contiguously and brings the 19 upstream populations into a tile, where it computes collision and rheology. The GPU writes the updated populations once.
Each tile covers a strip of grid cells. For each of the 19 directions it pulls the upstream population, substitutes the lattice weight at wall cells, and then runs the FP32 collision and rheology update using the same operation order as the channel-major reference. The full kernel also writes shear, velocity, relaxation time and the periodic streamwise halo.
The output buffer is aliased to a spare input buffer, so the kernel writes into the destination buffer while all tiles can still read their neighbours from the old state. The time loop alternates the two buffers across steps. A second kernel advances particles using the new velocity and shear. Pallas kernel calls and aliasing
From kernel speed to pipeline speed
The 32-sample pipeline improved from 5.54 to 3.74 s/sample (1.48×). The separate simulation benchmark accounts for 10.6% of the optimized total by arithmetic. The remainder includes derivation, transfers, audit, hashing, storage, and setup, with overlap between stages. With that remainder held fixed, eliminating the isolated simulation time would raise throughput by at most 1.12×.
The production reference enforces highest matmul precision, disables TF32, and requires FP64 transport. The fused FP32 Pallas kernel is a validated benchmark implementation. It delivers 9.10× simulation speedup against the original FP32-highest solver at 8.50 GLUPS, with bitwise parity to the channel-major FP32 rewrite on the tested frames.