Split pointwise ops over concat inputs to enable fused_concat fusion - #5182
Split pointwise ops over concat inputs to enable fused_concat fusion#5182pfultz2 wants to merge 8 commits into
Conversation
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.
| if(concat_ins->inputs().size() < 2) | ||
| return; | ||
| if(std::count(ins->inputs().begin(), ins->inputs().end(), concat_ins) != 1) | ||
| return; |
| // Merge a same-axis concat that feeds directly into another concat | ||
| struct find_nested_concat |
There was a problem hiding this comment.
We could make changes here, or refactor in a future PR
There was a problem hiding this comment.
Yes, I would prefer to refactor this in the future.
|
|
||
| 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. |
|
bdevorem
left a comment
There was a problem hiding this comment.
approving for now, but there should be a changelog and it does look like there is a new matcher being added that already exists
| // Merge a same-axis concat that feeds directly into another concat | ||
| struct find_nested_concat |
kahmed10
left a comment
There was a problem hiding this comment.
overall looks fine, consider what to do about the find_nested_concat suggestion.
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.