Repository navigation
Conversation
…es of one wave with subgroup barriers Default off; output unchanged. With on, a native compute/mesh shader gets an OpControlBarrier Subgroup (AcquireRelease|WorkgroupMemory) before an LDS access that conflicts with an earlier unordered one (forward data flow over the blocks; none after s_barrier, in the emulate path, or behind an SCC branch that may split a wave64 subgroup). Tests: cs_lds_wave_exchange, cs_w64x_lds_wave_exchange, tests/semantic/ test_lds_wave_order.py; docs/design.md row with the quoted spec text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested ce3f264 (the rebased head) on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass. This is a desktop Ampere run, next to your RTX 5070 Laptop and 880M results, which came from before the rebase. The PR's diff applied cleanly to
|
|
Tested ce3f264 on two GPUs in one laptop, Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (WSL Debian),
With the option on, One note for testers: |
|
Tested ce3f264 on Windows 11 Home 26300. AI-assisted (Claude Code). One possible sighting of the race, with the option off, that I could not reproduce afterwards; everything else passes. Hardware: AMD Ryzen 5 7600X; iGPU AMD Radeon(TM) Graphics (RDNA2, subgroup 32..64), AMD driver 24.10.24 (Vulkan driver 2.0.302); NVIDIA GeForce RTX 5060 Ti, driver 610.88 (subgroup 32..32). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.12.10. Test programs built at ce3f264. Implicit layers off. No game files. The one failure. In the first whole-suite run on the Radeon, native wave64, Every other test in that run passed. I then repeated them on the same build and GPU, with nothing else running on the GPU:
So that's 1 bad run in 27 with the option off, and 0 in 26 with it on. That's not enough to say the option fixed it: I can't rule out something else on this machine during that first run. It's the only time I've seen these tests fail. If it is the race, it shows on an RDNA2 iGPU with the 24.10.24 Windows driver, under the PR's default (off). Everything else,
Most of the Radeon skips are its 128-byte push-constant limit (#2048 isn't in this base).
|
|
Tested
Like your runs, no race showed up without the option on either AMD part, so this shows that it does no harm on RDNA2/RDNA3 with the AMD Windows driver, not that it fixes anything there. Synthetic shaders only. AI-assisted. |
|
@smowlyy, thank you. That's the first time anyone has seen these tests fail: 898 and 30 mismatches on an RDNA2 iGPU with the older 24.10.24 driver, option off, in a whole-suite run, i.e. with other work on the GPU. It also fits the mechanism: under load, waves of a workgroup are more likely to be split across SIMD slots and rescheduled. One run in 27 isn't proof, as you say, but it's the only failing data point anyone has. If you have time, a stress run could tell the two apart. Loop only the two tests many times, with the option off and then on, while something else keeps the iGPU busy (a second Then @TheHoracio, thanks for the RX 7800 XT and RDNA2 runs. The cross-half exchange ran natively on both and passed in both modes. AI-assisted (Claude Code). |
|
What the AMD driver makes of the subgroup barrier, measured on the ISA. Earlier I'd seen an unaudited report that AMD's Windows driver lowers a Subgroup-scope
So on this AMD driver the option costs nothing at run time and orders exactly what it should. That's one driver version on one GPU, and I haven't checked other AMD drivers. @smowlyy, this also makes your one failing run on the 24.10.24 driver more interesting: without the barrier, that compiler is free to reorder. AI-assisted (Claude Code). No game files. |
|
@AlxcBTW, @smowlyy: I ran the stress test you asked for on both of my AMD GPUs: 0 failing runs in 3,200. Setup:
Each cell is failing runs out of 200. Every run reported 0 mismatches, and there were no harness errors. This does not contradict @smowlyy's single sighting. That was a different driver branch: Windows AMD 24.10.24 (Vulkan 2.0.302) on a Ryzen 5 7600X iGPU, while both of my GPUs run 26.10.1. It also happened under a whole-suite rebuild, which my loop did not reproduce exactly. If the race is real, it hasn't shown on 26.10.1 on either RDNA2 or RDNA3, so a 200+200 loop on the 24.10.24 machine is still the run that would settle it. Windows 11 Pro 26300. Synthetic shaders only. AI-assisted. |
# Conflicts: # docs/design.md # tools/rdna2spirv.py
|
AI-assisted (Claude Code). |
# Conflicts: # tests/test_shader_checks.py # tools/rdna2spirv.py
# Conflicts: # docs/design.md # tests/test_shader_checks.py # tools/rdna2spirv.py
|
Tested 1. cmd = [sys.executable, "-I", TRANSLATOR, selected_disasm, "--out", spirv_dir]
if w64_emulated(): # wave64 compute/mesh exact on any subgroup size
cmd.append("--wave64-emulate")
+ if os.environ.get("LEONIDA_LDS_WAVE_ORDER") == "1": # subgroup barriers between LDS accesses of one wave
+ cmd += ["--lds-wave-order", "on"]
2. GPU-AV cannot check this option. VVL's shared-memory race pass only counts an Whole suite. Base: this head merged with #4025 (on #4005), #3347 and #4067, so the test programs honour
No game files. AI-assisted (Claude Code). |
…; note GPU-AV cannot check it The harness builds its own translator command and ignored the variable, so whole-suite runs with it set translated with the option off. Found by @TreXito in review of ItsNotRexed#2345. GPU-AV's shared-memory race pass counts only Workgroup-scope OpControlBarrier, so it reports the same races with the option off and on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @TreXito, both findings were right. 1. Harness. I've pushed 2. GPU-AV. The LDS row in AI-assisted (Claude Code). |
|
Tested 0a7a52e on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran AI-assisted. |
|
Tested 0a7a52e (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.
No game files. AI-assisted. |
|
Tested
As expected on AMD, the exchange is already right without the barriers (a wave's lanes run each instruction together here), so this run shows the opt-in mode costs no correctness on RDNA4 rather than that it is needed; the discriminating runs are the 32-wide GPUs. AI-assisted (Claude Code). Synthetic shaders only, no game files. |
This is #1608 rebased onto
mainas one commit, because a new merge round conflicted intools/rdna2spirv.py. I rebased rather than mergingmainin, as asked for that file. The conflicts were "keep both":fit_shared_memory()frommainandlds_order_setup()from here, plus the fixture count. Re-run on the rebased commit:test_translateandtest_shader_checks592 passed, 2 skipped; semantictest_lds_wave_orderandtest_wave64_halvesOK.Results carried over from #1608 and #1564, all pass:
Thanks to all of you.
What and why
Adds an opt-in translator option,
--lds-wave-order off|on. The default isoff, and output is unchanged.LEONIDA_LDS_WAVE_ORDER=1turns it on forruntime/test/shaders/build.py. Claimed in #1218.The problem: RDNA2 runs a wave in lockstep with an in-order LDS queue. Shaders therefore write LDS in one lane and read it in another with only
s_waitcnt lgkmcnt(0), or nothing, in between. Reductions, prefix sums and transposes all do this. SPIR-V and the Vulkan memory model order nothing between two invocations without a barrier or an atomic. A compiler may reorder the accesses, and a GPU with independent thread scheduling may have the lanes of a subgroup at different instructions. Prior art, facts only: shadPS4 #5285 saw RADV reorder such reads.What
ondoes: a native compute or mesh shader (not--wave64-emulate) gets anOpControlBarrier Subgroup Subgroup AcquireRelease|WorkgroupMemorybefore an LDS access that conflicts with an earlier, still unordered one. "Unordered" means nos_barrierand no earlier subgroup barrier sits between them. The conflicting pairs are RAW, WAR, WAW, and atomic vs plain; atomic after atomic needs no barrier. The unordered set is a forward data flow over the blocks, so a loop-carried pair and a join are handled.Where it emits nothing:
ds_bpermute,ds_permuteandds_swizzle;s_barrier;scc_logictakes a lane's own bit for a 32-bit op on one half of a lane mask).With
on, the index recordslds_wave_order, the number of barriers emitted.docs/design.mdhas the row, with the spec text quoted.Tested
cs_lds_wave_exchange(wave32) andcs_w64x_lds_wave_exchange(wave64, including the other half) run 512 groups × 256 rounds of four dependent exchanges; every thread must store 0. Thecheck.pylab on an RTX 5070 Laptop and a Radeon 880M passes on both, with the default and withLEONIDA_LDS_WAVE_ORDER=1.lds_fuzz(seed 1, 100 programs, wave both), native and--emulate, on both GPUs: no mismatch.tests/semantic/test_lds_wave_order.py(31 tests): barrier placement, no barrier where none is needed, default off unchanged vs on, the metadata, a loop-carried pair, a join, and the wave64 SCC exception.test_translate+test_shader_checks+tests/semantic: 1705 passed, 2 skipped (ms_f16_pack). The nested-barrier test ran and wasn't skipped. Tools were llvm-mc and spirv-val. This run was on the pre-rebase base. After the rebase onto currentmain, the LDS, barrier-round and shader-check tests pass (88).off, all 137 test shaders are byte-identical tomain.Honest limits
The race did not reproduce in 100 runs per variant on an RTX 5070 Laptop and a Radeon 880M (wave32 and native wave64). The SPIR-V is racy by the memory model, but these drivers kept program order. The tests pass with and without the option, so they show no benefit, only that it is harmless on these GPUs. There was no measurable cost either.
Intel is untested. Nested barriers lose the device on Xe-LPG; see the "Workgroup barriers" row.
The spec is ambiguous.
OpControlBarrierin non-uniform control flow is "defined by the client API". The current text dropped that sentence.GLSL_EXT_split_barriersays Subgroup-scope barriers need not be in uniform control flow under Vulkan.Hence the wave64 SCC exception and the opt-in default. Quotes and links are in
docs/design.md.Not done: skipping the barrier when a lane provably reads only its own slot.
Checklist
docs/design.mdrow (rule, why, source, how tested)AI-assisted (Claude Code).
🤖 Generated with Claude Code