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 1 commit into
ItsNotRexed:mainfrom
abnalstlll-byte:feat/row341-ds-add-f32-rdna2
Open

abnalstlll-byte wants to merge 1 commit 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

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

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.

6 participants