Repository navigation
Recompiler: a wave64 compute program folds into one 32-lane wave - #3562
Royalflamejlh wants to merge 6 commits into
Conversation
|
Review (head 988b298, diff read, not a merge-check; draft with
Fine: the rewrites of AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
Thanks for the read. On the points:
AI use: Claude Code. Claude Opus 5.5 checked the limit against the code and wrote the two changes; Claude Fable 5.2 ran the tests on the card and wrote this reply. |
|
Re-review (head bda4766, diff read, not a merge-check:
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
No open PR makes the same change. #3543 (throny) was a port of the same fold and was closed by its author on 2026-11-30 because it measured no gain on an RTX 4080. #3561 (same author) is a different approach to the same exchange cost: a lane loop for small programs. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
|
Folding is opt-in now (head
AI use: Claude Code with Claude Fable 5.2 made the change, ran the tests and wrote this. |
On a GPU of 32-lane waves the direct translator ran a wave64 compute program as two halves that exchange masks and lane reads through group-shared counters with a spin wait. A program is now first rewritten into a wave32 program in which each host lane runs console lanes t and t + 32 (gpu/dxil/fold.rs, ported from VIctory-NVIDIA 5fabb46e, GPL-3.0-or-later): VGPR v of the upper lane is VGPR v + N, a mask is two 32-bit ballots in its register pair, and the console's EXEC lives in a spare SGPR pair. One host wave is one console wave, so nothing is exchanged. The entry gives both lanes their thread ids and their EXEC words inside the dispatch's thread limits. What the rewrite does not cover (more than 128 VGPRs, ds_(b)permute, GDS, loads into LDS, scratch, movrel, calls and indirect jumps, vccz / execz / lds_direct operands) keeps the split form, and so does a folded program the wave32 translation refuses. XCL_WAVE64_FOLD=0 turns the form off; the translated cache's identity carries it. Tests run the console's programs in waves of 64 lanes and their folded code in waves of 32 on a small machine on the CPU, for ballots, lane reads and writes, mbcnt, nested saveexec branches, a loop with divergent exits, LDS across a barrier and a carry chain, in six group shapes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gpu_folded_wave64_matches_the_console_wave dispatches the folded DXIL of the five test programs in six group shapes and compares each thread's dwords with the console's waves run on the CPU; gpu_folded_wave64_keeps_the_thread_limits does a dispatch with thread limits that cut both halves. Both need a card with 32-lane waves and have not run on one: the CPU Vulkan driver skips them. wave64_fold_census (ignored, XCL_SAMPLE_RPF) counts a pack's wave64 compute programs that fold and those that do not, by reason. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Folded, the two copies of each repeated memory access are compact blocks of their own, so a folded program's tables can pass the limit its split form's stay under, and it then took the plain form. On a tree with xcl-dev#3516's limit of 12,288 words, a retail wave64 compute program of 78,920 reachable instructions took the compact form split (11,311 table words) and, folded (14,805 words), the plain form: 4,346,408 B of DXIL in one function, which NVIDIA's compiler had not finished after ten minutes at 4.9 GB. The folded translation now refuses a program whose compact form is refused only for the size of its tables (compact::wanted_plan: the automatic choice before its table check), and the split form takes the compact form as it did before folding. Under main's 32,768 words no program of that pack changes: two folded programs want the compact form, with 14,776 and 14,805 table words. Under xcl-dev#3516's 12,288 both do. The test folds a program of 57,344 copies of a load whose split form's tables fit and whose folded tables do not: the folded translation is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The folded form refused a program only when its twins could not be named (2N > 256 VGPRs). A host lane holds both copies, and a thread of an NVIDIA GPU has 255 registers: at 128 VGPRs the folded program names 256. The rewrite needs no VGPR beyond the twins (its scratch registers are spare SGPRs), so the refusal is now 2N > 255, VIctory-NVIDIA's rule (fits_host_regs: 2N + 2, its two temporary VGPRs, within 255) for this rewrite. In a retail pack no distinct wave64 compute program has 120 to 128 VGPRs: the largest that folds has 119, and the three of 129 (the programs VIctory-NVIDIA measured at 2 x 129) were refused before as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XCL_WAVE64_FOLD=1 turns it on. Its GPU time against the split form is not measured, and xcl-dev#3543, a port of the same idea, measured a median 1.27 times the split form's time on an RTX 4080. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
0c6bd4c to
913af19
Compare
|
AI use: Claude Code (Claude Opus 5.5). |
|
Follow-up review (head 913af19, since bda4766, diff read, not a merge-check; checks red):
New:
Not reviewed line by line again because of the size; the 20 lines changed since the last review (the opt-in switch, warm setting, test, docs) are correct. The provenance note and AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
@Foniass thanks for the follow-up. I'd rather keep it as one pull request, and the description now says why, under Why it is one pull request: The other open points stand as you list them: the smoke pair and a Windows run are owed (no Windows machine of ours answered today), the GPU tests compare with the interpreter rather than the split form on the same GPU, and the AI use: Claude Code (Claude Opus 5.5) drafted this reply and the description section. |
On a GPU with 32-lane waves only, a wave64 compute program now runs folded where it can: each host lane carries two console lanes (t and t + 32), so the whole console wave is one host wave and nothing is exchanged between halves. The split form's exchange is what #3114 measures at 2.6x a program's GPU time, and its spin wait ended runs on Linux here in a GPU hang (NVIDIA Xid 109) at the title's world start.
The form is ported from VIctory-NVIDIA (
crates/victory-shader/src/fold.rsat5fabb46e, GPL-3.0-or-later, https://github.com/trustno1-coder/VIctory-NVIDIA), as a rewrite of the console code into a wave32 program before translation. The provenance note is in the file andTHIRD_PARTY.mdhas the entry.Folding is opt-in:
XCL_WAVE64_FOLD=1turns it on, and without it nothing changes. Its GPU time against the split form is not measured here; #3543, a port of the same idea, measured a median 1.27 times the split form's time on an RTX 4080 with a run-to-run spread as large as the difference.What is in it
crates/xcl/src/gpu/dxil/fold.rs(new, 1,157 lines): the rewrite. VGPR v of console lane t + 32 is VGPR v + N of host lane t; a run of vector instructions is written twice, under each half of EXEC; a mask is the two copies' 32-bit ballots;v_readlane,v_writelane,v_readfirstlaneandv_mbcntname the copy that holds the lane. Scalar code is unchanged, since XCL keeps the console's scalar branches.crates/xcl/src/gpu/dxil/fold_tests.rs(new, 713 lines): the tests, with a small RDNA2 interpreter that runs a console program in 64-lane waves and its folded code in 32-lane waves and compares.gpu/dxil/kernel.rs(translate_compute_rodata): the folded form is tried for a split wave64 compute program; any refusal logs one line and the split form runs. It is tried only withXCL_WAVE64_FOLD=1, which is part of the translated cache's identity.ds_bpermute/ds_permute,ds_append/ds_consume, GDS, scratch,s_movrel*/v_movrel*, calls and indirect jumps, EXEC or VCC as a memory operand, fewer than seven spare SGPRs, and a few rarer forms.gpu/dxil/kernel.rs,compact.rs: a folded program whose compact plan is refused only for its table's size is not folded. On that other tree (compact table limit 12,288 words) two programs of about 122,000 instructions lost their compact form by folding and became 4.3 MB of DXIL each, which NVIDIA's compiler did not finish in ten minutes; withmain's 32,768 words both still fit, so onmainthis changes no program of that pack.fold.rs: a program folds only when its VGPRs and their twins fit 255 registers (2N <= 255); the rewrite uses no VGPR beyond the twins.docs/wave64-on-wave32.md: a section on the form.Why it is one pull request. 2,016 changed lines in six commits, over the ~800 the contributing guide asks a reason for. Of them, 1,158 are
fold.rsand 741 its tests; the rest (117 lines) are the wiring behindXCL_WAVE64_FOLD=1, the compact-limit check, the warm setting, the docs and the provenance entry.fold.rsis one rewrite pass over the instruction set: every instruction it accepts is rewritten in the same loop, against the same register plan and the same EXEC handling, so a part of it (say, the lane primitives without the driver) would be code nothing calls and nothing can test on its own: the tests run whole console programs through the interpreter and the folded form.fold.rsnot yet called / turning it on / the census would give three PRs whose diffs are each under 150 lines and one of ~1,900 that is this one: the review offold.rswould be the same review.XCL_WAVE64_FOLD=1is set: with the switch off the translation and the caches are as onmain.The commits are kept apart so each part can be read on its own: the rewrite (
ec2eff44a), its GPU tests and the pack count (aebe29efe), the docs (e1a954aab), the compact-limit check (74ba777fa), the register limit (e5558b14a) and the opt-in switch (913af192c).Tested
x86_64-pc-windows-gnu, release. Head913af192c(XCL_WAVE64_FOLDis also a warm pipeline library setting since; the fold andshaders::tests there, under Wine on the CPU: 122 passed, 0 failed, 1 ignored. Earlier head0c6bd4c0: the form made opt-in; the tests switch it on themselves).cargo test -p xcl --release --lib gpu::dxil -- --test-threads=2: 315 passed, 1 failed, 4 ignored. SKIPPED:dispatch_chain_native_wave64_builds_whole(no wave64). The failure isround_tests::directed_reference_basics, which fails the same way onmain.gpu_folded_wave64_matches_the_console_wave(five programs: masks and lane reads; nested saveexec branches; LDS across a barrier; a loop with divergent exits; a carry chain with lane writes andv_cmpx; in groups of 64, 128, 8x8, 8x8x4, 40 and 16x6 threads, against a small RDNA2 interpreter of the console wave) andgpu_folded_wave64_keeps_the_thread_limitspassed.the_folded_form_is_taken_for_a_split_program_and_has_no_exchange: the folded DXIL validates and has no atomic, compare-exchange or group-shared storage.XCL_GPU_PROFILE=1, which makes a queue run its draws and dispatches one after the other; on a later head of that tree the title lost its device at the world start without the switch (2 of 2 runs, with folding on and with it off) and ran 600 s with it (1 of 1), so the run says nothing about this change with the GPU's work overlapping. In a cold launch pass of that tree, of the 1,151 wave64 compute programs it translated, 732 folded, 351 ran as lone halves (another unmerged change) and 68 stayed split. Translated offline, folded DXIL was 1.11 times the split form's at the median and 1.73 times at the 95th percentile.Regression run
RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
SV_GroupIndexvalues, as the existing wave32 path does.v_div_fmas, MIMG/NSA and buffer instructions are ported but no test program uses them. The reference interpreter is this PR's own.AI use
6cec7afd) and the VGPR limit (bda4766f).