fix(stinkytofu): Enable ST waitcnt insertion by default#8804
fix(stinkytofu): Enable ST waitcnt insertion by default#8804pschang-phy wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (76.92%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #8804 +/- ##
========================================
Coverage 69.59% 69.59%
========================================
Files 2771 2771
Lines 452699 452699
Branches 66658 66658
========================================
Hits 315022 315022
Misses 117337 117337
Partials 20340 20340
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
17bb22c to
cb2f93a
Compare
✅ All Checks Passed — Ready for Review
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
|
🎉 All checks passed! This PR is ready for review. |
cb2f93a to
e356e2d
Compare
e592081 to
0488618
Compare
99b8429 to
2e1029a
Compare
|
@jaopaulolc, @ThanHenderson, could you help us review this PR, in particular, the "RequiresXCntForVolatileVMEM" behavior? In this PR, we enable the WaitCnt insertion pass by default for all SIA optimization levels in stinkytofu. This means we first remove all existing wait instructions, including the However, we're not completely sure about StreamK's policy. Does StreamK only insert Thank you! |
| using namespace stinkytofu; | ||
| using namespace stinkytofu::waitcnt; | ||
|
|
||
| bool isVolatileVmemAtomic(const StinkyInstruction& inst) { |
There was a problem hiding this comment.
addRequiredXcntDrains only re-emits s_wait_xcnt 0 before ops matched by isVolatileVmemAtomic (MUBUF/FLAT/GLOBAL atomics). That is narrower than StreamK's actual policy ("drain before volatile VMEM", not just atomics), so correctness today rests on an implicit, unenforced region invariant rather than on this predicate. I verified the mechanics in generated gfx1250 assembly (dynamic-StreamK SGEMM, built stinkytofu-opt on both develop and this PR head).
-
Empirically, the one in-region volatile-VMEM site is the dynamic work-queue atomic
global_atomic_inc_u32. Pre-PR develop with the ST pass ON strips its hand-writtens_wait_xcntand never regenerates it (a real latent dropped-drain bug); this PR restores it tightly immediately before the atomic. So the PR also fixes a pre-existing dropped-drain, and that site is covered precisely because it is an atomic. -
The 2 non-atomic volatile flag ops —
buffer_store_b32(partial-tile release) andbuffer_load_b32(acquire/poll) — retain theirs_wait_xcntin every build I generated (pass on/off, develop/PR) only because they sit in the epilogue, OUTSIDE the{loopWithPrefetch, noLoadLoopBody}region this pass processes. They areIF_MUBUFStore/IF_MUBUFLoad, soisVolatileVmemAtomicexcludes them; region scoping, not the predicate, is the guardrail. -
The gap is silent and I reproduced it: a crafted in-region non-atomic flag store has its hand-written drain stripped by
StinkyRemoveWaitCntPassand NOT regenerated. If any volatile-VMEM flag op ever moves into the covered region (in-loop variant, or code pulled intonoLoadLoopBody), XNACK-replay reordering around the partial-tile release/acquire handshake -> cross-workgroup data race. The added FileCheck (buffer_store_b32->CHECK-NOT: s_wait_xcnt) codifies this hole. -
Recommendation: broaden the predicate from "volatile VMEM atomics" to true "volatile VMEM" (atomics plus glc/dlc/dev-scope buffer/flat/global load/store), decoupling correctness from the region invariant. Beyond that, the current tests only cover the in-region atomic path; add positive-regression coverage for the out-of-region non-atomic sites so a refactor that pulls them in-region or drops their drain is caught:
- Add an end-to-end TensileLite StreamK gfx1250 codegen regression (golden
.s/ FileCheck via the Tensile path) assertings_wait_xcntis present before ALL 5 sites — the 3 RMW atomics AND the 2 non-atomic flag ops (buffer_store_b32release,buffer_load_b32acquire) — so the invariant that these flag ops stay out-of-region and keep their drains is actually guarded, not assumed. - Add a guard/assert encoding the invariant directly: fail if a volatile-VMEM op requiring an xcnt drain appears inside a processed region without a regenerated drain (an in-region assert/XFAIL for a volatile non-atomic store/load).
- Reconcile the PR's own unit FileCheck (
buffer_store_b32->CHECK-NOT: s_wait_xcnt): it currently asserts the opposite of what StreamK needs should that op ever be in-region. Scope it explicitly to the out-of-region/no-drain-required case (or flip it once the predicate is broadened) so the two tests don't encode contradictory invariants.
- Add an end-to-end TensileLite StreamK gfx1250 codegen regression (golden
There was a problem hiding this comment.
@jaopaulolc , Thank you! After some discussion, we decided to implement a dedicated hazard resolution pass in the next PR. As a temporary workaround, we won't modify streamk or tensilelite's xcnt placement in the non-SIA4 code generation path.
Keep live tensor queues for blocks with untagged tensor anchors instead of restoring the frozen sweep-0 tensor state, so loop-carried tensor loads can still force the conservative s_wait_tensorcnt 0 fallback.
Revert the temporary waitcnt-insertion xcnt handling and keep
hand-authored s_wait_xcnt drains on non-SIA4 paths.
SIA4 still removes all waits.
SIA0 preserves tensilelite and streamk's emitted xcnt drains.
TODO: land a dedicated hazard pass handles them and remove this
workaround.
JIRA ID : AIHPBLAS-3664
Motivation
Enable StinkyTofu waitcnt insertion, currently only on region loopWithPrefetch+noLoadLoopBody, by default for TensileLite.
Technical Details
Based-on #9407 to track returning atomics in waitcnt dataflow.
DisableSTWaitCntdefault toFalseso ST waitcnt insertion runs by default..fallthroughlabels for synthetic fallthrough blocks.s_wait_tensorcnt 0fallback.Test Plan
Test Result
Submission Checklist