Repository navigation
Conversation
…op's limit tools/spirv_loop_guard.py caps each loop at 65,536 visits from every entry, so nested loops multiply their caps: an inner loop may make 65,536 visits in each of 65,536 visits of the outer one. A loop bound computed by a float divide whose divisor is 0 is +inf. It converts to 0xFFFFFFFF, and an inclusive exit test against it never fails once the counter wraps. A compute program with nested loops of that kind ran at the caps for seconds a dispatch, and the device was lost with no faulting address. --loop-total N (default 1,048,576; 0 = none) adds one count of every guarded back edge of the invocation, in a Private variable listed by the entry point. No back edge passes once it reaches N. Each loop keeps its own limit, so a loop that ends by itself is cut only after the whole invocation made N visits. make_game.py passes the flag on and records it with the other translator flags. The default changes the translation of every program with a loop, so a shader library takes it when it is translated again. Tests (tests/semantic/test_loop_iteration_guard.py): two nested loops that never end stop at the total, in wave32 and in emulated wave64 (whose round scheduler spends from the same total); loops that end by themselves are untouched; without a total the per-loop counts multiply. Three test-local SPIR-V interpreters (test_loop_ballot_barrier, test_control_flow_branches, test_wave64_emulate_opt) now give each invocation its Private globals, which every module with a loop has from now on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
spirv_loop_guard: TypePointer|EntryPoint (PR) in main's CRLF-safe regex; main's bool/int check on limit applied to total too. Co-authored-by: QemmHD <290605352+QemmHD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Current main after ProjectLeonida#2566; no new conflicts on top of the earlier carry merge. Co-authored-by: QemmHD <290605352+QemmHD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16 (pytest, no GPU),
Not independent: this PR and this check share the same owner (OreoFR). Treat it as a second-machine run, not an independent review. AI-assisted: Claude Code |
|
Independent dynamic barrier counterexample on the carry. MEASURED. I translated the checked-in
A separate 64-invocation SPIR-V fixture has a finite first loop taking 1 or 3 iterations and then a shared loop with three workgroup barriers. At aggregate limit 4, only 32 invocations reach the third barrier. Main and a test-only control that leaves the aggregate check off that specific barrier loop complete with all 64 reaching all three barriers. All 10 generated modules pass Five stock test modules gave 65/65 on main and 66/67 on the PR. The sole stock failure is the separate single-wave |
… too Main's single-wave barrier test (merged after ProjectLeonida#2183 was written) allows only %pc in the conditions around a barrier. The invocation total of the loop guard is loaded in those conditions as well; it counts the guarded back edges, which every invocation takes alike when the loop conditions test only %pc and the total, so it is as uniform as %pc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wave64 barrier follow-up on 083c011I reran the two-wave fixture with MEASURED. All five targeted suites pass (66 tests on
The budget-16 assembly is byte-identical to the earlier report. In a test-only control, I exempted just the The results show the scheduler's aggregate exit can diverge at a caller-selected budget even with the updated single-wave check. Earlier report |
|
Full-suite failure on Windows at
Either the test needs AI-assisted: yes (opencode). |
|
Full-run summary for the failure above: *549 files, 6,677 tests, 1 file failed — \ est_wave64_single_wave_barrier* (448 s, -j 16). Every other file passes. |
|
Suggested resolution: the new # The invocation-wide loop total is uniform (a Private variable), so it may appear in a barrier guard.
self.assertLessEqual(loaded, {"%pc", "%loop_guard_total"})That keeps the property the test is about (no lane-varying value in a barrier guard) while accepting the new guard. The full suite then needs a rerun to confirm nothing else asserts the old set. |
|
Applied the one-line change locally on top of
So the widened set is the only blocker on this machine; no other test depends on the old assertion. The exact change I applied: # The invocation-wide loop total is uniform (a Private variable), so it may appear in a barrier guard.
self.assertLessEqual(loaded, {"%pc", "%loop_guard_total"})AI-assisted: yes (opencode). |
|
Confirmed on the updated head
The regression from the earlier head is resolved on Windows. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8. AI-assisted: yes (opencode). |
aslan2142
left a comment
There was a problem hiding this comment.
Although this carry of #2183 is mergeable with green CI on head 083c011, it still has a reproduced correctness blocker in tools/spirv_loop_guard.py:
- Non-uniform
OpControlBarrierhazard:%loop_guard_totalis a per-invocationPrivatecounter incremented at every guarded back edge, including outer wave64 round-scheduler loops (%loop_head/%loop_cont) and loops containingOpControlBarrier. When one wave executes more inner-loop iterations than another, it hits--loop-totalfirst and exits the barrier loop while the other wave loops back and waits atOpControlBarrier(independently reproduced on head083c011at budgets 12 and 16 usingBarrierInLoopsTests._wave_divergent_barrier_loop_cs(True):64/128 invocations arrived at OpControlBarrier).
Widening tests/semantic/test_wave64_single_wave_barrier.py does not resolve the multi-wave barrier divergence. Please exempt barrier-containing / outer round-scheduler loops from the per-invocation aggregate budget (or make their exit workgroup-uniform) and add a multi-wave regression test before merging.
(AI-assisted review.)
aslan2142
left a comment
There was a problem hiding this comment.
Keeping #2736 over closed original #2183 (SHADER-LOOP-TOTAL): thank you for preserving @QemmHD's commit 88abd1609, resolving the tools/spirv_loop_guard.py conflict with main's CRLF and bool checks, and fixing tests/semantic/test_wave64_single_wave_barrier.py so CI is green.
However, requesting changes before merge for the unresolved correctness defect reproduced by @qhukz13 on #2183 (which this carry preserves unchanged):
- In the
--wave64-emulateround-loop form (x_scheduler,x_mini_scheduler,bar_scheduler),%loop_guard_totalcounts every inner-loop back edge per invocation. When one wave does more inner-loop work than another wave in the same workgroup, the busier wave hits--loop-totaland exits the outer scheduler round loop while the other wave continues to the nextOpControlBarrier, producing a non-uniformOpControlBarrier(Vulkan UB / GPU hang — reproduced on 2–3 of 24 synthetic NGG mesh programs inspirv_mini_interp.run_workgroup). - Please either exempt barrier-containing scheduler round loops from the per-invocation total (keeping their uniform per-loop limit) or make the total-exceeded exit uniform across the workgroup, and add a regression test covering a two-wave workgroup with asymmetric inner-loop trip counts.
(AI-assisted review.)
KelboLive
left a comment
There was a problem hiding this comment.
Reproduced the blocker on 083c011a9 (Windows, CPU interpreter, no game data): BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True), 128 invocations, 32-lane subgroups, --wave64-emulate:
--loop-total |
result |
|---|---|
| 0 (main) | ok — lanes 0–63 → 2, 64–127 → 4 |
| 8 | silent wrong output (second wave unwritten, -1) |
| 12 | NonUniformBarrierError: 64/128 invocations arrived at OpControlBarrier |
| 16 / 24 / 32 / 1M | ok |
So the guard does not only truncate — it can make a valid program hit a non-uniform barrier, which is the class of bug the emulation layer exists to avoid.
The claim in the new test_wave64_single_wave_barrier.py comment — that %loop_guard_total is wave-uniform because it only follows %pc — holds only for that single-wave fixture. %loop_guard_total is a Private per-invocation counter, and the wave64 round-scheduler's %loop_head/%loop_cont spends from it, so as soon as two waves have different inner trip counts the per-lane totals diverge and the scheduler exits per lane. Please exempt barrier-containing/scheduler loops from the aggregate total (or make the total-exceeded exit workgroup-uniform) and add a two-wave asymmetric-trip-count regression test.
Separately, the total silently truncates a program main completes: a terminating nested loop with per-loop limit 4,000 that visits 9,000 times returns 9000 with total=0 and 6000 with total=6000, no diagnostic. At the 1M default any invocation legally exceeding 1M back edges is cut, so that trade-off needs an explicit note (and ideally a diagnostic) in the switch docs.
The boundary itself is pinned correctly: reverting the aggregate gate fails test_total_bounds_nested_loops ([2500] != [41]) and OpULessThan→OpULessThanEqual fails with [42] != [41]. Tests otherwise pass (15 targeted, 85 barrier/emulation, 42 make_game, full semantic 549 files / 6,677 tests), spirv-val is clean, merge-tree is clean, and nothing here is duplicated on main (#2183 is closed unmerged).
Minor: no total= unit test in tests/test_spirv_loop_guard.py, --loop-limit 0 silently suppresses --loop-total, and only the last OpEntryPoint gets the interface entry.
|
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime ( |
Carries #2183 by @QemmHD, because it conflicts with
mainafter #2566 and the reminder to mergemain(#2183 (comment)) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped.Item:
SHADER-LOOP-TOTAL-CARRY(claimed in #2570 (comment); original itemSHADER-LOOP-TOTAL).What this branch is
88abd1609, unchanged (no rebase, author commits kept).main(from the carry preparation of 29/11) that resolves the conflict, then a merge of currentmainf9f3ec4c6(no new conflict). Both merge commits carryCo-authored-bythe author.What conflicted and how it was resolved
tools/spirv_loop_guard.py(2 hunks): the PR'sTypePointer|EntryPointadded tomain's CRLF-safe regex;main's bool/int check onlimitapplied tototaltoo.Open question for a human:
tests/semantic/test_wave64_single_wave_barrier.py(amaintest, a02a5ef) fails on this branch: it requires that a barrier inside a loop depends only on%pc, and the PR adds%loop_guard_totalto the loop's exit condition. Is that safe for a barrier under emulated wave64, and should such loops be left out of the total or the test widened? Not decided here. The concern djrolfes raised and qhukz13 reproduced on #2183 (scheduler barrier) is the same area.Tests
mainf9f3ec4c6merged), Windows 11, Python 3.12, no GPU used:tests/semantic/test_loop_iteration_guard.py: 6 OK;tests/test_spirv_loop_guard.py: 9 OK;tests/semantic/test_wave64_single_wave_barrier.py: 1 failure (see above).test_loop_iteration_guard2 errors; full semantic suite 529 files / 6527 tests, 3 failures =main's 2 +test_wave64_single_wave_barrier.python -I scripts/check_no_game_data.pyon every file this PR changes: clean.ctest, the full translator suite).Depends on: none.
Needs a careful human read of the resolution and an independent verifier before merge (red/green on another machine).
AI-assisted (Claude Code, oreofr-agent).
🤖 Generated with Claude Code