Skip to content

tools/vrel_diff.py: whole-wave fuzzer for the relative VGPR moves; v_movreld_b32 takes any VOP1 source - #5168

Open
TreXito wants to merge 2 commits into
ItsNotRexed:mainfrom
TreXito:fuzz/vrel-diff
Open

TreXito wants to merge 2 commits into
ItsNotRexed:mainfrom
TreXito:fuzz/vrel-diff

Conversation

@TreXito

@TreXito TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claim: #5032 (comment)

What and why

No fuzzer generates the M0-relative VGPR moves (v_movrels_b32, v_movreld_b32, v_movrelsd_b32, v_movrelsd_2_b32, v_swaprel_b32) or v_swap_b32. The semantic tests check chosen words, one op at a time.

Translator fix. rdna2spirv raised Unsupported: v_movreld_b32 operands for any source but a VGPR. Only movreld's destination is indexed, so its source is any VOP1 source:

  • LLVM's VOP_MOVRELD takes VSrc_b32. The other three relative forms take VRegSrc_32.
  • llvm-mc 21.1.8 (-mcpu=gfx1030) assembles v_movreld_b32 v1, X with X = v2, s4, m0, 7, -3, 1.0, 0x12345678, vcc_lo or exec_lo, and v_movreld_b32_e64 with s4 and v2.
  • It rejects an SGPR source on movrels, movrelsd, movrelsd_2, swaprel and swap.

The fix reads the source through src_u, as other VOP1 ops do; a VGPR source loads as before. On main, 23 of 100 programs of --seed 1 are skipped for this.

tools/vrel_diff.py (new). It runs seeded straight-line programs through rdna2spirv and spirv_wave_interp (one subgroup, every lane at once). It compares all 32 VGPRs of the window v0..v31 in every lane, bit for bit, through eight exports. The reference is a per-lane model of the RDNA2 ISA descriptions and shares no code with the translator:

  • v_movrels_b32 D = V[S0 + M0], v_movreld_b32 V[D + M0] = S0, v_movrelsd_b32 V[D + M0] = V[S0 + M0].
  • v_movrelsd_2_b32 V[D + M0[25:16]] = V[S0 + M0[9:0]]. v_swaprel_b32 swaps those two registers, both read before either is written. The other M0 bits are ignored.
  • An inactive lane keeps every VGPR.

Generated

  • M0 from s_mov_b32 (a constant or an SGPR) and s_add_u32 m0, m0, K.
  • Under the two-field forms: random bits in M0[15:10] and M0[31:26], and both fields sometimes naming one register.
  • EXEC from edge masks and random words, exec_hi in wave64.
  • e32 forms, and e64 for movrels and movreld.
  • movreld sources: VGPR, SGPR, M0, integer and float inline constants (1/(2 pi) too), literals.
  • Plain VGPR moves, adds and xors in between, so static and relative accesses mix.

Not generated

Tested

Run Result
Seeds 912001 to 912008, --programs 2000 --max-ops 12 --wave both 16,000 of 16,000 match, 0 skipped, exit 0 each
Each op alone, --ops <op> --programs 1000 --wave both --seed 77 6 × 1,000 match
--programs 300 --seed 1 --wave both 300 of 300 match
Same tool on main 3faac55 (no fix), --programs 100 --seed 1 77 match, 23 skipped (v_movreld_b32 operands), exit 1
This branch applied to #2935 and to #4518 (register caching on), --programs 150 --seed 3 --wave both clean apply, 150 of 150 match on each
--self-test 23 checks ok, the ISA's own v_movrelsd_2_b32 example among them
python -I tests/test_vrel_diff.py 19 tests OK
tests/semantic/test_alu_movrel.py, test_alu_movrelsd_2.py, test_alu_swaprel.py, test_salu_movrels*.py, test_wave64_*, tests/test_spirv_opt.py, tests/test_lane_masks.py OK
The 10 tests/test_docs_*.py, tests/test_text_write_line_endings.py OK

The eight seeds generated about 10,300 to 10,800 of each op, 6,245 e64 forms, 5,735 two-field moves with ignored M0 bits set, 3,404 with one register on both sides and 19,512 moves under a partial EXEC. movreld sources: 3,673 VGPR, 2,140 SGPR, 523 M0, 1,578 inline integer, 1,057 inline float, 1,601 literal.

Mutations of the translator's lowerings (--programs 100 --seed 1 --wave both; every mutant exits 1, the unmutated translator exits 0):

Mutation Result
A: movrelsd_2 source field keeps M0[15:10] 14 skipped
B: movrelsd_2 destination field from M0 >> 17 13 mismatch, 7 skipped
C: swaprel writes inactive lanes 7 mismatch
D: swaprel source field keeps M0[13:10] 12 skipped
E: movreld/movrelsd write inactive lanes 15 mismatch
F: indexed read ignores M0 51 mismatch
G: indexed write ignores M0 45 mismatch
H: v_swap_b32 second write reads the first's result 39 mismatch
I: movreld source read as the VGPR of its number 25 mismatch
J: swaprel stores D's slot only 36 mismatch

A and D show as skips: any ignored bit that leaks adds 1,024 or more to the index, past the interpreter's 256-entry VGPR array, and a skip exits 1.

Setup: CPU only, no GPU needed.

  • Linux 7.0 with Python 3.14.4, and the long runs on Linux 6.18 with Python 3.13.5.
  • On main 3faac55.

Docs: a subsection in docs/shader_validation.md, before "Images on the GPU". The docs/design.md "Relative VGPR moves" row is left alone, because #2266 and #2935 rewrite it. Its text already says the source is S0.

No game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

…movreld_b32 takes any VOP1 source

No fuzzer generated v_movrels_b32, v_movreld_b32, v_movrelsd_b32, v_movrelsd_2_b32,
v_swaprel_b32 or v_swap_b32. vrel_diff runs seeded straight-line programs of them, with M0
and EXEC rewritten between them, through rdna2spirv and spirv_wave_interp and compares all 32
VGPRs of the window in every lane with a per-lane model of the RDNA2 ISA descriptions.

rdna2spirv raised Unsupported for v_movreld_b32 with an SGPR, M0, inline constant or literal
source. Only the destination is indexed, so the source is any VOP1 source (LLVM's
VOP_MOVRELD takes VSrc_b32; llvm-mc 21.1.8 accepts s4, m0, 7, -3, 1.0, a literal, e32 and e64).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 56af50d2d on Windows 11: pytest tests/test_vrel_diff.py -q -> 19 passed, 8 subtests passed; git diff --check clean.

The new tools/vrel_diff.py fuzzes the whole-wave relative VGPR moves (v_movreld_b32, v_movrels_b32, v_movrelsd_b32 and their _2 forms) against the reference model, and the translator change lets v_movreld_b32 take any VOP1 source instead of refusing the non-VGPR ones. The 214-line test covers the op table, the accepted source forms and the moved-lane results. I cannot run the hardware oracle here. No blocking issue.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At 56af50d, a negative program count makes the new differential test report success without testing a program. A CI job that uses the exit status can record a false pass.

Run on Windows 11 with CPython 3.14.7:

py -3.14 -I tools/vrel_diff.py --programs -1 --seed 1 --wave both
$LASTEXITCODE

Actual: 0/0 programs match, 0 mismatch, 0 skipped. Exit status is 0. Zero programs gives the same result. Expected: reject a negative count with an argument error. For a required test run, reject zero too. A positive run with --max-ops 0 also needs an argument check: it currently raises an uncaught ValueError from randint.

With valid arguments, all 19 unit tests pass. With --programs 12 --seed 1 --wave both, the head matches all 12 programs. With the same tool on merge base 3faac55, the translator rejects three programs with literal movreld sources and the tool exits 1.

AI-assisted.

@TurboSosiska304

Copy link
Copy Markdown

Checked 56af50d on Linux / Python 3.14.10 (CPU tool, no GPU needed):

  • python3 -m pytest -q tests/test_vrel_diff.py -> 19 passed, 8 subtests passed;
  • --self-test -> all canaries ok;
  • --programs 500 --seed 20261123 -> 500/500 match, 0 mismatch, 0 skipped (wave 32);
  • --programs 300 --seed 7 --max-ops 10 --wave 64 -> 300/300 match, 0 mismatch, 0 skipped (wave 64);
  • negative control with main's tools/rdna2spirv.py: test_vrel_diff.py -> 4 failed, 17 passed (canaries + short seeded run), and the fuzzer reports 26 skipped: translator unsupported: v_movreld_b32 operands.

Coverage of the specific change is visible in the run: v_movreld_b32 sources hit inline float (19), inline integer (35), literal (31), m0 (12), sgpr (50) and vgpr (76) in the 500-program run, so the "any VOP1 source" rule is exercised rather than assumed.

A negative or zero --programs reported success without testing a program, and
--max-ops 0 raised a ValueError from randint. Both now exit 2 with an argument
error, as vint_diff and wint_diff do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in e6730c6a. main() now rejects --programs and --max-ops below 1 with ap.error (exit 2), the same check vint_diff and wint_diff use.

Command Before (56af50d2) Now
--programs -1 exit 0, 0/0 programs match exit 2, --programs and --max-ops must be at least 1
--programs 0 exit 0, nothing tested exit 2
--max-ops 0 uncaught ValueError from randint exit 2

Cli.test_exit_codes now covers --programs -1, --programs 0, --max-ops 0 and --max-ops -3. python3 -B -m unittest tests.test_vrel_diff: 19 tests OK.

Environment: Linux 7.0, Python 3.14.4, CPU only. AI-assisted (Claude Code).

@davidesidoti

Copy link
Copy Markdown
Contributor

Tested 56af50d2 merged onto main 3faac557 (clean merge) on AMD Radeon RX 9070 XT (RDNA4), Adrenalin 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11 build 26300, llvm-mc 21.1.8: pass. This adds a GPU run of the translator fix, which the description checks on the CPU only.

  • The fix on the GPU. I wrote a compute shader by hand (wave32), translated it and ran it through vk_compute_test with VKC_DUMP. It uses v_movreld_b32 with each new source kind: an SGPR, m0, the inline integer -3, the inline float 1.0, the literal 0x89abcdef, _e64 with the inline 1/(2π) constant, and two writes under exec_lo = 0xfffffffe. Lanes 0 to 7 store v10..v17.
    • On main the shader is refused with Unsupported: v_movreld_b32 operands.
    • With this PR it translates, passes spirv-val, and all 8 lanes give the expected words: 0x12345678 1 0xfffffffd 0x3f800000 0x89abcdef 0x3e22f983. The last two words are kept as seeded in lane 0 and written in lanes 1 to 7.
  • tools/vrel_diff.py --programs 2000 --seed 5168 --wave both (a seed not in the description): 2000/2000 programs match, 0 mismatched, 0 skipped. That covers 169 SGPR, 58 M0, 149 inline integer, 91 inline float and 117 literal movreld sources, plus 1157 partial-EXEC cases.
  • python -I tests/test_vrel_diff.py: 19 tests OK.
  • scripts/run_gpu_tests.py: 221/221 translated and spirv-val valid, 202/217 passed, 15 skipped, the same outcome per test as main.
  • python -m unittest discover -s tests/semantic: 6245 tests. The only failures are the five test_loop_ballot_barrier.py subtests that fail identically on main 3faac557 (the Wave64 loop/barrier finding in the coordination issue).

Not covered: the GPU run is wave32 only, and no wave64 GPU run.

No game files. (AI-assisted test run.)

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested e6730c6a (on top of main 3faac557) on Apple M4, macOS (arm64), Python 3.15.2: pass. This is the first arm64 run.

  • Unit tests: tests/test_vrel_diff.py 19 OK; --self-test all ok.
  • New seeds: --programs 1000 --max-ops 12 --wave both with --seed 4242 and with --seed 5150 each give 1000/1000 match, 0 mismatch, 0 skipped (35–39 s).
  • Against main's translator: the tool with --programs 100 --seed 1 gives 77 match, 23 skipped, exit 1, as the description reports.
  • GPU suite (MoltenVK 1.4.2) with this translator: 152/217 passed, 58 skipped, every test identical to main on the same machine.

AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested e6730c6 on Windows Server 2022, CPython 3.13.12, CPU-only: pass

  • python -I tests/test_vrel_diff.py: 19/19 OK
  • Negative control: fails on main (new tool absent; 4 subtests fail/error)
  • git diff --check clean; python -m compileall -q on changed Python files: exit 0

No game files, no GPU. AI-assisted (Devin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants