Repository navigation
Translator: --fma exact, a single-rounded f32 FMA without VK_KHR_shader_fma (SHADER-497) - #3004
AmazingMoaaz wants to merge 2 commits into
Conversation
|
Independent Windows 11 (26200) check of |
|
Tested abc4582 on NVIDIA GeForce RTX 5070 Ti, driver 621.24, Windows 11 (10.0.26200), llvm-mc 21.1.8, Vulkan SDK 1.4.363.0: pass.
No game files used. Run with AI assistance. |
|
Tested
No game files. AI-assisted (Claude Code). |
…); khr or exact fix it there
ea784c1 to
d3e09d1
Compare
…); khr or exact fix it there
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: tests/semantic/test_fma_exact.py -> 9 tests OK; full semantic 4,146 passed / 48,105 subtests / 0 failed. The construction is the expected 12-bit Dekker split with Knuth TwoSum, round-to-odd and a final th+v, with every OpFMul/FAdd/FSub in no_contraction() so a driver cannot re-fuse it. An independent Fraction/integer-RNE fuzz over 14,738 triples gives 0 mismatches (625 denormal-range results excluded as documented); signed-zero, inf/NaN and spirv-val checks pass. --fma exact emits no OpFmaKHR/FMAKHR; khr is the only path that gates the extension, and both build/run tooling pass exact through. No game data or absolute paths. Approve.
Nit: the help/design text says "about 110" instructions per FMA; the emitted path is 131.
|
@Kam471, thanks for the review. On the count: compared with |
|
Re-checked after rebasing onto
|
…er_fma (SHADER-497)
…ction decorations, constants)
71c02e9 to
3f0c142
Compare
|
Rebased onto
|
# Conflicts: # docs/design.md # docs/testing.md
|
This was merged as 8860b36 ("Merge pull request #3004 from Moaaz Gewili") at head d3e09d1, so |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/design.md # docs/testing.md
SHADER-497 (claimed in #2716 (comment); finding in #2516 (comment)).
What and why
The Intel UHD Graphics driver (Xe-LP, Tiger Lake-H, Windows 101.7088) splits
GLSL.std.450 Fmainto two roundings and has noVK_KHR_shader_fma. So the default--fma glslisn't exact there, and--fma khrcan't be used. Onmain,check.py'scs_fma_fusedfails on that device: words 0, 2, 3 and 5 (v_fma_f32,v_fmaak_f32,v_fmac_f32) come out split. #2211'scs_w32_fma_mixfails word 1 the same way.This adds
--fma exact(Gen.fma_exact), a single-rounded f32 multiply-add built fromNoContractionf32 operations and needing no extension. It follows Boldo and Melquiond, "Emulation of a FMA and correctly-rounded sums: proved algorithms using rounding to odd" (IEEE Transactions on Computers 57(4), 2008):p + pe = x * y. The factors are split into 12-bit halves by masking their low 12 mantissa bits, so the split can't overflow.th + tl = z + p.v = tl + pe, rounded to odd asfma_f16_oddalready does.th + v, orthwhenvis zero, so a-0sum stays-0.The construction needs every intermediate in the normal range. So operands are first scaled by powers of two, which is exact, and the result is scaled back:
Infinite or NaN operands, and a finite product beyond even the scaled range (the result is ±inf), take the plain
Fma.Every
emit_fmacaller gets it:v_fma_f32,v_fmac_f32,v_fmaak_f32,v_fmamk_f32, andv_fma_mix*includingfma_mix_odd's product error. It costs about 110 instructions per multiply-add, so it's opt-in: the default stays--fma glsl.build.pyandrun_gpu_tests.pyacceptLEONIDA_FMA=exact.docs/design.mdrecords the rule and how it was confirmed, anddocs/testing.mdno longer says no tested driver splitsFma.Not exact, and documented: a result in the denormal range (it's scaled back with a second rounding), and denormal operands, which follow the driver's denormal mode like every f32 operation here (the translator emits no
DenormPreserve).Tested
tests/semantic/test_fma_exact.py(new, 9 tests). It runs the emitted instructions in the interpreter with itsFmasplit into two roundings, as on the Intel driver, so only the emulation can be exact. It compares 700 random triples (plain, cancelling, near-tie, tiny, huge, overflow-cancel, wide-exponent) and 96 edge triples with the exact rational reference (si.fma_f32), plus signed zeros, inf/NaN operands, every FMA form includingv_fma_mix_f32, andspirv-val. Negative control: the same harness gives--fma glslthe split words the Intel UHD gave (0x00000000,0x3a000000).check.pywithLEONIDA_FMA=exactat this branch (rebased onmainec8ec4c), on Windows 11 Pro build 26300:cs_fma_fusedok; 124 of 167 pass, 43 skipped, 0 failed (withglslon the same build: 123 of 167,cs_fma_fusedthe only failure).cs_fma_fusedok; 132 of 167 pass, 35 skipped, 0 failed.cs_w32_fma_mix(its tree, with this translator): passes withexacton both GPUs; withglslthe Intel UHD fails word 1 (0x3a000000).python -m unittest discover -s tests/semantic: 4146 tests OK.python -m compileall -q make_game.py tools tests,python -I make_game.py --help: ok.Built with
scripts\build_runtime.ps1(MSVC 19.51), llvm-mc 23.1.6, Vulkan SDK 1.4.363.AI-assisted.