[Mlir-commits] [mlir] Revert "[mlir][tensor] Refine the semantics of `createPadHighOp`" (PR #110153)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Thu Sep 26 13:26:44 PDT 2024
banach-space wrote:
Looking at the output for this example , what's the point of padding here?
```mlir
func.func @batch_matmul_f16(%arg0: tensor<1x?x1281xf16>, %arg1: tensor<1x1281x?xf16>, %arg2: tensor<1x?x?xf16>) -> tensor<1x?x?xf16> {
%cst = arith.constant 0.000000e+00 : f16
%c0 = arith.constant 0 : index
%0 = linalg.fill ins(%cst : f16) outs(%arg2 : tensor<1x?x?xf16>) -> tensor<1x?x?xf16>
%cst_0 = arith.constant 0.000000e+00 : f16
%padded = tensor.pad %arg0 nofold low[0, 0, 0] high[0, 0, 0] {
^bb0(%arg3: index, %arg4: index, %arg5: index):
tensor.yield %cst_0 : f16
} : tensor<1x?x1281xf16> to tensor<1x?x1281xf16>
%cst_1 = arith.constant 0.000000e+00 : f16
%padded_2 = tensor.pad %arg1 nofold low[0, 0, 0] high[0, 0, 0] {
^bb0(%arg3: index, %arg4: index, %arg5: index):
tensor.yield %cst_1 : f16
} : tensor<1x1281x?xf16> to tensor<1x1281x?xf16>
%c1 = arith.constant 1 : index
%dim = tensor.dim %arg0, %c1 : tensor<1x?x1281xf16>
%c2 = arith.constant 2 : index
%dim_3 = tensor.dim %arg1, %c2 : tensor<1x1281x?xf16>
%c1_4 = arith.constant 1 : index
%dim_5 = tensor.dim %0, %c1_4 : tensor<1x?x?xf16>
%c2_6 = arith.constant 2 : index
%dim_7 = tensor.dim %0, %c2_6 : tensor<1x?x?xf16>
%1 = linalg.batch_matmul ins(%padded, %padded_2 : tensor<1x?x1281xf16>, tensor<1x1281x?xf16>) outs(%0 : tensor<1x?x?xf16>) -> tensor<1x?x?xf16>
%extracted_slice = tensor.extract_slice %1[0, 0, 0] [1, %dim, %dim_3] [1, 1, 1] : tensor<1x?x?xf16> to tensor<1x?x?xf16>
%2 = bufferization.materialize_in_destination %extracted_slice in %0 : (tensor<1x?x?xf16>, tensor<1x?x?xf16>) -> tensor<1x?x?xf16>
return %2 : tensor<1x?x?xf16>
}
```
In this particular case, `tensor.pad` is a NOP - that's because both dynamic dimensions (input and output) are assumed identical. But is that a safe/valid assumption? IMO, it's not. IIUC, `tensor.pad` shouldn't be generated at all. WDYT?
https://github.com/llvm/llvm-project/pull/110153
More information about the Mlir-commits
mailing list