[Mlir-commits] [mlir] [mlir][tensor] Add support for tensor.unpack static shapes inference. (PR #81702)
Quinn Dawkins
llvmlistbot at llvm.org
Wed Feb 14 14:12:09 PST 2024
================
@@ -2176,3 +2211,18 @@ func.func @generate_negative_size_verifies() -> tensor<?x8xi32> {
} : tensor<?x8xi32>
return %tensor : tensor<?x8xi32>
}
+
+// -----
+
+func.func @infer_and_fold_pack_unpack_same_tiles(%t: tensor<10x20x?x?xf32>,
+ %dim1: index, %dim2: index, %dim3: index, %dim4: index, %tile1: index,
+ %tile2: index) -> tensor<10x20x?x?xf32> {
+ %tensor_empty = tensor.empty(%dim1, %dim2) : tensor<?x?xf32>
+ %unpacked = tensor.unpack %t inner_dims_pos = [0, 1] inner_tiles = [%tile1, %tile2] into %tensor_empty : tensor<10x20x?x?xf32> -> tensor<?x?xf32>
+ %tensor_empty1 = tensor.empty(%dim3, %dim4) : tensor<10x20x?x?xf32>
+ %packed = tensor.pack %unpacked inner_dims_pos = [0, 1] inner_tiles = [%tile1, %tile2] into %tensor_empty1 : tensor<?x?xf32> -> tensor<10x20x?x?xf32>
----------------
qedawkins wrote:
Does the static shape inference pattern kick in for this case? The tile sizes are dynamic here, so from what I can tell it doesn't apply. Can you add an additional test for something like this
```mlir
%tensor_empty = tensor.empty(%dim1, %dim2) : tensor<?x?xf32>
%unpacked = tensor.unpack %t inner_dims_pos = [0, 1] inner_tiles = [4, 4] into %tensor_empty : tensor<10x20x4x4xf32> -> tensor<?x?xf32>
%cast = tensor.cast %unpacked : tensor<?x?xf32> to tensor<40x80xf32>
%tensor_empty1 = tensor.empty() : tensor<10x20x4x4xf32>
%packed = tensor.pack %cast inner_dims_pos = [0, 1] inner_tiles = [4, 4] into %tensor_empty1 : tensor<40x80xf32> -> tensor<10x20x4x4xf32>
```
(might have written this wrong, but I'm wondering if we still get it to fold in this case).
https://github.com/llvm/llvm-project/pull/81702
More information about the Mlir-commits
mailing list