Skip to content

GPU fixtures for global_atomic_csub / buffer_atomic_csub (GPU-ATOMIC-CSUB) - #411

Open
milk4sale wants to merge 6 commits into
ProjectLeonida:mainfrom
milk4sale:gpu-test/atomic-csub
Open

milk4sale wants to merge 6 commits into
ProjectLeonida:mainfrom
milk4sale:gpu-test/atomic-csub

Conversation

@milk4sale

Copy link
Copy Markdown
Contributor

GPU-ATOMIC-CSUB (claim: #14 (comment))

What and why

The docs/design.md row "global_atomic_csub, buffer_atomic_csub (GFX10.3)" is CPU-checked only on main (tests/semantic/test_atomic_csub.py) and says that the translation is not GPU-verified.

Draft #59 (carried over, Unclaimed) already has a GPU fixture for it, runtime/test/shaders/cs_global_csub.asm, from old PR 7237 by xelerb-debug. This PR takes that part over on its own:

  • xelerb-debug's two commits, cherry-picked unchanged with their author: the cs_global_csub fixture and the ; mcpu: fixture header (build.py, run_gpu_tests.py, tests/test_rdna2_decode.py, tests/conftest.py). The fixture covers both forms:

    • DATA above, equal to and below M
    • 0xffffffff on 0x80000000
    • glc and no glc
    • 32 lanes on one dword
  • One new commit adds runtime/test/shaders/cs_w32_csub_ext.asm, a wave32 fixture for what that file leaves out:

    • Inactive lanes: for each form, the 16 even lanes work on one dword while the odd lanes are inactive and aimed at a trap word. Both trap words stay unchanged, the inactive lanes keep vdst/vdata, and the active lanes get their old values. Each lane ORs 1 << lane into a word, which gives the exact mask. A lane mask copied into a VGPR would read only that lane's bit in the translator (the "Whole-wave masks" row).
    • Buffer bounds: buffer_atomic_csub goes through a V# with num_records 8. Offset 4 is in range. Offsets 8 (glc) and 12 (no glc) are out of range: memory is untouched, and vdata is 0 with glc and kept without.

    Every expected word is derived in the file header from three docs/design.md rows:

    • the csub row
    • "Atomic natural alignment": a dropped glc lane gets 0, and an inactive lane keeps its register
    • "Buffer bounds checking"

    It is registered in check.py and run_gpu_tests.py the way cs_w32_fcmpswap is. It is also in WAVE32_LANE_DUMPS, because its masks cover 32 lanes.

  • The csub row now names both fixtures, the GPUs, and the faults each fixture catches.

#59 would then reduce to its cs_w32_dot_int commit, on top of this one.

out cs_w32_csub_ext value
0 lanes whose global vdst kept its preset 0xaaaaaaaa
1 global dword after (100 - 16) | trap word << 16 0x77770054
2 sum of global old values (100..85) | sum of buffer old values (50, 48, ..., 20) << 16 0x023005c8
3 lanes whose buffer vdata kept its preset 0xaaaaaaaa
4 buffer dword after (50 - 32) | trap word << 16 0x55550012
5 in range, glc: old 30 | M after (25) << 16 0x0019001e
6 past the range, glc: vdata 0 | M kept (0x99) << 16 0x00990000
7 past the range, no glc: vdata kept (3) | M kept (0xab) << 16 0x00ab0003

Depends on: none.

Tested

CachyOS (Linux 7.3.3) on this branch (main ece4ba5b3 plus 3 commits), with llvm-mc 23.1.4 and the runtime/build test programs, whose sources are the same as this branch's. The device was picked with VK_DRIVER_FILES. Both fixtures were run with run_gpu_tests.py --filter csub and with build.py + check.py:

GPU driver native LEONIDA_W64_EMULATE=1
NVIDIA GeForce RTX 4070 Ti 620.70.06 both PASS both PASS
AMD Radeon 610M (Ryzen 9 7900X iGPU, gfx1036, RDNA2) RADV, Mesa 26.2.6 both PASS both PASS

I planted translator faults one at a time and reverted each. The results are the same on both GPUs:

fault cs_global_csub cs_w32_csub_ext
plain subtract, no clamp FAIL pass
signed compare FAIL pass
no glc return FAIL FAIL
EXEC ignored FAIL FAIL
V# bounds ignored (buffer form) pass FAIL
a dropped glc lane gets its DATA, not 0 pass FAIL

Other checks:

  • python -m unittest discover -s tests/semantic -p test_atomic_csub.py: OK.
  • These pass with python -I: test_run_gpu_tests, test_runner_calls_all_tests, test_design_contract_rows, test_docs_links, test_docs_repo_paths, test_text_write_line_endings and test_shader_checks.
  • tests/test_rdna2_decode.py with LLVM_MC set: both csub fixtures pass the llvm-mc parity check. The test then fails on cs_w32_permlane_fi.asm, as it does on main.
  • Not run: the pytest-based tests, which are what the conftest.py change serves. pytest isn't installed here.
  • scripts/check_no_game_data.py on the changed files: clean.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

xelerb-debug and others added 3 commits November 24, 2026 01:47
…u:" fixture header

The GPU fixture runners assemble every .asm for gfx1013, which has no GFX10.3 instructions: llvm-mc rejects
global_atomic_csub and buffer_atomic_csub there, so the csub rows of docs/design.md could get no GPU check. A
fixture may now name its target in the leading comment ("; mcpu: gfx1030"), next to "; mattr:", in
scripts/run_gpu_tests.py, runtime/test/shaders/build.py and the decoder parity test; without it nothing changes.

cs_global_csub.asm runs both forms on a few seeded dwords (DATA above, equal to and below M, 0xffffffff on
0x80000000, no glc with the data register kept) and 32 lanes of one wave subtracting 1 from 20 at once (old values
20..1 then 0 twelve times, M ends at 0). Passes on an RTX 4060 (NVIDIA 621.01) through both runners; the translator
with the clamp removed, or with a signed compare, fails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
conftest.Shader, which tests/test_translate.py uses for every runtime/test/shaders/*.asm, still assembled for
gfx1013 only, so test_gpu_samples_translate_and_validate and test_wave64_emulate_uses_no_subgroup_ops failed on
cs_global_csub.asm (found by @tikD1337 in review). It now reads "; mcpu:" and "; mattr:" the way build.py and
run_gpu_tests.py do. tests/test_translate.py: 647 passed (both cases failed without this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…PU-ATOMIC-CSUB)

cs_global_csub.asm (xelerb-debug, carried here from old PR 7237) checks the
clamp at 0, the unsigned compare, glc and 32 lanes on one dword. This
wave32 fixture adds what it leaves out, for global_atomic_csub and
buffer_atomic_csub:

- the 16 even lanes on one dword while the odd lanes are inactive and
  aimed at a trap word: both trap words unchanged, the inactive lanes'
  vdst/vdata kept, the active lanes' old values returned (an atomic OR of
  1 << lane per lane gives the exact mask, since a lane mask copied into a
  VGPR reads this lane's bit in the translator);
- buffer_atomic_csub through a V# with num_records 8: offset 4 in range,
  offsets 8 (glc) and 12 (no glc) out of range, memory untouched, vdata 0
  with glc and kept without.

Registered in check.py (WAVE32_DUMPS, WAVE32_LANE_DUMPS, the expected
words) and run_gpu_tests.py (the wave32 dump list, its words and the
wave32-only list). The docs/design.md csub row now names both fixtures,
the GPUs they pass on and the planted faults each one catches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trigger337

Copy link
Copy Markdown
Contributor

Tested f21b390 on AMD Radeon RX 6900 XT (RADV NAVI21 / GFX1030, Mesa 26.2.5, Linux 7.3.1 CachyOS, Vulkan 1.4.328, subgroup 32..64): pass.

Physical hardware verification on discrete RDNA2 / GFX1030:

  • python3 scripts/run_gpu_tests.py --build runtime/build/linux --filter csub: 2/2 passed
    • cs_global_csub: PASS (0x10070905 0xd070000 0x630064 0x80000000 0x0 0xfffffffe 0xc0500 0x1d800d2)
    • cs_w32_csub_ext: PASS (2863311530 2004287572 36701640 2863311530 1431633938 1638430 10027008 11206659, exact match for 0xaaaaaaaa 0x77770054 0x023005c8 0xaaaaaaaa 0x55550012 0x0019001e 0x00990000 0x00ab0003)
  • LEONIDA_W64_EMULATE=1 python3 scripts/run_gpu_tests.py --build runtime/build/linux --filter csub: 2/2 passed with identical words.
  • Negative control: planted signed compare (OpSGreaterThan in csub handler) fails cs_global_csub on word 5 (got 0x0, expected 0xfffffffe) while cs_w32_csub_ext passes, confirming fixture sensitivity.
  • Full GPU suite:
  • Unit & semantic tests:
    • python3 -m unittest discover -s tests/semantic -p test_atomic_csub.py: 6/6 passed.
    • python3 -I tests/test_run_gpu_tests.py: 62/62 passed.
    • python3 -I tests/test_design_contract_rows.py: 5/5 passed.
    • python3 -I tests/test_shader_checks.py: 87/87 passed.
  • scripts/check_no_game_data.py: clean. No game files.

AI-assisted: yes
agent: yes

@Sangonapou

Copy link
Copy Markdown
Contributor

Tested e811439 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass

Runtime built at this head with scripts\build_runtime.ps1 (MSVC 19.51); llvm-mc 23.1.6, SPIRV-Tools 2026.4. No game files.

run_gpu_tests.py --filter <name>, native (subgroup 32) and with LEONIDA_W64_EMULATE=1, identical words both ways:

  • cs_global_csub: PASS 0x10070905 0xd070000 0x630064 0x80000000 0x0 0xfffffffe 0xc0500 0x1d800d2
  • cs_w32_csub_ext: PASS 2863311530 2004287572 36701640 2863311530 1431633938 1638430 10027008 11206659

@milk4sale

Copy link
Copy Markdown
Contributor Author

The red windows and linux-gpu-tools jobs come from main as it was when this run was created, not from this change. Their checkout step says Merge e81143926 into a28927849, and a28927849 is older than two fixes:

This pull request touches none of the files #877 and #892 change, and it merges into current main (58be9cdf8) without conflict. Re-running the failed jobs would test the same old merge, so I'm leaving e81143926, the head tested above, as it is rather than pushing just to restart CI. I haven't found a finished run of these jobs on a main that has both fixes yet.

AI-assisted.

One conflict, in scripts/run_gpu_tests.py: main's TEXT_ONLY_MARK path for
llvm-mc-less fixtures (cs_dpp_cmp, 957) next to this branch's asm_target()
and "; mcpu:" header. Both are kept: a text-only fixture returns before
llvm-mc runs, every other one is assembled for its "; mcpu:" target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milk4sale

Copy link
Copy Markdown
Contributor Author

Merged main (6261ca916) into the branch to clear the conflict with #957. The one conflict was in scripts/run_gpu_tests.py: #957's TEXT_ONLY_MARK path (cs_dpp_cmp) and this branch's asm_target() / ; mcpu: header touched the same lines of assemble_to_s. Both are kept: a text-only fixture returns before llvm-mc runs, and every other fixture is assembled for its ; mcpu: target. The other files merged without conflicts, and the three earlier commits are unchanged (fast-forward from e81143926).

I rebuilt the test programs from the merged tree, then ran both csub fixtures on an RTX 4070 Ti (NVIDIA 620.70.06): they pass natively and with LEONIDA_W64_EMULATE=1. tests/test_shader_checks.py, tests/test_run_gpu_tests.py and tests/test_rdna2_decode.py (llvm-mc 23.1.4) pass.

Brings the branch up to date with main 68d1331. No conflicts; the merged tree was tested before the push (every standalone
test file under tests/ passes except tests/test_ci_registration.py, which fails on main alone since ProjectLeonida#930).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@github-actions github-actions Bot added needs rebase Conflicts with the base branch: rebase it on main and removed needs rebase Conflicts with the base branch: rebase it on main labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants