[Mlir-commits] [mlir] [mlir][tensor] Fold pack and unpack of empty input tensor (PR #92247)

Adam Siemieniuk llvmlistbot at llvm.org
Fri May 17 08:00:43 PDT 2024


================
@@ -93,12 +93,76 @@ struct FoldEmptyTensorWithExtractSliceOp
   bool foldSingleUseOnly = false;
 };
 
+/// tensor.empty does not define any tensor contents, so an unpadded pack
----------------
adam-smnk wrote:

Sure, for example:
```
func.func @entry(%arg0: tensor<1x1x32x32xf32>) -> tensor<1x1x32x32xf32> {
  %pad = arith.constant 3.0 : f32
  %empty_unpacked = tensor.empty() : tensor<20x20xf32>
  %packed = tensor.pack %empty_unpacked padding_value(%pad : f32)
    inner_dims_pos = [0, 1] inner_tiles = [32, 32]
    into %arg0 : tensor<20x20xf32> -> tensor<1x1x32x32xf32>
  return %packed : tensor<1x1x32x32xf32>
}
```

Assuming `%empty_unpacked = tensor.empty()` gets lowering into `memref.alloc()`, the original shape `20x20` will contain random uninitialized data. However, the remaining padding up to `32x32` will have the predefined `%pad` value (here 3.0).

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


More information about the Mlir-commits mailing list