Repository navigation
GPU test cs_w32_atomic_contend: buffer_atomic_inc/dec under contention - #4331
LouisRiverstone wants to merge 6 commits into
Conversation
All 32 lanes of a wave32 group run each op on the same dwords, so the translated CAS loops race for real on a GPU (the CPU interpreter runs lanes in lockstep). Same op on every lane: the final words are order-independent, including inc/dec wrapping at a small D. Each lane adds 1 << (old - fill) into another word, so a lost or doubled update changes the sum; umax/umin of the returned values check the extremes. Registered in check.py, run_gpu_tests.py and regen_fixtures.py; tests/semantic/ test_atomic_contend_fixture.py runs it on the CPU against 32 sequential ops.
Kam471
left a comment
There was a problem hiding this comment.
Built and ran this at 559ce671 on Windows 11, RTX 5070 Ti: run_gpu_tests.py --filter atomic_contend -> 1/1 passed; translator 1/1 spirv-val.
cs_w32_atomic_contend returned 4008636174 4008636141 10 4008636110 4 4008636173 4008636111 4008636141, exercising the buffer_atomic_inc/dec compare-exchange loops under real cross-lane contention rather than the lockstep CPU interpreter. No blocking issue.
|
Hardware run as requested: NVIDIA GeForce RTX 3070 (Ampere, wave32), driver 617.42, Windows 11 24H2. So with all 32 lanes racing on the same dwords, the |
|
Independent check at I extended the same synthetic input to record the returned inc/dec values per invocation and ran it with 128 invocations in one workgroup (four subgroups sharing the same words). 16/16 dispatches returned the expected final words and both complete ranges of 128 previous values, with no duplicates or gaps. The 32-invocation readback variant also passed 4/4. Masking off one lane in a control changed the final words and left that lane's two output slots untouched, as expected. All four modules passed offline Vulkan 1.2 validation. I used the RDNA2 text as a listing with the repository's compute header and this head's Vulkan harness. One runner issue at this head: |
|
PASS. The inc/dec compare-exchange math checks out by hand (F+32, F-32, D=20 -> 0xA, D=5 -> 0x4, the bit sums -> F-1, umax -> F+31, umin -> F-31); the fixture is hand-written with expected words, registration is complete, 32-lane contention is real on a GPU, and Coordination: it inserts at the same anchors as #4337 and #4323 ( Approve. AI-assisted review, no game files, no GPU. |
|
Tested
Both are The words are identical on both cards. Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
python -I on the file failed with ModuleNotFoundError: support, as the folder was not on sys.path (found by @justr4mzi on ItsNotRexed#4323, the same template). It is now inserted, as test_cs_shared_memory_limit does.
|
Tested f4734c0 on AMD Radeon RX 6800 (RDNA2, subgroup 32..64), AMD 26.8.1 (Windows 32.0.21045.5002), Windows 11 Pro 25H2 (build 26200): pass. The runs so far were NVIDIA; this is the AMD side of the contention check.
Built with AI-assisted (Claude Code): it built both commits and ran the tests. |
|
Tested
|
# Conflicts: # runtime/test/shaders/check.py # scripts/run_gpu_tests.py # tests/semantic/regen_fixtures.py
|
Tested 1c49799 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 runtime build. AI-assisted (OpenCode). |
|
Tested
AI-assisted. |
…give the same word @sovljanskii on ItsNotRexed#4331: with 32 ops and D = 20, inc ends at 31 mod 21 = 10 and dec at 20 - (31 mod 21) = 10, so swapping buffer_atomic_inc v8 for a dec still passed on the GPU (D = 2, 6 and 8 coincide the same way). With D = 19 inc gives 31 mod 20 = 11 (0xB) and dec would give 8. Fixture, header, both expected-word lists and the CPU reference updated; the test now also checks that inc and dec differ at that D. llvmpipe: PASS with 11 in word 2.
|
Thanks @sovljanskii. Good mutation work: D = 20 really can't tell
Thanks also @javdc for the Steam Deck run. |
# Conflicts: # runtime/test/shaders/check.py # scripts/run_gpu_tests.py # tests/semantic/regen_fixtures.py
|
Tested cef6d5a (trial-merged onto main 1cc6e3c; vk_* test programs rebuilt from 1cc6e3c) on NVIDIA GeForce RTX 5090 (610.88, subgroup 32..32), Windows 11 Pro 26200, llvm-mc 23.1.6: pass.
No game files. AI-assisted. |
|
Tested The revised D=19 case catches an increment/decrement swap on Linux. The stock fixture matched all eight expected words, including 11 at word 2. In a temporary copy I changed only the atomic increment on that word to a decrement and kept the stock expectations. The runner reported a failure with 8 at word 2. I repeated each version in three fresh native wave32 dispatches. Only word 2 differed in each pair of full readbacks. This confirms the revised bound distinguishes the two instructions under contention; the stock result also agrees with the Windows hardware runs. AI-assisted verification. |
|
Tested AI-assisted (Claude Code). |
|
Tested cef6d5a on NVIDIA GeForce RTX 4090, driver 595.99.02, Linux (Debian 13 userspace), llvm-mc 21.1.8: pass
Test programs built from |
# Conflicts: # runtime/test/shaders/check.py # scripts/run_gpu_tests.py # tests/semantic/regen_fixtures.py
|
Tested
Toolchain: standalone tools ( |
|
Tested 0cda998 on RTX 5090, NVIDIA 615.71.09, Ubuntu 26.04: pass
|
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested
Overlap: this PR, #3039 and #4323 add to the same lists in No game files. AI-assisted (Claude). |
buffer_atomic_inc/dec(#2448) areOpAtomicCompareExchangeloops. Their tests run them in one lane, or in the CPU interpreter, which runs lanes in lockstep. @TheMrBeez checked the loops under contention by hand on #3097, but nothing in the suite does. This GPU fixture,runtime/test/shaders/cs_w32_atomic_contend.asm, has all 32 lanes of a wave32 group run every op on the same dwords, so the loops race for real on a GPU.The words start as the harness's 0xEE fill, F =
0xEEEEEEEE. Every lane applies the same op, so the final word doesn't depend on the order. The returned old values of one op are all different, so each lane adds1 << (distance of its old value from F)into another word. A lost or doubled update changes that sum.0xEEEEEF0E1 << (old − F)over word 0's returned values (F +0xFFFFFFFFiff each of 0…31 came back once)0xEEEEEEED0xA0xEEEEEECE0x4umaxof F and word 0's returned values: F + 310xEEEEEF0Duminof F and word 3's returned values: F − 310xEEEEEECF1 << (F − old)over word 3's returned values0xEEEEEEEDWAVE32_DUMPS/CS_DUMPS, the compute list, the expected words, the wave64-exclusion tuple,regen_fixtures.py). It's not a lane-mask test, so it also runs on llvmpipe.Tests:
tests/semantic/test_atomic_contend_fixture.pyruns the fixture on the CPU against 32 sequential ops. It also checks that a lost update would change the bit sum, and that both runners expect the same words. It passes 4/4,regen_fixtures.py --checkis clean, andtests/test_shader_checks.pyandtests/test_run_gpu_tests.pypass.Not run on a GPU by me: CI's llvmpipe job will run it, and hardware runs are welcome, especially AMD, NVIDIA and Intel, where the loops really interleave. No game files. Claimed on #4257 before starting.
AI-assisted (Claude Code): I reviewed and ran the change and the tests.