[Mlir-commits] [mlir] [mlir][linalg] Enable scalable vectorization of linalg.unpack (PR #149293)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Wed Jul 30 06:17:52 PDT 2025
================
@@ -1831,126 +1832,138 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, linalg::PackOp packOp,
return success();
}
-/// Vectorize a `linalg::UnPackOp` to these 4 Ops:
-/// Vector::TransferReadOp - Reads a vector from the source tensor
-/// vector::TransposeOp - Transpose the Source tensor
-/// ShapeCastOp - Reshape the data based on the target.
-/// vector::TransferWriteOp. - Write the result vector back to the destination
-/// tensor.
-/// If the vector sizes are not provided:
-/// * the vector sizes are determined by the input operand and attributes,
-/// * update the inBounds attribute instead of masking.
+/// Vectorize `linalg.unpack` into:
+/// * xfer_read -> vector.transpose -> vector.shape_cast -> xfer_write
+///
+/// The input-vector-sizes specify both the read and the write vector
+/// sizes and are passed as one array covering both operations, i.e.:
+///
+/// input-vector-sizes = [1, 1, 8, [8], 8, [8]]
+/// \ / \ /
+/// read-sizes write-sizes
+///
+/// (for brefity, in the diagram,
+/// * input-vector-sizes = `inputVectorSizes` + `inputScalableDims`
+/// )
+///
+/// If the vector sizes are not provided:
+/// * the vector sizes are determined by the operands,
+/// * the inBounds attribute is used instead of masking.
+///
+/// EXAMPLE (no vector sizes):
+/// ```
+/// %unpack = linalg.unpack %src
+/// inner_dims_pos = [0, 1]
+/// inner_tiles = [8, 8]
+/// into %dest : tensor<1x1x8x8xf32> -> tensor<8x8xf32>
+/// ```
+/// is vectorized as:
+/// ```
+/// // Reads a vector from the source tensor
+/// %read = vector.transfer_read %src
+/// : tensor<1x1x8x8xf32>, vector<1x1x8x8xf32>
+/// // Transpose %read as specified in `outer_dims_perm` attribute
+/// %tr = vector.transpose %read [0, 2, 1, 3]
+/// : vector<1x1x8x8xf32> to vector<1x8x1x8xf32>
+/// // Reshape the data based on the target
+/// %sc = vector.shape_cast %tr : vector<1x8x1x8xf32> to vector<8x8xf32>
+/// // Write the result vector to the destination tensor.
+/// vector.transfer_write %sc into %dest : vector<8x8xf32>, tensor<8x8xf32>
----------------
banach-space wrote:
Thanks!
https://github.com/llvm/llvm-project/pull/149293
More information about the Mlir-commits
mailing list