Repository navigation
shader: carry pre-branch EXEC mask subset facts into compute execz blocks (#2645 T1) - #2877
Conversation
eb09b2f to
33b4e3d
Compare
|
Independent T1 check at |
KelboLive
left a comment
There was a problem hiding this comment.
Complex and correct. This PR introduces subset-after tracking (#2645 T1) to prove that scalar words assigned from EXEC before an s_cbranch_execz carry a subset guarantee (sM <= EXEC), which prevents the translator from refusing exec writes inside the skipped block when the assignment is provably safe.
A few observations:
-
subset_after() handles four categories cleanly:
- Indirect scalar writes (s_movrel*) drop all non-EXEC facts
- Bitwise mask instructions propagate via clear_after
- EXEC writes: drop written wave half unless a move assigns EXEC from a scalar mask word or OR widens EXEC with a bitmask
- Otherwise keep subset facts surviving clear_after on un-written halves
-
The fixed-point iteration in execz_refusals() (pre_sub propagation) correctly merges joins via intersection, which is the right lattice operation for subset tracking.
-
The test harness is comprehensive: subset_after() unit checks, accepted setups (pre_and_copy, pre_mov), near-miss controls (narrowed_saveexec, narrowed_cmpx, overwritten_before/inside, join_one_arm), and the binary o-subset-remask-dropped test. The bad_wave vs bad_singles disagreement check (lane 1 skips in singleton but enters via stale mask in wave) is an excellent mutation test.
-
One potential concern: the fixed-point loop runs in place over pre_sub without an explicit termination condition beyond changed=False. For very large basic blocks this could be slow, though the fact lattice is small (EXEC_SUBSET + at most ~4 scalar words), so it terminates quickly in practice. Worth noting in a comment for future readers.
Looks solid. This is a quality addition to the translator safety guarantees.
pigalot
left a comment
There was a problem hiding this comment.
I tried to review 33b4e3d0 over current main 454fc0ed. The trial merge conflicts in docs/experiments.md. Since this PR's base b505c32b, main has added entries there in #3010, #2882, #2871, #2829 and #2857. The other three files merge cleanly.
I'll review it once it is updated with main.
This reply was AI-assisted.
Resolved conflicts: - docs/experiments.md
|
I merged Conflict and resolution.
What I ran. I built everything in ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^startup_gfx2hlsl_' -E '_hardware$'
python with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_gfx2hlsl_.*_hardware$'
These runs include this branch's This needs a re-review from someone else. I won't review or merge it myself. Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC (the one CTest picked up); Python 3.12.10. This reply was AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
Reviewed f4bf0949 (c's merge of main) integrated over current main f41806a9. The merge is clean (tree 371d047d) and git diff --cached --check is clean.
What I traced. subset_after is a forward must-analysis of sM <= EXEC facts. It is seeded by a s_mov of EXEC into an SGPR pair and kept across a s_mov/s_or/s_or_saveexec into EXEC only when the OR keeps an EXEC source word. It is dropped on any other EXEC write, on a write to the fact's word, on s_movrel*, and at a join that lacks it on any edge. execz_refusals seeds the skipped block's entry with those facts, while the per-instruction exec write check still compares against EXEC_SUBSET alone. So a saved mask that is overwritten inside the skipped block can't be restored as a subset. c's docs/experiments.md resolution keeps both sides, and main's T3 work doesn't touch entry.
What I ran.
- Builds: full
devandrelease/O2. - CPU:
ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^startup_gfx2hlsl_' -E '_hardware$': 270/270 pass in Debug and in Release. - Hardware:
ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute.*_hardware$': 34/34 pass, with no skips. On the earlier trial over0fe4cebcthe same 34 also passed inrelease. - Full suite:
ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)'gives 2016 tests: 1956 pass, 1 fails and 59 are capability skips.- The failure is
xmem_lazy_commit_off, which passes 5 of 5 runs alone at-j 1. - On the earlier trial over
0fe4cebc, the one full-run failure wasstartup_storage_alloc_failure. Alone at-j 1it failed 1 of 13 runs. - This PR changes only the translator, one Python check,
CMakeLists.txtand the docs, so I read both as unrelated intermittent failures.
- The failure is
- End to end: I spliced
s_mov_b64 s[22:23], execbefore the branch ands_mov_b64 exec, s[22:23]inside the skipped block. The baseline is accepted, and so is ans_or_b32 exec_lo, exec_lo, s30widening before the branch.
Mutants of tools/startup/gfx2hlsl.py, each run against tests/startup_gfx2hlsl_compute_check.py after an unmutated baseline that passes:
| Mutant | Result |
|---|---|
pre-branch facts ignored (entry = EXEC_SUBSET) |
killed (O-loop-subset refused) |
| join takes the union, not the intersection | killed (hangs; the fixpoint never settles) |
| a non-EXEC write keeps facts on the written word | killed |
s_movrel* keeps all facts |
killed |
| an EXEC write keeps facts on the written half | killed |
| an OR widening isn't recognised | killed |
s_mov into EXEC adds no source fact |
killed |
| the in-block step re-adds the pre-branch facts | killed (o-subset-remask-dropped) |
the in-block exec write check uses the entry facts |
killed |
| any OR into EXEC is treated as a widening | survives |
Restored afterwards; git diff --quiet is clean.
Non-blocking.
- A non-widening OR into EXEC isn't pinned. With the
any(...)test replaced byTrue,s_or_b32 exec_lo, s1, s2would keep everysM <= EXECfact, though the new EXEC needn't contain the old one. The code drops the facts correctly today; a near-miss control with that instruction before the branch, which must refuse, would pin it. - The OR check compares the source word with the wrong half.
src[p] == ('exec', 'exec_hi')[p]tests source wordpagainst EXEC halfp, not against the destination half. Fors_or_b32 exec_hi, exec_lo, s30, word 0 isexec_lo, so it counts as a widening and the(s23, 1)fact is kept, butexec_hi = exec_lo | s30needn't contain the oldexec_hi. I checked this by callingsubset_afterdirectly. It isn't reachable end to end today: the translator refusess_or_b32with destinationexec_hi(operand 'exec_hi'). Comparing each source word with the destination word would close it before that destination is ever accepted (unconfirmed suggestion).
Verdict: approve on f4bf0949.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on f4bf0949.
This reply was AI-assisted.
Summary
Test environment & results (commit \33b4e3d0)