Hi!
I am trying to add a canonicalization pattern that will handle tensor.dim of tosa.transpose,
for example:
Input:
func.func @inserts_slice_dynamic(%arg0: tensor<1x1x?x1xsi16>, %arg1: tensor<1x8x1x?xsi16>) -> (tensor<1x8x1x?xsi16>) {
%0 = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32>
%1 = tosa.transpose %arg0, %0 : (tensor<1x1x?x1xsi16>, tensor<4xi32>) -> tensor<1x1x1x?xsi16>
%c3 = arith.constant 3 : index
%dim = tensor.dim %1, %c3 : tensor<1x1x1x?xsi16>
%inserted_slice = tensor.insert_slice %1 into %arg1[0, 0, 0, 0] [1, 1, 1, %dim] [1, 1, 1, 1] : tensor<1x1x1x?xsi16> into tensor<1x8x1x?xsi16>
return %inserted_slice : tensor<1x8x1x?xsi16>
}
Output:
func.func @inserts_slice_dynamic(%arg0: tensor<1x1x?x1xsi16>, %arg1: tensor<1x8x1x?xsi16>) -> (tensor<1x8x1x?xsi16>) {
%c2 = arith.constant 2 : index
%dim = tensor.dim %arg0, %c2 : <1x1x?x1xsi16>
%inserted_slice = tensor.insert_slice %1 into %arg1[0, 0, 0, 0] [1, 1, 1, %dim] [1, 1, 1, 1] : tensor<1x1x1x?xsi16> into tensor<1x8x1x?xsi16>
return %inserted_slice : tensor<1x8x1x?xsi16>
}
I think the pattern should be under the canonicalization patterns of tensor::DimOp.
This means Tensor dialect should depend on Tosa dialect.
Since Tosa dialect already depends on Tensor dialect, I get cyclic dependency.
In the meantime I added my pattern locally to Tosa canonicalization patterns, just to see it works.
But I really don’t think it should be there…
Does anybody have an idea how I can solve it?
Thanks in advance,
Maya