Repository navigation
Lowering mhlo.reverse to linalg_ext.reverse. - #7163
Conversation
|
Depends on #7159 |
|
Got the smallest repro here: func @foo() -> tensor<1x2x2x3xf32> {
%cst = constant dense<[[[[-0.322270721, -0.454585314, 0.0548270941],
[0.0948997139, -0.129087329, 0.47688508]],
[[-0.0104956627, 0.771698594, 0.304780841],
[-0.580368757, 0.325046659, 0.251613259]]]]> : tensor<1x2x2x3xf32>
%0 = "mhlo.reverse"(%cst) {
dimensions = dense<[0, 1]> : tensor<2xi64>
} : (tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32>
return %0 : tensor<1x2x2x3xf32>
}It crashes in Looking... |
|
Looks like an issue starting from init_tensor. IR after DispatchLinalgOnTensors: https://gist.githubusercontent.com/hanhanW/eb687de16a0f320306100ced7deaa3b4/raw It will generate something like: %2 = linalg.init_tensor [1, 2, 2, 3] : tensor<1x2x2x3xf32>
// ...
%16 = tensor.extract_slice %2[0, %arg2, %arg3, %arg4] [1, %5, %8, %11] [1, 1, 1, 1] : tensor<1x2x2x3xf32> to tensor<1x?x?x?xf32>
%17 = tensor.cast %16 : tensor<1x?x?x?xf32> to tensor<?x?x?x?xf32>
%18 = linalg_ext.reverse ... outs(%17 ...After canonicalization, it turns into: %15 = linalg.init_tensor [1, %4, %7, %10] : tensor<1x?x?x?xf32>
%16 = tensor.cast %15 : tensor<1x?x?x?xf32> to tensor<?x?x?x?xf32>In this case, the mapping table can't map the source of |
|
Tested with add operation with 4D tensor, the main difference is that tensor.cast ops are inserted in this case. In the beginning, the IR is: %24 = tensor.extract_slice %cst[0, %arg1, %arg3, %arg5] [%8, %15, %19, %23] [1, 1, 1, 1] : tensor<1x2x2x3xf32> to tensor<?x?x?x?xf32>Then it triggers %12 = tensor.extract_slice <<UNKNOWN SSA VALUE>>[0, %arg1, %arg3, %arg5] [%c1, %3, %7, %11] [1, 1, 1, 1] : tensor<1x2x2x3xf32> to tensor<?x?x?x?xf32>Then %12 = tensor.extract_slice <<UNKNOWN SSA VALUE>>[0, %arg1, %arg3, %arg5] [1, %3, %7, %11] [1, 1, 1, 1] : tensor<1x2x2x3xf32> to tensor<1x?x?x?xf32>
%13 = tensor.cast %12 : tensor<1x?x?x?xf32> to tensor<?x?x?x?xf32>The original shape is tensor<?x?x?x?xf32>, and it could get inferred by canonicalizer. To keep the type consistently, we will insert |
|
There are couple workarounds. The most obvious one to me is adding a canonicalization pattern to pass the init_tensor op directly to linalg/linalg_ext ops if it is |
Yeah having this pattern makes sense to me. Let me know if you want me to look into this further. |
|
Linalg dialect already has the patterns, I copied it from upstream and added it to LinalgExt dialect in #7179 |
b298b31 to
9e9c360
Compare
It's a step toward #5045