Repository navigation
rdna2spirv: a lane mask read as a number is the wave's mask word (SHADER-MASK-AS-DATA) - #1043
thesubtleties wants to merge 3 commits into
Conversation
…DER-MASK-AS-DATA)
|
Independent Linux check (stdlib only, no game/GPU): all four files pass on head 02d6293 — test_mask_as_data 9/9, test_salu64_bitwise_data 11/11, test_salu_movrels_lane_mask 3/3, test_scselect_b64_data 12/12. Same files against the unmodified tools fail 172+9+32+2 respectively, so the tests fully exercise the change. Not claiming; review evidence. |
KernelSmoker
left a comment
There was a problem hiding this comment.
Verified on exact head 02d6293 (base 96e1e22). Focused tests pass: new mask-as-data 9/9; updated SALU64, MOVRELS and SCSELECT regressions 11/11, 3/3 and 12/12; lane-mask, planner and pixel-scan unit suites also pass (including wave64 emulation 31/31). One additional SPIR-V validation test skipped because spirv-as/spirv-val are absent. The full semantic run covered 471 files / 6,174 tests; only test_sopc_validation and test_unary_f16_validation failed, both because those executables are missing, so I do not report the full suite as green. Changed-file no-game-data/diff checks and merge-tree pass. The added docs/design.md contract entry is present. CPU semantic validation only; no local GPU or game-data run.
…how it is read (SHADER-MASK-AS-DATA)
|
Thanks @morodirule and @KernelSmoker. I pushed a second commit, so your checks cover |
|
Tested 68b964e on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, and a GPU before/after with Runtime built with
The base counts are identical to a run of the same seed on
Also at this head: |
|
More evidence on head
The first remaining failure in each is a The wave64 Not tested: the game corpus and RDNA2 console hardware. AI-assisted (Claude Code) |
|
Tested Local translator change. On entry to the scalar bit-scan loop, Reproduce on the PR head with Python onlyFrom the repo root at from collections import Counter
from pathlib import Path
import sys
sys.path.insert(0, str(Path("tests/semantic").resolve()))
import test_wave64_emulate_opt as t
insns = [
('v_cmp_lt_u32_e64 s[8:9], v0, 4', 8),
('s_and_b64 s[8:9], s[8:9], exec', 4),
('s_mov_b32 s20, 0', 4),
('s_cmp_lg_i32 s8, 0', 4),
('s_cbranch_scc0 8', 4),
('s_ff1_i32_b32 s12, s8', 4),
('s_lshl_b32 s12, 1, s12', 4),
('s_xor_b32 s14, s12, s8', 4),
('s_add_u32 s20, s20, 1', 4),
('s_cmp_eq_i32 s8, s12', 4),
('s_cbranch_scc1 2', 4),
('s_mov_b32 s8, s14', 4),
('s_branch 65528', 4),
('v_mov_b32_e32 v6, s20', 4),
('v_lshlrev_b32_e32 v1, 2, v0', 4),
('buffer_store_dword v6, v1, s[0:3], 0 offen', 8),
('s_endpgm', 4),
]
asm, _ = t._translate_encoded("cs_lowword_bitloop", insns, (64, 1, 1), emulate=True)
mem, _ = t.run_emulated_workgroup(asm, (64, 1, 1), push_constants=t.VSHARP + [0] * 28)
print(Counter(mem[4*i] for i in range(64)))For the GPU check, the same |
|
Thanks @MynFriend, I reproduced this in the CPU interpreters at While checking I found a straight-line relative: CPU only. AI-assisted (Claude Code) |
|
Native RDNA2 (gfx1036, GPU suite on this head: the only failures are the two |
|
Rebased by merging main Semantic suite: 488 files / 6,292 tests, 0 failed. GPU suite on the 3080 and gfx1036, native and emulated: per-test identical to main. Earlier approvals cover older heads. #1397 overlaps; I commented there. AI-assisted (Claude Code) |
…er reads Review fixes for the mask-as-data change: - The wave-mask gather is a group op over the lanes EXEC leaves active, and drivers differ on whether lanes EXEC has off still vote: NVIDIA, AMD and KosmicKrisp return the whole subgroup's bits, MoltenVK's ballot/reduce saw only the lanes a narrowed EXEC left on and produced the EXEC value instead of the frozen mask word (cs_mask_vgpr_exec). mask_word_read_ok now gathers only when a CFG must-analysis (mark_exec_state) proves every lane that can hold a set bit of the mask is EXEC-active at the read: each EXEC half is tracked as clean, a constant mask, or an unknown narrowing (s_mov/s_cselect resolve constants, saved-EXEC aliases and unchanged EXEC, so the common restore idioms still gather), and mask_exec_sigs records every EXEC state seen while each mask register held a mask. Unproven reads keep this lane's 0 / ~0 bit, the pre-change answer. - Scalar number ops read a lane mask operand as data too (MASK_NUMBER_READERS, ProjectLeonida#1043's NUMBER_READERS): s_add_u32 s20, s10, K after v_cmp wrote s10 yields the wave's mask word, while mask moves and mask logic ops keep this lane's bit for the saveexec idioms. - wave64_emulate_opt treats ins["mask_words"] (a mask read that will gather) as a cross-lane exchange for the lane-local fold planner and barrier scheduler, covering the scalar readers as well. - test_slot67_operand_forms' expectedFailure comes off: the packed vcc_hi word now reaches the data read. Co-Authored-By: Devin <noreply@cognition.ai>
…er reads Review fixes for the mask-as-data change: - The wave-mask gather is a group op over the lanes EXEC leaves active, and drivers differ on whether lanes EXEC has off still vote: NVIDIA, AMD and KosmicKrisp return the whole subgroup's bits, MoltenVK's ballot/reduce saw only the lanes a narrowed EXEC left on and produced the EXEC value instead of the frozen mask word (cs_mask_vgpr_exec). mask_word_read_ok now gathers only when a CFG must-analysis (mark_exec_state) proves every lane that can hold a set bit of the mask is EXEC-active at the read: each EXEC half is tracked as clean, a constant mask, or an unknown narrowing (s_mov/s_cselect resolve constants, saved-EXEC aliases and unchanged EXEC, so the common restore idioms still gather), and mask_exec_sigs records every EXEC state seen while each mask register held a mask. Unproven reads keep this lane's 0 / ~0 bit, the pre-change answer. - Scalar number ops read a lane mask operand as data too (MASK_NUMBER_READERS, ProjectLeonida#1043's NUMBER_READERS): s_add_u32 s20, s10, K after v_cmp wrote s10 yields the wave's mask word, while mask moves and mask logic ops keep this lane's bit for the saveexec idioms. - wave64_emulate_opt treats ins["mask_words"] (a mask read that will gather) as a cross-lane exchange for the lane-local fold planner and barrier scheduler, covering the scalar readers as well. - test_slot67_operand_forms' expectedFailure comes off: the packed vcc_hi word now reaches the data read. Co-Authored-By: Devin <noreply@cognition.ai>
|
RTX 3090 / 621.40, crosslane fuzz with maskdata, seed 309700: mismatches go 56+29 -> 12+9 (w32+w64) with this PR. Remaining are still mask-as-data, e.g. cs_xl32_30970929176 (native, group 50): minimized reprov_cmp_gt_u32_e64 s18, v7, v7
s_mov_b32 exec_lo, 0x110c5
v_mov_b32_e32 v6, s18
v_readfirstlane_b32 s14, v6s14: expected 0x00000000; threads 0-31 got 0xfffeef3a, threads 32-49 got 0x0002ef3a. |
|
Fix for the remaining mismatches: thesubtleties:mask-as-data...ammonium231:fix-1043-number-moves (on top of this PR, 4 files, +123/-10). number_moves dropped a plain v_mov of a mask when a later v_readfirstlane / v_and read the copy, so inactive lanes leaked into the mask. RTX 3090 fuzz, 2000 programs/seed, --dpp --ext: 309700 984/12/4 + 989/9/2 -> 1000/1000 both waves; held-out 309900 (36 failing) and 310100 (29 failing) -> 0, no new failures. Semantic suite 6296/0. |
|
Checked 4d58a05 merged into main 2859d0c (merges cleanly), by Claude Code (AI-assisted) on my behalf. Linux,
Not run: a hardware GPU, native wave32. Generated by Claude Code |
Claimed in the coordination issue as: SHADER-MASK-AS-DATA
What and why
A lane mask is one word for the wave on hardware; the translator keeps each lane's own 0 / ~0. An op that read the mask as a number therefore got a different wrong value per lane, with no error: with mask
0x3ff,s_add_u32 d, mask, 1was 0 or 1 andv_mov_b32 v, maskwas 0 or ~0 (crosslane_fuzz.py"maskdata", the old #293).s_bcnt/s_ff/s_flbitalready rebuild the word. This does the same for:lane_masks.NUMBER_READERS);v_mov_b32of a mask, when nov_readfirstlane_b32or vector bitwise op reads that value as a mask. Each copy is followed forward, through VGPR-to-VGPR copies (second commit).The emulation planner counts such an op as an exchange, it never joins an active run, and
wave32_pixel_scan.pycounts it asmask_word.Partial on purpose. Not covered: the values excluded above (the v_mov / v_or3 / v_readfirstlane idiom needs each lane's own bit), compares, SDWA and DPP, and 16-bit, float and 64-bit ops.
Three existing tests changed:
test_salu_movrels_lane_mask,test_scselect_b64_dataandtest_salu64_bitwise_dataread a mask back withv_mov_b32and expected the lane's own 0 / ~0; they now expect the mask word.Tested
Measured on base
82a2aabc, then rebased; the semantic suite and the touched tests were rerun after the rebase.tests/semantic/test_mask_as_data.py(wave32, native wave64, partial EXEC, the through-a-VGPR idiom, emulated translation): fails onmain, passes here.run_semantic_tests.py: 0 files failed.crosslane_fuzz.py, hard mismatches, main -> this PR; no program fails here that passed on main:--ext, seed 880606 (300), 3080 and gfx1036--ext, seed 880707 (300), gfx1036The 880xxx main rows were run on
98a977b4. With--no-maskdatathere are no hard mismatches there on main. Correction: the first version of this text said the remaining mismatches werev_readfirstlanereads. Minimizing them showed most came from a plain VGPR-to-VGPR copy that the first commit counted as a mask read; the second commit fixes that. What is left on wave32 seeds 991201, 991202 and 993301 (11 mismatches, plus 4 programs with a hypothesis op) is now minimized on the 3080: every reduction contains av_mov_b32of a mask into a VGPR that av_readfirstlane_b32or a vector bitwise op then reads, the idiom this PR leaves alone. The shortest isv_cmp_ne_u32_e32 vcc_lo, 9, v6/v_mov_b32_e32 v2, vcc_lo/v_readfirstlane_b32 s8, v2. The wave64 leftovers (seed 880606 emulated on the 3080, seed 880707 native on gfx1036) minimize to the same idiom. Caveat: two hard reductions stayed at 14 and 17 lines, where the pattern is present but not shown to be the cause, and the six programs with a hypothesis op (4 wave32, 2 wave64 native) are not explained.cf_diff.py: 2,000 programs on the second commit (wave32 and wave64), 0 mismatches.run_gpu_tests.py: per-test results identical to main: 3080 201/252, 3080 emulated 233/252, gfx1036 234/252, gfx1036 emulated 234/252; only the two known tfe fixtures fail (AMD Radeon 780M (RDNA3 iGPU, driver 26.10.2): cs_imgload_tfe and cs_imgload_d16_tfe fail on main - the tfe fetch status VGPR is read but never written #31). Rerun on the second commit.GPUs tested: NVIDIA RTX 3080 (620.73.04) and AMD RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS Linux 7.3.5
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.