Skip to content

[TritonToGraph](feat) Add merge-concat-load-buffer pass - #1494

Merged
WuTYSFG merged 1 commit into
triton-lang:main-devfrom
Popeyesxs:cat_opt_dev
Aug 13, 2026
Merged

[TritonToGraph](feat) Add merge-concat-load-buffer pass#1494
WuTYSFG merged 1 commit into
triton-lang:main-devfrom
Popeyesxs:cat_opt_dev

Conversation

@Popeyesxs

@Popeyesxs Popeyesxs commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

#1086
A masked tt.load lowers to a full-tile UB alloc, a linalg.fill with the padding value, and a memref.copy of only the in-bounds subview. When two such loads are concatenated by tl.cat, triton-to-linalg emits an extract_slice + insert_slice pair over two separate allocs of the same static shape, so the kernel pays for twice the UB it needs plus two whole-tile fills.

This pass recognises that shape and folds the two allocs into one. The rewrite only fires when the source copies land inside the insert region and the dest copies stay clear of it, which makes the merge a pure renaming of the second buffer onto the first.

The fills are dropped only when the union of the copy destinations provably covers every later read of the concatenated tensor. When the padding is still observable the allocs are merged but one fill is kept, and when the two fills disagree on the padding value the rewrite is abandoned entirely.

New contributor declaration

  • I am not making a trivial change, such as fixing a typo in a comment.

  • I have written a PR description following these
    rules.

  • I have run pre-commit run --from-ref origin/main --to-ref HEAD.

  • Select one of the following.

    • I have added tests.
      • /test for lit tests
      • /unittest for C++ tests
      • /python/test for end-to-end tests
    • This PR does not need a test because FILL THIS IN.
  • Select one of the following.

    • I have not added any lit tests.
    • The lit tests I have added follow these best practices,
      including the "tests should be minimal" section. (Usually running Python code
      and using the instructions it generates is not minimal.)

@github-actions github-actions Bot added compiler Changes to C/C++ compiler backend (lib/, include/) python Changes to Python runtime or bindings ascend-backend Changes to the Ascend NPU backend labels Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

OpenCodeReview: Review partially complete: 0 finding(s); 1 of 5 selected item(s) failed.

Comment thread third_party/ascend/include/TritonToGraph/MergeConcatLoadBuffer.h Outdated
@Popeyesxs

Copy link
Copy Markdown
Contributor Author

/retry

@Popeyesxs

Copy link
Copy Markdown
Contributor Author

/retry

Comment thread third_party/ascend/backend/compiler.py Outdated

@zhanwei33 zhanwei33 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.

The new end-to-end coverage is helpful. I found one correctness blocker in the fill-elision/merge ordering.

Comment thread third_party/ascend/lib/TritonToGraph/MergeConcatLoadBuffer.cpp
@Popeyesxs
Popeyesxs force-pushed the cat_opt_dev branch 2 times, most recently from 6bee74f to 47db7a0 Compare August 13, 2026 11:55
Comment thread third_party/ascend/backend/compiler.py Outdated
Comment thread third_party/ascend/lib/TritonToGraph/MergeConcatLoadBuffer.cpp
Comment thread third_party/ascend/lib/TritonToGraph/MergeConcatLoadBuffer.cpp
Comment thread third_party/ascend/lib/TritonToGraph/MergeConcatLoadBuffer.cpp
@Popeyesxs
Popeyesxs force-pushed the cat_opt_dev branch 2 times, most recently from bca7588 to 47db7a0 Compare August 13, 2026 13:28
A masked tt.load lowers to a full-tile UB alloc, a linalg.fill with the
padding value, and a memref.copy of only the in-bounds subview. When two
such loads are concatenated by tl.cat, triton-to-linalg emits an
extract_slice + insert_slice pair over two separate allocs of the same
static shape, so the kernel pays for twice the UB it needs plus two
whole-tile fills.

This pass recognises that shape and folds the two allocs into one. The
rewrite only fires when the source copies land inside the insert region
and the dest copies stay clear of it, which makes the merge a pure
renaming of the second buffer onto the first.

The fills are dropped only when the union of the copy destinations
provably covers every later read of the concatenated tensor. When the
padding is still observable the allocs are merged but one fill is kept,
and when the two fills disagree on the padding value the rewrite is
abandoned entirely.






The merged buffer ends up written by two disjoint memref.copy ops. On
910_9362 the generated code only honours the copy next to the surviving
to_tensor, so the rest of the tile reads back the padding value even
though the IR is unchanged and equivalent through bishengir-opt. The
pipeline therefore only enables the pass on 910_95/950.
@WuTYSFG
WuTYSFG merged commit 25e1c72 into triton-lang:main-dev Aug 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ascend-backend Changes to the Ascend NPU backend compiler Changes to C/C++ compiler backend (lib/, include/) python Changes to Python runtime or bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants