[Mlir-commits] [mlir] [MLIR][XeGPU] Refactor layout propagation utilities (PR #179016)
Jianhui Li
llvmlistbot at llvm.org
Tue Feb 3 21:55:53 PST 2026
================
@@ -471,6 +468,152 @@ LayoutAttr::setUnitDimLayout(SetVector<int64_t> unitDims) const {
getLaneData(), getOrder());
}
+// Derive a new layout with sg_data, inst_data and lane_data set to the
+// specified values for the given dimension
+DistributeLayoutAttr LayoutAttr::setDimData(int64_t dim, int64_t sgData,
+ int64_t instData,
+ int64_t laneData) {
+
+ SmallVector<int64_t> sgDataVec = getEffectiveSgDataAsInt();
+ SmallVector<int64_t> instDataVec = getEffectiveInstDataAsInt();
+ SmallVector<int64_t> laneDataVec = getEffectiveLaneDataAsInt();
+
+ if (dim < static_cast<int64_t>(sgDataVec.size()) && sgData != -1)
+ sgDataVec[dim] = sgData;
+ if (dim < static_cast<int64_t>(instDataVec.size()) && instData != -1)
+ instDataVec[dim] = instData;
+ if (dim < static_cast<int64_t>(laneDataVec.size()) && laneData != -1)
+ laneDataVec[dim] = laneData;
+
+ SmallVector<int32_t> sgDataVec32(sgDataVec.begin(), sgDataVec.end());
+ SmallVector<int32_t> instDataVec32(instDataVec.begin(), instDataVec.end());
+ SmallVector<int32_t> laneDataVec32(laneDataVec.begin(), laneDataVec.end());
+
+ return LayoutAttr::get(
+ getContext(), getSgLayout(),
+ sgDataVec.empty() ? DenseI32ArrayAttr()
+ : DenseI32ArrayAttr::get(getContext(), sgDataVec32),
+ instDataVec.empty() ? DenseI32ArrayAttr()
+ : DenseI32ArrayAttr::get(getContext(), instDataVec32),
+ getLaneLayout(),
+ laneDataVec.empty() ? DenseI32ArrayAttr()
+ : DenseI32ArrayAttr::get(getContext(), laneDataVec32),
+ getOrder());
+}
+
+// Derive a new layout by collapsing groups of dimensions.
+// Each inner array in `dimGroups` specifies a set of adjacent dimensions
+// that are collapsed into a single dimension in the derived layout.
+DistributeLayoutAttr
+LayoutAttr::collapseDims(SmallVector<SmallVector<int64_t>> dimGroups) const {
+
+ SmallVector<int64_t> sgLayout = getEffectiveSgLayoutAsInt();
+ SmallVector<int64_t> sgData = getEffectiveSgDataAsInt();
+ SmallVector<int64_t> instData = getEffectiveInstDataAsInt();
+ SmallVector<int64_t> laneLayout = getEffectiveLaneLayoutAsInt();
+ SmallVector<int64_t> laneData = getEffectiveLaneDataAsInt();
+
+ DenseI32ArrayAttr orderAttr = getOrder();
+ SmallVector<int64_t> orderVec;
+ if (orderAttr && !orderAttr.empty()) {
+ orderVec = llvm::to_vector(
+ llvm::map_range(orderAttr.asArrayRef(),
+ [](int32_t idx) { return static_cast<int64_t>(idx); }));
+ }
+
+ SmallVector<int64_t> collapsedSgLayout;
+ SmallVector<int64_t> collapsedSgData;
+ SmallVector<int64_t> collapsedInstData;
+ SmallVector<int64_t> collapsedLaneLayout;
+ SmallVector<int64_t> collapsedLaneData;
+ SmallVector<int64_t> collapsedOrder;
+ SetVector<int64_t> coveredDims;
+
+ for (const auto &group : dimGroups) {
+
+ // Collapse by multiplying values across dimension group
+ int64_t collapsedSg = 1, collapsedSgD = 1, collapsedInst = 1;
+ int64_t collapsedLaneL = 1, collapsedLaneD = 1;
+ int64_t collapsedOrderValue = -1;
+ int64_t dimBeforeCurrent = group.front() - 1;
----------------
Jianhui-Li wrote:
It still works.
https://github.com/llvm/llvm-project/pull/179016
More information about the Mlir-commits
mailing list