Repository navigation
Translator: order scalar loads with the wave's stores under --wave64-emulate (#1587) - #1716
Conversation
…emulate (ItsNotRexed#1587) x_memory_order cut a round at buffer/image accesses that conflict within a segment, but left s_load/s_buffer_load out, so a buffer_store and a later scalar load of the same address shared a segment and the half of the emulated wave in the other subgroup could load before this half stored. valu_fuzz --family mem --emulate showed it as lanes 32-63 reading the fill pattern. A scalar load now counts as a buffer read (RAW and WAR start a new round); loads alone still share one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IAmNotSiob
left a comment
There was a problem hiding this comment.
nice catch, an s_load reading memory the other half hasn't stored yet is exactly what lanes 32-63 seeing the fill pattern would look like. treating s_load/s_buffer_load as reads in the conflict check is the minimal fix. semantic tests pass merged with main ^^ AI-assisted review (Claude Code).
|
Tested 5816d32 on AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1, subgroup 32..64) and NVIDIA GeForce RTX 5080 (616.92, subgroup 32), Windows 11 10.0.26200: pass. The GPU race itself did not reproduce on either card, so the GPU runs show no regression but not the fix. Runtime build from a recent main (the PR changes no runtime C++),
Diff skimmed: the change is limited to AI-assisted. |
|
GPU run on the hardware you asked for — NVIDIA this time: RTX 4080 (Ada, subgroup 32..32), driver 617.14, Windows 11 Pro 10.0.26200.
The race does not reproduce on this card even before the fix — unlike @EmreO33's RTX 5060 (5/5 failing) and the RDNA1/RADV report in #1587, this 4080/617.14 combination runs main's single-segment ordering clean on all 53 before-programs. So the window is timing- or driver-dependent between NVIDIA generations too; the before-data point may still be useful for whoever characterises it. With the fix: the branch is clean on the same commands plus the 200-program run, the new AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine. |
|
GPU check on AMD Radeon RX 9070 (RDNA4, gfx1201, wave32 and native wave64), Windows 11, Vulkan SDK 1.4.363. Tested this PR's head 5816d32 merged onto
My first run reported Disclosure: tested with an AI assistant (Claude Code); runs done on my machine. |
|
Tested 5816d32 on Apple M1 (16 GB, 32-wide subgroups), Homebrew MoltenVK 1.4.2, macOS 27.0.1, Python 3.14.7: pass. As on the RX RDNA2 iGPU / RTX 5080 / RTX 4080 runs above, the race does not reproduce here even on main, so this shows no regression, not the fix.
|
|
A before/after that reproduces on Ada. The race shows on main here and is gone with this branch. Setup: RTX 4070 Ti SUPER (Ada, subgroup 32), driver 32.0.16.1088 (Windows), Windows 11.
The failing words are all The 0xeeeeeeee fill means the second half's scalar load ran before the first half's store, which is the ordering this PR fixes. Print the program with (AI-assisted run; synthetic fuzzer programs, no game files.) |
|
Tested 5816d32 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression. A Turing datapoint for the emulated path this PR changes. Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.
AI-assisted run (Claude). Synthetic programs only, no game files involved. |
|
The race reproduces on NVIDIA after all — and the fix kills it. RTX 4080 (Ada, subgroup 32..32), driver 617.14, Windows 11 Pro 10.0.26200, Python 3.12.10, llvm-mc 21.1.8 native. My earlier comment said seeds 1/7/5 ran clean on this card; seed 8 (
On this branch ( Reproduce before/after with AI-assisted (ZCode agent): the runs were executed by a coding agent on this machine. |
|
Ampere before/after verification: the #1587 race reproduces deterministically (10/10) on Setup: NVIDIA GeForce RTX 3060 Ti (Ampere, subgroup 32..32), driver
AI-assisted. |
Fixes #1587
Item: #1587 (no tracker ID yet; claimed in #1548)
What: Under
--wave64-emulate,Gen.x_memory_ordernow treatss_load*/s_buffer_load*as buffer-memory reads. Abuffer_storefollowed by a scalar load of the same wave (read after write), or a scalar load followed by a store (write after read), now runs in separate rounds, so the workgroup barrier between rounds orders them. Loads alone still share a round, and the native (non-emulated) output doesn't change. Thedocs/design.mdcontract row "Wave64 emulation" drops "not ordered: scalar loads of memory the wave wrote" and records the rule and how it was confirmed. New test:tests/semantic/test_w64x_scalar_load_order.py(+ README entry).Why: The bug is in the translator. The generator,
cpu_refand the emulatedv_readfirstlane_b32are all correct.valu_fuzz's model (f = t - t % wave, lane 0 of the whole 64-lane wave) matches the hardware. The emulatedv_readfirstlane_b32already reads the first active lane of the whole wave through%x_buf(rdna2spirv.py,v_readfirstlane_b32underif self.emulate), so both halves get slot 0 and the reporter's guess (32 in the second half) doesn't hold. The actual cause is memory ordering. On hardware the wave issuesbuffer_store→s_waitcnt vmcnt(0)→s_buffer_loadin order, so lane 0's store is done before the wave's scalar load. In the emulation the two halves can be two 32-wide subgroups that only synchronise at the barrier between rounds.x_memory_ordercut rounds at conflicting vector/LDS accesses but left scalar loads out (its docstring and design.md said so). So the store and the scalar load shared a segment, and lanes 32–63 could load before lane 0 had stored, which gives the fill pattern0xeeeeeeee, as seen on RDNA1/RADV (#1587) and on the RTX 5060 (@EmreO33's comment).Tested (RX 7900 XTX, AMD 26.10.1 LLPC, Windows 11 Pro, Ryzen 9 5900X):
python -m compileall -q make_game.py tools tests,python -I make_game.py --help: OKpython -m unittest discover -s tests/semantic): 1343 OKtest_w64x_scalar_load_order.py: 5/5 with the fix; with upstream/main'srdna2spirv.py(viaLEONIDA_TOOLS_DIR) 3/5 fail (store→s_load, store→s_buffer_loadat thev_readfirstlaneslot,s_load→store each land in one segment)tests/test_valu_fuzz.py: 66 passed, 6 skipped;tests/test_translate.py: 435 passed, 2 skipped (llvm-mc 21.1.8 AMDGPU, SPIRV-Tools from Vulkan SDK)valu_fuzz.py --family mem --seed 5 --programs 21 --wave 64 --emulate: 21/21 before and after (3 runs each). The race doesn't show on RDNA3. After the fix also--seed 1 --programs 33 --wave 64 --emulate33/33 and native--wave 6421/21.Not covered: a GPU reproduction where the race shows. @bobcatchris, could you run the before/after on your V540s (RDNA1/RADV)?
--family mem --seed 5 --programs 21 --wave 64 --emulateand--seed 7 --programs 20 ..., with upstream/main and with this branch. @EmreO33's RTX 5060 command (--seed 1 --programs 33 --wave 64 --emulate, 5/5 failing) would confirm it on NVIDIA too. Not measured: how many extra rounds this costs on the game corpus (no work folder on this PC). The extra round only appears where a scalar load and a buffer store conflict inside one segment. Sampling an image the wave wrote is still not ordered (unchanged).Depends on: none (#1608 edits next to
x_memory_orderbut not the same lines)Game files: none
— Claude Opus 5.5 (high effort), AI-assisted
🤖 Generated with Claude Code