[Mlir-commits] [mlir] [mlir][ArmSME] Add support for vector.transpose (PR #66760)
Cullen Rhodes
llvmlistbot at llvm.org
Thu Sep 21 00:54:59 PDT 2023
================
@@ -241,11 +242,84 @@ struct BroadcastOpToArmSMELowering
}
};
+/// Conversion pattern for vector.transpose.
+///
+/// Stores the input tile to memory and reloads vertically.
+///
+/// Example:
+///
+/// %transposed_src = vector.transpose %src, [1, 0]
+/// : vector<[4]x[4]xi32> to vector<[4]x[4]xi32>
+///
+/// is converted to:
+///
+/// %alloca = memref.alloca(%svl_s, %svl_s) : memref<?x?xi32>
+/// %arm_sme.tile_store %src, <hor>, %alloca[%c0, %c0]
+/// : memref<?x?xi32>, vector<[4]x[4]xi32>
+/// %transposed_src = arm_sme.tile_load <ver>, %alloca[%c0, %c0]
+/// : memref<?x?xi32>, vector<[4]x[4]xi32>
+///
+/// NOTE: Tranposing via memory is obviously expensive, the current intention
+/// is to avoid the transpose if possible, this is therefore intended as a
+/// fallback and to provide base support for Vector ops. If it turns out
+/// transposes can't be avoided then this should be replaced with a more optimal
+/// implementation, perhaps with tile <-> vector (MOVA) ops.
+struct TransposeOpToArmSMELowering
+ : public OpRewritePattern<vector::TransposeOp> {
+ using OpRewritePattern<vector::TransposeOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(vector::TransposeOp transposeOp,
+ PatternRewriter &rewriter) const final {
+ auto tileType = transposeOp.getResultVectorType();
+ if (!tileType || !arm_sme::isValidSMETileVectorType(tileType))
+ return failure();
+
+ SmallVector<int64_t> transp;
+ for (auto attr : transposeOp.getTransp())
+ transp.push_back(cast<IntegerAttr>(attr).getInt());
+
+ if (transp[0] != 1 && transp[1] != 0)
+ return failure();
+
+ OpBuilder::InsertionGuard g(rewriter);
----------------
c-rhodes wrote:
> OK, so only `[0, 1]` and `[1, 0]` would be valid and we need to make sure that it's the latter, cool. Like I said, I'd add a comment to explain this, e.g.:
>
> > Make sure that this is indeed a transposition (it could also be an identity).
I added a comment already, is it ok?
https://github.com/llvm/llvm-project/pull/66760
More information about the Mlir-commits
mailing list