[Mlir-commits] [mlir] [mlir][Vectorizer] Added support to Vectorize tensor.unpack (PR #76087)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Feb 14 13:22:15 PST 2024


================
@@ -1559,6 +1571,90 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, tensor::PackOp packOp,
   return success();
 }
 
+/// Vectorize a `tensor::UnPackOp` without OuterDimsPerms 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
+static LogicalResult vectorizeAsUnpackOp(RewriterBase &rewriter,
+                                         tensor::UnPackOp unpackOp,
+                                         ArrayRef<int64_t> inputVectorSizes,
+                                         SmallVectorImpl<Value> &newResults) {
+
+  OpBuilder::InsertionGuard g(rewriter);
+  rewriter.setInsertionPoint(unpackOp);
+
+  RankedTensorType unpackTensorType = unpackOp.getSourceType();
+
+  SmallVector<int64_t> readMaskShape(unpackTensorType.getShape());
----------------
Max191 wrote:

I think we should try to support outer_dims_perm cases here. I believe it should work as long as the readMaskShape is corrected for outer_dims_perm here. The following should work:

1. initialize `readMaskShape` equal to the `inputVectorSizes`
2. Divide by inner_tiles the same as before
3. Apply outer_dims_perm to `readMaskShape`
4. Append the inner_tiles to the end of `readMaskShape`

https://github.com/llvm/llvm-project/pull/76087


More information about the Mlir-commits mailing list