About tosa lowing to linalg problems?

A simple tosa mlir:

func.func @test_clamp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
  %0 = "tosa.clamp"(%arg0) {min_fp = 0.0 : f32, max_fp = 1.0: f32, min_int = 0 : i64, max_int = 1 : i64} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
  return %0 : tensor<13x21x3xf32>
}

and I use mlir-opt clamp.mlir --tosa-to-linalg but with error <unknown>:0: error: unable to schedule pass 'TosaToLinalg' on a PassManager intended to run on 'builtin.module'! how to lowing tosa to linalg or other lower dialect?

try --pass-pipeline='func.func(tosa-to-linalg)'

1 Like

Yes. Right. But where is the document?

If you look at the definition of the pass, the InterfacePass<..., "FunctionOpInterface"> means it needs to be scheduled on a function-like operation, like func.func. The IR you have gets parsed with an implicit top-level module op, so it’s really:

module {
  func.func @test_clamp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
    %0 = "tosa.clamp"(%arg0) {min_fp = 0.0 : f32, max_fp = 1.0: f32, min_int = 0 : i64, max_int = 1 : i64} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
    return %0 : tensor<13x21x3xf32>
  }
}

When you use --tosa-to-linalg it tries to run the pass directly on that top-level builtin.module op, which doesn’t work, so you need to explicitly nest it using --pass-pipeline='func.func(...)'

1 Like