How to lower tensor.scatter

I’m trying to lower tensor.scatter op like this:

%scatter_262 = tensor.scatter %4909 into %scatter_260[%4910] scatter_dims([0]) unique : (tensor<1x2x11xf32>, tensor<16x2x11xf32>, tensor<1x1xi32>) -> tensor<16x2x11xf32>

I don’t know how to do it. When I low it by --convert-tensor-to-linalg, it doesn’t work. When I try to use --convert-linalg-to-affine-loops , it shows this:

xxx: error: failed to legalize operation 'tensor.scatter'
    %scatter = tensor.scatter %385 into %cst_12[%cst_39] scatter_dims([0]) unique : (tensor<1x2x64x64x64xf32>, tensor<16x2x64x64x64xf32>, tensor<1x1xi32>) -> tensor<16x2x64x64x64xf32>```

Does anyone can give me some help?
Thanks a lot!

I didn’t aware patterns to lower to and from tensor.scatter. Here is some discussion about tensor.scatter.

You posted your question here. Do you work on TOSA dialect? Is it possible to use tosa.scatter in your case? There is a pattern to lower tosa.scatter to SCF. Can you give more context about what you want to do?

1 Like

Indeed, I can use tosa.scatter, thank you for your reply, it’s helpful!