[Mlir-commits] [mlir] [mlir][ArmSME] Add support for vector.transpose (PR #66760)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Wed Sep 20 00:50:30 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);
----------------
banach-space wrote:
Add a comment that this is verifying that this is indeed "transposing" the input 2D matrix.
Btw, would `%1 = vector.transpose %0, [0, 0] ` or `%1 = vector.transpose %0 [1, 1]` be valid (as in, in general, not in the context of this transformation)?
https://github.com/llvm/llvm-project/pull/66760
More information about the Mlir-commits
mailing list