The mlir-hlo-opt tool fails to run the -hlo-legalize-to-lhlo command

  1. When i execute “mlir-hlo-opt cur-mhlo.mlir -hlo-legalize-to-lhlo -o cur-lhlo.mlir” to convert this file:
    module attributes {tf.versions = {bad_consumers = [], min_consumer = 0 : i32, producer = 561 : i32}} {
    func @main(%arg0: tensor<1x224x224x3xf32>) → tensor<1x230x230x3xf32> attributes {tf.entry_function = {control_outputs = “”, inputs = “Input”, outputs = “resnet50/conv1_pad/Pad”}} {
    %0 = mhlo.constant dense<0.000000e+00> : tensor
    %1 = “mhlo.pad”(%arg0, %0) {edge_padding_high = dense<[0, 3, 3, 0]> : tensor<4xi64>, edge_padding_low = dense<[0, 3, 3, 0]> : tensor<4xi64>, interior_padding = dense<0> : tensor<4xi64>} : (tensor<1x224x224x3xf32>, tensor) → tensor<1x230x230x3xf32>
    return %1 : tensor<1x230x230x3xf32>
    }
    }

  2. MLIR reported this error:
    cur-mhlo.mlir:4:10: error: failed to legalize operation ‘mhlo.pad’ that was explicitly marked illegal

I didn’t find conversion logic for “mhlo.pad” operation in hlo_legalize_to_lhlo.cc createLegalizeToLhloPass(). How to convert “mhlo.pad” to Lhlo dialect? Or maybe it is not supported, i should directly use “LegalizeHloToLinalgPass”?

Looks like the mhlo to lmhlo conversion remained unimplemented/not contributed to yet. You will find it on the HLO to linalg path though:

On upstream TF:
tensorflow/compiler/mlir/hlo/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc

  /// Converts mhlo.pad operation to linalg.pad_tensor op.
  struct PadOpOnTensorsConversion : public OpConversionPattern<mhlo::PadOp> {
    using OpConversionPattern<mhlo::PadOp>::OpConversionPattern;

(I haven’t tried this path though.)