Skip to content

semantic: the ballot/barrier audit runs structured wave64 helper calls - #4727

Open
bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/semantic-structured-calls
Open

bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/semantic-structured-calls

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

What and why

main (98fa503f) is red in this audit:

cd tests/semantic && python -I test_loop_ballot_barrier.py
FAIL: test_divergent_loop_wave64_emulate_and_native_cs (emulate_64_sg32, emulate_128_sg32, emulate_40_partial_sg32)
  'emulated wave64 structured' != 'emulated wave64 rounds'
ERROR: test_nested_divergent_loops_emulate (emulate=True)
ERROR: test_bug4b_loop_carried_split_sgpr_pair_ballot (emulate=True)
  NotImplementedError: Unsupported SPIR-V op OpFunctionCall in %blk2 / %blk1

4d9ef4eb (structured inline/hybrid wave64 emulation) routes these reducible compute CFGs through plan_structured_emulation. That path labels gen.control_flow emulated wave64 structured and emits the mask setup as helper functions (%x_pre_mask_fn, %x_pre_both_fn, %x_pre_vote_fn) called from %main. The audit's interpreter parsed only %main, so it failed the old label assertion and had no way to execute the new default path at all.

What changed

tests/semantic/test_loop_ballot_barrier.py only:

  • _parse_spv records every OpFunction with its OpFunctionParameters, entry label and function-local OpVariables (main's stay where they were).
  • step_inv implements OpFunctionCall, OpReturnValue and OpReturn with a per-invocation frame (return block, ip, destination register, previous block) plus a scope stack for helper locals. Locals are keyed per call, so two calls cannot alias.
  • The emulation label check accepts emulated wave64 rounds or emulated wave64 structured; the same per-lane memory assertions then run, so whichever scheduler the translator picks is checked against the RDNA2 oracles.

The helper bodies use only parameters, SSA and the already-supported %x_buf atomics; no translator change is needed.

Checks

  • python -I tests/semantic/test_loop_ballot_barrier.py → 15 tests, OK (was 3 failures + 2 errors).
  • Negative control: the unmodified test file on 98fa503f still fails 3+2; only the interpreter and the label assertion changed.
  • git diff --check clean.

Synthetic hand-written RDNA2 listings only; no hardware, game data or GPU run involved.

AI-assisted.

main is red: python -I tests/semantic/test_loop_ballot_barrier.py reports 3 failures
and 2 errors on 98fa503. 4d9ef4e routes these reducible compute CFGs through
structured inline wave64 emulation, which labels the path "emulated wave64
structured" and emits the mask setup as %x_pre_mask_fn / %x_pre_both_fn /
%x_pre_vote_fn called from %main. The audit's interpreter parsed only %main, so it
failed the label check and then raised NotImplementedError on OpFunctionCall.

_parse_spv now records every OpFunction with its OpFunctionParameters, entry label
and function-local OpVariables, and step_inv implements OpFunctionCall,
OpReturnValue and OpReturn with a per-invocation frame (return block, ip,
destination, previous block) and a local scope stack. Helper locals are allocated
per call, so a future helper with locals cannot alias another call's. The emulation
label check accepts either structured or round scheduling, and the same per-lane
memory assertions run, so whichever path the translator picks is audited.

Checked: 15/15 tests pass after the change; the unmodified test on 98fa503 still
fails 3+2. Pure stdlib and synthetic RDNA2 listings; no hardware, game data or
translator change.

AI-assisted.
@Atomic258

Copy link
Copy Markdown

Tested head 7a9dd621c4dd86c5c8febe5eda4fedd4bb456d4e on Windows 11, Python 3.15.2.

Command: cd tests/semantic && python -I test_loop_ballot_barrier.py

  • PR head: 15 tests, OK (1.8s)
  • Red control: restored tests/semantic/test_loop_ballot_barrier.py from origin/main and re-ran — FAILED with 3 failures + 2 errors ('emulated wave64 structured' != 'emulated wave64 rounds', NotImplementedError: Unsupported SPIR-V op OpFunctionCall), matching the PR description. Restored the PR file afterwards; re-run green (15 OK), worktree clean.

All pass.

AI-assisted (Devin).

@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 7a9dd621c on Windows 11: tests/semantic/test_loop_ballot_barrier.py -> 15 tests, OK; git diff --check clean.

The ballot/barrier audit now also runs the structured wave64 helper calls (the same expected words), so the structured path is checked alongside the round-based one; test-only. No blocking issue.

@memorypressure

Copy link
Copy Markdown

Verified on Linux: this fixes a genuinely red-on-main test — at base the file fails 3 + errors 2 (all wave64-emulate modes, red since structured inline emulation landed); at the head all 15 tests pass under python -I (re-run here), and the translator-use guard is satisfied (the file imports rdna2spirv directly). One caution for maintainers: #4152 extends the same interpreter's function-call support and edits the same control_flow hunk with a stricter assert — the two will conflict; worth deciding which one lands. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@l-CatDemon-l

Copy link
Copy Markdown

Checked 7a9dd621c4dd86c5c8febe5eda4fedd4bb456d4e on Windows 11 Pro x64 (26200), native Python 3.13.1.

Command in each checkout:

python -I -B -m unittest discover -s tests/semantic -p test_loop_ballot_barrier.py -v
  • Base 98fa503f: 15 tests, 3 failures + 2 errors.
  • PR head 7a9dd621: 15 tests, OK, no skips.

The base reproduces the three structured-vs-round scheduler label failures and the two unsupported OpFunctionCall errors. With the PR, the per-lane memory assertions run and pass. This was a focused CPU test of this module; no game files.

@bielfreedom

Copy link
Copy Markdown

Tested 7a9dd621 (merge-base 98fa503f) on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD Windows driver 32.0.32029.2010, Windows 11 Pro 26200, MSVC 14.51, Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1: pass for what this PR changes.

  • tests/semantic: 6,245 tests, OK (1 skipped, 1 expected failure).

  • This PR's file against main: on main 98fa503f, test_loop_ballot_barrier.py alone gives FAILED (failures=3, errors=2):

    • test_nested_divergent_loops_emulate and test_bug4b_loop_carried_split_sgpr_pair_ballot fail with NotImplementedError: Unsupported SPIR-V op OpFunctionCall;
    • test_divergent_loop_wave64_emulate_and_native_cs fails in its three emulate_*_sg32 modes.

    With this PR all 15 pass. So it fixes 5 failures that are currently on main.

  • GPU suite (run_gpu_tests.py): 221/221 translated and pass spirv-val; 202/217 passed, 15 skipped.

  • ctest: 172/173 passed. The one failure, d3d12_sparse_queue_family_contract, is unrelated: this PR only touches tests/semantic. That test is intermittent here, an access violation (exit=3221225477, no VUID) in 5 of 20 isolated runs of the same build. I'll file it separately.

@bobcatchris

Copy link
Copy Markdown
Contributor Author

Whole-surface evidence that this is the one red module on main, so it should be the fastest merge in the queue.

On a clean worktree at 98fa503f I ran the surface the way the repo's own runners do:

  • all 341 tests/test_*.py, one process per file with -I, exactly like ci.yml's loop: all pass;
  • all 396 tests/semantic/test_*.py, run from tests/semantic (they import support; -I also implies -P, so the script's folder stays off sys.path): test_loop_ballot_barrier.py is the only failure, 3 failures + 2 errors;
  • the 30 pytest-marked modules: 1,663 passed, 6 skipped, 5 failed only because Pillow is not installed here (ModuleNotFoundError: No module named 'PIL' in tools/swizzle_search.py/amd_swizzle.py previews).

At this PR's head (7a9dd621) the same module is 15 tests OK, as Kam471 and Atomic258 reported. Nothing else in the semantic suite touches these helpers, so the change is isolated to the red file.

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor Author

Re-review request. This is the only red module on main's CPU surface: on a clean worktree at 98fa503f, all 341 tests/test_*.py and all 396 tests/semantic/test_*.py were run, and test_loop_ballot_barrier.py is the single failure (3 failures + 2 errors); at this head (7a9dd621) it is 15 tests OK. Three independent testers have confirmed the head. AI-assisted.

@amarovndres

Copy link
Copy Markdown

Tested 7a9dd621 on Windows 11 Pro (build 26200), CPython 3.12.10, llvm-mc 23.1.6: pass. python -I -m unittest discover -s tests/semantic -p test_loop_ballot_barrier.py: 15 tests OK.

On main 3faac557 the same command gives 3 failures and 2 errors, all in the wave64-emulate cases. One of the errors is NotImplementedError: Unsupported SPIR-V op OpFunctionCall in %blk2, which is what this PR teaches the test's interpreter.

For whoever picks between them: #3995 (60e63dae, Vonsek) fixes the same module and also touches only tests/semantic/test_loop_ballot_barrier.py. It passes the same command here as well, 15 tests OK. The two will conflict, so only one of them should land.

AI-assisted (Claude Code). CPU only, no game files.

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.

7 participants