[Graph Optimization](feat) Layout Optimization for main-dev - #1267
Merged
WuTYSFG merged 40 commits intoAug 8, 2026
Merged
Conversation
zhanwei33
marked this pull request as ready for review
July 28, 2026 10:01
Contributor
Author
|
retry |
zhanwei33
force-pushed
the
codex/upstream-main-dev-graph-optimize-v1
branch
from
July 28, 2026 11:25
01fa625 to
8c4d01c
Compare
…olding, ConvertModuloToMask passes and comprehensive unit tests
…ing and DiagonalShiftFolding to DiagonalMaskRemoval Rename the two passes across the codebase (namespaces, functions, files, header guards, DEBUG_TYPE, comments, error strings, unit tests): - TileChunkCoalescing -> ChunkCoalescing (rewriteTileChunkCoalesce -> rewriteChunkCoalesce) - DiagonalShiftFolding -> DiagonalMaskRemoval (rewriteDiagonalShiftFold -> rewriteDiagonalMaskRemoval)
WuTYSFG
previously approved these changes
Aug 8, 2026
HinPeng
previously approved these changes
Aug 8, 2026
zhanwei33
force-pushed
the
codex/upstream-main-dev-graph-optimize-v1
branch
from
August 8, 2026 08:05
22e466a to
4437f2c
Compare
zhanwei33
force-pushed
the
codex/upstream-main-dev-graph-optimize-v1
branch
from
August 8, 2026 08:07
4437f2c to
9d6d5e1
Compare
Contributor
Author
|
/retry |
hongziqi
approved these changes
Aug 8, 2026
Contributor
Author
|
/retry |
4 similar comments
Contributor
Author
|
/retry |
Contributor
Author
|
/retry |
Contributor
Author
|
/retry |
Contributor
Author
|
/retry |
WuTYSFG
approved these changes
Aug 8, 2026
zhanwei33
added a commit
to zhanwei33/triton-ascend
that referenced
this pull request
Aug 14, 2026
…in-dev (triton-lang#1267)" (triton-lang#1467)" This reverts commit 678c78b. Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com>
zhanwei33
added a commit
to zhanwei33/triton-ascend
that referenced
this pull request
Aug 14, 2026
…in-dev (triton-lang#1267)" (triton-lang#1467)" This reverts commit 678c78b. Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com>
hongziqi
pushed a commit
that referenced
this pull request
Aug 14, 2026
* Revert "Revert "[Graph Optimization](feat) Layout Optimization for main-dev (#1267)" (#1467)" This reverts commit 678c78b. Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> * fix(ascend): guard nested modulo pointer relays (cherry picked from commit 88f10af) Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> --------- Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> Co-authored-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com>
HinPeng
pushed a commit
that referenced
this pull request
Aug 15, 2026
* Revert "Revert "[Graph Optimization](feat) Layout Optimization for main-dev (#1267)" (#1467)" This reverts commit 678c78b. Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> * fix(ascend): guard nested modulo pointer relays (cherry picked from commit 88f10af) Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> --------- Signed-off-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> Co-authored-by: zhanwei33 <22679270+zhanwei33@users.noreply.github.com> (cherry picked from commit fd29c24)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
main-dev.coalescing, and migrated legacy layout-memory rules.
retaining explicit capacity bounds.
Why
mainandmain-devhave diverged, so opening #1262's original head directlyagainst
main-devwould include dozens of unrelatedmaincommits. This PRreplays only the feature commits on top of
main-dev.main-dev integration
main-dev's runtime Ascend patch initialization.third_party/ascend/patch/triton-ascend-3.6.0.patch.Validation
triton-ascendwheel with LLVM/Clang 22 andCANN 9.0.
0.0.Related: #1262
Graph Optimize : Layout Optimization
This document covers only:
1. Registration Flow
flowchart TD A["Passes.td defines<br/>GraphOptimize<br/>constructor=<br/>createGraph<br/>OptimizePass"] B["C++/pybind exposes<br/>add_graph_optimize"] C["Python make_ttir"] D{"enable_graph_<br/>optimize?"} E["Do not add<br/>GraphOptimizePass<br/>to the PassManager"] F["Build<br/>GraphOptimization<br/>Options<br/>rule mask /<br/>rewrite cap /<br/>UB / remarks /<br/>force SIMT"] G["createGraph<br/>OptimizePass<br/>(options)"] H["Add<br/>GraphOptimizePass<br/>to the PassManager"] I["pm.run invokes<br/>runOnOperation"] J["populateBuiltin<br/>GraphOptimization<br/>Rules"] K["Construct and<br/>enable rules<br/>according to<br/>the rule mask"] A --> B C --> D D -->|No| E D -->|Yes| B B --> F --> G --> H --> I --> J --> KRegistered rules:
LoadStoreTransposeRuleTransposePointwiseReorderRuleStoreCoalescingRuleRowCoalescingRuleforceSimtOnly=trueThe first three rules run in a fixed phase order.
RowCoalescingRuleis attempted once after those phases and is not limited by the per-function rewrite budget.2. Main Graph Optimization Flow
2.1 Main Optimization and Non-Match Exit Flow
flowchart TD A["GraphOptimizePass<br/>::runOnOperation"] B["Validate and<br/>stabilize options"] C["Construct enabled<br/>builtin rules"] D["For each tt.func:<br/>create context;<br/>rewriteCount = 0"] E{"Any enabled phase<br/>remaining among<br/>the first three<br/>rules?"} F["Select next phase<br/>in fixed order:<br/>LoadStoreTranspose<br/>Rule →<br/>TransposePointwise<br/>ReorderRule →<br/>StoreCoalescing<br/>Rule"] G{"Per-function<br/>rewrite budget<br/>remaining?"} H["Prepare analyses<br/>needed by pattern<br/>matching and proof"] I["findCandidates:<br/>run pattern match<br/>and prove<br/>applicability;<br/>do not modify IR"] J{"Any candidate<br/>plans?"} K["Sort candidates<br/>benefit →<br/>program order →<br/>rule id"] L["Discard stale<br/>plans;<br/>revalidate the<br/>remaining plans"] M{"Any usable plan<br/>remaining?"} N["Enter the<br/>rewrite flow"] O["Rewrite succeeds"] P["Destroy all<br/>stale plans;<br/>invalidate<br/>analyses; epoch++"] Q{"Was this<br/>RowCoalescing?"} R["rewriteCount++;<br/>continue current<br/>phase"] S["Non-match:<br/>current attempt<br/>does not<br/>modify IR;<br/>no pass failure"] T{"Processing<br/>RowCoalescing?"} U["End the current<br/>phase"] V{"RowCoalescing<br/>enabled by mask<br/>and forceSimtOnly?"} W["Attempt<br/>RowCoalescingRule<br/>once after phases;<br/>not limited by the<br/>per-function<br/>rewrite budget"] X["Finish current<br/>tt.func;<br/>process the next"] A --> B --> C --> D --> E E -->|Yes| F --> G E -->|No| V G -->|Yes| H --> I --> J G -->|No| V J -->|Yes| K --> L --> M J -->|No| S M -->|Yes| N --> O --> P --> Q M -->|No| S Q -->|No| R --> G Q -->|Yes| X S --> T T -->|No| U --> E T -->|Yes| X V -->|No| X V -->|Yes| W --> HPreparing analyses is only a prerequisite for matching. The actual pattern match and applicability proof run inside
findCandidates(), which does not modify the IR. The optimization takes effect only after candidate matching and revalidation succeed andapply()commits the new IR.The
maxRewritesPerFunctionbudget is initialized once pertt.funcand shared byLoadStoreTransposeRule,TransposePointwiseReorderRule, andStoreCoalescingRulein that fixed phase order. Reaching the budget skips the remaining phases among these three rules, but it does not suppress the one-shotRowCoalescingRuleattempt.The following cases take the normal non-match exit:
findCandidates()produces no candidate plan;revalidate()fails;These cases only discard a candidate, end the current phase among the first three rules, or finish the one-shot Row attempt; they do not fail the compilation.
Only an analysis-construction failure or
findCandidates()itself returningfailure()is an internal processing error that triggerssignalPassFailure().2.2 Rewrite and Rewrite-Failure Exit Flow
flowchart TD A["Select a<br/>successfully<br/>revalidated plan"] B["Create IRRewriter"] C["plan.apply<br/>(rewriter)"] D["Attempt to create<br/>replacement IR<br/>or a detached<br/>sandbox"] E{"Did creation<br/>succeed?"} F["Verify new ops,<br/>types, attributes,<br/>and additional<br/>proofs"] G{"Did verification<br/>or a secondary<br/>proof fail?"} H["Replace old uses /<br/>IR / module attrs"] I["Erase old ops"] J["apply returns<br/>success"] K["Driver destroys<br/>plans and<br/>invalidates<br/>analyses"] L["Erase IR created<br/>by this attempt<br/>or discard the<br/>sandbox"] M["Do not commit<br/>or erase<br/>the old IR"] N["apply returns<br/>failure"] O["Driver clears<br/>selectedPlan<br/>and the remaining<br/>plans"] P["function.emitError"] Q["signalPassFailure<br/>+ return"] A --> B --> C --> D --> E E -->|Yes| F --> G G -->|No| H --> I --> J --> K E -->|No| L G -->|Yes| L L --> M --> N --> O --> P --> QRewriting uses transactional commit semantics: construct and verify the new IR first, then replace the old IR only after every check passes. After a successful rewrite, all analyses are invalidated, and the next match must be computed against a new epoch. If creation, verification, or a secondary proof fails, the attempt cleans up its new IR, preserves the old IR, and terminates the Graph Optimize pass.
A rewrite failure differs from a non-match:
3. Summary
The core Graph Optimize path is: