Repository navigation
Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (#336) - #517
Conversation
…ll#336) Preparation for classifying wave64 VS / PS by whether their result depends on how a 32-lane GPU cuts their waves: that needs to know which blocks run because of a wave-wide vote. No behaviour change: nothing calls it yet. cfg::Cfg builds a program's basic blocks from upper_lanes::successors (now shared), and gives each block's immediate post-dominator (Cooper, Harvey and Kennedy's iteration on the reversed graph, with one exit after every block that ends the program) and the branches it is control-dependent on (Ferrante, Ottenstein and Warren). A program with an indirect jump has no graph; a block from which no path ends the program has no post-dominator. Measured over all 26 698 programs of a retail shader pack (release, one thread): no panic, 195 with an indirect jump, at most 15 995 blocks in one program, at most 15 ms for one program's graph, post-dominators and control dependence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed), rustc 1.100.0 MSVC, debug, Pass: 702 passed, 0 failed, 41 ignored. SKIPPED: only the 2 No behaviour change to check on the GPU yet, since nothing translates by the tier. Once a part of #336 acts on Run and written with Claude Code (Claude Opus 5.5). |
|
Thanks for this. The structure (a forward pass over the #341 blocks, with reasons per sink) reads well, and the fixed point is fine: taint only grows, flags only fall, and a tainted VCC / SCC / EXEC reaches its branch, also across a back edge. Your 10 The problem is in the direction that matters for NVIDIA: I found programs that get 1. With only lane 32 passing, the wave exports s5 everywhere, while the upper half exports s6. The same holds for 2. Image loads (:135, :287). 3. A scalar written behind an exempted vote is A loop's trip count read after the loop behaves the same way. 4. The vote exemptions check less than they assume (:266, :297-304, :329-340, :429).
5. A vote read as data is not tainted (:295-305, :170-172, :279). Your 6. Register uses (:133-158, :256, :278).
Separately, 7. Precision. An all-discarded early-out inside an 8. Small things. The 29 counter-examples (all failing on Reviewed on an RTX 4070 SUPER machine (CPU unit tests only for this PR). Points 1, 5 and the counter-example runs were checked by hand against the code before posting. |
|
Thank you – this is exactly the review this needed, and you're right on every point I've checked so far; an What I'll do on this PR:
AI use: Claude Code with Claude Opus 5.5 wrote this reply. |
|
NVIDIA test report for ed04b05 (this PR's head, stack included). Tested
Not tested
AI use
|
|
A second machine ran the census with the PR's own code, unmodified and without writing a Machine: Windows 11 Pro 26300, Ryzen 7 9700X (8C/16T), Rust 1.98.0 How: a throwaway
13 034 distinct programs, 9 255 distinct Exact (71.0 %). Every program decoded and every The distinct-program numbers and the reason counts match yours exactly – Two numbers the PR body does not have, which change how much the cut matters:
Suite: the branch head is three commits behind Not tested (same as you): whether a MayDiffer program actually differs on a 32-lane No game data in this comment – only counts printed by the tool. AI use: written with Cline; the runs are from my machine. |
29 programs partition::classify reports as Exact although a 32-lane cut changes what they export, plus 7 passing checks (fixed point, the PR's own Exact programs under 5 000 random cuts, precision cases, timing). Each unsound case is run by a small reference interpreter (run / cut / must_differ, ~30 instructions, DPP as in emit.rs) as one 64-lane wave and as two 32-lane halves, then asserted not Exact. a5, a6, both d2 and g are classifier-only, argued from the operand tables. On ed04b05: 22 passed, 29 failed (the counter-examples), by design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
|
Glad it helps. The tests and the interpreter are one commit on top of
Everything is in AI-assisted (Claude Code, Claude Opus 5.5). |
ed04b05 to
ad4add0
Compare
|
Updated to ad4add0 (one commit on #341; #528 folded in and closed). Each of your points as I handled it:
Your snippets are tests (some tightened: the exec_hi one now has no divergent compare after it, so it only passes for the right reason); all 31 tests pass, suite 714 / 0 / 41. Over the pack: 7 208 Exact (was 9 424 before, which included wrong ones). 7 (precision: early-out inside an if, spill slots) is next, once the soundness side is settled – your patch with the 29 cases would let me check every one of them too. AI use: Claude Code with Claude Opus 5.5 made the changes, ran the tests and wrote this reply. |
|
Ran all 29 counter-examples against
Separately, P3 lost precision: the plain Your 31 tests and the Branch with the module on top of AI-assisted (Claude Code, Claude Opus 5.5). |
ad4add0 to
c5e0ded
Compare
|
Thanks. Updated to c5e0ded (still one commit on #341). All three are fixed, and P3 is back to
All four are tests in the PR now, so it has 35 tests. Your module on c5e0ded: 35 of its 36 tests pass. The one that fails, Cost over the same shader pack: 6 043 |
|
Confirmed on No further soundness findings from our side. The AI-assisted (Claude Code, Claude Opus 5.5). |
|
Five more ways In all of them
Possible fixes: A, skip only when I can post the tests as a branch or a patch if you want them. Tested: Not tested: whether any retail program has these shapes (B to E look unusual for compiler output); nothing ran on a GPU. AI use: Claude Code (Claude Opus 5.5) found the cases and wrote the tests and this comment; Codex (GPT-6.2 Astra) reviewed them by reading the code, without running anything. |
c5e0ded to
223065f
Compare
|
Thanks, all five confirmed and fixed in 223065f. A to D come from the same flaw: the side's "saved" masks were an unordered set. So I replaced the set with an ordered data flow rather than patching each case.
Each case is a test now (five tests, 40 in all), with the exact variants you gave as Over the same shader pack: 6 121 No need for the branch, thanks; the description of each case was enough to write the tests. |
|
Three more programs that A. A vote on VCC whose taken side narrows EXEC and never restores it ( B. A write under the launch mask, then C. A number combined into a mask ( All three classify outputs, with the scratch test's input programs: Nothing calls AI-assisted (Claude Code), read-only review plus one scratch test run of |
…them Part of xcl-dev#336. A GPU that runs a console wave64 VS / PS in 32-lane waves runs each half of the console wave on its own. upper_lanes follows what lanes >= 32 hold when they are read; this follows the other ways the cut shows: wave-wide votes are taken per half, and lane counts, ranks, first-lane indices, masks used as numbers and other lanes' values differ in a half. Classification only: nothing translates by it yet. partition::classify runs a forward data-flow pass over the program's blocks (cfg) with taint bits per register and reports Exact / MayDiffer with the reasons: - a tainted value reaching an export, a store (LDS / GDS ones included), a branch or EXEC; one word of EXEC or a number written to EXEC; - a vote (vccz/vccnz, execz/execnz, scc on a mask) unless the side taken with the mask empty is the join or ends the program writing nothing, and the other side starts by narrowing EXEC to the mask (for a mask other than EXEC) and does not widen it again before the join (a restore of a mask saved inside, an if/else flip, a restore right before the join are fine) – or the mask is all or none of the active lanes; - a scalar written in the blocks a vote decides and read after the join (a half that took the other side never wrote it). Values every lane has are followed (written under the launch EXEC by plain VALU ops of such values, through all-or-none selectors, or loaded at such addresses), so reading one from the first lane is exact. Register uses come from x64_masks::uses (read-modify-write destinations, SDWA scalar sources, SMEM offsets, src_vccz / src_execz) plus src_scc, NSA addresses and image loads by their DMASK (upper_lanes::vgpr_writes, now shared). Tests include the review's counter-examples (values written under a narrowed EXEC or selected per lane, a vote read as a number, mask words moved, read-modify-write taint, a side that widens EXEC again, an SCC vote whose mask is rewritten, EXEC's high word, image DMASK, DS writes) and one for every reason. Over the 13 210 wave64 VS / PS of a retail shader pack (local run): 7 208 Exact (5 118 of 10 974 PS, 2 090 of 2 236 VS), at most 159 ms a program. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, all three hold, and all are fixed in dfc5578:
Each is a test (three tests, 43 in all). All three fail on 223065f and pass on dfc5578. QemmHD's module gives the same result as before: 35 of 36, with only Same shader pack: 6 057 |
223065f to
dfc5578
Compare
|
Independent AMD RDNA2 (native wave64) test report on exact head Tested
Not tested
AI use
|
|
NVIDIA report on the exact head Tested
Not tested: whether a Run and written with Claude Code (Claude Opus 5.5). |
…cl-dev#336) The partition classifier accepted a mask vote only if the side the wave runs starts with an instruction that narrows EXEC by the vote's mask. The console compiler's pixel-shader discard early-out narrows it one step later: `s_wqm_b64 s, live; s_and_b64 exec, exec, s`, often with scalar loads in between. Such votes were reported as `vote-branch`. The side now only has to turn EXEC off, in a half whose mask is empty, before its first lane instruction. The zero flow of the vote's side checks it: wqm(0) and x & 0 are zero there. Before that only scalar ALU ops, scalar loads, s_waitcnt and s_nop are allowed; their writes are the wave's and are followed as stale where the sides join. s_setreg, s_sendmsg, PC writes and any lane instruction end the search. Every shape the old first-instruction check accepted passes the new one. Over the 13 210 wave64 VS / PS of a retail shader pack: 7 015 Exact instead of 6 057 (PS 4 912 of 10 974, from 3 954), `vote-branch` 5 186 programs instead of 6 375. A reference interpreter of a 64-lane wave and its two 32-lane halves (from the review of xcl-dev#517) shows no difference for the new exact form over 5 000 random cuts, and differs for an export placed before the narrowing, which stays `vote-branch`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stacked on #341; only the top commit (dfc5578) belongs here. Part of #336. Reworked after the reviews below (QemmHD, CuteBooty, upipibi); #528 (stale scalars) is folded in.
A GPU that runs a console wave64 VS / PS in 32-lane waves runs each half of the console wave on its own.
upper_lanes(#133) follows what lanes ≥ 32 hold when they are read; this classifies the other ways the cut shows: wave-wide votes are taken per half, and lane counts, ranks, first-lane indices, masks used as numbers and other lanes' values differ in a half. Classification only – nothing translates by it yet, so there is no behaviour change.What is in it
gpu/recomp/partition.rs(new),partition::classify: a forward data-flow pass over the program's blocks (cfg, Recompiler: basic blocks, post-dominators and control dependence (#336) #341) with taint bits per register, run twice (the second with stale scalars), reportingTier::Exact/Tier::MayDifferand the reasons:lane-count,rank,first-lane,lane-id,mask-data,cross-lane,tainted-exec); DPP16 row / bank masks andv_writelanearelane-id,row_bcastiscross-lane, a number combined with a mask ismask-data;vccz/vccnz,execz/execnz,sccon a mask) unless the side taken with the mask empty is the join or ends the program writing nothing, the other side starts by narrowing EXEC to the mask (for a mask other than EXEC) and does not widen it again before the join (a forward flow of the registers that are zero in a half that skipped the side, and of those that hold the EXEC it had at the vote: EXEC may be written only from the first, and must reach the join as the second) – or the mask is all or none of the active lanes (under a narrowed EXEC only if neither side widens EXEC before the join) (vote-branch,unsafe-execz-branch);stale-scalar); masks that only accumulate behind the vote (s_andn2_b64/s_or_b64of themselves with a mask zero in that half) are not stale.x64_masks::uses(read-modify-write destinations, SDWA scalar sources, SMEM offsets,src_vccz/src_execz) plussrc_scc, NSA addresses, and image loads by their DMASK (upper_lanes::vgpr_writes, nowpub(super)).Exactand exported something else when cut), one per reason, and the exact cases (if that narrows EXEC, uniform votes, the discard early-out, a load at a uniform address, nested restores).Not yet (the next parts of #336): exact idioms (waterfall loops, spill slots, wave-aggregated atomics). Unknown counts as
MayDiffer.Size: 860 lines of code and 572 of tests. The review showed that leaving the stale-scalar rule to a later PR makes this one report
Exactfor programs that differ, so it is in here; what is left (idioms) only turnsMayDifferintoExactand comes separately.Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug for the suite, release for the runs.cargo test --workspace -- --test-threads=4at dfc5578: 726 passed, 0 failed, 41 ignored; noSKIPPEDlines.vote-branch6 375,cross-lane3 824,unsafe-execz-branch2 858,tainted-exec2 966,stale-scalar1 418,mask-data815,lane-count432,lane-id420,first-lane353. (Before the first review: 9 424 Exact; at ad4add0: 7 208; at c5e0ded: 6 043; at 223065f: 6 121; some of each wrong.)Regression run
Nothing in the runtime calls the new code, so this only shows the build is unchanged in use. The
gpu:line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log namesbackend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM).main:
PR:
Not tested
MayDifferprograms actually differ on a 32-lane GPU (no 64-lane reference on the GPU yet; the review's interpreter checked the counter-examples).AI use
🤖 Generated with Claude Code