[mlir][Tosa][tosa-to-linalg] Code design problem of Tosa to Linalg conversion
When I use mlir-opt -pass-pipeline="func.func(tosa-to-linalg)" to lowering the tosa dialect,
I encounter the error failed to legalize operation tosa.max_pool2d.
After reading the source code, I find that this pass can only handle part ops of Tosa,
while some of the rest ops are marked as legal directly in TosaToLinalgPass.cpp.
// in file TosaToLinalgPass.cpp
target.addLegalOp<tosa::ApplyScaleOp>();
target.addLegalOp<tosa::IfOp>();
target.addLegalOp<tosa::ConstOp>();
target.addLegalOp<tosa::WhileOp>();
target.addLegalOp<tosa::SliceOp>();
but the other part is not processed, such as tosa.max_pool2d.
TosaToLinalgPass.cpp should probably use a partial conversion or be absolutely complete in terms of defining the legality criteria.
Can you give test cases and commands?
@LiqinWeng Sure, this is the command I use : ${build}/bin/mlir-opt 1.mlir -pass-pipeline=func.func(tosa-to-linalg) , and the test case as follows:
func.func @test_matmul() -> tensor<1x14x28xf32> {
%c0 = "tosa.const"() {value = dense<1.0> : tensor<1x14x19xf32>} : () -> tensor<1x14x19xf32>
%c1 = "tosa.const"() {value = dense<2.0> : tensor<1x19x28xf32>} : () -> tensor<1x19x28xf32>
%0 = "tosa.matmul"(%c0, %c1) : (tensor<1x14x19xf32>, tensor<1x19x28xf32>) -> tensor<1x14x28xf32>
return %0 : tensor<1x14x28xf32>
}
Several developers have discussed this issue in the LLVM forum, and i think you might want to know this