Skip to content

GPU test cs_w32_atomic_contend: buffer_atomic_inc/dec under contention - #4331

Open
LouisRiverstone wants to merge 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:gpu-test-atomic-contend
Open

LouisRiverstone wants to merge 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:gpu-test-atomic-contend

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

buffer_atomic_inc/dec (#2448) are OpAtomicCompareExchange loops. 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 adds 1 << (distance of its old value from F) into another word. A lost or doubled update changes that sum.

word case expected
0 32 × inc, D = ~0: F + 32 0xEEEEEF0E
1 F + Σ 1 << (old − F) over word 0's returned values (F + 0xFFFFFFFF iff each of 0…31 came back once) 0xEEEEEEED
2 32 × inc, D = 20: the first gives 0, then it wraps every 21 0xA
3 32 × dec, D = ~0: F − 32 0xEEEEEECE
4 32 × dec, D = 5: the first gives 5, then 5…0 repeats 0x4
5 umax of F and word 0's returned values: F + 31 0xEEEEEF0D
6 umin of F and word 3's returned values: F − 31 0xEEEEEECF
7 F + Σ 1 << (F − old) over word 3's returned values 0xEEEEEEED
  • Registration: like the other wave32 fixtures (WAVE32_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.
  • Scope: LDS is left out on purpose. The CPU interpreter gives each invocation its own LDS, so it couldn't check those words.

Tests: tests/semantic/test_atomic_contend_fixture.py runs 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 --check is clean, and tests/test_shader_checks.py and tests/test_run_gpu_tests.py pass.

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.

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 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MKmajster

Copy link
Copy Markdown

Hardware run as requested: NVIDIA GeForce RTX 3070 (Ampere, wave32), driver 617.42, Windows 11 24H2. run_gpu_tests.py --filter cs_w32_atomic_contend at 559ce67, three runs: PASS each time, same words:

PASS  cs_w32_atomic_contend  4008636174 4008636141 10 4008636110 4 4008636173 4008636111 4008636141

So with all 32 lanes racing on the same dwords, the OpAtomicCompareExchange loops of buffer_atomic_inc/dec lose no update on NVIDIA's driver. llvm-mc 23.1.6, runtime built from main aa2988c. No game files. AI-assisted (Claude).

@akimfomin

Copy link
Copy Markdown

Independent check at 559ce671 on RTX 4070 Ti SUPER (617.14), Windows 11 28000.3501, physical subgroups of 32. The exact fixture returned all eight expected words in 3/3 dispatches.

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: python -B -I tests/semantic/test_atomic_contend_fixture.py -v exits with ModuleNotFoundError: support, while unittest discovery passes 4/4. In a scratch copy, adding the test directory to sys.path before the two helper imports (as in test_valu_permlane16.py) made both entry points pass 4/4. Synthetic inputs only. AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

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 regen_fixtures --check/compileall/test_shader_checks/test_run_gpu_tests are clean.

Coordination: it inserts at the same anchors as #4337 and #4323 (check.py:88,119, run_gpu_tests.py:947,975,1063, regen_fixtures.py:24) and conflicts on top of #4337, so rebase after whichever lands first.

Approve. AI-assisted review, no game files, no GPU.

@theswiss24

Copy link
Copy Markdown

Tested 559ce671 (contains main 03b09a08) on two NVIDIA GPUs, test programs built from main 03b09a08: pass on both, with the same words.

GPU driver, OS llvm-mc run_gpu_tests.py
RTX 4070 (Ada) 621.24, Windows 11 21.1.8 196/211 passed, 15 skipped, 0 failed
RTX 2060 SUPER (Turing) 580.178.04, Ubuntu 24.04 20.1.2 196/211 passed, 15 skipped, 0 failed

Both are main's 195/210 plus the new fixture, with every other test unchanged:

PASS  cs_w32_atomic_contend  4008636174 4008636141 10 4008636110 4 4008636173 4008636111 4008636141

The words are identical on both cards. LEONIDA_W64_EMULATE=1 on both. No game files.

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.
@vibryxcx

Copy link
Copy Markdown

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.

  • run_gpu_tests.py --filter cs_w32_atomic_contend --require-pass: 1/1 in four runs (three at 559ce67, one at f4734c0; the fixture is the same in both), the same words each time: 4008636174 4008636141 10 4008636110 4 4008636173 4008636111 4008636141, which is your table (0xEEEEEF0E 0xEEEEEEED 0xA 0xEEEEEECE 0x4 0xEEEEEF0D 0xEEEEEECF 0xEEEEEEED).
  • tests/semantic/test_atomic_contend_fixture.py at f4734c0 under python -I: 4 OK.
  • Full run_gpu_tests.py at 559ce67: 196/211 passed, 15 skipped, 0 failed; the base 03b09a0: 195/210 with the same skips. The only difference is the new fixture.
  • Full ctest: one failure, vk_pipeline_check_cli, on both the PR and the base (a timeout in its CLI checks that passes when rerun alone), so not from this change.

Built with scripts\build_runtime.ps1 (MSVC 14.44), Vulkan SDK 1.4.363, llvm-mc 23.1.6 (conda-forge), Python 3.12.10. No game files.

AI-assisted (Claude Code): it built both commits and ran the tests.

@radv-tinker

Copy link
Copy Markdown
Contributor

Tested f4734c0a on AMD Radeon RX 9070 XT (RDNA4), RADV GFX1201, Linux (Fedora 43), subgroup 32..64: pass. The earlier checks don't include RADV.

python3 -I scripts/run_gpu_tests.py --filter <test> with the Mesa shader cache off, for the 1 test(s) this PR adds. Each passed in all three configurations: Mesa 25.3.6 (Fedora package) with ACO, the same with LLVM (RADV_DEBUG=llvm), and Mesa 26.3.1 (built from source) with ACO. The three give the same words:

  • cs_w32_atomic_contend: 4008636174 4008636141 10 4008636110 4 4008636173 4008636111 4008636141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants