Hello everyone!
I am new to MLIR and I am struggling to fix the following error when lowering tosa.transpose to llvm.
transpose.mlir:4:14: note: see current operation: %14 = "builtin.unrealized_conversion_cast"(%13) : (!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>) -> memref<2xi32>
here is the code
module {
func.func @generated_func(%arg0: tensor<2x3xf32>) -> tensor<3x2xf32> {
%cst = arith.constant dense<0.000000e+00> : tensor<3x2xf32>
%cst_0 = arith.constant dense<[1, 0]> : tensor<2xi32>
%0 = "tosa.transpose"(%arg0, %cst_0) : (tensor<2x3xf32>, tensor<2xi32>) -> tensor<3x2xf32>
return %0 : tensor<3x2xf32>
}
}
here is the pass pipeline I use to lower the code snippet to llvm
mlir-opt --pass-pipeline="builtin.module(func.func(tosa-to-arith), convert-elementwise-to-linalg, arith-bufferize, func.func(linalg-bufferize), func.func(tensor-bufferize), func-bufferize, func.func(buffer-deallocation), memref-expand, func.func(convert-linalg-to-loops), convert-scf-to-cf, convert-linalg-to-llvm, convert-arith-to-ll
vm, expand-strided-metadata, finalize-memref-to-llvm, reconcile-unrealized-casts)" ~/transpose.mlir
I have checked this post
According to this post, it said that the error means type conversion wasn’t completed by some previous passes, and the solution is to remove reconcile-unrealized-casts
to see the IR and look for unrealized_conversion_cast
operations that are not paired with the casts going into the other direction. Then, add the missing passes. I removed reconcile-unrealized-casts
, and the unrealized_conversion_cast
operation is
builtin.unrealized_conversion_cast %22 : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> to memref<2xi32>
The question is, I don’t know what passes should I add to fix the error.
Any insight would be greatly appreciated.
Thank you and apologies if this is a dumb question!