[Mlir-commits] [mlir] [MLIR][XeGPU] Refactor isEvenlyDistributable() to Layout attribute interface (PR #191945)
Artem Kroviakov
llvmlistbot at llvm.org
Wed Apr 15 05:32:54 PDT 2026
================
@@ -299,26 +302,60 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> {
} else {
return failure();
}
- assert(
- !subShape.empty() &&
- "sgdata or lanedata cannot be empty for distributed shape computation");
+ // sgdata or lanedata cannot be empty for distributed shape computation
+ if (subShape.empty())
+ return failure();
SmallVector<int64_t> distributedShape(shape.size());
for (auto [i, dim] : llvm::enumerate(shape)) {
int64_t distriUnit = layout[i]*subShape[i];
if ((dim % distriUnit) == 0) {
// Evenly divisible case, divide the dimension by the layout factor.
distributedShape[i] = dim / layout[i];
- assert((distributedShape[i] % subShape[i] == 0) &&
- "Even distribution: sgdata or lanedata must divide the distributed dimension");
+ if (distributedShape[i] % subShape[i] != 0)
+ return failure();
} else {
// wrap around case, the dimension size must be equal to subShape value
- assert(dim == subShape[i] &&
- "Wrap-around distribution: sgdata or lanedata must be same as tensor tile shape");
+ if(dim != subShape[i])
+ return failure();
distributedShape[i] = dim;
}
}
return distributedShape;
}]>,
+ InterfaceMethod<[{Checks if the given shape can be distributed by the layout}],
+ /*retTy=*/"bool",
+ /*methodName=*/"isDistributable",
+ /*args=*/(ins "SmallVector<int64_t>":$shape),
+ /*methodBody=*/[{
+ DistributeLayoutAttr curLayoutAttr = $_self;
+ SmallVector<int64_t> curShape = shape;
+ // Phase 1: Distribute across subgroups (sg_layout + sg_data).
+ if (curLayoutAttr.isForWorkgroup()) {
+ auto maybeSgShape = curLayoutAttr.computeDistributedShape(curShape);
+ if (failed(maybeSgShape))
+ return false;
+ curShape = maybeSgShape.value();
+ curLayoutAttr = curLayoutAttr.dropSgLayoutAndData();
+ if (!curLayoutAttr)
+ return true;
+ }
+ // Phase 2: Distribute across instruction data (inst_data).
+ if (curLayoutAttr.isForSubgroup() && !curLayoutAttr.isForLane()) {
+ SmallVector<int64_t> instData = curLayoutAttr.getEffectiveInstDataAsInt();
+ for (size_t i = 0; i < curShape.size(); ++i) {
----------------
akroviakov wrote:
Can we distribute "recursively", as in a while loop of `computeDistributedShape` that progressively unravels the shape and removes the "outermost" layout? This would contain the distribution logic in one place.
https://github.com/llvm/llvm-project/pull/191945
More information about the Mlir-commits
mailing list