Repository navigation
tools: wint_diff.py, a whole-wave differential fuzzer for integer VALU under random EXEC - #2336
Conversation
…U under random EXEC Seeded integer VALU programs run on every lane of a wave32 or wave64 wave with EXEC rewritten between instructions: compares into SGPR masks and VCC, v_cmpx, v_cndmask on the masks, carry-out/carry-in forms, v_mad_u64/i64 with a mask carry-out, 16-bit op_sel half writes and 32-bit ops. A per-lane ISA model is compared with rdna2spirv run in tests/semantic/spirv_wave_interp.py, optionally with the hardware through tools/hw_oracle. Known divergences (VCC data read as a mask, ItsNotRexed#2206; a mask read as data, ItsNotRexed#293) only with --known. AI-assisted.
|
Reviewed PR #2336 ( Files read
Checks run
FindingsLooks clean. All 18 unit tests (covering reference wave32/wave64 EXEC/mask/carry/16-bit semantics, generator coverage and |
x2Tweek
left a comment
There was a problem hiding this comment.
Static review — PR #2336
Branch: head of PR #2336
Commit: bbf009f
Author: Vonsek
State: OPEN
What it does
Adds tools/wint_diff.py — a whole-wave differential fuzzer for integer VALU under random EXEC (FUZZ differential testing). Seeded integer VALU programs run on every lane of a wave32/wave64 wave with EXEC rewritten between instructions (compares into SGPR masks and VCC, v_cmpx, v_cndmask on masks, carry-out/carry-in forms, v_mad_u64/i64 with mask carry-out, 16-bit op_sel half writes, 32-bit ops). A per-lane ISA model is compared with rdna2spirv run in tests/semantic/spirv_wave_interp.py, optionally with hardware via tools/hw_oracle. Known divergences (VCC data read as a mask #2206; a mask read as data #293) only with --known.
Also adds tests/test_wint_diff.py (reference oracle against hand-worked values, seeded fuzz canaries) and a doc row in docs/shader_validation.md.
Coverage
New tests:
Reference.test_carry_out_and_in_under_exec—v_add_co_u32/v_add_co_ci_u32under partial EXEC, carry propagation, inactive lanes untouched.Reference.test_borrow—v_sub_co_ci_u32borrow chains under EXEC.Reference.test_inactive_lanes_get_a_zero_mask_bit— compare producing mask clears inactive lanes.Reference.test_cmpx_writes_exec—v_cmpxwrites EXEC, subsequent ops respect it.Reference.test_mad64_carry—v_mad_u64_u32/v_mad_i64_i32carry-out under mask.Reference.test_16bit_writes_one_half— 16-bitop_selhalf writes.Reference.test_wave64_exec_hi_and_pairs— wave64exec_hi, SGPR pairs.- Plus CLI canary tests (
test_ops_normalization, unknown/empty ops, self-test).
No translator/runtime changes — the fuzzer compares the ISA model against rdna2spirv output, so mismatches would surface translator bugs. No game data; synthetic seeded programs only. Standard library only.
Code review
The fuzzer is well-architected:
- Whole-wave model with per-lane VGPRs, SGPRs, VCC, and EXEC mask (lo/hi for wave64).
- EXEC rewritten between instructions via compares, matching real shader control flow.
- Known-divergence handling via
--knownflag (documents open hardware questions without failing the run). - Hardware oracle optional via
--oracle hwfor validation on real RDNA2. - Tests use hand-worked expected values, not circular reasoning.
The test file is focused (18 tests, 3 subtests) and covers carry chains, EXEC masking, cmpx, mad64 carry, 16-bit half writes, and wave64 pairs.
Test results
tests/test_wint_diff.py: 18 passed, 3 subtests (2.52s)python -m compileall: clean on both changed files
Reviewer recommendation
Approve (CPU tests). Adds a whole-wave integer VALU differential fuzzer with EXEC masking, carry chains, mad64, 16-bit op_sel, and wave64 support, plus reference tests and doc row. All 18 tests / 3 subtests pass; compileall is clean.
AI-assisted. CPU tests only.
Requested by Lucas · project thread
Claimed in the coordination issue as: EGEN-TOOL-WINT-DIFF (claim)
What and why
The repo's ALU fuzzers (
shader_diff.py,salu_diff.py, the SDWA one in #2113) run one lane, so they never see which lanes an instruction writes or the lane masks that compares and carries make and read. A scratch whole-wave checker found #2206 (wave32 VCC holding data, read as a mask). This PR makes it a repo tool,tools/wint_diff.py, in the style oftools/salu_diff.py(stdlib only,python -I,--programs/--seed/--max-ops/--ops/--list-ops/--self-test, shrinking on mismatch, skips counted with reasons, exit 0/1/2/77):--wave 32|64|both), withs_mov_b32 exec_lo/exec_hibetween instructions (edge masks and random words).s20/s21(s[20:21]/s[22:23]in wave64) or VCC and e32 into VCC,v_cmpxinto EXEC,v_cndmask_b32e64/e32 on those masks,v_add/sub/subrev_co_u32e64 and_co_ci_u32e64/e32,v_mad_u64_u32/v_mad_i64_i32with a mask carry-out, 16-bit e64/VOP3 ops withop_selwriting one half, plain data moved into an SGPR mask, and 23 32-bit VOP1/VOP2/VOP3 ops. Sources are VGPRs, SGPRs and inline constants within the GFX10 constant bus.cpu_ref.py. The translated side runs intests/semantic/spirv_wave_interp.py. Every lane's four words are compared.--oracle hwruns each program as one wave (32 or 64 threads) throughtools/hw_oracle, each lane storing its own words.--known: VCC written with data and read as a mask (rdna2spirv: wave32 VCC holding data, read as a lane mask, gives lane L bit L #2206 for wave32; wave64 is still open, see the Coordinating who works on what (9) (moved to #2078) #1902 finding), and a mask read as VALU data (Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) #293). The docstring lists what is modelled and these forms.tests/test_wint_diff.py(18 tests): hand-worked reference values (carry out/in under EXEC, borrow, inactive lanes clearing mask bits,v_cmpx, bothv_mad_*64carries, 16-bit half writes, wave64exec_hiand mask pairs, data in a mask SGPR), the translator on hand cases in both wave sizes, a short seeded run, generator coverage (every op in both wave sizes; known forms only with--known), canaries (a faked wrong lane is caught, shrinking keeps the guilty instruction), the hardware kernel shape and the exit codes including 77.docs/shader_validation.mdgets a short section.Tested
Windows 11, Python 3.
python -I tools/wint_diff.py --wave both --max-ops 10: seeds 1 and 100, 4000 programs each (half wave32, half wave64), 0 mismatch, 0 skipped.--known --programs 500 --seed 1 --wave both: 128 mismatches from the two known forms (the shrunk first one iss_mov_b32 vcc_lo, 0xdeadbeefthen a_co_cicarry-in from VCC; hand probes ofs20/vcc_loread as data give 0xffffffff per lane where the hardware has the wave's bits).--oracle hwon the AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, gfx1036, driver 26.10.1, HIP oracle), wave32 and wave64 natively, known forms included:--programs 500with seeds 1 and 2 (1,000 programs), plus 1,340 programs with an earlier version of the generator (one of them--oracle translator,hw). 0 mismatch between the reference and the hardware on every lane. The NVIDIA RTX 5080 has no part here (CPU tool; the hardware oracle needs AMD).OpLogicalAnd %bool {carry_nz} {self.active_b()}->carry_nzonly,tools/rdna2spirv.pyin the_co_branch) failstest_hand_cases_match_the_translator(lane 1 word 0 (v1): reference 0x00000000, translated 0x00000001) and gives a mismatch in a 400-program run. Reverted.python -I tests/test_wint_diff.py(18 tests, about 3 s) OK,python -m compileall -q tools testsOK,tests/test_docs_links.py,test_docs_repo_paths.py,test_docs_list_items.py,test_tool_startup.py,test_tool_stdout_encoding.pyOK.Checklist
docs/design.md, with how it was confirmed. (No translator change.)AI-assisted.