[Mlir-commits] [mlir] [mlir][xegpu] Add SIMT distribution support for GEMM transpose B case. (PR #155517)
Adam Siemieniuk
llvmlistbot at llvm.org
Mon Sep 15 06:12:56 PDT 2025
================
@@ -235,6 +235,61 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> {
"FailureOr<SmallVector<SmallVector<Value>>>",
"getOffsets",
(ins "OpBuilder &": $builder, "Location":$loc, "Value":$linearId, "ArrayRef<int64_t>":$shape)>,
+ InterfaceMethod</*desc=*/[{Check if this layout can be achieved by applying a transpose
+ to some other layout according to given permutation of (0...n-1).}],
+ /*retTy=*/"bool",
+ /*methodName=*/"isTransposeOf",
+ /*args=*/(ins "const xegpu::DistributeLayoutAttr&": $other, "ArrayRef<int64_t>": $perm),
+ /*methodBody=*/[{
+ if (!other)
+ return false;
+ if ($_self.getRank() != other.getRank() || perm.size() != static_cast<size_t>($_self.getRank()))
+ return false;
+ // check if the permutation is valid
+ int64_t rank = $_self.getRank();
+ SmallVector<bool, 8> seen(rank, false);
+ for (const auto &ta : llvm::enumerate(perm)) {
+ if (ta.value() < 0 || ta.value() >= rank)
+ return false;
+ if (seen[ta.value()])
+ return false;
+ seen[ta.value()] = true;
+ }
+ auto checkTranspose = [](ArrayRef<int64_t> dst, ArrayRef<int64_t> src, ArrayRef<int64_t> perm) {
+ // If both `dst` and `src` are empty, conservatively return true
+ // here because some layout fields can be empty.
+ if (dst.empty() && src.empty())
+ return true;
+ for (const auto &ta : llvm::enumerate(perm)) {
+ if (src[ta.index()] != dst[ta.value()])
+ return false;
+ }
+ return true;
+ };
+ // Check sgLayout
+ if (!checkTranspose($_self.getEffectiveSgLayoutAsInt(), other.getEffectiveSgLayoutAsInt(), perm))
+ return false;
+ // Check sgData
+ if (!checkTranspose($_self.getEffectiveSgDataAsInt(), other.getEffectiveSgDataAsInt(), perm))
+ return false;
+ // Check instData
+ if (!checkTranspose($_self.getEffectiveInstDataAsInt(), other.getEffectiveInstDataAsInt(), perm))
+ return false;
+ // Check laneLayout
+ if (!checkTranspose($_self.getEffectiveLaneLayoutAsInt(), other.getEffectiveLaneLayoutAsInt(), perm))
+ return false;
+ // Check laneData
+ if (!checkTranspose($_self.getEffectiveLaneDataAsInt(), other.getEffectiveLaneDataAsInt(), perm))
+ return false;
+ // Check order if both sides have order field.
+ if ($_self.getOrder() && other.getOrder()) {
----------------
adam-smnk wrote:
Is it really safe to claim it is a transpose if one doesn't have order?
https://github.com/llvm/llvm-project/pull/155517
More information about the Mlir-commits
mailing list