Repository navigation
rdna2spirv: ds_append and ds_consume (LDS), once per wave - #3976
evilclanker9000 wants to merge 2 commits into
Conversation
One add / subtract of the wave's active-lane count at the offset address, done by the first active lane; the old value to every active lane by a subgroup shuffle (an exchange round under --wave64-emulate). Measured natively on gfx1036: the offset alone is the address, M0 does not move it. The gds form stays Unsupported. GPU fixtures cs_w32/w64_ds_append, semantic test test_ds_append.py, design.md row. AI-assisted.
|
Tested 0fc8a15 on NVIDIA GeForce RTX 4090 (driver 32.0.16.2101) and on AMD Radeon(TM) Graphics (driver 32.0.21043.5001), Windows 11, MSVC 14.51: pass. Vulkan reports subgroup sizes 32..64 on the AMD GPU and 32..32 on the NVIDIA GPU. The runner confirmed the compute subgroup size of each dispatch. I translated the checked-in synthetic disassembly with the translator of this head. For each of
This pull request does not change runtime C++ code. I did not make the disassembly again with LLVM, and I did not run the full CTest suite on this head. AI-assisted. |
|
Tested 0fc8a15 (contains Native,
GPU fixtures,
CPU: AI-assisted (Claude Code). |
|
Tested 0fc8a15 (up to date with main aa2988c) on three setups,
Also OK: AI-assisted. |
|
Tested |
|
AI-assisted. No game files used. Tested 0fc8a15 with four waves per workgroup sharing one LDS counter: Ryzen 5 7600X iGPU (RDNA2 gfx1036, AMD 26.10.1), Windows 11 build 26200, llvm-mc 23.1.6, Four local fixtures (not part of the PR), each with 4 waves in one workgroup on the same LDS words:
Each run's whole 200 runs per mode on the AMD iGPU, all passing:
The validated loop histories are highly interleaved: sorted by returned counter value, 254 or 255 of the 255 adjacent append pairs belong to different waves. This describes observed counter order, rather than measuring simultaneous hardware execution. On the parent, all four fixtures fail to translate ( Negative control: in a local copy of the translator, I replaced the one
So in this sample the one-wave fixtures don't detect a non-atomic implementation, and the multi-wave ones do. One of them might be worth adding to the suite. cs_w32_ds_append_mw.asm (wave32, one append + one consume per wave; the others are similar)Not run: NVIDIA, RDNA1, the |
|
Tested 0fc8a15 (contains main aa2988c) on AMD Radeon RX 6650 XT (gfx1032, discrete RDNA2, subgroup 32..64), driver 32.0.21045.29003, Windows 11, MSVC 19.44, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1): pass.
The PR changes no C++, so the test programs were built from aa2988c. No game files used. AI-assisted. |
slopradish
left a comment
There was a problem hiding this comment.
CPU verification: checked out pull/3976/head in an isolated worktree and ran pytest -q tests/semantic/test_ds_append.py: 4 passed, 8 subtests passed.
The implementation matches the documented hardware behaviour: one LDS add/subtract per wave by the first active lane, with the old value broadcast to the other active lanes via subgroup shuffle (or an exchange round under wave64 emulation). The semantic test checks the count, the performing lane, and that inactive lanes keep vD — those are exactly the parts most likely to be wrong in a first implementation.
The change also updates the contract table, GPU fixtures, checker word lists and GPU runner registration together, so the CPU test won't silently drift from the hardware fixture. I could not run the GPU fixtures here, so the RDNA2/RTX measurements remain the author's; the CPU path is verified.
No game files or keys involved.
docs/design.md AI-assisted.
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested 84eec83 merged with main d974c88 on Linux (WSL2), Python 3.12.16: pass Semantic tests only, GPU fixtures and check.py/run_gpu_tests.py not run (no GPU). tests/semantic/test_ds_append.py 4 ok; test_fixtures.py and test_rule_gpu_fixtures.py ok; regen_fixtures.py --check exits 0; all tests/test_docs_*.py pass with the docs/design.md row. I read the ds_append translator, the expected-word tables in check.py and run_gpu_tests.py (identical for both) and the two new test fixtures; nothing wrong found. The expected GPU words themselves are not verified here. Negative control: tools/rdna2spirv.py checked out from main, test_ds_append fails (1 failure, 9 errors), restored afterwards. |
|
checked: #3976 at 84eec83, composed onto main 427a7ec | on: Windows x64, Python 3.14.6, SPIRV-Tools v2026.4.rc2, CPU only | result: a guarded multi-wave emulation case hits
This complete synthetic reproduction uses the existing test helper, from the repo root with the PR applied: import sys
sys.path.insert(0, "tests/semantic")
from test_wave64_emulate_opt import _translate_encoded
insns = [
("v_cmp_lt_u32_e64 s[6:7], v0, 32", 8),
("s_and_saveexec_b64 s[10:11], s[6:7]", 4),
("s_cbranch_execz 2", 4),
("ds_append v8", 8),
("s_mov_b64 exec, -1", 4),
("s_endpgm", 4),
]
_translate_encoded("cs_guarded_ds", insns, (128, 1, 1), emulate=True)Changing the operation to A local proof adding both names to The integration also contains #6446 and #7489; these synthetic inputs use neither TG_SIZE_EN nor scalar VCC addressing. No game inputs or GPU execution were used for this report. |
|
I integrated this translator change into a recent boot stack ( One rebase detail for the CPU fixture. On this base, the SPIR-V interpreter shares Workgroup memory. The original test assumes a private LDS copy per invocation, so seven subtests fail on the final LDS word even though the returned per-lane value matches. I added With those fixture-only changes, all four tests in |
Validated against the real retail compute corpusApplied this PR's translator change (
+26 programs, every one also passing
Your Heads-up: GitHub marks this PR CONFLICTING, but that's in non-translator files — the Env: Windows 11 x64, Python 3.12.10, SPIRV-Tools v2026.4. GPU: none available — translate + |
|
Tested It's an Cause. Under emulation, Fix, one line. On this branch's "ds_bpermute_b32", "ds_permute_b32", "ds_swizzle_b32",
+ "ds_append", "ds_consume",
"s_wqm_b32", "s_wqm_b64",Reproducer (hand-written; wave64 header with
With the line added, all 12 translate. On the game. Over the 2,684 compute programs of the pipeline library (#7529's step; the ones device slot 67 creates at boot), with #6446 also applied, exactly 1 program hits this. On the run without #6446 it's rejected earlier by the thread-group SGPR check, which is why it doesn't show up yet. With the fix, it translates and passes AI-assisted (Claude Code). |
Requested by Lucas · project thread
Claimed in the coordination issue as: EGEN-DS-APPEND, #3796 (comment)
What and why
ds_appendandds_consumeraisedUnsupported. Compute shaders use these GFX10 LDS ops for wave-level stream compaction. I found them by translating every gfx1013 opcode form onmain. In the open PRs they appear only in #2323's decoder tables and in a CI script comment.Change (
tools/rdna2spirv.py,Gen.ds_append):s_bcnt1does.x_round) under--wave64-emulate. Without emulation, a wave64 on 32-wide subgroups is only right in the half that holds the first active lane. That is the known cross-half approximation.lds_op's per-lane EXEC selection, so the subgroup operations stay in uniform control flow.gdsform staysUnsupported.Measured natively on RDNA2 gfx1036 (Radeon iGPU of a Ryzen 9 9950X3D, driver 26.10.1,
tools/hw_oracleraw kernels, wave32 and wave64):ds_consume offset:8on 3 lanes subtracts 3.s_nops after the write) do not move the address. The offset field alone is the address. RDNA1 is not measured.New contract row in
docs/design.md.Tested
Windows 11, LLVM
llvm-mc(-mcpu=gfx1013),VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time,python -I scripts/run_gpu_tests.py --filter ds_append:cs_w32_ds_appendcs_w64_ds_append100 57005 200 57005 108 197 108 140100 100 57005 103 200 199 103 167LEONIDA_W64_EMULATE=1, same words (SKIP without: no 64-wide subgroup)New fixtures:
runtime/test/shaders/cs_w32_ds_append.asmandcs_w64_ds_append.asm. They cover partial-EXEC append and consume, the returned value read in active and inactive lanes (lanes 32, 33 and 63 for wave64), the LDS words, and a full-wave append. The words are derived in their headers. Both are registered incheck.py,run_gpu_tests.pyandregen_fixtures.py.New test:
tests/semantic/test_ds_append.py.spirv_mini_interpkeeps one LDS copy per invocation, so the test checks the parts that don't need shared LDS against a plain-Python reference:gdsis refused.The shared-LDS words are checked by the GPU fixtures.
Red on
main: the test errors withUnsupported: ds_append/ds_consume.Negative control: I made every active lane perform the op. The test fails, and on the Radeon both fixtures fail: the first append leaves
164instead of108, and the wave64 one109instead of103. Then I reverted it.Passing:
python -m unittest discover -s tests/semantic(no new failures: the 7 failures and 3 errors it reports fail the same way onmainaa2988cc, intest_loop_ballot_barrier(emulate),test_vcmp16_opsel(spirv-val),test_cmp_class_f64(TEST-853) andtest_mutations(v_mul_legacy_f32anchor)),python tests/semantic/regen_fixtures.py --check(clean),python -I tests/test_shader_checks.py, andpytest tests/test_docs_design_rows.py tests/test_run_gpu_tests.py.AI-assisted.
Checklist
docs/design.md, with how it was confirmed.