[Codegen][GPU] Add DistributeArgCompare pattern#23793
Open
bangtianliu wants to merge 3 commits intoiree-org:mainfrom
Open
[Codegen][GPU] Add DistributeArgCompare pattern#23793bangtianliu wants to merge 3 commits intoiree-org:mainfrom
bangtianliu wants to merge 3 commits intoiree-org:mainfrom
Conversation
4c874b1 to
9e800bb
Compare
11 tasks
8bb34ff to
f46ba08
Compare
06be48b to
3f67dda
Compare
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
3f67dda to
69599c5
Compare
sommerlukas
reviewed
Mar 31, 2026
Contributor
sommerlukas
left a comment
There was a problem hiding this comment.
Some comments on style and tests. For the distribution logic, it would be good to also get @Groverkss's eyes on this.
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Show resolved
Hide resolved
.../iree/compiler/Codegen/Common/GPU/test/gpu_nested_layout_vector_distribution_argcompare.mlir
Show resolved
Hide resolved
Contributor
Author
Sure, thanks for your time reviewing this PR. |
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
14e99c0 to
a2f50ff
Compare
Contributor
Author
|
cc @Groverkss for review |
sommerlukas
reviewed
Apr 2, 2026
Contributor
sommerlukas
left a comment
There was a problem hiding this comment.
Some more nits and questions.
| /// Returns arith.cmpf for floating-point types and arith.cmpi for integers. | ||
| static Value createEqualityComparison(RewriterBase &rewriter, Location loc, | ||
| Value lhs, Value rhs) { | ||
| if (isa<FloatType>(lhs.getType())) { |
Contributor
There was a problem hiding this comment.
Should we assert here that lhs and rhs have the same type?
Contributor
Author
There was a problem hiding this comment.
the arith.cmpf and arith.cmpi verifiers will catch any type mismatch.
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUNestedLayoutDistributionPatterns.cpp
Show resolved
Hide resolved
- Extract shared helpers and to deduplicate shape computation logic between DistributeMultiReduction and DistributeArgCompare - Simplify broadcastShape computation by deriving from distributed input shape instead of manual construction - Reuse existing elemTy/indexElemTy variables instead of repeated getElementType() calls - Simplify resultValue initialization by setting common case first - Fix inaccurate comment about yielded value check Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
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.
This PR adds the
DistributeArgComparepattern to distributeiree_vector_ext.arg_compareoperations across GPU threads and subgroups.For supported comparators, we use a ballot-based approach that leverages
gpu.subgroup_reduce+gpu.ballotfor reduction.Supported comparators include:
Unsupported comparators fall back to the portable butterfly shuffle approach. Currently, this is mainly used for argmax/argmin operations, but we can extend support for additional comparators as needed.
Issue: #23005
Assisted-by: Claude Code