[Mlir-commits] [mlir] [MLIR][XeGPU] Enhance XeGPU lane layout to support "wrap-around" distribution (PR #186958)
Charitha Saumya
llvmlistbot at llvm.org
Thu Mar 19 10:48:21 PDT 2026
================
@@ -396,6 +384,70 @@ bool LayoutAttr::isEqualTo(const xegpu::DistributeLayoutAttr &other) {
return *this == dyn_cast<xegpu::LayoutAttr>(other);
}
+/// Implements DistributeLayoutAttr::computeStaticDistributedCoords to
+/// compute multi-dimensional offsets for a given linear ID when distributed by
+/// LayoutAttr.
+SmallVector<SmallVector<int64_t>>
+LayoutAttr::computeStaticDistributedCoords(int64_t linearId,
+ ArrayRef<int64_t> shape) {
+ SmallVector<int64_t> layoutVec;
+ SmallVector<int64_t> subShape;
+ SmallVector<int64_t> instData;
+ if (isForWorkgroup()) {
+ layoutVec = getEffectiveSgLayoutAsInt();
+ subShape = getEffectiveSgDataAsInt();
+ } else if (isForSubgroup()) {
+ instData = getEffectiveInstDataAsInt();
+ layoutVec = getEffectiveLaneLayoutAsInt();
+ subShape = getEffectiveLaneDataAsInt();
+ }
+ if (!instData.empty()) {
+ linearId = 0;
+ subShape = instData;
+ }
+ assert(!subShape.empty() && "sgdata or lanedata cannot be empty");
+
+ // Delinearize the linear ID using the order attribute.
+ DenseI32ArrayAttr orderAttr = getOrder();
+ SmallVector<int64_t> order;
+ if (orderAttr && !orderAttr.empty()) {
+ order = llvm::map_to_vector(orderAttr.asArrayRef(), [](int32_t idx) {
+ return static_cast<int64_t>(idx);
+ });
+ } else {
+ order =
+ llvm::to_vector(llvm::reverse(llvm::seq<int64_t>(0, layoutVec.size())));
----------------
charithaintc wrote:
This type of reversing is not needed if you use `getEffectiveOrder`
https://github.com/llvm/llvm-project/pull/186958
More information about the Mlir-commits
mailing list