Skip to content

rdna2spirv: use OpAtomicLoad in ds_add_f32 CAS preheader and verify row 341 on RDNA2 (gfx1036) - #4230

Open
abnalstlll-byte wants to merge 2 commits into
ItsNotRexed:mainfrom
abnalstlll-byte:feat/row341-ds-add-f32-rdna2
Open

abnalstlll-byte wants to merge 2 commits into
ItsNotRexed:mainfrom
abnalstlll-byte:feat/row341-ds-add-f32-rdna2

Conversation

@abnalstlll-byte

Copy link
Copy Markdown
Contributor

Summary

Uses \OpAtomicLoad %uint {p} {sc} {sem}\ (\Workgroup\ scope 2, relaxed semantics 0) in the \ds_add_f32\ / \ds_add_rtn_f32\ CAS preheader in \ ools/rdna2spirv.py, adds edge-case tests, and documents full hardware verification for Row 341 on native RDNA2 silicon.

  • \OpAtomicLoad\ in CAS Preheader: Replaces non-atomic \OpLoad\ with \OpAtomicLoad %uint {p} {sc} {sem}\ using Workgroup scope (\2) and relaxed semantics (\

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

Ran this at adf27a10 on Windows 11: python tests/semantic/test_lds_add_f32.py -> 6 tests, OK; compileall and git diff --check clean.

The CAS preheader now reads the initial word with OpAtomicLoad instead of a plain OpLoad, so it participates in the same atomic ordering as the compare-exchange loop. The new cases pin signed-zero results (-0 + -0 -> -0, +0 + -0 -> +0), infinities, +Inf + -Inf -> qNaN and qNaN propagation through the CAS loop. No blocking issue.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested adf27a1 on NVIDIA GeForce RTX 4090 (driver 32.0.16.2101) and on AMD Radeon(TM) Graphics (driver 32.0.21043.5001), Windows 11: pass on the GPU. I did not run the full CTest suite, because this change has no runtime C++ code.

I translated a hand-written compute shader with this head. In one workgroup, 32 lanes each add 1.0 to the same LDS word with ds_add_rtn_f32. Each run used 32-wide subgroups.
On the two GPUs, each integer from 0 to 31 occurs exactly one time among the returned old values. All lanes read 32.0 after the barrier.

One gap in the test coverage. The added test does not find the change to the atomic load.
python -m pytest -q tests/semantic/test_lds_add_f32.py gives 6 tests passed and 128 subtests passed with this head and with the merge-base translator (aa2988c).
I counted the instructions in the translated shader. This head makes one OpAtomicLoad and one OpAtomicCompareExchange. The merge base makes zero OpAtomicLoad and one OpAtomicCompareExchange.
Possible correction: add an assertion that the first value of the CAS loop comes from OpAtomicLoad on the same workgroup pointer. Keep the value tests.

Script for the shader (run from the repository root; then run vk_compute_test.exe ../4230-add.spv 1 dump with VKC_SUBGROUP_SIZE=32; the first 256 dump bytes are 64 floats, the even entries are the old values and the odd entries are the final values):

import pathlib, sys
sys.path.insert(0, "tests/semantic")
import support, spirv_asm
from test_lds_atomics_values import FSSM
lines = ["v_mov_b32 v1, 0", "v_mov_b32 v2, 0", "v_mov_b32 v3, 0x3f800000", "s_mov_b32 exec_lo, 1", "ds_write_b32 v1, v2",
         "s_mov_b32 exec_lo, -1", "s_barrier", "ds_add_rtn_f32 v5, v1, v3", "s_barrier", "ds_read_b32 v6, v1",
         "v_lshlrev_b32 v7, 3, v0", "buffer_store_dwordx2 v[5:6], v7, s[0:3], 0 offen", "s_endpgm"]
spv = support.translate_lines("cs_add32", lines, fssm=FSSM)
print("atomic load instructions", spv.count("= OpAtomicLoad"), "CAS", spv.count("= OpAtomicCompareExchange"))
pathlib.Path("../4230-add.spv").write_bytes(spirv_asm.assemble(spv))

AI-assisted.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Tested adf27a10 (main aa2988cc is an ancestor, no rebase needed) on Linux, no game files.

GPU tests (RTX 3080, driver 615.71.09, Vulkan 1.4.351) — identical to main on this machine:

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-20/bin/llvm-mc
    → 195/210 passed, 15 skipped, 0 failed (main: same numbers, same skips).
  • without the variable → 164/210 passed, 46 skipped, 0 failed on both.

Semantic side, which is what your one-line change touches: python -m unittest discover -s tests/semantic

  • your branch: 7457 tests, 8 failures, 2 errors in 291 s;
  • main aa2988cc, same command, same machine: 7456 tests, 8 failures, 2 errors in ~295 s.

One more test (yours) and the same failing set with the same names — test_loop_ballot_barrier (5 cases in the
wave64-emulate modes), test_cmp_class_f64.test_rejected_forms (2), test_mutations on the v_mul_legacy_f32
anchor (2, already looked at in #3883), test_anchors_match_crlf_translator_copies, and test_fma_khr where our
Ubuntu spirv-as (SPIRV-Tools 2025.1~rc1) reports Invalid capability 'FMAKHR', which is a gap on this box.
Your new tests/semantic/test_lds_add_f32.py: 6 tests OK.

Translator pytest side: 1592 passed, 1 failed on your branch, the same 1592 passed, 1 failed on main
(the single failure is test_u16_high_half::test_d16_buffer_store_no_redundant_extract_after_shr16, coming from
aa2988cc and fixed by #3902). python -m compileall -q make_game.py tools tests: clean.

The RTX 5080 was not run in this pass — 186 MiB free on that card (another job holds it here), so I skipped it
rather than post an allocation failure against your change.

Machine: Linux Mint 22 (Ubuntu 24.04 base), llvm-mc 20.1.2, SPIRV-Tools 2025.1~rc1, GCC 13.3, Python 3.12.3 with
pytest 9.2.0 and numpy 2.5.5, built with cmake -S runtime -B runtime/build/linux -DLEONIDA_VULKAN_HEADERS_FETCH=ON.
AI-assisted testing, counts read through by hand.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested adf27a1 (merge base = main aa2988c) on NVIDIA GeForce RTX 5080, driver 580.65.06, Ubuntu 22.04 (Linux): pass

The PR is a one-line translator change (OpLoad -> OpAtomicLoad %uint <ptr> Workgroup None for the initial read in the ds_add_f32 CAS preheader), one new CPU test and a docs row. Merge base is the current main tip, so there is nothing to merge.

Setup

  • Fresh clone, git fetch origin pull/4230/head, checked out the PR head. runtime/ is not touched by the PR, but I built it from the same checkout anyway: cmake -S runtime -B runtime/build/linux -DVulkan_INCLUDE_DIR=<SDK>/include, cmake --build runtime/build/linux -j12 (Vulkan SDK 1.4.363.1, llvm-mc 21), 91/91 targets built.

Commands and results

  • python -I tests/semantic/test_lds_add_f32.py -v: 6 tests OK, including the new test_signed_zeros_and_infinities.
  • All LDS and atomic semantic files, one by one (test_lds_*.py, test_atomic_inc_dec.py, test_global_atomic*.py, test_cs_shared_memory_limit.py, test_ds_permute.py, test_wave64_emulate_opt.py): 39 files, all OK. (Three of them import support and need to run without -I; they pass that way.)
  • python -I -m unittest discover -s tests/semantic: 7457 tests, 7 failures + 2 errors, 1 skipped, 1 expected failure. The same 7 failures and 2 errors (test_cmp_class_f64 test_rejected_forms, test_loop_ballot_barrier, test_mutations v_mul_legacy_f32 anchor) appear on main aa2988c (7456 tests). So nothing new from this PR.
  • python -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-21/bin/llvm-mc --build runtime/build/linux: 164/210 passed, 46 skipped, 0 failed (same as the main baseline).
  • Same with LEONIDA_W64_EMULATE=1: 195/210 passed, 15 skipped, 0 failed (same as the main baseline).
  • Translated a ds_write_b32 + ds_add_rtn_f32 listing with the PR translator: the output contains OpAtomicLoad %uint %t20 %c2 %c0 (Workgroup scope, no semantics) and passes spirv-as + spirv-val --target-env vulkan1.3. Main's output has no OpAtomicLoad and also validates.

Negative control

  • The PR's new test_lds_add_f32.py run against main's tools/rdna2spirv.py also passes (6/6). So the new test does not fail without the translator change. That is expected, since the CPU interpreter treats OpLoad and OpAtomicLoad the same, but the test does not guard the OpAtomicLoad itself.

Not tested

  • No GPU shader in runtime/test/shaders uses ds_add_f32 / ds_add_rtn_f32, so no GPU test runs the changed path. The gfx1036 hardware claims in the new docs row (Windows 11, driver 32.0.21045.29003, FTZ/DAZ of the LDS adder, contention results) cannot be reproduced on an NVIDIA GPU and were not checked.
  • Not tested: Windows, AMD GPUs, other NVIDIA driver versions.

AI-assisted. No game files.

@theswiss24

Copy link
Copy Markdown

Tested adf27a10 merged onto main 03b09a08 (clean) on NVIDIA GeForce RTX 4070 (Ada), driver 621.24, Windows 11 (26300), Python 3.14.2, Vulkan SDK 1.4.363.1, llvm-mc 21.1.8, with test programs built from main 03b09a08: pass.

  • python -I -m unittest discover -s tests/semantic -p test_lds_add_f32.py: 6 tests, OK.
  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build <main build>: 195/210 passed, 15 skipped, 0 failed, the same result on every test as main 03b09a08. That includes the LDS tests, which now go through the OpAtomicLoad preheader.

No game files.

AI-assisted (Claude Code).

@abnalstlll-byte
abnalstlll-byte force-pushed the feat/row341-ds-add-f32-rdna2 branch from adf27a1 to 241b8a7 Compare November 23, 2026 04:15
@kapitche

Copy link
Copy Markdown
Contributor

Tested 241b8a7 merged with main 98fa503 on Linux, Python 3.12.16: fail (docs test)

  • tests/test_docs_design_rows.py fails with this PR and passes on main: rows to fix in docs/design.md (line, cells, header cells): [(367, 4, 3), (368, 4, 3)]. Cause: the diff also rewrites the ds_mskor_b32 row (docs/design.md:367) and the ds_{inc,dec,rsub}_u32 row (368), changing the escaped \| to a bare | in (tmp & ~DATA) | DATA2 and (M == 0 | M > DATA), so each row splits into 4 cells under a 3-cell header. Restoring those two escapes should clear it. The other 9 tests/test_docs_*.py pass.
  • Semantic tests: tests/semantic/test_lds_add_f32.py 6 OK (new test_signed_zeros_and_infinities included), test_lds_atomics_cas 12 OK, test_lds_mskor 4 OK; -p "test_lds*.py" as a whole: 670 tests OK, 4 skipped.
  • Negative control: with tools/rdna2spirv.py restored from main, test_lds_add_f32.py still passes (6 OK). So neither the new test nor the others in that file pin the OpLoad to OpAtomicLoad change at rdna2spirv.py:4023; the CPU interpreter treats them the same.
  • Stale comment: tools/rdna2spirv.py:4013-4015 still says how the LDS adder treats denormals and NaN payloads "is not measured", while the new docs row now reports NaN payload and FTZ results measured on gfx1036.
  • The gfx1036 hardware results in the new row (Windows 11, driver, 0 mismatches, FTZ note) were not re-measured here; no GPU run. Linux only.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 241b8a7 merged onto main 98fa503 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 170/217 passed, 47 skipped, 0 failed. main 98fa503 gives 170/217, 47 skipped, 0 failed. All 221 test shaders translate and pass spirv-val.
  • tests/semantic/test_lds_add_f32.py: ran 6 tests in 1.387s; OK.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested f055624 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.
Ran -I -m unittest discover -s tests/semantic -p test_lds_add_f32.py: 6 tests OK (includes the new signed-zero/inf/NaN test), and all 10 tests/test_docs_*.py OK.
Negative control: with tools/rdna2spirv.py reverted to main, the same file still passes 6/6, so the new test does not detect the OpLoad -> OpAtomicLoad change (it checks values, which the CPU run gives either way). It is a value regression test, not a guard for that line.
Read: sc/sem (Workgroup, semantics 0) are in scope for the new OpAtomicLoad, matching the design.md wording. Minor: the code comment above the ds_add_f32 branch in rdna2spirv.py still says denormal/NaN-payload handling is "not measured", while the doc row now says hardware-verified; I could not check the hardware claim here.

@Tanju42

Tanju42 commented Nov 23, 2026

Copy link
Copy Markdown

Tested f055624c4 (merge base 0db7fed5; merges cleanly onto current main 3faac557 per git merge-tree --write-tree, and tests/test_docs_design_rows.py passes on the simulated merge tip) on Linux Ubuntu 24.04, AMD Ryzen 7 9800X3D iGPU (gfx1036, RADV RAPHAEL_MENDOCINO, Mesa 25.2.8, subgroup 32..64) — native RDNA2, the part row 341's verification claims; this complements @kapitche's head check, which ran the value/semantic suites but could not check hardware. llvm-mc-21 21.1.8, Python 3.12 (system).

Build note: the pinned vulkan-sdk-1.4.363.0 headers are needed (-DVulkan_INCLUDE_DIR override; the Ubuntu libvulkan-dev 1.3.275 headers lack VK_KHR_pipeline_binary, the vk_harness build failure @ray3242 reported). The PR touches no runtime C++, so the same runtime sources as main were built for both runs.

  • scripts/run_gpu_tests.py (device: line verified per run: RADV RAPHAEL_MENDOCINO): 199/217 passed, 16 skipped, 2 failed — identical to current main 3faac557 on this device. Both failures are the two Mesa 25.2.8 bugs already documented in docs/testing.md ("Two Mesa bugs, not translator bugs"): cs_w32_salu64 (our dump 510274632 4660 0 256 47 48 4294934528 4294967294 is word-for-word the recorded ACO row) and cs_signed_zero_nan (NIR range analysis, word 5 0x0 want 1). Unrelated to this PR.

  • tools/lds_fuzz.py seed 1, --programs 100 --wave both: native 200/200 programs match (0 mismatched, 0 skipped, 0 not translated, 0 harness errors); --emulate 200/200. Current main under the same seed and modes: also 200/200 native, 200/200 emulated — the OpLoad -> OpAtomicLoad preheader changes nothing observable for the LDS family on native gfx1036, in either wave mode.

  • tests/semantic/test_lds_add_f32.py: 6 tests pass at head (the new signed-zero/inf/NaN case included).

  • Full semantic suite python3 -m unittest discover -s tests/semantic: 6246 tests, 4 failures + 2 errors — all in test_loop_ballot_barrier.py (5, emulate-mode) and test_fma_khr.py::test_spirv_tools_accept_it (1, spirv-tools acceptance); all six reproduce identically on main 3faac557 on this box (pure CPU interpreter tests), pre-existing, none in a file this PR touches.

  • Full pytest tests/ -q at head (the new tests/test_tex_mode_probe.py excluded: it imports numpy, which this box's system Python lacks — collection error, not PR-specific): 13004 passed, 6 failed, 184 skipped, 1 xfailed (33 min). All six failures — the four semantic ones above plus test_joaat_agreement.py::test_every_copy_matches_the_pinned_dictionary and test_missing_input_exit_codes.py::test_missing_input_is_exit_2_with_one_error_line — reproduce identically on main 3faac557 here. Nothing in the PR's files fails.

Verdict: pass — the GPU behaviour row 341 claims is confirmed on native RDNA2 gfx1036 under RADV (a second driver stack on top of the Windows measurement), and the full GPU suite, the LDS fuzzers and the CPU suites are main-parity.

No game files. AI-assisted.

@lunarminus

Copy link
Copy Markdown

Tested f055624c merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Merge: d0835dd9 is an ancestor of the PR head, so the merge was a fast-forward and the tree tested is f055624c itself. Its base is 0db7fed5, and 0db7fed5..f055624c changes only the PR's 3 files.
  • Test programs: built from a tree whose runtime/ is identical to this head's (HEAD:runtime 4e4623f5).
  • CPU tests:
    • python -m compileall -q make_game.py tools tests: clean.
    • python -I -m unittest discover -s tests/semantic -p test_lds_add_f32.py: 6 tests OK.
    • -p 'test_lds*.py': 670 tests OK.
    • All 10 tests/test_docs_*.py: OK, including test_docs_design_rows.py.
  • scripts/run_gpu_tests.py (device line AMD Radeon 760M Graphics (RADV PHOENIX) (subgroup 32..64)):
    • Without LEONIDA_W64_EMULATE: 202/217 passed, 15 skipped, 0 failed.
    • With LEONIDA_W64_EMULATE=1: 202/217 passed, 15 skipped, 0 failed.
    • Per-test comparison with d0835dd9 without the PR (196/210 passed, 14 skipped in both modes): all 210 baseline result lines have the same PASS/SKIP word in both modes.
    • The 7 extra tests were added on main between d0835dd9 and 0db7fed5, not by this PR: 6 PASS (cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_b_cl, ps_texture_cl) and 1 SKIP (ps_m2_literal).
    • No fixture in runtime/test/shaders uses ds_add_f32 or ds_add_rtn_f32, so the suite does not run the changed line.
  • The changed line, using @shdann's 32-lane ds_add_rtn_f32 shader:
    • Translation: this head emits 1 OpAtomicLoad and 1 OpAtomicCompareExchange; 0db7fed5 and d0835dd9 emit 0 OpAtomicLoad and 1 CAS. All three pass spirv-val.
    • GPU runs: vk_compute_test <spv> 1 dump, 5 runs each at VKC_SUBGROUP_SIZE=32 and =64, for each of the 3 translations. A separate run at each setting printed compute subgroup size 32 and 64.
    • All 30 runs: the 32 returned old values are each of 0..31 exactly once, and all 32 lanes read 32.0 after the barrier. Head and both controls give the same result.
  • tools/lds_fuzz.py --seed 1 --programs 100 --wave both: 200/200 programs match native and 200/200 with --emulate. The same at 0db7fed5. The fuzzer generates no ds_add_f32, so this checks only the rest of the LDS family.
  • Negative control: with the 0db7fed5 translator, test_lds_add_f32.py also passes 6/6. This agrees with the earlier comments: the new test checks values and does not guard the OpLoad → OpAtomicLoad change.
  • Not checked: the gfx1036 / Windows claims in the new docs/design.md row (FTZ/DAZ, NaN payload, driver 32.0.21045.29003), since this machine is gfx1103 under RADV.

No game files.

AI-assisted (Claude Code).

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Re-checked the current head f055624c from this Linux box (RTX 3080, llvm-mc 20.1.2, no game files). My earlier
report was at adf27a10; the new commits since then are documentation and test-side, so I re-ran the Python side
only, not the GPU battery.

  • the 31 pytest-marked translator files, as CI's translator-tests job runs them → 1637 passed, 37 skipped,
    108 subtests, 0 failed
    ;
  • tests/test_cube_sample.py (the file that broke in rdna2spirv: intra-block %vgpr/%sgpr value forwarding #4518) → 18 passed;
  • python -m compileall -q make_game.py tools tests: clean.

The GPU figures I reported at adf27a10 (195/210 with LEONIDA_W64_EMULATE=1, 0 failed, on the 3080) were not
re-measured at this head — if you want the battery re-run on the current tip, say so and I will run it. AI-assisted
testing, counts read through by hand.

@bielfreedom

Copy link
Copy Markdown

Corpus check of f055624c (base 0db7fed5; the translator is the same as 7b7d73f8, which I used as the reference), full game corpus, 26,503 disassembled shaders:

  • 26,503 / 26,503 translated and spirv-val valid on both sides;
  • byte-identical: 0 modules differ, index.json identical.

That is expected. No listing in the corpus contains ds_add_f32 or ds_add_rtn_f32 (0 of 26,503), so the CAS preheader never appears in game shaders. This change is covered only by the semantic and GPU tests.

AI-assisted (Claude Code). Counts only.

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.