[Mlir-commits] [mlir] [MLIR][XeGPU] Lowering 2-Dimensional Reductions of N-D Tensors into Chained 1-D Reductions (PR #186034)
Charitha Saumya
llvmlistbot at llvm.org
Fri Mar 13 11:01:02 PDT 2026
================
@@ -444,33 +440,27 @@ class MultiRed2dOpPattern
auto loc = reductionOp.getLoc();
auto acc = reductionOp.getAcc();
- // The first reduction's dist attribute does not have the cross lane dim.
- auto resSliceLayoutAttr = cast<xegpu::SliceAttr>(resLayout);
- SmallVector<int64_t> dropDims{crossLaneDim};
- auto intraLaneRedResLayout = resSliceLayoutAttr.dropSliceDims(dropDims);
-
SmallVector<int64_t> accShape(sourceVecType.getShape());
accShape.erase(accShape.begin() + intraLaneDim);
- if (acc) {
- acc = vector::BroadcastOp::create(
- rewriter, loc,
- VectorType::get(accShape, sourceVecType.getElementType()), acc);
- xegpu::setDistributeLayoutAttr(
- llvm::dyn_cast<OpResult>(acc),
- cast<xegpu::DistributeLayoutAttr>(intraLaneRedResLayout));
- }
+ Type eTy = sourceVecType.getElementType();
+ Attribute eVal;
+ if (eTy.isFloat())
+ eVal = FloatAttr::get(eTy, 0.0);
+ else
+ eVal = IntegerAttr::get(eTy, 0);
+ Value const_zero = arith::ConstantOp::create(
+ rewriter, loc,
+ DenseElementsAttr::get(VectorType::get(accShape, eTy), eVal));
Value intraLaneReduced = vector::MultiDimReductionOp::create(
- rewriter, loc, reductionOp.getKind(), reductionOp.getSource(), acc,
- ArrayRef<int64_t>(intraLaneDim));
- xegpu::setDistributeLayoutAttr(
- llvm::dyn_cast<OpResult>(intraLaneReduced),
- cast<xegpu::DistributeLayoutAttr>(intraLaneRedResLayout));
-
- Value crossLaneReduced = vector::ReductionOp::create(
- rewriter, loc, reductionOp.getKind(), intraLaneReduced, nullptr);
- xegpu::setDistributeLayoutAttr(
- llvm::dyn_cast<OpResult>(crossLaneReduced),
- cast<xegpu::DistributeLayoutAttr>(resLayout));
+ rewriter, loc, reductionOp.getKind(), reductionOp.getSource(),
+ const_zero, ArrayRef<int64_t>(intraLaneDim));
+
+ // Adjust crossLaneDim after the first reduction.
+ if (crossLaneDim > intraLaneDim)
+ crossLaneDim -= 1;
+ Value crossLaneReduced = vector::MultiDimReductionOp::create(
+ rewriter, loc, reductionOp.getKind(), intraLaneReduced, acc,
+ ArrayRef<int64_t>(crossLaneDim));
assert(crossLaneReduced.getType() == reductionOp.getResult().getType() &&
----------------
charithaintc wrote:
not relayed to this change, but why is this assertion needed?
https://github.com/llvm/llvm-project/pull/186034
More information about the Mlir-commits
mailing list