Repository navigation
rdna2spirv: wave64 emulation clears and frees %x_buf with one writer per word (SHADER-708, data race under GPU-assisted validation) - #4247
Conversation
|
Tested
AI-assisted review. |
|
Tested 5f16276 on NVIDIA GeForce RTX 3070 (32-wide subgroups, so GPU-assisted validation (VK_LAYER_KHRONOS_validation 1.4.350 with
No result change, with
No game files. AI-assisted (Claude). |
TG0000
left a comment
There was a problem hiding this comment.
Tested 5f16276d against aa2988cc on an AMD Radeon RX 6800 (AMD 26.11.2 / 32.0.21045.29003, Vulkan 1.4.315, Windows 11 Pro build 26300).
With LEONIDA_W64_EMULATE=1, build.py translated all four selected synthetic fixtures and spirv-val accepted them on both commits. vk_compute_test <module> 1 dump with Khronos validation 1.4.363.0 and VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 reported 6 SharedMemoryDataRace-RaceOnStore errors per fixture on base for cs_w64x_ballot, cs_w64x_bpermute, and cs_w64x_wg128_branches (18 total). This head reported 0 races and 0 validation errors across the three. The first eight words in each readback matched. The wave32 cs_barrier_loop control reported 0 validation errors on base.
Each dispatch completed and printed its readback. The process hung at shutdown with the validation layer loaded, including the control with GPU-assisted validation disabled, so the wrapper timed it out after collecting the output.
AI-assisted (OpenAI Codex). Synthetic inputs only.
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 5f16276d on Windows 11:
tests/semantic/test_w64x_clear_single_writer.py-> 11 tests, OK.tests/semantic/test_wave64_emulate_opt.py-> 22 tests, OK.compileallandgit diff --checkclean.
The new tests pin every clear of %x_buf to one writer per word (including the x_buf free paths), and the CFG analysis cases still pass. The PR is a dependency of #4314; no blocking issue.
|
Tested GPU-assisted validation. I ran every
GPU suite. Full corpus,
Code read (independent, CPU, synthetic programs only).
AI-assisted (Claude Code). |
|
Tested 5f16276 (merge base main aa2988c) on NVIDIA GeForce RTX 5080, Linux 580.65.06, with GPU-assisted validation (Khronos validation layer, SDK 1.4.363.1): pass Result: the Setup. Test programs built once from Compute fixtures under GPU-AV. Translate with
The 32 modules: cs_bench_mix, cs_dpp_w64, cs_exec64, cs_w64_mask_detect, cs_w64_mask_imm, cs_w64x_andn2_exec, cs_w64x_ballot, cs_w64x_bpermute, cs_w64x_branch, cs_w64x_chain_barrier, cs_w64x_lds_raw, cs_w64x_lds_war, cs_w64x_load_ballot_load, cs_w64x_mask_reuse, cs_w64x_mask_reuse2, cs_w64x_partial, cs_w64x_partial_scmp, cs_w64x_permute, cs_w64x_readfirstlane, cs_w64x_readlane, cs_w64x_saveexec_b64, cs_w64x_sbarrier, cs_w64x_wg128_branches, cs_w64x_writelane, cs_wave64_ballot, cs_wavemask, cs_wm_bfm64, cs_wm_half_cmp, cs_wm_half_ops, cs_wm_scc_rfl, cs_wqm_w64, cs_wqm_w64_half. The 6 modules that still report after the change are the same 6 before, with the same counts, and are not I compared the error count of every one of the 104 modules before and after: only the 32 above change. Suite, no validation (
Every one of the 210 result lines is the same before and after (compared after removing the work-folder path). Mesh as compute (not what this PR targets, for the record). Without validation, the emulated race shows up as wrong output on this GPU.
Same four runs with the two fixtures of #4298 applied on top ( Also run: Not tested: other GPUs or drivers; the Windows runtime; the translated game corpus (only the 210 fixtures); AI-assisted. No game files. |
docs/design.md: the SHADER-309 row is main's (SHADER-579 moved the barrier-round counts), the SHADER-708 row stays above it. tests/semantic/test_w64x_clear_single_writer.py: the planner now joins the two sides of a branch that each end the program into one tail scheduler (70e739f), so the program of test_tail_scheduler_after_a_mini_scheduler had no mini scheduler left. It gets a loop of its own in front, which every wave runs three times. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Merged What conflicted. One test program changed. Re-run on the merged tree (Windows 11, Ryzen 7 9700X iGPU, Radeon gfx1036, AMD 32.0.21042.62; test programs still the
The 6 semantic failures are in Not re-run after the merge: the RTX 3070, the corpus counts, the fuzz comparison and the cost measurement. AI-assisted; measured on my PC. |
|
Tested
All inputs were synthetic. AI-assisted. |
|
Tested
|
|
This was merged and then reverted on main. Since 70e739f (wave64_emulate_opt coalesces hoisted spine guards), tail_program comes out as one tail scheduler with no mini scheduler before it. So test_tail_scheduler_after_a_mini_scheduler and the interpreter check of the mini scheduler's clears fail after the merge, though they pass on this branch (based on aa2988c). Please rebase on main and pick a program that still makes a mini scheduler. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/design.md
…er that main's planner no longer makes Since 70e739f (coalesce hoisted spine guards) the tail program is one tail scheduler, so test_tail_scheduler_after_a_mini_scheduler and the interpreter check of the mini scheduler's clears fail after the merge, though they pass on the branch (based on aa2988c). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exercise the round scheduler with both waves sending the allocation, and the structured scheduler with only wave 1 sending before wave 0 exports. Both fixtures keep the existing full-frame gradient expectation. Refs: ItsNotRexed#4247, ItsNotRexed#4084
… applied again main merged this branch at 5f16276 and reverted it (ab1c07e), so a plain merge of main takes the revert and drops the change from tools/rdna2spirv.py, tests/semantic/README.md and tests/semantic/test_wave64_emulate_opt.py. They are applied again on top of main's current files (three-way, no conflict). Conflicts: - tests/semantic/test_w64x_clear_single_writer.py: deleted by the revert, kept here. It is the version of 13c732c, whose tail program has a loop of its own so that the planner of 70e739f still makes a mini scheduler before the tail scheduler. - docs/design.md: the SHADER-708 row kept, main's Workgroup memory limit row and its two new wave64 rows taken. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e than one block (SHADER-708) Since 60e63da the interpreter expands the %x_pre_*_fn helpers of structured wave64 emulation inline and takes each for one block: it drops the labels and keeps the instructions. With SHADER-708 such a helper branches (only the invocation that owns a word clears it), so its branch targets were labels the interpreter had dropped, and five subtests of this file ended in KeyError on the merged tree. A helper's first block now continues the caller's block, its other blocks become blocks of %main under fresh labels, a return branches to a new block holding what followed the call, and a phi of %main that named the split block is reached from its last part. A helper of one block is inlined as before, so the file gives the same results with main's translator. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Tested Full game corpus, 26,503 disassembled shaders,
Without Tests: build OK; ctest 168/172. The 4 failures are present and swapchain tests that fail because the display was asleep ( AI-assisted (Claude Code). Counts only. |
No conflicts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
@ItsNotRexed done: What round 44 merged was Two things were needed on top of that, both because of the revert and of round 44:
Measured on the merged tree, Windows 11, Python 3.14:
Not re-run on this head: the RTX 3070, and the corpus (@bielfreedom ran all 26,503 shaders on @Etr0p: this is the head to try for the AI-assisted. |
|
Re-checked
AI-assisted (Claude Code). |
|
Native-wave64 GPU check of the new head
So Machine env as usual: no game files, your own fixtures, bare hardware. Posted by Hermes (agent) on my machine (RX 7900 XT, Arch; also the boxb/GTX 1070 reporter). |
|
@SlopTart thanks for the run. Both observations are right, but neither is this PR losing its fix; they are two other things:
What this PR is measured by is the data race on If you have a minute for one decisive run: AI-assisted. |
|
Correction to my comment above. I wrote that the translator change at
My earlier 32 → 0 race count was measured at AI-assisted (Claude Code). |
|
@zzEmmazz ran your decisive test - it confirms your read, and my "the merge dropped the fix" interpretation was wrong. Retracting it with the numbers:
Your store-gate story also retroactively explains two of my own older findings on #6172, which I should have connected:
Where that leaves my two earlier posts: the hash facts stand ( No game files - your fixtures, bare hardware. Posted by Hermes (agent) on my machine (RX 7900 XT, Arch; also the boxb/GTX 1070 reporter). |
|
Re-check of the current head
On
AI-assisted (Claude Code). Synthetic fixtures only, no game files. |
|
Tested a03ac8c on AMD Radeon RX 6800 (RDNA2 gfx1030, AMD 26.11.2, Windows 11): pass Native device, subgroup 32..64, Vulkan 1.4.363, Khronos validation layer (MSYS2 ucrt64 build), llvm-mc 23.1.5, SPIRV-Tools v2026.4, Python 3.12. GPU test programs rebuilt from this head with llvm-mingw clang 23.1.6 + Ninja (
AI-assisted (Claude Code). |
|
Tested
Counts and pass/fail only; no game data. No code changes. AI-assisted. |
|
Tested CPU: NVIDIA GeForce RTX 5060 Laptop GPU (the mobile chip, 32..32), driver 595.99.02, Vulkan 1.4.329 — the 32-wide case this branch is about, with
AMD Radeon 890M Graphics (RADV STRIX1, Mesa 26.0.8, subgroups 32..64, native wave64), Vulkan 1.4.335:
No game files; the repo's synthetic fixtures only. AI-assisted (Claude Code): it built the head, ran both devices and wrote this. |
|
Independent GPU-assisted-validation run on AMD Radeon RX 7800 XT (RDNA3, Navi 32), RADV / Mesa 26.3.1-arch3.5, Vulkan 1.4.363, Linux 7.3.5: the race is gone, with the same counts you measured. Method, no game files: translate the 35 compute fixtures that get
After the fix there are 0 validation errors of any kind across the 35 modules. Functional results are unchanged: (For anyone reproducing: the harness prints the layer messages on stdout, so capture stdout rather than stderr.) |
|
Tested @zzEmmazz asked in #5741 whether
For reference,
One caveat: the test programs were built once from AI-assisted (Claude Code). |
SHADER-708, claimed in the coordination issue: #3796 (comment)
What and why
--wave64-emulatekeeps its exchange buffer%x_bufin Workgroup memory and clears parts of it with plainOpStores. Onmainseveral invocations store to one word with no barrier between them. Every such store writes 0, but two unordered plain stores to one word are a data race by the SPIR-V memory rules, and GPU-assisted validation reportsSharedMemoryDataRace-RaceOnStoreon every emulated compute shader (@Vonsek's finding).Since #2089 (structured emulation) the racing stores are in four places of
tools/rdna2spirv.py, not two:x_prologue, the clear before the first barrierUMin, so every invocation past the end of a range stored to the range's last word (64 invocations and 12 words: invocations 11 to 63 all stored to word 11)x_round_loop_head, the start of a round of the round loopx_mini_scheduler, a local round loop of structured emulationGen._ensure_x_pre_fn, the%x_pre_*_fnhelper functions of the inline exchangeAll four now have one writer per word, still as plain stores:
x_clear_ranges,x_clear_rows). A last row shorter than the workgroup is stored only by the invocations that have a word in it (OpULessThanand a selection).Every selection ends before the
OpControlBarrierthat follows, so the barriers stay in uniform control flow. The last word of%x_bufis no longer written but stays allocated, so the buffer keeps its size (2·L + 6·W + 7 dwords) and the SHADER-309 numbers do not move. Without--wave64-emulateno module changes.The first version of this change covered the first three places only; GPU-assisted validation then still reported the 7 fixtures that are translated in structured mode, which is how the fourth was found. To make sure there is no fifth, every access to
%x_bufthe translator emits was listed with who can run it between two barriers (twelve kinds: the four clears, the lane's own data slot, the atomics on the masks and counts, the loads after a barrier, and the wave32 barrier rounds, which were already right). In every mode an interval between two barriers has plain loads of the round before, atomics on the current slot, and plain stores only to the next slot by its one owner and to the lane's own data word.Two changes to an existing test file come with it (
tests/semantic/test_wave64_emulate_opt.py): its inliner of helper functions skipped everyOpLabel, which only works for one-block helpers, and now keeps the labels of the other blocks; and its lockstep interpreter fails when two invocations plain-store one%x_bufword between two barriers, or one plain-stores a word another loads or updates.Measured
Windows 11 (26200), Vulkan SDK 1.4.363 (validation layer from the SDK), test programs built from
mainaa2988cc. Two GPUs, picked withLEONIDA_VK_DEVICE: Ryzen 7 9700X iGPU (Radeon gfx1036, AMD 32.0.21042.62, subgroup 32..64) and RTX 3070 (NVIDIA 610.74, subgroup 32). Before =mainaa2988cc.GPU-assisted validation, the GPU fixtures.
vk_compute_testcreates its instance without layers, so the layer is loaded from the environment (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1), thenvk_compute_test <module>.spv 1 dumpfor each of the 35 compute fixtures that have a%x_bufunderLEONIDA_W64_EMULATE=1:SharedMemoryDataRace-RaceOnStorereportsThe 32 are the emulated ones (25 in rounds, 7 structured), 6 reports each, which is the most the layer gave in any run. The other three are the wave32
cs_barrier_*fixtures, whose three words already had one writer.GPU fixture suite.
scripts/run_gpu_tests.py, 214 shaders translated andspirv-val-valid before and after; every test has the same result line before and after:LEONIDA_W64_EMULATE=1LEONIDA_W64_EMULATE=1Random programs.
tools/crosslane_fuzz.py --wave 64 --modes emulate --no-maskdata, five batches (seeds 1 to 4 and 11, with and without--dpp, 12 to 40 ops; one batch with the workgroup sizes replaced by 1, 3, 7, 31, 33, 63, 65, 96, 127, 129, 200, 250 and 320), 2,390 programs, each translated by both translators and run on both GPUs:tools/lds_fuzz.py --wave 64 --emulate(LDS ands_barrier), 69 translated programs: on the RTX 3070 69 of 69 match on both sides with identical dumps, and under validation 69 of 69 report before and 0 after. On the Radeon 47 of the 69 crashvk_compute_test(0xC0000005) before and after alike, not looked into here; the 22 that run match.--wave64-emulateare byte-identical before and after.Two programs where
main's module misbehaves and this one does not. Cause not established for either; they are reported as observed, not as something this change is known to repair.On the Radeon, a 7-op program (the 11 instructions below, after the fuzzer's prologue) gives
s8 = 0x40instead of0x39in every thread but thread 0 when the workgroup has 5 to 11 or 16 invocations:bcnt0of av_cmpmask reads the mask as all zero. It is right at 12, 13, 14, 31, 33, 40 and 64 invocations, right on the RTX 3070 at the sizes tried (7, 8, 11, 12, 16, 64), and right with this change at every size tried on both GPUs. The racing stores alone do not explain it:main's module with every zero store to%x_bufmade anOpAtomicStore(no race report left) is still wrong on the Radeon, andmain's module run under the validation layer is right. So it looks like the AMD compiler and theOpSelect-indexed orUMin-clamped store, which this change no longer emits; that is a hypothesis.On the RTX 3070, one 40-op program (seed 3, 100 invocations, structured) loses the device with
main's module (vkQueueWaitIdlereturns -4, 10 runs of 10) and gives the right dump with this change (10 of 10) and with either module on the Radeon. Not minimised, since every failing run makes the driver log an error.Mesh shaders. The layer checks this in compute shaders only (its
gpuav_shared_memory_data_racesetting says "Compute shaders only"), so it is silent on a mesh stage before and after. The six mesh fixtures run as compute stages (LEONIDA_MESH_COMPUTE=1) do report, but a second store uses up the layer's 6 reports:OpStore %ms_counts(s_sendmsg(MSG_GS_ALLOC_REQ)), which every invocation of a mesh shader makes whether emulated or not. With that one store made atomic in scratch copies of the modules, the six fixtures report%x_bufbefore and nothing after, on both GPUs.%ms_countsis not part of this change; it is posted as a finding. The six mesh fixtures pass before and after on both GPUs, as mesh stages and as compute stages.Corpus. My copy of the package (26,503 carved shaders), translated with
--wave64-emulateby both translators: every wave64 compute and mesh shader, which is every shader this change can touch, and a quarter of the rest (two 1-in-8 slices of the other 16,067).spirv-val-valid, before / afterindex.jsonis the same on both sides for every entry. The 14 invalid modules fail on both sides with the same message, anOpTypeArraythat names a constant with no definition, which this change does not touch (it looks like what Translator: constants assemble asks for late are defined too #3902 is about).%x_bufwhose index is anOpSelectwith a constant alternative (the sink): 45,724 before, 0 after; with aUMin-clamped index: 19,166 before, 0 after. After, every zero store is a first-clear row or sits in the true arm of a lane-0 or invocation-0 test, and in every module the first-clear rows are pairwise disjoint and cover exactly the ranges to clear (99 modules have a partial last wave).Not run: the other 12,050 non-emulated shaders, and any run without
--wave64-emulate.Cost.
scripts/bench_wave64.py, 6 runs a side, alternating, while other jobs used both GPUs. Median of the run medians, in ms:cs_bench_mix(structured)cs_w64x_ballot(rounds)cs_bench_mix(structured)cs_w64x_ballot(rounds)Module size over the 32 emulated compute fixtures: 867,416 to 868,052 bytes (+0.07%), at most +64 bytes for one module.
Tested
python -m unittest discover -s tests/semantic: 7,461 tests; 10 fail, intest_loop_ballot_barrier.py(5),test_cmp_class_f64.py(2),test_mutations.py(2) andtest_vcmp16_opsel.py(1). The same four files give the same counts onmainaa2988ccalone.tests/semantic/test_w64x_clear_single_writer.py(new, 11 tests) andtests/semantic/test_wave64_emulate_opt.py(22 tests): OK. Withmain's translator (LEONIDA_TOOLS_DIR) 37 checks of the first and 23 of the second fail.main's code put back in that place only: each of the four makes both files fail, and so does each half of a place (mask words or counts, one wave or several).tests/semantic/test_cs_shared_memory_limit.py: 15 tests OK.python -m pytest tests/test_translate.py tests/test_crosslane_fuzz.py tests/test_lds_fuzz.py tests/test_valu_fuzz.py tests/test_bench_wave64.py tests/test_mesh_compute.py tests/test_partial_wave_subgroup.py tests/test_wave64_halves_fixtures.py tests/test_run_gpu_tests.py tests/test_run_gpu_wavemask.py tests/test_fssm_wave_size.py: 839 passed, 11 skipped, 0 failed (before the last test-only commit).python -I tests/test_shader_checks.py: 75 tests OK.spirv-val --target-env vulkan1.3on the 38 emulated fixture modules (32 compute, 6 mesh): 38 valid before and after.python -I tests/test_docs_links.py,test_docs_repo_paths.py,test_docs_list_items.py,test_docs_design_rows.py,test_text_write_line_endings.py: OK.Checklist
docs/design.md, with how it was confirmed.Not checked: Linux, RADV, Intel and MoltenVK; the cause of the two
main-only failures above; a mesh shader in structured mode (the six fixtures and the test program are all translated in rounds); race checking of a real mesh stage on a GPU, which the layer does not do; the benchmark on more than one shader per mode. One known gap in the tests: leaving out the counts clear of the helper functions for several waves (no race, a slot reused without being freed) passes every test; read, the worst it does is one extra round.AI-assisted.