wave64_emulate_opt: a mask pair with one constant half is a lane mask to the planner (OLD-4480) #160

Manually merged
github merged 1 commit from gh-pr/160/head into gh-pr/160/base 2026-11-26 08:46:55 +00:00
Owner

@⁠ItsMrDubey on GitHub · 2026-11-24 02:32 UTC · original
ItsMrDubey:wave64-planner-const-half → main · +65 −1 · 3 files · 1 commits · merged 2026-11-24 03:27 UTC

Claimed in the coordination issue as: OLD-4480 (#14)

What and why

Old #4480: in wave64 mode, the --wave64-emulate planner (tools/wave64_emulate_opt.py, which decides which s_cbranch_execz regions it can fold and where barriers can happen) did not count an SGPR pair as a lane mask when one half was a mask and the other half was a constant. Examples are v_cmp_* s[4:5] followed by s_mov_b32 s5, 0, or s_mov_b64 s[12:13], -1 followed by s_mov_b32 s13, s5. Its _holds_lane_mask required both words to be in the lane_masks map. That map has no constant (EITHER) entries. The translator's Gen.holds_lane_mask, on the other hand, accepts one mask word plus one 0 / -1 word. Because the planner missed the mask, it folded a region with an s_bcnt1_i32_b64 on such a pair as lane-local. The translator then emitted the cross-lane x_split inside the fold, and translate() failed with AssertionError: wave64 emulation: x_split inside a folded lane-local region.

The fix: for a 64-bit SGPR pair, the planner now treats one mask word as enough. The planner's map does not record constants, so a pair with a mask word and a data word is also counted. That is conservative: it can only cost a fold, never let an unsafe fold through. This matches how the planner already treats slist pairs.

This PR does not add or change a translator rule; the translator's output for these instructions is unchanged. It only makes the planner agree with the translator.

Tested

Windows 11, Python 3.11.9, no GPU needed. Checked with the CPU interpreter only; no GPU was available.

  • New hand-written fixture tests/semantic/fixtures/wave64_mask_const_half.asm (both shapes above, counted with s_bcnt1_i32_b64 inside an execz region). The new test in test_wave64_emulate_opt.py runs it under --wave64-emulate on the strict 64/128-thread barrier interpreter and expects (8, 40) for threads >= 16 and (0, 0) below. Native wave64 (no emulate) gives the same words on run_compute_workgroup, both before and after the fix.
  • python -I tests/semantic/test_wave64_emulate_opt.py: before the fix 3 failures (the new test at 64 and 128 threads hits the assertion above; the new _holds_lane_mask unit checks); after it 31 tests OK.
  • python -I scripts/run_semantic_tests.py tests/semantic: 463 files, 6076 tests, 4 files failed: test_exec_computed, test_image_atomics_guard, test_sopc_validation, test_unary_f16_validation (the same four fail on main on this machine; none touch the planner).
  • python -I scripts/check_no_game_data.py on the three changed/added files: clean.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • No new translator rule, so nothing to add to the contract table of docs/design.md (planner/translator agreement fix; confirmed on the CPU interpreter).
**@⁠ItsMrDubey** on GitHub · 2026-11-24 02:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/160) `ItsMrDubey:wave64-planner-const-half` → `main` · +65 −1 · 3 files · 1 commits · merged 2026-11-24 03:27 UTC Claimed in the coordination issue as: OLD-4480 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Old #4480: in wave64 mode, the `--wave64-emulate` planner (`tools/wave64_emulate_opt.py`, which decides which `s_cbranch_execz` regions it can fold and where barriers can happen) did not count an SGPR pair as a lane mask when one half was a mask and the other half was a constant. Examples are `v_cmp_* s[4:5]` followed by `s_mov_b32 s5, 0`, or `s_mov_b64 s[12:13], -1` followed by `s_mov_b32 s13, s5`. Its `_holds_lane_mask` required both words to be in the `lane_masks` map. That map has no constant (EITHER) entries. The translator's `Gen.holds_lane_mask`, on the other hand, accepts one mask word plus one 0 / -1 word. Because the planner missed the mask, it folded a region with an `s_bcnt1_i32_b64` on such a pair as lane-local. The translator then emitted the cross-lane x_split inside the fold, and `translate()` failed with `AssertionError: wave64 emulation: x_split inside a folded lane-local region`. The fix: for a 64-bit SGPR pair, the planner now treats one mask word as enough. The planner's map does not record constants, so a pair with a mask word and a data word is also counted. That is conservative: it can only cost a fold, never let an unsafe fold through. This matches how the planner already treats `slist` pairs. This PR does not add or change a translator rule; the translator's output for these instructions is unchanged. It only makes the planner agree with the translator. ### Tested Windows 11, Python 3.11.9, no GPU needed. Checked with the CPU interpreter only; no GPU was available. - New hand-written fixture `tests/semantic/fixtures/wave64_mask_const_half.asm` (both shapes above, counted with `s_bcnt1_i32_b64` inside an execz region). The new test in `test_wave64_emulate_opt.py` runs it under `--wave64-emulate` on the strict 64/128-thread barrier interpreter and expects (8, 40) for threads >= 16 and (0, 0) below. Native wave64 (no emulate) gives the same words on `run_compute_workgroup`, both before and after the fix. - `python -I tests/semantic/test_wave64_emulate_opt.py`: before the fix 3 failures (the new test at 64 and 128 threads hits the assertion above; the new `_holds_lane_mask` unit checks); after it 31 tests OK. - `python -I scripts/run_semantic_tests.py tests/semantic`: 463 files, 6076 tests, 4 files failed: test_exec_computed, test_image_atomics_guard, test_sopc_validation, test_unary_f16_validation (the same four fail on main on this machine; none touch the planner). - `python -I scripts/check_no_game_data.py` on the three changed/added files: clean. AI-assisted: yes ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] No new translator rule, so nothing to add to the contract table of `docs/design.md` (planner/translator agreement fix; confirmed on the CPU interpreter).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:46:53 +00:00
github manually merged commit bed6382f78 into gh-pr/160/base 2026-11-26 08:46:55 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.