[AMDGPU] comgr: fix SR FP8 carry-propagation in E5M3 stochastic rounding#3275
[AMDGPU] comgr: fix SR FP8 carry-propagation in E5M3 stochastic rounding#3275suryajasper wants to merge 4 commits into
Conversation
The stochastic noise injection in patchCvtSrFp8F32 extracted the F32 mantissa, added noise, then masked with & 0x007FFFFF. When mantissa + noise overflowed 23 bits, the carry into the exponent field was discarded, causing the UE5M3 byte to wrap within the same exponent instead of advancing to the next one. Fix: add the shifted noise directly to the F32 bitpattern. Integer addition naturally carries from mantissa into exponent, matching ISA behavior. This also reduces the trampoline from 6 to 2 instructions. Affected instruction: v_cvt_sr_fp8_f32 with CLAMP=1 and non-zero seed. Symptom: 3.1% of lanes produce output 7 less than correct (mantissa zeroed instead of exponent incremented) when the truncated UE5M3 byte has mantissa=0b111 and SR decides to round up.
… fix Remove stale v_and_b32 0x7fffff (mantissa mask) CHECK patterns from SR_NEG and SR_ABS check blocks in hotswap-cvt-fp8-modifiers.s. The carry-propagation fix changed the SR noise injection path from a 6-instruction extract/add/mask sequence to a 2-instruction direct F32 bitpattern addition (v_lshrrev_b32 + v_add_u32), which no longer includes the mantissa mask step.
38e3701 to
d20a206
Compare
|
Where is the test |
|
How are we really ensuring numeric correctness here ? Can you add tests that exercise the corner cases ? negative values, NaNs, Infs, etc. |
Shorten the noise injection comment to describe current behavior without referencing the old buggy code path.
These are part of our internal testing repo, where we added unit test kernels that directly test these corner cases. This is where we originally identified these failures, and I validated they all pass with this patch added. I've removed them from the description since we don't have those here within llvm.
We can't validate numerical correctness through lit tests. There's also no A0 unit testing CI in llvm-project that I can hook into for hardware validation. However, all these instruction conversion patterns are covered by the lit tests in this PR. Numerical correctness was validated on gfx1250 A0 hardware using our internal test suite, which exercises v_cvt_sr_fp8_f32 CLAMP=1 across these corner cases:
All 19 tests pass with 0/256 mismatches against CPU reference implementations. |
Summary
Fix carry-propagation bug in
patchCvtSrFp8F32. The old stochastic noise injection path extracted the F32 mantissa, added noise, and masked back to 23 bits -- discarding the carry when mantissa + noise overflowed. This caused 3.1% of stochastic rounding results to be off by exactly 7 (the full UE5M3 mantissa range).Root cause
Fix
Integer addition on the whole F32 bitpattern lets mantissa overflow carry into the exponent, matching the ISA's stochastic rounding behavior. Also reduces trampoline from 6 to 2 instructions.
Covered instructions
v_cvt_sr_fp8_f32with CLAMP=1 (UE5M3 stochastic rounding)Changes
comgr-hotswap-patch-f32-to-e5m3.cpphotswap-cvt-sr-fp8.shotswap-cvt-fp8-modifiers.sTest plan