Repository navigation
rdna2spirv: ds_add_u64 and ds_sub_u64 (and _rtn_) as two 32-bit LDS atomics, GPU-checked - #2738
evilclanker9000 wants to merge 4 commits into
Conversation
…cs with carry/borrow The memory is exact under any contention; the returned high dword is an approximation like ds_and/or/xor_b64. GPU fixture cs_w32_ds_add_sub_u64 on an RTX 5080 and the Radeon RDNA2 iGPU, semantic tests, design.md row. AI-assisted.
|
Tested I also tested the Across 12 runs, both final counters matched and each operation returned all 128 expected prior values exactly once. I saw no mixed high/low return on this GPU and driver. A control with separate counters per thread also passed. AI-assisted |
|
Independent RTX 5070 check at
All the synthetic modules passed Vulkan 1.2 SPIR-V validation and the ten LDS semantic tests passed. The split path's post-barrier results look sound for these workloads. For a shader that uses the returned pair under contention, the mismatch counts make the native feature path worth distinguishing from the approximation. AMD RDNA 2 ISA reference · Khronos Workgroup memory aliasing extension |
|
Independent 8-lane Vulkan check ( AI-assisted (Codex). |
|
Tested 67e6eb8 on AMD Radeon RX 9070 XT (RADV GFX1201) 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
Tools: llvm-mc 21.1.8 with AMDGPU target, SPIRV-Tools 2026.1, GCC 13.3.0, Python 3.12.3. No code was edited or pushed; only synthetic fixtures were used. AI-assisted. |
runtime/test/shaders/check.py scripts/run_gpu_tests.py AI-assisted.
docs/design.md runtime/test/shaders/check.py scripts/run_gpu_tests.py tests/semantic/regen_fixtures.py AI-assisted.
Both 64-bit add/sub forms raised Unsupported. They are exact with 32-bit atomics: the low dword's atomic returns its old value, which gives this op's own carry (borrow), and the high dword then takes DATA.hi + carry. Addition commutes and the carries over any order add up to the low dword's wraps, so the memory is exact under contention (as ItsNotRexed#2738 does for LDS); only the returned high dword can be torn. x2_atomic_words holds the per-dword part for the global and buffer paths. Tests: carry and borrow across the dword (global), add/sub in the value grids of test_global_atomics_x2.py / test_buffer_atomics_x2.py, and 32 lanes adding / subtracting on one element (they interleave in the interpreter) ending exact. The rejected-form lists move to min/max_x2. docs/design.md rows updated; a stale 'the _x2 forms stay Unsupported' sentence in the global atomics row goes.
|
Tested
AI-assisted (Claude Code). Synthetic shaders only, no game files. |
|
Tested The new AI-assisted verification with synthetic inputs. |
|
Tested
|
|
Tested
The GPU test programs are the runtime build of main |
|
Tested
I did not run the contention or torn-return experiments from the earlier comments. Synthetic shaders only, no game files. AI-assisted (Claude Code). |
docs/design.md runtime/test/shaders/check.py scripts/run_gpu_tests.py tests/semantic/regen_fixtures.py AI-assisted.
|
Tested 99215f9 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.
No runtime C++ changes in this PR; tested from the PR worktree against the existing main runtime build. AI-assisted (OpenCode). |
|
Tested
AI-assisted. |
|
Tested 99215f9 on two Vulkan devices, Windows 11, Vulkan SDK 1.4.363, MSVC 14.50, llvm-mc 23.1.6 (AMDGPU, LLVM-MinGW build):
AI-assisted. No game files. |
Requested by Lucas · project thread
Claimed in the coordination issue as: #2516 (comment)
What and why
ds_add_u64,ds_sub_u64and their_rtn_forms raisedUnsupported. They now translate to two 32-bit atomics on the two dwords of the element, with no Int64 atomics on Workgroup memory (optional in Vulkan, like the existingds_and/or/xor_b64): the low dword takesDATA.lo, and the carry (add) or borrow (sub) it made, found from the old low dword the atomic returns, goes into the high dword'sDATA.hi. The number of carries over any order of the ops is the same, so the memory result is exact under any contention. The returned high dword comes from its own atomic, so another lane's op on the same element between the two can show up half done; this is documented as an approximation in thedocs/design.mdrow.Not done:
ds_min/max_u64/i64,ds_rsub/inc/dec_u64andds_cmpst_b64still raiseUnsupported. A 64-bit min or max cannot be made of two independent dword atomics without sometimes giving a wrong word under contention, and an exact version needs eithershaderSharedInt64Atomicsplus an aliasing layout for the 32-bit LDS accesses (VK_KHR_workgroup_memory_explicit_layout; the feature would have to be enabled in every runtime and test device, as forVK_KHR_shader_fma) or a lock. Left for a separate decision. The 32-bitrsub/inc/decforms are #2495's.Related open PRs #2350 and #2317 add semantic tests for
ds_add_u64/ds_sub_u64; this PR does not touch them.Tested
tests/semantic/test_lds_add_sub_u64.py(carry and borrow edges, offsets,vdstaliasing the data, seeded values, the fixture's lane-0 twin). Onmainthe value tests fail (199 errors,Unsupported); with the fix all 10 pass.cs_w32_ds_add_sub_u64.asm(hand-derived words in the header): 32 lanes runds_add_u64andds_sub_u64on one element each (most adds carry out of the low dword), then lane 0 runs the wrapping/borrowing_rtn_forms.main: translation fails (Unsupported) on both GPUs. With the fix, 8/8 words exact on the NVIDIA GeForce RTX 5080 (driver 616.92) and the AMD Radeon RDNA2 iGPU (driver 26.10.1), each selected withLEONIDA_VK_DEVICE.OpULessThan dl new_lo) fails the fixture on both GPUs (out[1]0x1fd, out[6]0x1) and the semantic tests.python -m unittest discover -s tests/semantic,regen_fixtures.py --check,tests/test_shader_checks.py: 2577 tests OK (3 skipped); the fixture check is clean and the shader checks pass.Checklist
docs/design.md, with how it was confirmed.AI-assisted.