Commit Graph

4 Commits

Author SHA1 Message Date
9e085fa6c3 rdna2spirv: eliminate absent-lane subgroup UB and add static/GPU checks
Guard all cross-lane subgroup shuffles and broadcasts against unlaunched
lanes, eliminate %uint_0 fallbacks in favor of SubgroupLocalInvocationId,
and add static SPIR-V verifier (check_absent_lane_ub.py), wave-interpreter
unit tests, and a Vulkan GPU validation test.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 21:00:08 -05:00
14887e6828 Translator: honour V# OOB_SELECT in MUBUF/MTBUF bounds checks
buffer_address() picked the bounds check from the stride alone and never read
word3. It now reads OOB_SELECT (bits 29:28) and applies the rule measured
natively on RDNA2 (gfx1036, docs/buffer_bounds.md; Mesa's GFX11 column): a
dword is out of range in mode 0 at idx >= NR or off + 4 > stride, mode 1 at
idx >= NR, mode 2 at NR == 0, mode 3 (RAW) at offs + 4 > NR, where off is
inst_offset + vaddr and offs adds soffset. A literal word3 folds the mode, a
run-time one selects with OpSelect.

Builds on the raw tail rule of #443 (per-dword loads): x2..x4 loads AND stores
are per dword in modes 0 and 3 (a store that straddled the edge used to write
past it), modes 1 and 2 take the whole access, a typed element
(buffer_load/store_format) is all or nothing at its format's size, an atomic
checks its dword's end. Measured on a Radeon 880M (gfx1150), a valid proxy for
RDNA2: 504 buffer_load_dword cases over idxen/offen/inst_offset/soffset at the
stride and record edges agree with the rules, plus the x2/x4, typed and atomic
edges.

Swizzle (V# word1 bit 31 SWIZZLE_ENABLE, word3 bit 23 ADD_TID_ENABLE; Mesa
gfx10-rsrc.json lines 326 and 337): a literal V# with either is Unsupported in
every mode; a run-time one is translated unswizzled (documented known gap).

A V# with word3 = 0 is mode 0 / stride 0 and so always out of range, as on
hardware: the harness output V# (vk_compute_test, interpreter push constants),
cs_bounds, cs_fmt_1010102, cs_store, mem_diff and the format tests now say
OOB_SELECT 3 (or 1 with a stride) explicitly.

Tests: tests/semantic/test_buffer_oob_select.py (33 hand-tabulated cases plus
multi-dword stores, typed elements and the swizzle gate, literal and run-time
V#), GPU tests cs_oob_select.asm and cs_oob_tail.asm (the second tells the end
check from Mesa's GFX10 start check). docs/design.md, Buffer bounds checking,
has the per-mode rule; docs/buffer_bounds.md notes the translator reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 07:40:20 +01:00
87c56d2d8a tests: record the RTX 4070 SUPER measurement of the wave64 wrap model
Without --wave64-emulate, vk_compute_test on cs_w64x_readlane, _writelane and
_bpermute (NVIDIA GeForce RTX 4070 SUPER, subgroup 32, driver 610.88, Vulkan
SDK 1.4.363.0, llvm-mc 21.1.8 in WSL) wrote exactly WRAP32_EXPECTED: 24 of 24
words. With LEONIDA_W64_EMULATE=1, scripts/run_gpu_tests.py passes 42/44 on
the same GPU (cs_wavemask and ps_vcc_x2 skip).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 16:51:03 -06:00
2fde230ea2 tests: run wave64 cross-half lane ops across 64 lanes of the translated SPIR-V
spirv_mini_interp gains run_workgroup: invocations run in lockstep and meet at
OpGroupNonUniformShuffle (Subgroup scope), with an explicit subgroup size. A
shuffle from a lane outside the subgroup raises UndefinedResult, or wraps
mod the subgroup size on request (the issue #94 symptom, a model and not the
spec). A shift by at least the bit width is now an undefined value that only
raises when used: v_mbcnt computes 1 << lane for lanes >= 32 and selects it
away, which is valid SPIR-V.

test_wave64_cross_half translates cs_w64x_readlane, cs_w64x_writelane and
cs_w64x_bpermute (no --wave64-emulate):
- one 64-wide subgroup: all 24 words equal check.py's GPU values;
- two 32-wide subgroups: bpermute and the writelane writes stay exact, a
  cross-half readlane is undefined; the wrap model gives the words a 32-wide
  GPU without emulation is predicted to show;
- SPIR-V sabotages (readlane lane & 31, bpermute without its half base) must
  change the 64-wide result.

CPU only (Windows 11, Python 3.11.9): 382 semantic tests pass. Not yet
measured on a GPU. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 16:51:03 -06:00