Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][ReshapeOpsUtils] ComposeExpandOfCollapseOp is not detecting complicated dynamic shapes #117117

Open
hockyy opened this issue Nov 21, 2024 · 3 comments
Labels

Comments

@hockyy
Copy link

hockyy commented Nov 21, 2024

module {
  func.func @broadcast_test(%arg0: tensor<4x8x?x3x?xf32>) -> tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32> {
    %c2 = arith.constant 2 : index
    %c4 = arith.constant 4 : index
    %dim = tensor.dim %arg0, %c4 : tensor<4x8x?x3x?xf32>
    %dim_0 = tensor.dim %arg0, %c2 : tensor<4x8x?x3x?xf32>
    %collapsed = tensor.collapse_shape %arg0 [[0], [1, 2, 3, 4]] : tensor<4x8x?x3x?xf32> into tensor<4x?xf32>
    %0 = tensor.empty(%dim_0, %dim) : tensor<4x3x8x?x3x?x14xf32>
    %collapsed_1 = tensor.collapse_shape %0 [[0], [1], [2, 3, 4, 5], [6]] : tensor<4x3x8x?x3x?x14xf32> into tensor<4x3x?x14xf32>
    %broadcasted = linalg.broadcast ins(%collapsed : tensor<4x?xf32>) outs(%collapsed_1 : tensor<4x3x?x14xf32>) dimensions = [1, 3]
    %collapsed_2 = tensor.collapse_shape %broadcasted [[0, 1, 2, 3]] : tensor<4x3x?x14xf32> into tensor<?xf32>
    %expanded = tensor.expand_shape %collapsed_2 [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] output_shape [1, 4, 3, 8, 1, 1, %dim_0, 3, 1, 1, %dim, 1, 14] : tensor<?xf32> into tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32>
    return %expanded : tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32>
  }
}
    %collapsed_2 = tensor.collapse_shape %broadcasted [[0, 1, 2, 3]] : tensor<4x3x?x14xf32> into tensor<?xf32>
    %expanded = tensor.expand_shape %collapsed_2 [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] output_shape [1, 4, 3, 8, 1, 1, %dim_0, 3, 1, 1, %dim, 1, 14] : tensor<?xf32> into tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32>

This part is not canonicalized

@hockyy hockyy changed the title ComposeExpandOfCollapseOp is not detecting complicated dynamic shapes [MLIR][ReshapeOpsUtils] ComposeExpandOfCollapseOp is not detecting complicated dynamic shapes Nov 21, 2024
@hockyy hockyy changed the title [MLIR][ReshapeOpsUtils] ComposeExpandOfCollapseOp is not detecting complicated dynamic shapes [mlir][ReshapeOpsUtils] ComposeExpandOfCollapseOp is not detecting complicated dynamic shapes Nov 21, 2024
@hockyy
Copy link
Author

hockyy commented Nov 21, 2024

@jpienaar @pifon2a

@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/issue-subscribers-mlir

Author: Hocky Yudhiono (hockyy)

``` module { func.func @broadcast_test(%arg0: tensor<4x8x?x3x?xf32>) -> tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32> { %c2 = arith.constant 2 : index %c4 = arith.constant 4 : index %dim = tensor.dim %arg0, %c4 : tensor<4x8x?x3x?xf32> %dim_0 = tensor.dim %arg0, %c2 : tensor<4x8x?x3x?xf32> %collapsed = tensor.collapse_shape %arg0 [[0], [1, 2, 3, 4]] : tensor<4x8x?x3x?xf32> into tensor<4x?xf32> %0 = tensor.empty(%dim_0, %dim) : tensor<4x3x8x?x3x?x14xf32> %collapsed_1 = tensor.collapse_shape %0 [[0], [1], [2, 3, 4, 5], [6]] : tensor<4x3x8x?x3x?x14xf32> into tensor<4x3x?x14xf32> %broadcasted = linalg.broadcast ins(%collapsed : tensor<4x?xf32>) outs(%collapsed_1 : tensor<4x3x?x14xf32>) dimensions = [1, 3] %collapsed_2 = tensor.collapse_shape %broadcasted [[0, 1, 2, 3]] : tensor<4x3x?x14xf32> into tensor<?xf32> %expanded = tensor.expand_shape %collapsed_2 [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] output_shape [1, 4, 3, 8, 1, 1, %dim_0, 3, 1, 1, %dim, 1, 14] : tensor<?xf32> into tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32> return %expanded : tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32> } } ```
    %collapsed_2 = tensor.collapse_shape %broadcasted [[0, 1, 2, 3]] : tensor&lt;4x3x?x14xf32&gt; into tensor&lt;?xf32&gt;
    %expanded = tensor.expand_shape %collapsed_2 [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] output_shape [1, 4, 3, 8, 1, 1, %dim_0, 3, 1, 1, %dim, 1, 14] : tensor&lt;?xf32&gt; into tensor&lt;1x4x3x8x1x1x?x3x1x1x?x1x14xf32&gt;

This part is not canonicalized

@CoTinker
Copy link
Contributor

Maybe it's same to #109650.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants