[Mlir-commits] [mlir] [MLIR][XeGPU] Improve multi-reduction layout inference (PR #224618)
Jianhui Li
llvmlistbot at llvm.org
Mon Sep 21 21:48:10 PDT 2026
================
@@ -2493,13 +2458,39 @@ xegpu::SliceAttr xegpu::setupMultiReductionResultLayout(
"source shape not divisible by sg_layout");
sgData[i] = srcShape[i] / sgLayout[i];
remainingSgCount /= sgLayout[i];
- order[i] = remainOrder++;
}
}
- DenseI32ArrayAttr resOrderAttr = DenseI32ArrayAttr::get(
- context, SmallVector<int32_t>(order.begin(), order.end()));
- if (!orderAttr || orderAttr.empty())
- resOrderAttr = nullptr;
+
+ DenseI32ArrayAttr resOrderAttr = nullptr;
+ int numRetainedDims = srcRank - static_cast<int>(reductionDims.size());
+ if (orderAttr && !orderAttr.empty() &&
+ static_cast<int>(consumerOrder.size()) == numRetainedDims) {
+ // Fill known order
+ int retainedRank = 0;
+ for (int dim = 0; dim < srcRank; dim++)
+ if (!llvm::is_contained(reductionDims, dim))
+ order[dim] = consumerOrder[retainedRank++];
+ // Each new order is placed as close as possible to its neighbors,
+ // row-major. Re-index the order of higher walk orders.
+ for (int reducedDim = 0; reducedDim < srcRank; reducedDim++) {
+ if (!llvm::is_contained(reductionDims, reducedDim))
+ continue;
+ int64_t insertRank = 0;
+ // Add as an inner dim to the outer neighbor
+ if (reducedDim)
+ insertRank = order[reducedDim - 1];
+ // Add as an outer dim to the inner neighbor if no left neighbor
+ // exists.
+ else if (reducedDim + 1 < srcRank)
+ insertRank = order[reducedDim + 1] + 1;
----------------
Jianhui-Li wrote:
isn't this condition means reduceDim == 0? (comment says: no left neighbor exist)
https://github.com/llvm/llvm-project/pull/224618
More information about the Mlir-commits
mailing list