Repository navigation
spirv_mini_interp: run_workgroup shares LDS; OpControlBarrier - #4537
LouisRiverstone wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
Tested
AI-assisted (Devin). |
|
Tested
No game data. AI-assisted. |
Flyander
left a comment
There was a problem hiding this comment.
[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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Cross-platform check on Apple M2 (macOS 26.4, arm64, Python 3.13.18) at head af4929c: AI-assisted. |
spirv_mini_interp.run_workgroupgave every invocation its own zero-initialised Workgroup variables. The module docstring said so: they were "only meaningful with one invocation". It also refusedOpControlBarrier(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.pyonly:run_workgroupkeeps 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.OpControlBarrieryields like a subgroup operation, sorun_workgrouprequires every invocation to reach it at the same point. A barrier only some invocations reach raisesUnsupportedConstruct, as before for subgroup operations.run_fragmentstill refuses it (test_barrier_control.pypins 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:s_barrier, every lane reads the value (32 and 64 invocations)ds_add_u32on one dword, then all read the totalds_add_rtn_u32returns each old value 0…31 exactly onceds_add_f32CAS loop on shared LDS reaches 32.0run_workgroupcalls don't sharerun_fragmentstill refuses oneWith 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: onlymain'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.