W64-APPEND-CONSUME-BARRIER-REGRESSION: guard one-wave branch barriers #2803

Merged
thiefyzheng merged 1 commit from upstream-pr/2803 into main 2026-12-01 08:17:52 +00:00
thiefyzheng commented 2026-12-01 00:15:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by thiefyzheng on 2026-12-01T00:15:22Z.


Claimed in the coordination issue as: W64-APPEND-CONSUME-BARRIER-REGRESSION (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7296006442)

What and why

Adds a mutation-sensitive regression test for ds_append / ds_consume through the Wave64 optimizer. In a 128-thread shader only wave 0 enters the SCC branch; the wave-wide LDS counter operation requires an isolated mini-scheduler and real workgroup barriers. The test checks the structured-hybrid plan, mini-scheduler, emitted OpControlBarriers, and the append/consume atomic operation.

Previously, restoring the source to its pre-classifier form left all 31 PR tests green (finding: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7288312704). This shape fails when either classifier entry is removed instead of merely restating the classifier membership.

Tested

  • Linux, CPU-only: python3 -I tests/semantic/test_wave64_emulate_opt.py — 36 tests, OK.
  • Independent red controls: removing ds_append alone and ds_consume alone from _ALWAYS_BARRIER_OPS (and clearing the metadata cache) each makes its new subtest fail at rdna2spirv.py: unexpected OpControlBarrier in sync-free multi-wave block. Restoring the entries gives the green result above.
  • Independent read-only worker review found no correctness or test-isolation defects and reproduced both mutation failures.
  • python3 -m compileall -q tests/semantic/test_wave64_emulate_opt.py, scripts/check_no_game_data.py on the changed file, and git diff --check: clean.
  • Full no-game-data semantic suite: python3 -I scripts/run_semantic_tests.py tests/semantic — 553 files, 6,721 tests, 0 files failed in 386 s with 8 jobs. No hardware shader corpus/GPU comparison performed.

GPUs tested: n/a (synthetic CPU translation only)
AI-assisted: yes (Kimi K3.1 Pro lead, GLM 5.3 Flash review)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5576226649 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803). Originally posted by [thiefyzheng](https://github.com/thiefyzheng) on 2026-12-01T00:15:22Z. --- Claimed in the coordination issue as: W64-APPEND-CONSUME-BARRIER-REGRESSION (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7296006442) ### What and why Adds a mutation-sensitive regression test for `ds_append` / `ds_consume` through the Wave64 optimizer. In a 128-thread shader only wave 0 enters the SCC branch; the wave-wide LDS counter operation requires an isolated mini-scheduler and real workgroup barriers. The test checks the structured-hybrid plan, mini-scheduler, emitted `OpControlBarrier`s, and the append/consume atomic operation. Previously, restoring the source to its pre-classifier form left all 31 PR tests green (finding: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7288312704). This shape fails when either classifier entry is removed instead of merely restating the classifier membership. ### Tested - Linux, CPU-only: `python3 -I tests/semantic/test_wave64_emulate_opt.py` — **36 tests, OK**. - Independent red controls: removing `ds_append` alone and `ds_consume` alone from `_ALWAYS_BARRIER_OPS` (and clearing the metadata cache) each makes its new subtest fail at `rdna2spirv.py`: `unexpected OpControlBarrier in sync-free multi-wave block`. Restoring the entries gives the green result above. - Independent read-only worker review found no correctness or test-isolation defects and reproduced both mutation failures. - `python3 -m compileall -q tests/semantic/test_wave64_emulate_opt.py`, `scripts/check_no_game_data.py` on the changed file, and `git diff --check`: clean. - Full no-game-data semantic suite: `python3 -I scripts/run_semantic_tests.py tests/semantic` — **553 files, 6,721 tests, 0 files failed in 386 s with 8 jobs**. No hardware shader corpus/GPU comparison performed. GPUs tested: n/a (synthetic CPU translation only) AI-assisted: yes (Kimi K3.1 Pro lead, GLM 5.3 Flash review) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here.
OreoFR commented 2026-12-01 00:20:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T00:20:07Z.


Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head 8aada4fc2, main b7a1be296. CPU only, synthetic translation.

MEASURED

  • This PR only adds a test, so red and green run the same code: tests/semantic/test_wave64_emulate_opt.py gives 36 passed, 40 subtests passed, both on main + this test and on main + the PR (merge-tree).
  • Mutations, each run on the PR head:
    • Without "ds_append" in _ALWAYS_BARRIER_OPS (tools/wave64_emulate_opt.py:137): 1 failed, 35 passed. The failure is test_append_consume_in_one_wave_branch_keeps_workgroup_barriers (op='ds_append'), with unexpected OpControlBarrier in sync-free multi-wave block.
    • Without "ds_consume": 1 failed, 35 passed. Same test, subtest op='ds_consume', same message.
  • So each classifier entry is now pinned by its own subtest, and no other test notices either removal, which matches the gap you cite.

READ IN CODE

  • _ALWAYS_BARRIER_OPS is used at wave64_emulate_opt.py:316 (op in _ALWAYS_BARRIER_OPS), which is the path the mutation changes.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7296213465 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803#issuecomment-7296213465). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-12-01T00:20:07Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head `8aada4fc2`, main `b7a1be296`. CPU only, synthetic translation. **MEASURED** - This PR only adds a test, so red and green run the same code: `tests/semantic/test_wave64_emulate_opt.py` gives 36 passed, 40 subtests passed, both on main + this test and on main + the PR (merge-tree). - Mutations, each run on the PR head: - Without `"ds_append"` in `_ALWAYS_BARRIER_OPS` (`tools/wave64_emulate_opt.py:137`): 1 failed, 35 passed. The failure is `test_append_consume_in_one_wave_branch_keeps_workgroup_barriers (op='ds_append')`, with `unexpected OpControlBarrier in sync-free multi-wave block`. - Without `"ds_consume"`: 1 failed, 35 passed. Same test, subtest `op='ds_consume'`, same message. - So each classifier entry is now pinned by its own subtest, and no other test notices either removal, which matches the gap you cite. **READ IN CODE** - `_ALWAYS_BARRIER_OPS` is used at `wave64_emulate_opt.py:316` (`op in _ALWAYS_BARRIER_OPS`), which is the path the mutation changes. AI-assisted: Claude Code
thiefyzheng commented 2026-12-01 00:25:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by thiefyzheng on 2026-12-01T00:25:17Z.


Additional local verification on the same head 8aada4fc2d012a22081383911a36c18f77b58eb1: full python3 -I scripts/run_semantic_tests.py tests/semantic completed with 553 files, 6,721 tests, 0 files failed in 386 s using 8 jobs. Still no GPU or hardware-corpus run; this is the no-game-data synthetic suite.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7296314560 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803#issuecomment-7296314560). Originally posted by [thiefyzheng](https://github.com/thiefyzheng) on 2026-12-01T00:25:17Z. --- Additional local verification on the same head `8aada4fc2d012a22081383911a36c18f77b58eb1`: full `python3 -I scripts/run_semantic_tests.py tests/semantic` completed with **553 files, 6,721 tests, 0 files failed in 386 s using 8 jobs**. Still no GPU or hardware-corpus run; this is the no-game-data synthetic suite.
fiestorra commented 2026-12-01 01:16:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T01:16:29Z.


Verified on Windows, and the test does what its comment claims: it catches a mutation that the other 35 tests in the file do not.

The PR only adds a test, so the check that matters is not "do the tests pass" - they pass on the base too, which is what scripts/red_green.py correctly reported as verdict: no red. The check is whether the new test catches the change it was written for. So I made the change it names, in tools/wave64_emulate_opt.py:141 only:

-    "ds_append", "ds_consume",

Result, at this head, main d920d850d plus the PR:

the new test, with the mutation:     2 failed, 1 passed      <- ep_append and ds_consume subtests
the other tests, same mutation:     35 passed, 38 subtests  <- they do not notice

So the comment's sentence - "Removing either op from _ALWAYS_BARRIER_OPS let every existing test pass even though this shape reaches the sync-free-block assertion" - is exactly right, and this is the test that stops it. Both subtests fail independently, which is what the for op in (...) loop is for.

What I could not verify: that the shape reaches the real assertion in a real translation - the test asserts spv.count("OpControlBarrier") >= 3 and the plan's steps, not that a later stage rejects it. That is enough for the claim as written ("keeps workgroup barriers"), and it is not the same as proving the sync-free-block path fires.

One note on my first attempt, since it is a trap: I removed the ops by matching the text, and that also hit a second set ("ds_consume", "ds_append", "ds_ordered_count",), which made the "other tests" arm fail and would have made me report the opposite conclusion. The precise cut is the line in _ALWAYS_BARRIER_OPS and nothing else.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7297307417 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803#issuecomment-7297307417). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-01T01:16:29Z. --- **Verified on Windows, and the test does what its comment claims: it catches a mutation that the other 35 tests in the file do not.** **The PR only adds a test, so the check that matters is not "do the tests pass" - they pass on the base too, which is what `scripts/red_green.py` correctly reported as `verdict: no red`. The check is whether the new test catches the change it was written for.** **So I made the change it names, in `tools/wave64_emulate_opt.py:141` only:** ```python - "ds_append", "ds_consume", ``` **Result, at this head, `main` `d920d850d` plus the PR:** ``` the new test, with the mutation: 2 failed, 1 passed <- ep_append and ds_consume subtests the other tests, same mutation: 35 passed, 38 subtests <- they do not notice ``` **So the comment's sentence - *"Removing either op from `_ALWAYS_BARRIER_OPS` let every existing test pass even though this shape reaches the sync-free-block assertion"* - is exactly right, and this is the test that stops it.** **Both subtests fail independently, which is what the `for op in (...)` loop is for.** **What I could not verify:** **that the shape reaches the real assertion in a real translation** - **the test asserts `spv.count("OpControlBarrier") >= 3` and the plan's steps, not that a later stage rejects it.** **That is enough for the claim as written ("keeps workgroup barriers"), and it is not the same as proving the sync-free-block path fires.** **One note on my first attempt, since it is a trap:** **I removed the ops by matching the text, and that also hit a second set (`"ds_consume", "ds_append", "ds_ordered_count",`), which made the "other tests" arm fail and would have made me report the opposite conclusion.** **The precise cut is the line in `_ALWAYS_BARRIER_OPS` and nothing else.** **AI-assisted:** yes - DeepSeek v4.1 (flash). Written with an AI assistant.
KelboLive commented 2026-12-01 05:54:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T05:54:17Z.

Review: COMMENTED


The guard is real, and I checked it the right way: with ds_append or ds_consume removed from _ALWAYS_BARRIER_OPS (tools/wave64_emulate_opt.py:137-143), in a fresh process, exactly this test fails at rdna2spirv.py:22752 (unexpected OpControlBarrier in sync-free multi-wave block), while the other 35 tests in the file and test_ds_append.py / test_absent_lane_ub.py stay green. So it is the missing guard, not a restatement. 36/36 with the entries restored; check_no_game_data and git diff --check clean.

The fixture is hand-built (ten synthetic instructions, 128 threads, wave 0 takes the branch and wave 1 skips), not a clipped game shader, and the assertions are the right ones for the regression: plan structured_hybrid, a mini_scheduler step, emitted OpControlBarriers, and the append/consume atomic. No full instruction list, so no over-pinning.

One thing to be aware of rather than change: OpControlBarrier >= 3 is the only hard threshold. If a future plan legitimately emits fewer barriers for this shape the test will fail even though the translation is correct — the file's own SPIR-V interpreter could check barrier uniformity instead, or the count could be tied to the plan step. The plan-mode and step strings match the neighbouring tests (:1423, :1532-1535), so that part follows house style. No blockers from this review.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6125877710 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803#pullrequestreview-6125877710). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T05:54:17Z. **Review:** COMMENTED --- The guard is real, and I checked it the right way: with `ds_append` or `ds_consume` removed from `_ALWAYS_BARRIER_OPS` (`tools/wave64_emulate_opt.py:137-143`), in a fresh process, **exactly this test fails** at `rdna2spirv.py:22752` (`unexpected OpControlBarrier in sync-free multi-wave block`), while the other 35 tests in the file and `test_ds_append.py` / `test_absent_lane_ub.py` stay green. So it is the missing guard, not a restatement. 36/36 with the entries restored; `check_no_game_data` and `git diff --check` clean. The fixture is hand-built (ten synthetic instructions, 128 threads, wave 0 takes the branch and wave 1 skips), not a clipped game shader, and the assertions are the right ones for the regression: plan `structured_hybrid`, a `mini_scheduler` step, emitted `OpControlBarrier`s, and the append/consume atomic. No full instruction list, so no over-pinning. One thing to be aware of rather than change: `OpControlBarrier >= 3` is the only hard threshold. If a future plan legitimately emits fewer barriers for this shape the test will fail even though the translation is correct — the file's own SPIR-V interpreter could check barrier uniformity instead, or the count could be tied to the plan step. The plan-mode and step strings match the neighbouring tests (`:1423`, `:1532-1535`), so that part follows house style. No blockers from this review.
MoonEyes commented 2026-12-01 07:30:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T07:30:38Z.


Verified by MoonEyes (another person than the author) on head 8aada4fc2 merged with main 9372a4d4f: Windows 11, Python 3.14. tests/semantic/test_wave64_emulate_opt.py 36 OK. By mutation, with ds_append and ds_consume out of _ALWAYS_BARRIER_OPS, exactly this test fails (both subtests), as KelboLive found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7304142353 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803#issuecomment-7304142353). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T07:30:38Z. --- Verified by MoonEyes (another person than the author) on head `8aada4fc2` merged with `main` `9372a4d4f`: Windows 11, Python 3.14. `tests/semantic/test_wave64_emulate_opt.py` 36 OK. By mutation, with `ds_append` and `ds_consume` out of `_ALWAYS_BARRIER_OPS`, exactly this test fails (both subtests), as KelboLive found. AI-assisted (Claude Code).
MoonEyes commented 2026-12-01 08:17:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T08:17:49Z.


Merging. Head 8aada4fc2 merges cleanly with main 1d73465e8 and does not force a rebase of #2566. CI green on this head and on main. fiestorra and KelboLive checked it on this head by mutation; I did the same on main + PR (Windows, Python 3.14): 36 tests OK, and removing ds_append and ds_consume from the barrier list fails only this test. MoonEyes asked for this merge. A test only. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7305130675 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2803#issuecomment-7305130675). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T08:17:49Z. --- Merging. Head `8aada4fc2` merges cleanly with `main` `1d73465e8` and does not force a rebase of #2566. CI green on this head and on main. fiestorra and KelboLive checked it on this head by mutation; I did the same on main + PR (Windows, Python 3.14): 36 tests OK, and removing ds_append and ds_consume from the barrier list fails only this test. MoonEyes asked for this merge. A test only. Merged by MoonEyes. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2803
No description provided.