I’m using insertOp to update tensor value, but result in " legalize operation ‘builtin.unrealized_conversion_cast’ that was explicitly marked illegal".
Here’s the code snippet,(which update three numbers for the initial tensor):
func.func @example() → (tensor<4xf64>) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c3 = arith.constant 3 : index
%f0 = arith.constant 0.000000e+00 : f64
%num = arith.constant dense<[37.62, 15.43, -2.401]> : tensor<3xf64>
%index = arith.constant dense<[0, 2, 4]> : tensor<3xindex>
%splat = tensor.splat %f0 : tensor<4xf64>
%newTensor = scf.for %iv = %c0 to %c3 step %c1
iter_args(%tmpTensor = %splat) -> (tensor<4xf64>){
%scalar = tensor.extract %num[%iv] : tensor<3xf64>
%idx = tensor.extract %index[%iv] : tensor<3xindex>
%nextTensor = tensor.insert %scalar into %tmpTensor[%idx] : tensor<4xf64>
scf.yield %nextTensor : tensor<4xf64>
}
return %newTensor : tensor<4xf64>
}
The lowering pass i use:
-tensor-bufferize -arith-expand -linalg-bufferize -tensor-bufferize -convert-linalg-to-loops -func-bufferize -arith-bufferize -convert-scf-to-cf -expand-strided-metadata -memref-expand -arith-expand -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts
The complete error message:
example.mlir:2:11: error: failed to legalize operation ‘builtin.unrealized_conversion_cast’ that was explicitly marked illegal
%c0 = arith.constant 0 : index
When i remove the scf.for loop(also the code in it), everything work fine with the above passes. So it seems like the problem comes from the tensor.insert operation, but result in message for airth.constant. I’m open to any guidance or suggestions you might have, and I’m eager to learn from your expertise.