Recompiler: a lane loop form for small split wave64 compute programs #3561
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3561"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T05:57:46Z.
(Edited: head
cab682f3e, rebased ontomain5ad98adbc, after three rounds of review: the lane loop now has the split form's per-dispatch loop caps (kernel::loop_head, shared), gives each console wave a hardware wave of its own, taken by arrival at the entry (a group of one wave stays one thread, for itss_barrier), and refuses a program larger than a dispatch piece; a test for each. Before: rebased ontomain38ad22da, after #3655; head4a6534767. The change itself: the lane loop now fills theexchange_sitesfield #3655 added toKernel(the form exchanges nothing, so 0), and its cache tag sits beside #3655'sXCL_WAVE64_IDIOMS=0tag.)A third form for wave64 compute programs on a GPU with 32-lane waves only: one host thread runs a whole console wave, all 64 lanes, in a loop. Nothing is exchanged and nothing waits, so it cannot spin. It is meant as the exact fallback for small programs that the split form runs badly: on Linux (RTX 4060 Ti) a split program of 64 threads a group stayed 16 s in one dispatch at the title's world start and the run ended in a GPU hang; #3114 measures the same exchange at 2.6x a program's GPU time.
The form is opt-in (
XCL_WAVE64_LANE_LOOP=1): without the switch nothing changes. Tests on other cards (Windows, AMD, other NVIDIA) are wanted. It has not run in a title from this branch.What is in it
crates/xcl/src/gpu/dxil/lane_loop.rs(new, about 430 lines of code and 200 of tests): the form. A vector instruction is a 64-pass loop around the existing per-lane lowering with the lane's EXEC bit as the guard; each VGPR is a 64-dword array; a mask is built lane by lane; lane reads (v_readlane,v_readfirstlane, DPP, swizzle, permlane,ds_bpermute) read the array. numthreads becomes[ceil(N/64) * 64, 1, 1]: at the entry the first lane of each hardware wave takes the next console wave from a count in the LDS (two group syncs) and the others return, so each console wave is a hardware wave of its own however the driver packs threads; a group of one wave is[1, 1, 1]. Loops have the split form's caps (kernel::loop_head,loop_passesover the console group's threads).XCL_X_LDS_ORDERdoes not affect it; withXCL_WAVE64_LANE_LOOPset it also takes the single-wave LDS programs thatXCL_X_LDS_ORDER=0sends to the HLSL path onmain.s_barrierin a group of more than one console wave,v_movrel*, scratch memory, image stores and atomics, a lane read of a computed value, a program larger than a dispatch piece (dispatch_piece_limit, which the split form cuts into a chain), and any instruction that touches per-lane state it does not track.gpu/recomp/pso.rs(direct_compute): one call,lane_loop::choose, before the split translation.lanes.rs: two early returns (ballot,rla).kernel.rs: the cache tag, and the loop head taken out intoloop_head.module/split.rs:Module::dispatch_cost, the sumsplit_computealready weighed.XCL_WAVE64_LANE_LOOP=1split programs of at most 512 code dwords (lane_loop::MAX_WORDS) take it, with=allevery program the form supports. The 512 is a first guess, and GPU time against the split form is not measured, which is why it is opt-in. The switch is part of the translated cache's identity.docs/wave64-on-wave32.md: a section on the form.817 added lines and 43 removed, 709 of them the new file with its tests; the form is not useful in smaller parts.
Tested
x86_64-pc-windows-gnu, release. Headc15bcb172. (Edited: the earlier head659efb76did not carry the opt-in its commit describes: the edits were left uncommitted, so659efb76ran the form by default on programs of at most 512 code dwords.c15bcb172has them, andXCL_WAVE64_LANE_LOOPis a warm pipeline library setting; the lane-loop andshaders::tests there, under Wine on the CPU: 103 passed, 0 failed.)cargo test -p xcl --release --lib -- gpu::dxil --test-threads=4: 311 passed, 1 failed, 3 ignored. SKIPPED:dispatch_chain_native_wave64_builds_whole(no wave64). The failure isround_tests::directed_reference_basics("Invalid bitcode signature"), which fails the same way here on a tree without this change; not rerun onmainalone.gpu_lane_loop_gives_the_console_waves_values(groups of 48, 64, 96, 256 and 8x8x4 threads; ballot, readlane, readfirstlane, mbcnt, a saveexec loop, LDS write then read; against the console's values and the split form's),gpu_lane_loop_reads_other_lanes_before_any_is_written,gpu_lane_loop_leaves_out_the_lanes_past_a_thread_limit.Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:11:50Z.
Review (head
1216e709, diff read, not a merge-check: thePR descriptioncheck fails, so not built or run here yet):lane_loop.rs~24, taken first atpso.rs~1327). It runs one host thread per console wave (a 64-thread group becomes[1,1,1]), loops 64 lanes per vector instruction and keeps 256 bytes of local memory per VGPR (~236, ~299). GPU time against the split form isn't measured, nothing ran in a title, and the 512 limit is a first guess; opt-in (XCL_WAVE64_LANE_LOOP=1) until a measurement shows a gain would be safer.kernel.rs~324), and lane-loop programs never get a dispatch chain (dispatch_chain: None, ~174).compact_nest_tag, and for small programs bypasses the split path #3504 extends.PR descriptionfails), the whole suite and native Windows are missing.Fine: the
ballot/rlahooks cover the lowering's lane reads (the remaining direct hardware-wave calls are split-only or pixel-only), results of instructions that read other lanes are held until every lane has read, lanes past the thread limits never run, and the tests compare against both the console's values and the split form.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:16:46Z.
Triage (#1607) – head
1216e70No open PR adds a lane-loop form. #3562 (same author) attacks the same problem, the split wave64 exchange on 32-lane GPUs, by folding two console lanes into one host lane. This PR instead runs a whole console wave per thread for small programs (at most 512 code dwords by default). These are different approaches. If both merge, the lane loop runs first in
pso::direct_computeand the fold inkernel::translate_compute_rodata, and both add sections todocs/wave64-on-wave32.md.No problems found in the parts read. The failing check is the PR description check: the smoke pair is still owed.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T14:25:56Z.
Edited:
659efb76did not carry the opt-in described here;c15bcb172does (see below).Thanks for the review. The lane loop is opt-in now (head
659efb76): withXCL_WAVE64_LANE_LOOP=1split programs of at most 512 code dwords take it, with=allevery program the form supports, and without the switch no program changes form. The 512 is still a first guess and GPU time against the split form is still not measured; the description says so.On the other points: a lane-loop program gets no dispatch chain, as you say (one thread a wave has nothing to cut); and it does take single-wave programs with LDS when the switch is on. If both this and #3562 merge, the order between them needs one decision point; I would put the choice in
kernel::translate_compute_rodatain whichever lands second.cargo test --lib gpu::dxilon that head, RTX 4060 Ti under Wine: 311 passed, 1 failed (directed_reference_basics, as onmain), 3 ignored; the five lane-loop tests passed, three of them on the GPU.AI use: Claude Code with Claude Fable 5.2 made the change, ran the tests and wrote this.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T20:47:11Z.
A correction to my comment above: head
659efb76did not carry the opt-in. The edits that make the form opt-in were left uncommitted, so659efb76ran the lane loop by default on split programs of at most 512 code dwords. Headc15bcb172has them: withoutXCL_WAVE64_LANE_LOOPno program changes form, and the switch is now also a warm pipeline library setting (it was missing there, like #3563's). Lane-loop andshaders::tests on that head, under Wine on the CPU: 103 passed, 0 failed.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:13:47Z.
Follow-up review (head
c15bcb17, since1216e70, diff read, not a merge-check; checks red):lane_loop::mode(lane_loop.rs~28) returnsNonewhenXCL_WAVE64_LANE_LOOPis unset or0, andchoose(~45) then returnsNone;=1and=allturn it on. The value is in the translated cache identity (compact_nest_tag,kernel.rs~107) and the warm settings (shaders.rs~40), and the test checks thatNonekeeps the split form (~615).choosestill takes LDS programs that main sends to the HLSL path whenXCL_X_LDS_ORDER=0(kernel.rs~322), and lane-loop kernels still havedispatch_chain: None(lane_loop.rs~179), which matters for large programs, so in practice only with=all.compact_nest_tag(kernel.rs~107) differently, so whichever merges second conflicts there; withXCL_WAVE64_FOLD=1also set the lane loop takes small programs first (pso.rs~1327). All three are opt-in now.PR descriptionis red), only filtered tests ran under Wine, and there is no native Windows run.New: none.
Fine: the
0/unset/1/allcases map to the cache tag and warm settings consistently,XCL_DIRECT_DXIL_SOURCE_IDcovers the new file, and with the switch offdirect_computebehaves as on main.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T11:40:30Z.
merge-check
base:
1c8b551475head:
c15bcb1722merge: clean (3f227198be4bc70bd7322538f7f11bc333352360; 8 files, +684/-4; git diff --check ok)
build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture -> 2915 passed, 0 failed, 51 ignored across 43 targets (28 SKIPPED lines matching clean base
1c8b551475: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache). All 6 new tests passed on RTX 4060 with 0 skips: gpu::dxil::lane_loop::tests::{gpu_lane_loop_gives_the_console_waves_values, gpu_lane_loop_leaves_out_the_lanes_past_a_thread_limit, gpu_lane_loop_reads_other_lanes_before_any_is_written, lane_loop_has_one_thread_a_wave_and_nothing_to_wait_for, lane_loop_is_chosen_by_size_and_refusals_keep_the_split_form} and shaders::warm_settings_keep_the_wave64_lane_loop_switch_on_both_backends.review: Full diff audited across all 8 files (+684/-4). Opt-in only (off by default;
XCL_WAVE64_LANE_LOOP=1for programs up to 512 words,=allfor all eligible) and keyed into bothkernel::compact_nest_tagandshaders::semantic_pipeline_settingso translated and warm caches stay separate.lane_loop::each_lanedeliberately omits an SSA backedge fromendtohead, so scalar inputs stay at their pre-loop values across all 64 iterations (including carry-in/out instructions) while scalar writes and ballots are read atafterfrom lane 63. VGPR outputs are double-buffered viaheldwheneverll.crossedis set (handling in-place cross-lane ops such asds_bpermute), and unsupported constructs (multi-waves_barrier,v_movrel*/v_swaprel_b32, scratch, image writes, and lane reads of computed values) fail closed and fall back to the split form. In the liveXCL_WAVE64_LANE_LOOP=1retail smoke, 67 refused shaders (51 image writes, 16 multi-waves_barrier) fell back cleanly to the split form with zero errors. No scope creep or unintended changes.performance: Two 60 s release smokes on title 29640639 vs clean base
1c8b551475(1462 frames, presents per 2 s last 3: 48 53 59, peak commit 16043 MB): default (switch unset) ran 1629 frames (+11.4%, steady 61 60 60, peak commit 17007 MB, +6.0%, 0 removals, 0 crashes); opt-inXCL_WAVE64_LANE_LOOP=1ran 1649 frames (+12.8% vs base, +1.2% vs default, steady 60 60 60, peak commit 15160 MB, -5.5% vs base, 0 removals, 0 crashes).Default (switch unset):
Opt-in (
XCL_WAVE64_LANE_LOOP=1):verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:49:02Z.
Follow-up review (head
4a653476, sincec15bcb17, diff read, not a merge-check; checks red):git range-diffshows the own commit changed only wheremainmoved under it (theXCL_WAVE64_IDIOMSwarm setting and cache tag now sit next to this PR's own inshaders.rs/kernel.rs); this push is a rebase.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:06:44Z.
Review: COMMENTED
Review of
4a653476: 3 finding(s) (1 critical, 1 high, 1 medium), most severe first.crates/xcl/src/gpu/dxil/lane_loop.rs:138: The lane loop's CFG walk drops the per-dispatch loop-pass cap (loop_passes/ VAR_LOOP_PASSES from IO_LOOP_BUDGET) that kernel.rs applies to every plain-form compute program. (inline)crates/xcl/src/gpu/dxil/lane_loop.rs:175: Not certain about this one, because it depends on scheduling the hardware doesn't guarantee: numthreads becomes[ceil(N/64),1,1], so all console waves of a group run as threads of one 32-lane hardware wave. (inline)crates/xcl/src/gpu/dxil/lane_loop.rs:179: The lane loop always finishes withtry_finish(..)anddispatch_chain: None, bypassingfinish_dispatch'ssplit_compute/dispatch_piece_limit()(12,500 instructions). (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:06:45Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 138Critical: The lane loop's CFG walk drops the per-dispatch loop-pass cap (
loop_passes/ VAR_LOOP_PASSES from IO_LOOP_BUDGET) that kernel.rs applies to every plain-form compute program. Loop headers only decrement the 65,536-pass VAR_BUDGET. A compute program whose loop runs away (a spin on memory that never changes, or an exit condition the translation gets wrong) runs up to 65,536 passes per console wave, where the plain form stops it at the dispatch's share (DISPATCH_LOOP_PASSES / threads, min 1024). Each pass also runs every vector instruction as a 64-iteration loop in one thread, so a dispatch the split form cuts short runs ~64x longer per pass: the GPU hang / TDR the form is meant to avoid. Applying the same per-dispatch cap at the lane loop's loop headers would keep it bounded.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:06:45Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 175High: Not certain about this one, because it depends on scheduling the hardware doesn't guarantee: numthreads becomes
[ceil(N/64),1,1], so all console waves of a group run as threads of one 32-lane hardware wave. Waits between console waves that don't uses_barrier(LDS-flag or atomic spin loops) then depend on divergent threads of one hardware wave making progress, which GPUs without independent thread scheduling don't guarantee. In a 256-thread group (4 console waves) where wave 0 polls an LDS or global flag that wave 1 sets with no s_barrier (accepted, since only S_BARRIER with waves > 1 is refused), thread 0 loops while thread 1 is masked at the reconvergence point on AMD. The flag is never written, so the loop spins until VAR_BUDGET runs out and exits with wrong results, or hangs the GPU. Refusing programs with cross-wave waits other than s_barrier (e.g. LDS/global loads inside loops whose exit depends on them) would keep them on the split form.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:06:45Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 179Medium: The lane loop always finishes with
try_finish(..)anddispatch_chain: None, bypassingfinish_dispatch'ssplit_compute/dispatch_piece_limit()(12,500 instructions). WithXCL_WAVE64_LANE_LOOP=all, a large split-wave64 program the split form would run as a dispatch chain becomes one monolithic shader running 64 lanes per thread, and its lane-loop module is already much bigger than the split form's. That brings back the driver compile times, size limits and GPU timeouts the chain avoids. Routing throughfinish_dispatch, or refusing programs over the piece limit, would keep the chain.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:11:12Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:02:00Z.
Follow-up review of
50f65e53, since4a653476(code reading only, not a merge-check;PR descriptionred) · 1 high, 3 nitsIn short: Since
4a653476the lane loop gives every console wave 64 host threads instead of one: thread 64 x runs wave x and the other 63 leave. Loops take their pass count from the dispatch's share throughkernel::loop_head/loop_passes, and a program larger than a dispatch piece is refused, so the split form keeps it with its chain. The new layout breaks the one-waves_barriercase the form still accepts. It has not run on a GPU: the tested head (c15bcb17) and the smoke head (4a653476) both predate it, andPR descriptionis red.High
A one-wave group with
s_barriernow syncs a group whose other 63 threads have left.translate_on_this_threadrefusess_barrieronly whenwaves > 1(lane_loop.rs~107), and the test expects the one-wave barrier program to be taken (~649).split: false, wave64: true,barrier_wavesis 1 (kernel.rs~831), so the safe barrier is off.s_barrierlowers to a plainGROUP_SYNC(lower.rs~1187) that only 1 of 64 threads reaches.emit.rs~6749 records thatbar.syncwaits forever on NVIDIA when a warp exits early. Before this push the group had one thread, so it was harmless.Fix: lower
s_barrierof a one-wave group in the lane loop without the group sync (keep the LDS fence), or declare[1, 1, 1]whenwaves == 1. Add a GPU test that runs the barrier program.Nit
XCL_X_LDS_ORDER=0(still open).choosestill takes programs thatmainsends to the HLSL path withXCL_X_LDS_ORDER=0(kernel.rs~322). The lane loop keeps LDS order itself, so the result is right, butlds_order_wantedis not consulted and the interaction is not written down.compact_nest_tag(kernel.rs~113) and tosemantic_pipeline_setting, and both add a section todocs/wave64-on-wave32.md. Whichever merges second resolves the conflicts. WithXCL_WAVE64_FOLD=1also set, the lane loop takes small programs first (pso.rs~1327).ceil(N / 64)threads with thread x being wave x, but the code now declareswaves * 64. Tested refers toc15bcb17, before this change.Checked and fine
dispatch_costexceedsdispatch_piece_limit()is now refused and keeps the split form (lane_loop.rs~170), using the same measure as the split path.lane_loop_refuses_a_program_larger_than_a_dispatch_piececovers it.loop_passestakes the console group's thread count.gpu_direct_compute_loop_passes_follow_the_dispatchnow also runs on the lane loop, andlane_loop_loops_have_the_passes_of_the_console_threadschecks the divisor.loop_headmoved out oftranslate_on_this_threadunchanged and is shared by both forms.tg_size, the per-lane thread coordinates and the thread-limit gate all derive fromtid >> 6. Lanes past the group or a limit still never run.XCL_WAVE64_LANE_LOOPunset,choosereturnsNone, as onmain.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:40Z.
Review: COMMENTED
Review of
50f65e53: 2 finding(s) (1 high, 1 medium), most severe first.crates/xcl/src/gpu/dxil/lane_loop.rs:107: With one console wave (waves == 1),s_barrieris let through and lowered by the scalar path (lw.instat line 146) to a real GROUP_SYNC barrier, but only thread 0 of the 64-thread group reaches it: the other 63 have already left at th.... (inline)crates/xcl/src/gpu/dxil/lane_loop.rs:364: The 'reads a VGPR it does not name' refusal only sees reads that fall through toinit.load(init.touched). (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:40Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 107High: With one console wave (waves == 1),
s_barrieris let through and lowered by the scalar path (lw.instat line 146) to a real GROUP_SYNC barrier, but only thread 0 of the 64-thread group reaches it: the other 63 have already left at theruns && leadsgate (lines 135/258). A cs([64,1,1]) program with DS_WRITE; S_BARRIER; DS_READ under XCL_WAVE64_LANE_LOOP=all gets GroupMemoryBarrierWithGroupSync in non-uniform control flow after a whole 32-lane hardware wave returned. That's undefined behaviour in D3D12 and in vkd3d-proton's SPIR-V (OpControlBarrier), and can hang on drivers that don't count exited waves. The kernel path avoids exactly this (leave = !any S_BARRIER). Since the test calls it 'one wave: nothing to wait for', dropping the barrier in the lane loop would match.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:40Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 364Medium: The 'reads a VGPR it does not name' refusal only sees reads that fall through to
init.load(init.touched). Once an earlier lane loop has written VAR_VGPR+m, a read of an unnamed VGPR resolves to that SSA definition, which is lane 63's value from the earlier loop, and nothing is refused. If instruction A names and writes v7, and later instruction B's lowering reads v7 without naming it (e.g. an implicit second dword of a 64-bit or NSA operand thatrdna2::vgpr_usesdoesn't list), every lane of B silently reads lane 63's v7. Checking the reads themselves, or clearing the VGPR SSA definitions after each lane loop, would make the refusal reliable.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:17:12Z.
Follow-up review of
f66d74c9, since50f65e53(code reading only, not a merge-check;PR descriptionred) · 3 nitsIn short: This push fixes the one-wave barrier problem from the last review: a group of one console wave is now declared as one thread (
lane_loop.rs,threads = if waves == 1 { 1 } else { waves * 64 }), sos_barrierhas no threads that left early. It adds a GPU test that runs a barrier program through LDS, and a check of the declarednumthreads. The two smaller points are unchanged. The description still describes the old layout, and its smoke block names4a653476.Nit
XCL_X_LDS_ORDER=0(still open).choosestill takes programs thatmainsends to the HLSL path withXCL_X_LDS_ORDER=0(kernel.rs~322). The lane loop keeps LDS order itself, so the result is right, butlds_order_wantedis not consulted and the interaction is not written down.compact_nest_tagand tosemantic_pipeline_setting, and a section todocs/wave64-on-wave32.md. Whichever merges second resolves the conflicts.[ceil(N/64), 1, 1]: thread x is console wave x". The code declareswaves * 64threads, one thread for a single wave, with thread 64 x running wave x. The commit message is already updated.Checked and fine
s_barriersynced a group whose other 63 threads had left. With one thread declared,tidis 0,lane == 0passes the gate, andtid >> 6gives wave 0, sotg_sizeand the thread coordinates are unchanged.gpu_lane_loop_passes_the_barrier_of_a_group_of_one_wavewrites each lane's value to LDS, meets ats_barrier, reads the neighbour's value, and checks all 64 results.choosetest now asserts!{i32 1, i32 1, i32 1}in the disassembly when it can disassemble.docs/wave64-on-wave32.mddescribe the one-thread case.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:33:25Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 258Medium: Not certain about this one, because it depends on how drivers form hardware waves: giving each console wave its own hardware wave assumes the driver packs consecutive flat thread ids into hardware waves, which the codebase says elsewhere isn't guaranteed (
setup_lanes: 'the PC need not form waves from consecutive thread indices'). If a driver puts leading threads 0 and 64 in the same lockstep hardware wave, and console wave 0 spins on memory console wave 1 writes (the cross-wave polling the module docs say now 'waits as on the console'), the spinning thread starves the other and the dispatch hangs, the GPU hang this form was meant to avoid. Leading with one thread per hardware wave derived fromWaveGetLaneIndex()/wave id, rather than from flat ids, would remove the assumption.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:33:25Z.
Review: COMMENTED
Review of
f66d74c9: 1 finding(s) (1 medium), most severe first.Re-review at
f66d74c9. Both findings from the50f65e53review look addressed: the single-waves_barrierafter the other threads exit isn't flagged any more, and unnamed VGPR reads are now refused (every read and write is recorded intouched). One new item below.crates/xcl/src/gpu/dxil/lane_loop.rs:258: Not certain about this one, because it depends on how drivers form hardware waves: giving each console wave its own hardware wave assumes the driver packs consecutive flat thread ids into hardware waves, which the codebase says elsewhere.... (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:51:20Z.
Follow-up review of
cab682f3, sincef66d74c9(code reading only, not a merge-check;PR descriptionred) · 3 nitsIn short: This push changes how the lane loop gives out console waves: no longer thread 64 x to wave x, but by arrival (
wave_by_arrival,lane_loop.rs~305), because a driver need not form hardware waves from consecutive thread indices. Every thread zeroes a counter, the group syncs, the first lane of each hardware wave adds 1, the group syncs again, and hardware waves pastwavesleave. The sequence is right for 32- and 64-lane hardware waves and does not clash with the safe barrier or the program's own LDS. The three earlier nits are still open, and no run of this head is recorded (PR descriptionis red).Nit
XCL_X_LDS_ORDER=0(still open).choosestill takes programs thatmainsends to the HLSL path withXCL_X_LDS_ORDER=0(kernel.rs~339). The result is right, because the lane loop keeps LDS order itself, but the interaction is not written down.compact_nest_tagand tosemantic_pipeline_setting, and both add a section todocs/wave64-on-wave32.md. Whichever merges second resolves the conflicts.[ceil(N/64), 1, 1]: thread x is console wave x". Tested namesc15bcb17, so the new entry sequence has no recorded run. The commit message and the doc are up to date.Checked and fine
Lwhassplit: falseand refusess_barrierwhenwaves > 1(~109), sosafe_baris never set (kernel.rs~831, ~855).setup_lanes_compute, the other user of 8191, is not called.xcl_ll_wavesis used.waves * 64threads make2 * waveshardware waves. The firstwavesto arrive take 0..waves-1 and the rest leave. With 64-lane waves, each takes one.leadsisfirst && wave < waves. A one-wave group still takes(0, true)with one thread and no syncs.wavechanged.atomicrmw addand 1waveIsFirstLanefor a 96-thread group. The GPU tests run groups of several waves through both counters (with LDS: 96, 256 and 8x8x4 threads; without: 128) and compare per-thread results, so a wave taken twice or not at all fails.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:07Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 138Right: the lane loop's loop heads counted only the lane's 65,536 budget. Fixed in
cab682f3e: the head now goes throughkernel::loop_head(taken out oftranslate_on_this_thread, so both forms share it), andloop_passesdivides the dispatch's share by the console group's threads, so a console lane gets the passes it gets in the split form.Tests:
lane_loop_loops_have_the_passes_of_the_console_threads(red before the fix: the program never loadedIO_LOOP_BUDGET), and the lane loop is now a third case ofgpu_direct_compute_loop_passes_follow_the_dispatch, with the same expected counts as the split form.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:09Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 175Taken, though fixed another way than a refusal: each console wave now has a hardware wave of its own. The group is declared with 64 threads for each console wave; at the entry the first lane of each hardware wave takes the next console wave from a count in the LDS, and the other threads return (
wave_by_arrival,cab682f3e; it does not assume the driver forms waves from consecutive thread indices). So on 32- and 64-lane hosts alike a wave that polls LDS or memory another wave writes is in a different hardware wave, as on the console. A group of one console wave is declared as one thread, so thes_barrierthe form accepts there has nobody to wait for.Not reproduced: we have no AMD card, and on NVIDIA the old layout may well have made progress anyway. Test:
lane_loop_has_one_thread_a_wave_and_waits_only_at_its_entryexpects numthreads 128 for a group of 96 (2 before the fix) and the entry's two group syncs, onewaveIsFirstLaneand one atomic add.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:11Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 179Right. A dispatch chain cannot carry the lane arrays across its cuts, so in
cab682f3ethe lane loop refuses a program whose module costs more thandispatch_piece_limit(), measured assplit_computemeasures it (Module::dispatch_cost, now shared). Such a program keeps the split form and its chain. A program of 512 code dwords (MAX_WORDS) still fits.Test:
lane_loop_refuses_a_program_larger_than_a_dispatch_piece(2,048 instructions; translated whole before the fix).Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:13Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 107Right, and already fixed in
f66d74c9f, the head this comment sits on: a group of one console wave is declared as one thread (lane_loop.rs~174), so itss_barrierwaits for nobody who left; groups of several waves still refuses_barrier. Tests:lane_loop_is_chosen_by_size_and_refusals_keep_the_split_formchecks numthreads 1 for the one-wave barrier program (64 at50f65e53), andgpu_lane_loop_passes_the_barrier_of_a_group_of_one_waveruns one.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:15Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 364I don't think this one happens.
Lw::rdputs every variable it reads intoinit.touched(lower.rs~410-411), before the SSA looks for a definition, so a read that finds an earlier lane loop'sVAR_VGPR + mis recorded the same as one that falls through toinit.load.vregreads throughrd(lower.rs~809).lane_loop_instemptiestouchedbefore the lanes run (lane_loop.rs~311) and refuses after them if a VGPR outside the instruction's arrays is in it (~366). So an instruction whose lowering reads a VGPR thatvgpr_usesdoes not list is refused, whatever wrote that VGPR before.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:16Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 258Right that it was an assumption: numthreads is 1-D there, but
setup_lanesalready counts on no particular packing, so the lane loop now does the same. Incab682f3ethe first lane of each hardware wave takes the next console wave from a count in the LDS at the entry (wave_by_arrival: zero the count, group sync,WaveIsFirstLaneadds 1, group sync), and only those up to the group's console waves run; every other thread returns. Whatever the driver packs, each running thread is the only one of its hardware wave. The count is the LDS's top word (or a word of its own when the program has no LDS), which the program finds as undefined as at any start, since the second sync comes before any of its code.Test:
lane_loop_has_one_thread_a_wave_and_waits_only_at_its_entry(two syncs, onewaveIsFirstLane, one atomic add; none atf66d74c9). The GPU tests run on the RTX 2070 SUPER PC; their results go into the description.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:38Z.
Thanks for the follow-ups (to 21:51). At
cab682f3e(rebased onmain5ad98adbc):translate_on_this_thread,lane_loop.rs~174), so thes_barrierthe form accepts there strands nobody; groups of several waves still refuse it. (And since bmjask's 21:33 point, a console wave's hardware wave is chosen at the entry by arrival rather than by thread index:wave_by_arrival.) Tests:lane_loop_is_chosen_by_size_and_refusals_keep_the_split_formnow checks numthreads 1 for the one-wave barrier program (64 at50f65e53), andgpu_lane_loop_passes_the_barrier_of_a_group_of_one_waveruns one: LDS write,s_barrier, the neighbour's dword read back.XCL_X_LDS_ORDERhas no choice to make for it, and it is only taken withXCL_WAVE64_LANE_LOOPset. The description's What is in it now says so.compact_nest_tag,semantic_pipeline_settingand the docs. With both switches set the lane loop is tried first for the programs it takes; both are opt-in.cab682f3eon the RTX 2070 SUPER PC (whole suite and smoke); the description says so once they are in.AI use: Claude Code (Claude Opus 5.5) wrote the fixes, the tests and the replies in this round.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:09:53Z.
Review: COMMENTED
Review of
cab682f3: 1 finding(s) (1 medium), most severe first.Re-review at
cab682f3. The wave-packing assumption from thef66d74c9review looks addressed: waves are now assigned by arrival (wave_by_arrival). One new item below.crates/xcl/src/gpu/dxil/lane_loop.rs:172: The only time limit on the lane loop is a check of static DXIL size (dispatch_cost() > dispatch_piece_limit()), but each lane-loop body runs 64 times in one thread, so GPU time per dispatch is roughly 64x what that size suggests and is.... (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:09:54Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 172Medium: The only time limit on the lane loop is a check of static DXIL size (
dispatch_cost() > dispatch_piece_limit()), but each lane-loop body runs 64 times in one thread, so GPU time per dispatch is roughly 64x what that size suggests and isn't bounded. With XCL_WAVE64_LANE_LOOP=all, a program just under 12 500 static instructions, or one with long loops (up to 65 536 passes, each now 64 lanes run one after another in one thread), runs about 64x longer per thread than the split form and is never cut into a dispatch chain. That can cause the same TDR/device hang the PR is trying to avoid (the 16 s dispatch at the title's world start). Counting the 64x in the cost estimate, or scaling the loop budget down for the lane loop, would keep it bounded.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:26:28Z.
Code review location:
crates/xcl/src/gpu/dxil/lane_loop.rs; line 172Not changed, on purpose; here is the reasoning. The loop cap already gives a console lane the passes it gets in the split form (
loop_passesover the console group's threads), so the total work of a runaway dispatch is the split form's; what the lane loop gives up is parallelism, by design (one thread per console wave), and that is why it is opt-in and its GPU time is listed under Not tested. Scaling the cap by 64 would end a working loop after 16 passes (1024 / 64, against the floor that keeps working programs whole), and counting 64x indispatch_costwould refuse nearly every program (about 195 DXIL instructions). The 16 s dispatch in the description is the split form's exchange, not a long loop. If GPU time on real programs shows the lane loop near a timeout, the size limit (MAX_WORDS) is the place to narrow it.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.