Repository navigation
tools: sad_diff.py, a differential fuzzer for the SAD family - #2749
Merged
Merged
Conversation
Seven opcodes (v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32, v_msad_u8, v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8) against an ISA-written reference and the translated SPIR-V in spirv_mini_interp, four exported words, bit for bit. A 785-program sweep covers every source-kind combination (the 64-bit constant rule pinned both ways), random seeded programs widen the values. 12,810 programs across six seeds match with zero mismatches and zero skips; two translator mutations make 36/60 and 17/60 programs fail. clamp, op_sel/neg/abs, v_mqsad_u32_u8 (ItsNotRexed#1926/ItsNotRexed#2163) and null as a 64-bit quad source (ItsNotRexed#2650) are out of scope, on purpose.
Contributor
|
Tested on Linux (WSL2 Ubuntu, Python 3.10.12) and native Windows 11 (Python 3.13.1), CPU only: pass. Head e64bebf, clean merge with main.
|
Contributor
|
Tested
AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: new FUZZ item — SAD-family differential fuzzer (claim)
What and why
The SAD family —
v_sad_u8,v_sad_hi_u8,v_sad_u16,v_sad_u32,v_msad_u8,v_qsad_pk_u16_u8,v_mqsad_pk_u16_u8— has no differential fuzzer:cpu_ref.pydoes not implement the ops, and the open fuzz PRs (#2113 sdwa_diff, #2371 vint_diff, #2336 wint_diff) name none of them; the merged translator rules (#544, #623) carry small hand counts and a 300-case run in their PR text only.tools/sad_diff.py(claimed as a new FUZZ item) makes that check permanent, in the style oftools/salu_diff.pyandtools/mem_diff.py(stdlib only,python -I,--programs/--seed/--max-ops/--ops/--list-ops/--self-test, skips counted with reasons, exit 0/1/2):docs/design.md's contract rows (the "Sum of absolute differences" row hardware-verified on gfx1035 through SHADER-137'sint_hw_proberun; thev_qsadrow bit-exact on an RTX 3060 in Translator: v_qsad_pk_u16_u8 and v_mqsad_pk_u16_u8 #623), compared with the translation run intests/semantic/spirv_mini_interp.py— the four exported mrt0 words, bit for bit (integer ops only, so a mismatch is never a rounding convention).clamp(the contract rows say the translator rejects it; pinned as expected rejections in--self-test),op_sel/neg/abs(the ISA does not define them for these opcodes),v_mqsad_u32_u8(open PRs Tests: GPU coverage for v_mqsad_u32_u8 and the floor/+0.5 float conversions #1926/test(semantic): add interpreter tests for quad-byte sum of absolute differences v_mqsad_u32 #2163 are on that op) andnullas a 64-bit quad source (shader: accept zero-source null operands in quad-byte SAD #2650's subject).tests/test_sad_diff.py(11 tests, about 2 s): hand-worked reference words (per-op SAD sums, the quad sliding windows, the wrap cases, the 64-bit constant rule, dst overlap), generator determinism and dst confinement, the sweep covering the whole kind space (125 + 80), a short seeded run and a canary (a faked wrong translation word is reported).docs/shader_validation.mdgets a section next tomem_diff's with the coverage numbers and a mutation check.No translator bug surfaced: every program matches, so there is no rule to add and
docs/design.mdis unchanged.Tested
Windows 11, Python 3.11.9, CPU only (no GPU, no game files anywhere in the tool or this PR).
python -m compileall -q make_game.py tools tests: OK.python -m unittest discover -s tests/semantic -v: Ran 2567 tests, OK (skipped=3), unchanged from base.python -I tests/test_sad_diff.py: Ran 11 tests, OK.python -I tests/test_text_write_line_endings.py: Ran 2 tests, OK.python -I tests/test_docs_links.py: Ran 5 tests, OK.python -I tools/sad_diff.py --programs 2000 --seed 7: sweep 785/785 + random 2000/2000 match, 0 mismatch, 0 skips, 7 of 7 ops (about 1,050 to 1,175 cases per op).--programs 1500), 11, 12 (--max-ops 12 --programs 800) and 7: 12,810 programs, 0 mismatches, 0 skips.tools/rdna2spirv.pyrun throughLEONIDA_TOOLS_DIR,--programs 60 --seed 2 --max-ops 5 --no-sweep): the per-byteUMax/UMinpair replaced by a wrapped subtraction makes 36 of 60 programs mismatch; thev_sad_hi_u8<<16dropped makes 17 of 60. Both reverted; the shipped translator is untouched.Checklist
docs/design.md, with how it was confirmed. (No translator change.)AI-assisted (Qoder agent).