VS / PS whole-wave reductions as wave operations (partial waves, every GPU) #152
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!152
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/152/head"
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?
@Foniass on GitHub · 2026-11-23 16:49 UTC · original
Foniass:nvidia/wave-reductions→main· +1465 −70 · 7 files · 4 commits · closed without mergingFollow-up to #133, as asked there: whole-wave reductions in VS / PS are recognised as a whole and emitted as wave operations.
Problem (every GPU)
v_permlanex16andv_readlane32 / 0.Change
Matcher (
recomp/reductions.rs): it recognises the whole sequence, with these checks:The pack's DPP8 selects aren't xor permutations, so it follows the set of lanes each lane has read and requires whole rows after the mirror. Anything else keeps the old steps.
Emitted:
xcl_wave_<op>(x, mask)gives the op over the mask's lanes for each 16-lane row of the hardware wave. From those rows, every register (vA, vB, sH, sT) is written as the console leaves it.WaveActive*returns 0 in helper lanes.xcl_half.Scope: wave64 VS / PS, and also wave32 PS, which has the same reduction and the same partial-wave bug (926 programs). Compute and mesh keep the steps (see below).
Switch:
XCL_NO_WAVE_REDUCTIONS=1gives the old translation for comparison.Test runner: draws share one command queue per device instead of making one per draw.
gpu_sparse_vram_descriptors_buffers_and_xmembrings up the D3D12.X backend (real::init), whose hooks then sit on the adapter's device, and the per-draw queues made through them were not given back. With several test threads, the draw-heavy tests here ended in E_OUTOFMEMORY atCreateCommandQueue, depending on order.Census (
retail_wave_reductions_census, ignored)retail_wave64_graphics_lane_forms: the native HLSL changes for exactly the 1 362 programs with a reduction; the 25 336 others are byte-identical (per-program digests, checked againstXCL_NO_WAVE_REDUCTIONS=1, which reproducesmain's digests). The other modes' 32-lane digest stays09d45ad13eddc30d, and the 32-lane form now differs for 287 programs. DXC compiles all 1 362, with 0 errors.Tests (RTX 5070 Ti, 32-lane waves)
gpu_ps_partial_wave_reductions: wave64 and wave32; min / max / or over the odd pixels and over whole quads; whole target, 3 quads and 55 pixels. sT, sH, vA and vB of every pixel are checked against a CPU model of the console wave. With the old translation every partial-wave min is 0.gpu_vs_partial_wave_reductions: a wave of 3 vertices.gpu_ps_reduction_result_in_helper_lanes: the result in helper lanes, read throughquad_perm; 46 of 54 cases differed before the helper fix.gpu_ps_reductions_in_branches_and_loops: the retail structure (s_wqm, a kill,s_and_saveexec/s_cbranch_execz, a min, an or in a loop) in five shapes.reductions::tests: matcher unit tests, for accepted and rejected variants.cargo test --workspace --releasewithXCL_SAMPLE_RPF: 576 passed, 0 failed (2no wave64skips, as onmain). Lib tests withXCL_SPLIT_WAVE64=1: 543 passed.main, 60 fps.xcl_halfpath.Not covered
v_cmpafters_wqmhas no helper-lane bits on the PC (WaveActiveBallot), so the quad-read step only helps when the mask is the saved EXEC. Only 10 wave32 PS sites in the pack may take the mask that way. #134 addresses that in general, and the two shouldn't conflict.🤖 Generated with Claude Code
@WarmMilkCodes on GitHub · 2026-11-23 18:56 UTC · original
Tested #152
4ba00d9merged onto main956a476on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): fail – one of the new testscargo test --workspace --no-fail-fast -- --test-threads=4: 576 passed, 2 failed (main: 568 / 1). The 8 new tests run; 7 pass.gpu_wave64_ps_whole_wave_reductionsfails on main too on this card (the 32-lane PS case, #155).New failure:
gpu_ps_partial_wave_reductions, and only for min_u32:Every wrong value is 0, in sT, vA and vB, e.g.
wave32, 3 quads, over the odd pixels: min_u32 sT: pixel 2 (lane 4): 0x0, want 0x2andwave64, 55 pixels: … pixel 38 (lane 0): 0x0, want 0x28. Pixels per wave here: 3 quads → [6], 55 pixels → [31, 24], whole target → 8 × 32.Since max and or have identity 0, a stray 0 is invisible to them, so this looks like a lane outside the mask (a helper or an unlaunched lane of a partial quad) contributing 0 instead of the identity – probably in the quad step for helper lanes. On this AMD driver, quad reads of those lanes seem to return 0 rather than what the step expects. Full output available.
@WarmMilkCodes on GitHub · 2026-11-23 19:10 UTC · original
Follow-up on the
gpu_ps_partial_wave_reductionsfailure on RX 6600 XT (RDNA2, driver 32.0.21045.29003): found the cause and a one-line change that makes it pass here.What happens: the reduction call is not in divergent control flow (checked the dumped HLSL:
uint4 t9 = xcl_wave_min_u32(v13, s10, 0u);at top level), but the final stepreturns 0 in live lanes whose quad has a helper lane: a live lane's
QuadReadLaneAt(h, k)of a helper lane doesn't see the identity the helper set there – plausibly because AMD's compiler leaves whole-quad mode around theWaveActive*results, so the helpers'his never written. Max and or have identity 0, so only min shows it – exactly the pattern in my earlier comment.Change tried (in
wave_reduction_fn, pixel branch): a live lane keeps its ownt, which is already the wave's result; only helper lanes take their quad's:Result on RX 6600 XT:
gpu_ps_partial_wave_reductionsgoes from 42 wrong results (every one 0, min only) to pass (1 passed; 0 failed), all shapes, wave32 and wave64, both masks.Caveat: a helper lane's own copy still comes from quad reads, so on AMD it may still be off – which matters only for derivatives of the result in partly covered quads, and the test checks live pixels only. Not tested on NVIDIA; the change shouldn't alter live lanes there, since
tis whatcreduces to when no helper interferes.@srcamarda on GitHub · 2026-11-23 20:21 UTC · original · edited 2026-11-23 20:35 UTC
Tested on an RX 7800 XT (RDNA3, driver 32.0.32029.2010, Windows 11 26300). This driver runs wave64 PS in 32-lane waves.
gpu_wave64_ps_whole_wave_reductions(fails onmaintoo; #155 fixes it) andgpu_ps_partial_wave_reductions(new): "42 results wrong".recomp/mod.rs):gpu_wave64_ps_whole_wave_reductionspasses,gpu_ps_partial_wave_reductionsstill fails, 42 results.The 42 are exactly the
min_u32cases, for wave32 and wave64, 3 quads and 55 pixels, over the odd pixels and over the quads' lanes, and all four results (sT, sH, vA, vB). Every wrong value is 0. max, or and the sum all pass. Examples:Edit:
Tested @WarmMilkCodes' one-line change on RDNA3: RX 7800 XT. It fixes
gpu_ps_partial_wave_reductionshere too.gpu_ps_partial_wave_reductionscargo test -p xcl --libXCL_SPLIT_WAVE64=14ba00d9as ismin_u32, all 0)4ba00d9+ the changegpu_ps_partial_wave_reductions,gpu_vs_partial_wave_reductions,gpu_ps_reductions_in_branches_and_loops,whole_wave_reductions_translate_to_wave_operationsand thereductions::testsmatcher tests.gpu_wave64_ps_whole_wave_reductions([2, 928, 2]vs[2, 464, 2]), the 32-lane PS case that fails onmaintoo and is fixed by #155. WithXCL_SPLIT_WAVE64=1it passes, so nothing else fails.@Kalmarv on GitHub · 2026-11-23 20:42 UTC · original
@Foniass, a note on the compute side that this PR's "Not covered" names, and an offer.
I measured the same gap (lanes EXEC turns on but the wave never launched) for wave64 compute groups on main
956a476, RTX 5070 Ti, split form. A program that widens EXEC and then runs VALU code only sees the launched lanes:s_not_b64 exec, execthenv_cmp_eq_u32 vcc, v0, v0: bits of VCCs_or_saveexec_b64 s, -1then the same comparev_movunder EXEC = -1,v_readlaneof lane 63s_wqm_b64 exec, execfollowed by the compare gives 42 instead of 44 in the 42-thread group and 10 instead of 12 in the 10-thread one. Full waves are right. The expected values are the ISA definition, not a console measurement, and the results are the same withXCL_X64_ALL_MASKS=1andXCL_WAVE64_SPIN=1. I have not run 64-lane hardware.For compute there is a way that needs no matcher: launch the missing lanes. Declare
numthreadsrounded up to whole console waves (64 for a 40-thread group, thread ids derived from the index as the split form already does) and start with EXEC = ballot(thread index < the console's thread count). The padding lanes then exist and are inactive, as on the console, so whole-wave code, compares,v_readlaneand DPP see them. It costs up to 63 idle threads per group and changes nothing for groups that are already whole waves.I can send that as a separate PR. It would only touch the compute entry, so it should compose with this one: your reductions keep VS / PS, and a compute reduction would simply run its steps in real lanes. It does nothing for mesh.
Would you rather do the compute part yourself, as the follow-up you describe? If so I will leave it and hand over the tests (24 mask programs in partial groups of 40 / 42 / 20 / 10 / 96 threads, plus the case above). Otherwise I will open the PR and link it here.
AI-assisted (Claude); tested on an RTX 5070 Ti, NVIDIA 610.74.
@Kalmarv on GitHub · 2026-11-23 20:59 UTC · original
Linux / Turing run of
4ba00d9merged ontomain956a476(merged1417aa, clean; onlyHANDOFF.mdauto-merged). Ubuntu 24.04, GeForce RTX 2060 (Turing, 32-lane waves), NVIDIA 595.91.07, Wine 11.21 Staging (wow64), vkd3d-protonmaster30b0eb9 (relaxed as in #175), DXVK 3.1.1dxgi; XCL cross-built forx86_64-pc-windows-gnu, release; DXC 1.7.2308. So the D3D12 path is vkd3d-proton → dxil-spirv → NVIDIA Vulkan, which translates the wave, quad and helper-lane operations itself.gpu::recompfilter,--test-threads=1:main956a476No new failures. The new tests pass here:
gpu_ps_partial_wave_reductions(including themin_u32cases that fail on RDNA2/RDNA3 above),gpu_vs_partial_wave_reductions,gpu_ps_reduction_result_in_helper_lanes,gpu_ps_reductions_in_branches_and_loops,whole_wave_reductions_translate_to_wave_operationsand the 4reductions::tests.retail_wave_reductions_censusis ignored, needing samples.gpu_wave64_ps_whole_wave_reductionspasses as well.The 5 failures on every build are this stack's memory-window reads, which return zeros (explained in #175), and are the same on
main:gpu_memory_windows_above_4_gib,gpu_unified_memory_arena,gpu_mesh_mode_reads_memory_windows,gpu_sparse_vram_descriptors_buffers_and_xmem,gpu_bvh64_intersect_ray_across_memory_windows_and_grazing. The 2 skips on every build areno wave64(gpu_geometry_*).So the helper-lane quad reads in the
min_u32final step come out right through dxil-spirv on NVIDIA. That matches the RTX 3090 Windows result: themin_u32failure looks specific to AMD's driver, not to the HLSL.Not covered: AMD under Linux (RADV);
#155combined; the e2e binaries; any title.AI-assisted (Claude Code).
@ic3bear-ai on GitHub · 2026-11-24 00:34 UTC · original
#152 on an RTX 3070: the helper-lane change on NVIDIA, and where the reduction coverage ends
Setup: NVIDIA GeForce RTX 3070 8 GB (driver 616.92, D3D12 wave range 32..32), Ryzen 5 5600X, Windows 11 build 26200, Rust 1.95.0, debug build, DXC 1.8.2502.11.
1. The helper-lane change works on NVIDIA. This is the one-line change proposed above for the AMD
min_u32failure, which was untested on NVIDIA. I rebuilt it from the description ("live lanes keep their ownt, only helper lanes take the quad result"):uint4 c = <quad op>; return IsHelperLane() ? c : t;.cargo test --workspace --no-fail-fast -- --test-threads=4on4ba00d9merged locally intomaina6f5f7a:maina6f5f7amain+ #152 + the extra test belowgpu_ps_reduction_result_in_helper_lanesincluded. #152 as posted passing here agrees with the RTX 3090 result above (same driver).gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).main:recomp/mod.rs;draw_console_viewsinrecomp/tests.rs, which main added and this PR'sdraw_console_astouches. I kept both sides;draw_console_viewsgot awave64parameter.2. An extra check, written separately from this PR's code and tests. A GPU test against its own CPU model of the console wave64: the 64 lanes stepped through as the ISA defines each instruction, unlaunched lanes holding the identity. The model is checked against a plain fold over the masked lanes. Source below.
s_or_saveexec -1,v_cndmaskwith the identity, DPP8 xor 1/2/4, row_mirror,v_permlanex16,v_readlane32 / 0), run as a wave64 PS.mainmain+ #152 (either variant)and(160) andadd(24)andandaddaren't among the ops #152 recognises, so in a VS / PS they keep the step-by-step translation and stay wrong in partial waves. The commit message says sums keep the old steps in compute; this is the same in a pixel shader. If no title uses them, that's fine. I'm only showing where the coverage ends.mainthe identity-0 ops are wrong too, without helper lanes. The description reportsorover a 3-quad wave with helper lanes. Here, in a 3-quad wave with whole quads only (lanes 0..11), max_u32, or and add are all wrong onmain. On the console, lanes 12..15 pick up the total of lanes 8..15 in the DPP8 steps and pass it to lanes 0..3 through row_mirror. On the PC those lanes don't exist, so lane 0 gets only lanes 0..7.docs/wave64-on-wave32.mdsays max / or / sum are right in partial waves; #152 fixes max and or.Not tested:
The extra test (paste into
recomp/tests.rs; it needs thedraw_consoleof this PR)Report written with Claude Code (Claude Opus 5.5), from runs on the hardware above. I checked the results before posting.
@Alpha325 on GitHub · 2026-11-24 01:30 UTC · original
Independent RDNA4 check on
4ba00d9796c3deec01be4497830e0ef96620485c, with and without @WarmMilkCodes’ proposed helper-lane change (return IsHelperLane() ? c : t;).Setup: Radeon RX 9060 XT, driver
32.0.32029.2010, Windows 11 build26200.9974, Rust 1.100.0 MSVC x64, DXC 1.9.2602.17, release. Synthetic fixtures only.cargo test --offline --locked --release -j 4 -p xcl --lib reduction -- --test-threads=1 --nocapturegpu_ps_partial_wave_reductionsreported 24 failing groups, allmin_u32, covering 68 mismatched pixel comparisons in wave32 cases and 78 in wave64 cases.This confirms the proposed change fixes the reported failure on RDNA4 for these fixtures. I did not run the full workspace suite.
AI use: OpenAI Codex (GPT-6.2 Sol) ran both builds and drafted this report.
@raylitebull on GitHub · 2026-11-24 10:43 UTC · original
Closing as a stale, conflicting ~1,500-line pre-template PR (touching
HANDOFF.mdand missing requiredCONTRIBUTING.mdsections). Feel free to open a fresh, scoped PR against currentmainif still needed.Pull request closed