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

Closed
opened 2026-11-26 20:17:09 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/160
Author: @ItsMrDubey
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: wave64-planner-const-half


📝 Commits (1)

  • bed6382 wave64_emulate_opt: an SGPR pair with one mask half and one constant half counts as a lane mask

📊 Changes

3 files changed (+65 additions, -1 deletions)

View changed files

➕ tests/semantic/fixtures/wave64_mask_const_half.asm (+24 -0)
📝 tests/semantic/test_wave64_emulate_opt.py (+34 -0)
📝 tools/wave64_emulate_opt.py (+7 -1)

📄 Description

Claimed in the coordination issue as: OLD-4480 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964)

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/160 **Author:** [@ItsMrDubey](https://github.com/ItsMrDubey) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `wave64-planner-const-half` --- ### 📝 Commits (1) - [`bed6382`](https://github.com/ubiquitarianism/leonida/commit/bed6382f78cdc0265e58bc70cf1e3b70afac6efb) wave64_emulate_opt: an SGPR pair with one mask half and one constant half counts as a lane mask ### 📊 Changes **3 files changed** (+65 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `tests/semantic/fixtures/wave64_mask_const_half.asm` (+24 -0) 📝 `tests/semantic/test_wave64_emulate_opt.py` (+34 -0) 📝 `tools/wave64_emulate_opt.py` (+7 -1) </details> ### 📄 Description Claimed in the coordination issue as: OLD-4480 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964) ### 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:09 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#210
No description provided.