Split pointwise ops over concat inputs to enable fused_concat fusion - #5182
Open
pfultz2 wants to merge 8 commits into
Open
Split pointwise ops over concat inputs to enable fused_concat fusion#5182pfultz2 wants to merge 8 commits into
pfultz2 wants to merge 8 commits into
Conversation
pfultz2
requested review from
CharlieL7,
TedThemistokleous,
bdevorem and
shivadbhavsar
August 24, 2026 15:28
Contributor
There was a problem hiding this comment.
Pull request overview
Distributes pointwise operations across concat segments to enable GPU fused_concat fusion and avoid intermediate buffers.
Changes:
- Adds pointwise-concat splitting and nested-concat flattening.
- Adds structural fusion and bailout tests.
- Review used a single pass without agent fan-out.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/fuse_concat.cpp |
Implements the new fusion rewrites. |
test/fuse_concat.cpp |
Tests splitting, outer concat flattening, and multi-use bailout. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+271
to
+274
| if(concat_ins->inputs().size() < 2) | ||
| return; | ||
| if(std::count(ins->inputs().begin(), ins->inputs().end(), concat_ins) != 1) | ||
| return; |
Comment on lines
+309
to
+310
| // Merge a same-axis concat that feeds directly into another concat | ||
| struct find_nested_concat |
|
|
||
| void fuse_concat::apply(module_pass_manager& mpm) const | ||
| { | ||
| match::find_matches(mpm, find_pointwise_concat_split{}); |
…aphX into fuse-pointwise-concat-split
Regressions detected 🔴 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
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.
Motivation
Patterns like rotate-half (used in RoPE) produce a
concatof slices that feeds a pointwise op. Since the concat's inputs are not pointwise,fuse_concatcannot fuse this into afused_concatkernel, so the concat and the pointwise op each launch a separate kernel and materialize an extra intermediate buffer. By distributing the pointwise op over the concat segments, the whole pattern becomes a concat of pointwise ops, which the existingfind_concat_pointwisematcher can fuse into a single kernel.Technical Details
Two new matchers are added to the
fuse_concatpass, run before the existing fusions:find_pointwise_concat_split: matches a single-use pointwise op with a single-useconcatinput whose inputs are all non-pointwise. For each concat segment, it clones the pointwise submodule and re-applies it to the segment, slicing the remaining pointwise inputs along the concat axis to the segment's range. The original pointwise op is then replaced by a concat of these per-segment pointwise ops. It bails out when the concat has fewer than two inputs or is used more than once by the pointwise op.find_nested_concat: flattens a single-useconcatthat feeds anotherconcaton the same axis into its parent, so the concat produced by the split (and any outer concat around it) collapses into one concat before the pointwise-concat fusions run.Each matcher is followed by
dead_code_elimination, and the existingfind_pointwise_concat_pointwise/find_concat_pointwisematchers then fuse the resulting concat-of-pointwise into afused_concat.Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.