[Mlir-commits] [mlir] [mlir][tensor] Refine the semantics of `createPadHighOp` (PR #109667)

Han-Chung Wang llvmlistbot at llvm.org
Thu Sep 26 11:15:44 PDT 2024


hanhanW wrote:

This breaks the behavior of [linalg::padAndHoistLinalgOp](https://github.com/llvm/llvm-project/blob/fbec1c2a08ce2ae9750ddf3cecc86c5dd2bbc9d8/mlir/lib/Dialect/Linalg/Transforms/Padding.cpp#L265C7-L265C34), which calls [makeComposedPadHighOp here](https://github.com/llvm/llvm-project/blob/fbec1c2a08ce2ae9750ddf3cecc86c5dd2bbc9d8/mlir/lib/Dialect/Linalg/Transforms/Padding.cpp#L148-L149). The implementation of [makeComposedPadHighOp](https://github.com/llvm/llvm-project/blob/83368191a21340a6c3a8f88b01ecae6433640957/mlir/lib/Dialect/Linalg/Utils/Utils.cpp#L192) relies on the behavior to create valid pad ops.

In the transform script, it asks for padding `dim 3`, so it does not care about the padding values of other dimension and use the createPadHighOp method to generate the pad op.

Can we revert it until it is fixed? 

To repro: `mlir-opt --transform-interpreter ~/repro.mlir`

```mlir
module {
  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>
    %1 = linalg.batch_matmul ins(%arg0, %arg1 : tensor<1x?x1281xf16>, tensor<1x1281x?xf16>) outs(%0 : tensor<1x?x?xf16>) -> tensor<1x?x?xf16>
    return %1 : tensor<1x?x?xf16>
  }
  module attributes {transform.with_named_sequence} {
    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
      %0 = transform.structured.match ops{["linalg.batch_matmul"]} in %arg0 : (!transform.any_op) -> !transform.any_op
      %padded, %pad, %copy = transform.structured.pad %0 {pack_paddings = [1, 1], padding_dimensions = [3], padding_values = [0.000000e+00 : f16, 0.000000e+00 : f16, 0.000000e+00 : f16]} : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.op<"bufferization.materialize_in_destination">)
      %1 = transform.num_associations %copy : (!transform.op<"bufferization.materialize_in_destination">) -> !transform.param<i64>
      transform.debug.emit_param_as_remark %1 : !transform.param<i64>
      transform.yield
    }
  }
}
```

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


More information about the Mlir-commits mailing list