[Mlir-commits] [mlir] [mlir][linalg] Vectorize unpack op without masking (PR #89067)
Han-Chung Wang
llvmlistbot at llvm.org
Tue Apr 30 11:49:04 PDT 2024
================
@@ -1560,11 +1574,32 @@ vectorizeAsTensorUnpackOp(RewriterBase &rewriter, tensor::UnPackOp unpackOp,
ArrayRef<int64_t> innerDimPos = unpackOp.getInnerDimsPos();
ArrayRef<int64_t> innerTiles = unpackOp.getStaticInnerTiles();
+ ArrayRef<int64_t> sourceShape = unpackTensorType.getShape();
+ bool useInBoundsInsteadOfMasking = false;
+ ArrayRef<int64_t> outerDimsPerm = unpackOp.getOuterDimsPerm();
+
+ auto destSize = unpackOp.getDestRank();
+
+ // initVectorShape is the shape of the vector that will be read from the
+ // source tensor. It is set like this: Let's say the sourceShape is 'M' and
+ // the vectorSize (VS) array is size 'N' where N <= M. Thus:
+ // - initVectorShape = sourceShape.take_front(N)
+ // - if outer_dims_perms is present: do that permutation on initVectorShape.
+ // - Multiply all the locations pointed by innerDimPos by the innerTileSize
+ // attribute value.
+ SmallVector<int64_t> initVectorShape{sourceShape.take_front(destSize)};
----------------
hanhanW wrote:
two nit:
1. Move this into the if statement because it is only used there.
2. Avoid brace-list initialization, instead we can use constructor directly.
```suggestion
SmallVector<int64_t> initVectorShape(sourceShape.take_front(destSize));
```
We prefer using `()` constructor or `=` assignment instead of brace-list initialization. This kind of code is dangerous when the type is not an integer type. E.g.,
```
std::vector<std::string> strings{2}; // A vector of two empty strings.
std::vector<int> ints{2}; // A vector containing only the integer 2.
```
See https://abseil.io/tips/88 for more details.
https://github.com/llvm/llvm-project/pull/89067
More information about the Mlir-commits
mailing list