Skip to content

spirv_mini_interp: run_workgroup shares LDS; OpControlBarrier - #4537

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:interp-shared-lds
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:interp-shared-lds

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

spirv_mini_interp.run_workgroup gave every invocation its own zero-initialised Workgroup variables. The module docstring said so: they were "only meaningful with one invocation". It also refused OpControlBarrier (s_barrier). So no CPU test could check lanes communicating through LDS, or racing on an LDS dword: each lane saw only its own writes. I hit this writing GPU fixtures for the LDS atomics (#4323, #4331), and several fixture tests have to cut EXEC to lane 0 to stay meaningful on the CPU.

Change, in tests/semantic/spirv_mini_interp.py only:

  • Shared LDS: run_workgroup keeps one box per Workgroup variable for the whole workgroup. The first invocation creates it and the others use it. Lanes at the same instruction already run it in invocation order, so racing lanes get a defined interleaving.
  • Barrier: OpControlBarrier yields like a subgroup operation, so run_workgroup requires every invocation to reach it at the same point. A barrier only some invocations reach raises UnsupportedConstruct, as before for subgroup operations.
  • Unchanged: run_fragment still refuses it (test_barrier_control.py pins that), and a single invocation keeps its own Workgroup memory.

Tests: tests/semantic/test_interp_shared_lds.py, using translated compute shaders with one or two wave32 waves and 512 B of LDS:

  • one lane writes, s_barrier, every lane reads the value (32 and 64 invocations)
  • 32/64 lanes ds_add_u32 on one dword, then all read the total
  • ds_add_rtn_u32 returns each old value 0…31 exactly once
  • the ds_add_f32 CAS loop on shared LDS reaches 32.0
  • two run_workgroup calls don't share
  • a barrier reached by one invocation of two is refused, and run_fragment still refuses one

With it, 7/7 pass. Against main's interpreter, five error (OpControlBarrier) and one fails (every lane gets ticket 0).

python -I -m unittest discover -s tests/semantic: only main's 10 known failures, each with an open PR (#3883, #3885/#3948, #3995, #4004). No other test depended on per-invocation LDS.

CPU only. No game files. Claimed on #4421 before starting.

AI-assisted (Claude Code): I reviewed and ran the change and the tests.

Every invocation of run_workgroup had its own zero-initialised Workgroup
variables, so no CPU test could check lanes communicating through LDS or
racing on an LDS dword, and OpControlBarrier was refused. The Workgroup boxes
are now the workgroup's (created by the first invocation, shared by the
rest), and OpControlBarrier is a point every invocation must reach together,
as a subgroup operation is. run_fragment still refuses it
(test_barrier_control pins that).

tests/semantic/test_interp_shared_lds.py: one lane writes and all read after
s_barrier (one and two waves), lanes racing with ds_add_u32 and its
returned values, the ds_add_f32 CAS loop on shared LDS, separate workgroups,
and a barrier only one invocation reaches.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran this at af4929c2 on Windows 11: tests/semantic/test_interp_shared_lds.py -> 7 tests, OK; compileall and git diff --check clean.

spirv_mini_interp.run_workgroup() now shares the LDS across invocations and implements OpControlBarrier, and the new tests cover cross-invocation exchange and barrier ordering. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested af4929c2d7 on Linux, Python 3.10, CPU only, synthetic fixtures, no game files: pass.

  • python -m unittest discover -s tests/semantic -p test_interp_shared_lds.py → 7/7; test_interp.py → 35/35 (no regression).
  • Negative control on main's tests/semantic/spirv_mini_interp.py: 1 failure + 5 errors, so the shared-LDS/OpControlBarrier cases discriminate.
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@mrbean56

Copy link
Copy Markdown

Tested af4929c2d7 on Linux (Debian 13), Python 3.13.5: pass, and the negative control is red.

  • pytest tests/semantic/test_interp_shared_lds.py -q: 7 passed, 4 subtests.
  • Negative control: with 03b09a08's spirv_mini_interp.py (per-invocation Workgroup variables) and this test file, 6 tests fail, including test_returned_values_are_each_old_value_once; so the shared-LDS model is what the tests measure.
  • The barrier semantics are the right shape for a lockstep interpreter: OpControlBarrier becomes a point every invocation must reach at the same step (the "same point" check the loop already does for subgroup operations), with None as its result, and run_fragment still refuses it. This is a test tool, not the runtime, so "lockstep and invocation order" is an honest model rather than a pretend scheduler.
  • The docstring change keeps the old guarantee where it still applies ("one invocation alone has its own").
  • Worth confirming in a follow-up that a program where one invocation branches past the barrier is reported as an error rather than deadlocking the loop; the "same point" check suggests it is, and that is the one way a shared-LDS model can hang.

No game data. AI-assisted.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Validate OpControlBarrier scopes and memory semantics

run_workgroup treats every OpControlBarrier at the same PC as a workgroup memory barrier: the opcode handler yields without checking its three operands, and the scheduler rendezvouses the whole workgroup. The SPIR-V operands define the execution scope, memory scope, and memory semantics: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html. The LDS tests would therefore still pass if s_barrier lowering regressed to Invocation scope or omitted WorkgroupMemory/AcquireRelease semantics. Please reject unsupported operand combinations or assert the emitted Workgroup scopes and required memory semantics in the tests.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-assisted independent Windows CPU integration check at af4929c2 with #3952 de0bed34 and #4513 aa8a9868. All three merged cleanly onto d0835dd9 (tree e43ab1fd). uv CPython 3.12.13, synthetic SPIR-V only.

A fresh module ran with two modeled wave32 subgroups. Lanes held pointers to LDS elements through a whole-array replacement, then added atomically through those pointers. Exact #4537 updated the prior array through the saved pointers while fresh pointers saw the replacement, as expected from the existing #3952 issue. The combined tree matched all 576 expected output words across three independent calls with changed inputs. The parse cache did 77 line matches on the first call and none on the other two.

Exact #4537 passed the five positive shared-LDS tests. The combined tree passed all five plus three pointer-liveness tests. Eleven distinct modules, including the new one, passed Vulkan 1.2 spirv-val. This tests the CPU model with workgroup-scope barriers. The opening interpreter docstring still says invocations meet only at subgroup operations and could include barriers too.

@slopradish slopradish 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.

CPU verification: checked out pull/4537/head in an isolated worktree and ran pytest -q tests/semantic/test_interp_shared_lds.py: 7 passed, 4 subtests passed.

The change makes the semantic interpreter's run_workgroup share LDS between invocations and honour OpControlBarrier, which is a prerequisite for testing any LDS-based cross-lane operation through the interpreter rather than a private model. The added tests check the shared-memory and barrier behaviour directly.

This is test/interpreter infrastructure only; no translator semantics change, so it cannot mask a codegen bug. No game files or GPU needed.

@bobcatchris

Copy link
Copy Markdown
Contributor

Cross-platform check on Apple M2 (macOS 26.4, arm64, Python 3.13.18) at head af4929c: pytest -q tests/semantic/test_interp_shared_lds.py → 7 passed, 4 subtests passed in 0.32 s. No GPU or game files involved.

AI-assisted.

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @Kam471, on the current head af4929c2. Nothing is pending.

@memorypressure

Copy link
Copy Markdown

Merged cleanly with current main: all seven new shared-LDS and barrier tests pass plus the 47 nearby interpreter tests (re-run). The five ballot-barrier emulate-mode failures reproduce identically on plain main — not yours. Confirmed #4152 reworks that regression suite but is not an ancestor here. Synthetic FSSM in memory, no new writes or deps. Main's 2fde230 introduced related workgroup execution, not shared LDS in the mini interpreter. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @memorypressure, including the confirmation that the five ballot-barrier failures reproduce on plain main. Nothing is pending.

@ItsNotRexed
ItsNotRexed merged commit 28ec8eb into ItsNotRexed:main Nov 23, 2026
2 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.

10 participants