[Mlir-commits] [mlir] [mlir][xegpu] Add support for `vector.reduction` and `vector.multi_reduction` subgroup to work-item distribution. (PR #180308)
Artem Kroviakov
llvmlistbot at llvm.org
Tue Feb 10 01:46:06 PST 2026
================
@@ -362,6 +395,137 @@ struct SgToWiPrefetchNd : public OpConversionPattern<xegpu::PrefetchNdOp> {
}
};
+/// This pattern distributes a subgroup-level vector.reduction op to
+/// workitem-level. This require shuffling the data across the workitems (using
+/// gpu::ShuffleOp) and reducing in stages until all workitems have the final
+/// result.
+struct SgToWiVectorReduction : public OpConversionPattern<vector::ReductionOp> {
+ using OpConversionPattern<vector::ReductionOp>::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::ReductionOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ auto layout = xegpu::getDistributeLayoutAttr(op.getVector());
+
+ // If no layout, nothing to do.
+ if (!layout || !layout.isForSubgroup())
+ return failure();
+
+ VectorType vectorType = op.getSourceVectorType();
+
+ // Only rank 1 vectors supported.
+ if (vectorType.getRank() != 1)
----------------
akroviakov wrote:
`vector::ReductionOp` description limits rank to 1, but its verifier also allows rank 0. For rank 0, can't we return the value itself? Then this failure would not be needed.
https://github.com/llvm/llvm-project/pull/180308
More information about the Mlir-commits
mailing list