Log inStart free
LESSON 6.08 · 5 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Why GPU results aren't bit-reproducible

Watch the same eight numbers add up to different bits on one GPU.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 6.08 · REDUCTION BAYFP32 · CPU LOOP · TOTAL 2.4699965
01
Stage 1 of 5 · Each add rounds
The CPU loop adds x1 to x8 in order. Each add rounds to the nearest FP32 number: a rounding error.
Explain it simply

A float can hold only some numbers, with a gap between each one and the next. Every add lands on the nearest number, and the brick bars show how far it moved. Near −22, the gap is 8 times wider than near the total. So the order of the adds decides where the biggest errors happen.

The top row holds the 8 values. The row below holds the running sums, with brick error bars. The total is 2.4699965.

valuessums and totalsthread blocks, flagrounding error, bits that differ
+0.13+0.25−0.50−0.500.000.00−0.50gap near s5 = −22.1400032: 1.9e−6gap near s8 = 2.4699965: 2.4e−71.3400000x112.1300001x21.5100000x3−35.8300018x4−1.2900000x52.0799999x621.1599998x71.3700000x81.3400000s113.4700003s214.9800005s3−20.8500023s4−22.1400032s5−20.0600033s61.0999966s72.4699965s8the CPU loopxsrounding error(in gaps)bits 401e146cgap betweenfloatss8 = fl(s7 + x8) = fl(1.0999966 + 1.3700000) = 2.4699965 · exact sum of stored FP32 values: 2.4699981+0.13+0.25−0.50−0.500.000.00−0.50gap near s5 = −22.1400032: 1.9e−6gap near s8 = 2.4699965: 2.4e−71.3400000x112.1300001x21.5100000x3−35.8300018x4−1.2900000x52.0799999x621.1599998x71.3700000x81.3400000s113.4700003s214.9800005s3−20.8500023s4−22.1400032s5−20.0600033s61.0999966s72.4699965s8the CPU loopxsrounding error(in gaps)bits 401e146cgap betweenfloatss8 = fl(s7 + x8) = fl(1.0999966 + 1.3700000) = 2.4699965 · exact sum of stored FP32 values: 2.4699981
Toy: 8 values, 4 runs, 4 devices
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
sk=fl(sk−1+xk)\sy{s}{out}{s_k} = \mathrm{fl}(\sy{s}{out}{s_{k-1}} + \sy{x}{data}{x_k})
s8=fl(1.0999966+1.3700000)=2.4699965s_8 = \mathrm{fl}(1.0999966 + 1.3700000) = 2.4699965

Each running sum is the last one plus the next value, rounded.

Common mix-ups

MYTHA fixed random seed makes GPU results repeatable.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With 2 thread blocks, do the 4 atomic runs give the same total?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.