Skip to content

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

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
thiefyzheng:test/w64-append-consume-barrier
Dec 1, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
thiefyzheng:test/w64-append-consume-barrier

Conversation

@thiefyzheng

@thiefyzheng thiefyzheng commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: W64-APPEND-CONSUME-BARRIER-REGRESSION (#2570 (comment))

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: #2570 (comment)). 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.

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MoonEyes

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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

@MoonEyes
MoonEyes merged commit 2e822df into ProjectLeonida:main Dec 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants