[Mlir-commits] [mlir] [MLIR][XeGPU] Support Layout propagation for interleave and deintereleave op (PR #194966)
Artem Kroviakov
llvmlistbot at llvm.org
Thu Apr 30 03:04:10 PDT 2026
================
@@ -458,6 +458,85 @@ xegpu::inferBitCastSourceLayout(xegpu::DistributeLayoutAttr resLayout,
return finalSrcLayout;
}
+/// Infers the source layout attribute for an interleave operation given the
+/// result layout attribute. Interleave doubles the size of the innermost
+/// dimension, so the layout inference is similar to bitcast where the source
+/// element type is larger than the result element type (ratio = 2).
+xegpu::DistributeLayoutAttr
+xegpu::inferInterleaveSourceLayout(xegpu::DistributeLayoutAttr resLayout) {
+
+ SmallVector<int64_t> sgData = resLayout.getEffectiveSgDataAsInt();
+ SmallVector<int64_t> instData = resLayout.getEffectiveInstDataAsInt();
+ SmallVector<int64_t> laneData = resLayout.getEffectiveLaneDataAsInt();
+ size_t sgDataSize = sgData.size();
+ size_t instDataSize = instData.size();
+ size_t laneDataSize = laneData.size();
+ int64_t sgDataValue = -1;
+ int64_t instDataValue = -1;
+ int64_t laneDataValue = -1;
+ int64_t dim = resLayout.getRank() - 1;
+
+ // Interleave doubles the innermost dimension, so we need to halve the
+ // layout values (similar to bitcast with ratio = 2)
+ int ratio = 2;
+ if (sgDataSize) {
+ assert((sgData.back() % ratio) == 0 &&
+ "sgData not divisible by interleave ratio");
+ sgDataValue = sgData.back() / ratio;
+ }
+ if (instDataSize) {
+ assert((instData.back() % ratio) == 0 &&
+ "instData not divisible by interleave ratio");
+ instDataValue = instData.back() / ratio;
+ }
+ if (laneDataSize) {
+ assert((laneData.back() % ratio) == 0 &&
+ "laneData not divisible by interleave ratio");
+ laneDataValue = laneData.back() / ratio;
+ }
+
+ xegpu::DistributeLayoutAttr finalSrcLayout;
+ finalSrcLayout =
+ resLayout.setDimData(dim, sgDataValue, instDataValue, laneDataValue);
+
+ return finalSrcLayout;
----------------
akroviakov wrote:
```suggestion
return resLayout.setDimData(dim, sgDataValue, instDataValue, laneDataValue);
```
Same in other places.
https://github.com/llvm/llvm-project/pull/194966
More information about the Mlir-commits
mailing list