Skip to content

fix(stinkytofu): represent exec-masked spans as atomic DAG nodes#9004

Open
KKyang wants to merge 6 commits into
developfrom
users/kkyang/stinkytofu-exec-mask-group
Open

fix(stinkytofu): represent exec-masked spans as atomic DAG nodes#9004
KKyang wants to merge 6 commits into
developfrom
users/kkyang/stinkytofu-exec-mask-group

Conversation

@KKyang

@KKyang KKyang commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Collapses each exec-narrowing span into a single opaque ExecMaskGroup pseudo-instruction before DAG scheduling, then expands it back afterward. This prevents the scheduler from reordering instructions into or out of the lane-masked region.

The pattern matched is the canonical if() {} shape:

  • Open: any exec write whose result is not the literal -1 (opcode-agnostic — StinkyTofu IR is written by hand, not machine-generated, so we match semantic intent rather than an opcode allowlist)
  • Close: any exec write whose sole source is the literal -1 (single-source constraint covers all sane reset idioms without needing to evaluate multi-operand expressions)

Register aliasing is handled explicitly: EXEC (64-bit) aliases both EXEC_LO and EXEC_HI, so s_mov_b64 exec, -1 is correctly recognized as a reset in wave32. EXEC_LO and EXEC_HI do not alias each other, so an EXEC_HI write inside a wave32 span is a no-op to the depth counter.

Unmatched spans (no matching -1 reset before end of basic block) are left ungrouped — silent fallback to pre-fix scheduling behavior rather than a hard error.

Changes

  • ExecMaskGrouping.hpp/.cpp — new collapseExecMaskedRegions() / expandExecMaskedGroups() pass
  • StinkyAsmIR.hppcreateExecMaskGroup(), isExecMaskGroup()
  • StinkyModifiers.hppExecGroupData (non-owning child pointer list)
  • StinkyDAGSchedulerPass.cpp — zip → schedule → unzip call site
  • GenInstructions.cppEXEC_GROUP unified opcode
  • ExecMaskGroupingTest.cpp — unit tests: round-trip, nesting, unmatched narrow, sibling spans, b64 reset in wave32, non-mov opener
  • DAGSchedulerPassTest.cpp — scheduler treats ExecMaskGroup as atomic node

Test plan

  • ExecMaskGroupingTest — collapse/expand unit tests pass
  • DAGSchedulerPassTestExecMaskGroup_* tests pass

@therock-pr-bot

therock-pr-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

❌ PR Check — Action Required

Check Status Details
🌿 Branch Name ✅ Pass
📝 PR Title/Description ❌ Fail Error: PR description must reference a JIRA ID, ISSUE ID, or a GitHub closing keyword.
Expected: include a JIRA ID / ISSUE ID line (separator : or -, or omitted; value may be a JIRA key, a number with/without #, or a link), OR a closing keyword + issue reference. Accepted examples:
JIRA ID : TESTAUTO-6039
JIRA ID - #330
JIRA ID #330
ISSUE ID : TESTUTO-3334
ISSUE ID #3334
ISSUE ID - TESTAUTO-3433
ISSUE ID : https://github.com/<org_name>/<repo_name>/issues/1234
Closes #10
Fixes octo-org/octo-repo#100
Resolves: #123
#123
https://github.com/<org_name>/<repo_name>/issues/123
Current: no valid JIRA/ISSUE/closing-keyword reference found
Forbidden Files ✅ Pass
🧪 Unit Test ❌ Fail Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: shared/stinkytofu/include/stinkytofu/ir/asm/StinkyAsmIR.hpp, shared/stinkytofu/include/stinkytofu/ir/asm/StinkyModifiers.hpp, shared/stinkytofu/include/stinkytofu/transforms/asm/ExecMaskGrouping.hpp, shared/stinkytofu/src/transforms/asm/ExecMaskGrouping.cpp, shared/stinkytofu/src/transforms/asm/StinkyDAGSchedulerPass.cpp (+3 more); no test file found
🔎 pre-commit ✅ Pass
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled

⚠️ 2 policy check(s) failed. Please address the issues above before this PR can be Reviewed.

🚫 Please fix the failed policies

  • ❌ PR Title/Description
  • ❌ Unit Test

The Not ready to Review label was added to this PR. Once all policies pass, the label is removed automatically.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

@therock-pr-bot

therock-pr-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Title/Description
  • ❌ Unit Test

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

@codecov-commenter

codecov-commenter commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project status has failed because the head coverage (76.84%) 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    #9004   +/-   ##
========================================
  Coverage    65.36%   65.36%           
========================================
  Files         2685     2685           
  Lines       422293   422293           
  Branches     62747    62747           
========================================
  Hits        276009   276009           
  Misses      125493   125493           
  Partials     20791    20791           
Flag Coverage Δ *Carryforward flag
TensileLite 35.05% <ø> (ø) Carriedforward from 5ca4af4
hipBLAS 90.81% <ø> (ø) Carriedforward from 5ca4af4
hipBLASLt 34.69% <ø> (ø)
hipCUB 82.68% <ø> (ø) Carriedforward from 5ca4af4
hipDNN 86.13% <ø> (ø) Carriedforward from 5ca4af4
hipFFT 50.88% <ø> (ø) Carriedforward from 5ca4af4
hipRAND 76.12% <ø> (ø) Carriedforward from 5ca4af4
hipSOLVER 69.18% <ø> (ø) Carriedforward from 5ca4af4
hipSPARSE 86.10% <ø> (ø) Carriedforward from 5ca4af4
rocBLAS 47.91% <ø> (ø) Carriedforward from 5ca4af4
rocFFT 55.50% <ø> (ø) Carriedforward from 5ca4af4
rocRAND 57.03% <ø> (ø) Carriedforward from 5ca4af4
rocSOLVER 76.84% <ø> (ø) Carriedforward from 5ca4af4
rocSPARSE 72.37% <ø> (ø) Carriedforward from 5ca4af4
rocThrust 91.36% <ø> (ø) Carriedforward from 5ca4af4

*This pull request uses carry forward flags. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KKyang KKyang force-pushed the users/kkyang/stinkytofu-exec-mask-group branch from 20bb3a8 to 03a7728 Compare July 13, 2026 03:13
YangWen Huang added 5 commits July 13, 2026 11:18
Collapse a narrow-write..full-mask-reset exec span into one opaque
ExecMaskGroup pseudo-instruction before DAG scheduling and restore it
afterward, so the existing RAW/WAW/WAR graph builder orders it correctly
without teaching every vector instruction class about exec.

Closes #9003
- Forward-declare StinkyInstruction as struct, not class, in
  StinkyModifiers.hpp -- matches its actual definition and clears
  -Werror,-Wmismatched-tags under the Microsoft C++ ABI (clang-cl/MSVC).
- Add missing ArchHelper.hpp include for getGfxArchID() in
  StinkyDAGSchedulerPass.cpp.
runPass() always runs expandExecMaskedGroups() on every BB, so a
hand-built EXEC_GROUP without a real ExecGroupData modifier hit its
assertion and aborted the whole test binary. Give both tests a minimal
but real ExecGroupData so unzip has something valid to do, and adjust
their expected output accordingly.

Verified locally: full build + unit_tests.exe now 804/804 passing.
Replace all "See docs/developer/exec-mask-grouping.md" references with
short inline descriptions at each declaration site. Remove the doc file.
@KKyang KKyang force-pushed the users/kkyang/stinkytofu-exec-mask-group branch from 03a7728 to 5ca4af4 Compare July 13, 2026 03:19
@KKyang KKyang marked this pull request as ready for review July 13, 2026 03:21
@KKyang KKyang requested a review from a team as a code owner July 13, 2026 03:21
Replace exact register comparison and opcode allowlist with two
semantic predicates:

isFullMaskReset: any exec write whose sole source is literal -1.
  Single-source constraint covers all sane reset idioms without
  needing to evaluate multi-operand expressions.

isExecNarrowWrite: any exec write that is not a full-mask reset.
  Opcode-agnostic — unlike LLVM where codegen is machine-generated,
  StinkyTofu IR is written by hand, so we match semantic intent
  (exec != -1) rather than an opcode allowlist.

overlapsExec: alias-aware register check so s_mov_b64 exec, -1
  is recognized as a reset in wave32 (EXEC aliases EXEC_LO).

Tests added:
  B64ResetClosesWave32Span: s_mov_b64 exec, -1 closes a wave32 span.
  NonMovExecWriteOpensSpan: s_or_b32 exec_lo opens a span.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants