Repository navigation
FUZZ-3: float VALU differential fuzzer; v_mac_f32 unfused, VOP3 output modifiers on conversions - #394
Conversation
… output modifiers tools/f32_fuzz.py runs seeded VOP1/VOP2/VOP3 float programs (neg/abs, clamp, omod) through an exact-arithmetic RDNA2 model and through the translated SPIR-V in tests/semantic's interpreter, and compares them bit-exact. Denormals, and inputs the emitted SPIR-V leaves undefined, are counted separately instead of being compared. Translator fixes it found: - v_mac_f32 is the VOP2 form of v_mad_f32 (product rounded before the add), not of v_fma_f32 (LLVM getNewFMAInst: V_MAC_F32 -> V_MAD_F32_e64). It emitted Fma. - VOP3 clamp and mul:2/mul:4/div:2 were dropped on v_cvt_f32_i32/u32, v_cvt_f32_ubyte0..3, v_cvt_f32_f16 and v_rcp_iflag_f32 (LLVM VOPProfileI2F: $src0, $clamp, $omod). Interpreter: RoundEven keeps the sign of a zero result; Fma rounds once (it double-rounded through a double); adds OpFDiv, OpIsNan, OpIsInf, Floor/Ceil/Trunc/Exp2/Log2/Sqrt/InverseSqrt, raising where SPIR-V or GLSL.std.450 leave the result undefined. Pinned by runtime/test/shaders/ps_f32_mods.asm (check.py, run_gpu_tests.py, tests/semantic/test_f32_valu.py) and tests/test_f32_fuzz.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested ed6da6b on NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 (build 26300): pass.
AI-assisted (Claude Code). |
|
Tested ed6da6b on NVIDIA GeForce RTX 3050 Laptop GPU (Ampere, subgroup 32), driver 610.91, Windows 11 build 26300: pass. AI-assisted (Claude Code).
Toolchain: llvm-mc 21.1.8 (built with Edit: the fuzzer line first said that the only non-compared cases were "undefined in SPIR-V". That missed the 34 skipped programs. The exit code and mismatch count I first posted had not been read from the fuzzer itself (I had |
Keep both sides in docs/design.md (contract rows), regen_fixtures.py (ps_f32_mods + ps_fma_literal), spirv_mini_interp.py (our OpFDiv, Floor/Ceil/Trunc, Exp2/Log2/Sqrt/InverseSqrt and RoundEven sign fix; upstream's OpIsNan/OpIsInf, OpConvertUToF/SToF and FMax/FClamp) and rdna2spirv.py (upstream fmamk/fmaak fix; v_mac_f32 stays with v_mad_f32). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged
After the merge: semantic unittest 472 OK, pytest 1769 passed / 178 skipped, |
|
Tested Verified both sides of the multiply-add translator merge on Ubuntu 26.04.1 LTS. I built the runtime from this head and ran each fixture with a separate empty work directory. Both shaders passed SPIR-V validation. A separate comparison of the raw framebuffer matched all four expected words at every pixel in each draw.
The first draw confirms the fixture’s unfused MAC result and conversion output modifiers. The second confirms the literal multiply-add cases retained from main. Coverage was limited to these two synthetic fixtures. AI-assisted verification. |
|
Tested 8a6deb1 on two GPUs, Linux 7.3.5 (CachyOS): pass.
Ran |
spirv_mini_interp.py: keep main's _F32 (sNaN bits, #533) and its vector-aware RoundEven/Floor/Ceil/Trunc; keep this branch's fma_f32, OpFDiv and Exp2/Log2/Sqrt/InverseSqrt. regen_fixtures.py: both sides' shaders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Updated onto |
…2_mods and ps_f64_mods) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested Rebuilt the runtime at the rebased head and replayed the two synthetic pixel shaders from the earlier RTX 5090 check. Each shader translated and passed spirv-val. I checked the four raw 32-bit RGBA words at every pixel against the expected tuple.
Both fixtures retained their earlier bit-exact results after integration with c432cdc. Coverage here is limited to the two GPU draws. Earlier RTX 5090 readback at 8a6deb1 AI-assisted verification. |
Item: FUZZ-3 (32-bit float VALU), claimed in #156; findings posted there before fixing (comment).
What this adds
tools/f32_fuzz.py: a differential fuzzer for the translator's 32-bit float VALU. Seeded VOP1/VOP2/VOP3 programs (with neg/abs source modifiers,clampandmul:2/mul:4/div:2) run through two independent paths, and their results are compared bit-exact:tools/rdna2spirv.py, whose SPIR-V output is then run bytests/semantic/spirv_mini_interp.py.It covers 36 ops: add/sub/subrev/mul, legacy mul/mad, mad/mac/fma/fmac/fmaak/madak,
v_cvt_f32_{i32,u32,ubyte0..3,f16},v_cvt_f16_f32,v_cvt_pkrtz_f16_f32,v_cvt_pk_u8_f32, floor/ceil/trunc/rndne, rcp/rsq/sqrt/exp/log (exact-result inputs only), the cube ops andv_cmp_class_f32. Three kinds of input are counted, never compared:--self-testchecks the harness can both pass and fail.Translator fixes it found
v_mac_f32was emitted asFma. It is the VOP2 form ofv_mad_f32, so the product is rounded before the add. LLVMSIInstrInfo.cppgetNewFMAInstmapsV_MAC_F32toV_MAD_F32_e64andV_FMAC_F32toV_FMA_F32_e64. It now lowers likev_mad_f32(OpFMul+OpFAdd, bothNoContraction). Example: 0xbc500c59 × 0x435a2099 + 0x3e3db015 gives 0xc0256a01; fused gives 0xc0256a00.clampand output modifiers were dropped onv_cvt_f32_i32/u32,v_cvt_f32_ubyte0..3,v_cvt_f32_f16andv_rcp_iflag_f32. LLVM'sVOPProfileI2FhasIns64 = $src0, $clamp, $omod, and the float-source profiles have both. These handlers now callclamp_mods.Not in this PR:
v_med3_f32(#350) andv_cvt_f32_f64(#380) are fixed elsewhere. Still open, for discussion in #156:v_rcp_f32(±0),v_rsq/v_logof ±0 or a negative,v_sqrtof a negative andv_cvt_pk_u8_f32(NaN)emit SPIR-V that is undefined on inputs where the ISA defines the result (recorded in the newdocs/design.mdrow).Interpreter (test infrastructure)
RoundEvenlost the sign of a zero result (Python'sround()returns an int), soroundEven(-0.4)gave +0.Fmarounded through a double. It is now exact: (1 + 2⁻¹²)² + 2⁻⁷⁰ lands on a binary32 midpoint, and the double path gave 0x3f801000 instead of 0x3f801001. That is the trapdocs/shader_validation.mdwarns about.OpFDiv,OpIsNan,OpIsInf,Floor/Ceil/Trunc/Exp2/Log2/Sqrt/InverseSqrt. Each raisesUnsupportedConstructwhere SPIR-V or GLSL.std.450 leave the result undefined, like the existing ops.Tests
runtime/test/shaders/ps_f32_mods.asm: one word per rule, wired intocheck.py,run_gpu_tests.pyand the semantic fixtures. Each missing modifier gives a different word.tests/semantic/test_f32_valu.py: the fixture against hand-written constants, cross-checked by a plain-Python reference, plus interpreter tests against GLSL.std.450.tests/test_f32_fuzz.py: model spot checks, harness canaries, and a seeded 400-program sweep that must have no mismatch.Run on Windows 11, Python 3.11, rebased on
d7cbc3e:python -m unittest discover -s tests/semantic: 450 OK.python -m pytest tests --ignore=tests/semantic: 1188 passed, 160 skipped.tests/test_*.py: all pass.regen_fixtures.py --checkandcompileall: OK.GPU-tested by @Pipodi on
ed6da6b: NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 (build 26300):python scripts/run_gpu_tests.py --filter ps_f32_modspasses, spirv-val 1/1, 4096/4096 pixels exact (comment). I did not run it myself (this machine has nollvm-mc/SPIR-V tools or MSVC); the expected words come from the ISA and LLVM references above.Other open PRs touch the same files:
runtime/test/shaders/check.py,scripts/run_gpu_tests.pyandtests/semantic/regen_fixtures.py(one added line each), and #350 and #331 edit nearby lines of the multiply-add block intools/rdna2spirv.py.No game files. AI-assisted (Claude Code).
🤖 Generated with Claude Code