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

Failed to convert mhlo dialect to Linalg dialect #8

Open
wwwwcu opened this issue Jul 8, 2021 · 0 comments
Open

Failed to convert mhlo dialect to Linalg dialect #8

wwwwcu opened this issue Jul 8, 2021 · 0 comments

Comments

@wwwwcu
Copy link

wwwwcu commented Jul 8, 2021

I want to convert the conv2d operator from mhlo to linalg dialect. It seems like that it can't process the situation when the layout of conv2d is NCHW.
The mhlo dialect of conv2d.mlir is shown below:

module  {
  func @main(%arg0: tensor<64x3x7x7xf32>, %arg1: tensor<1x3x224x224xf32>) -> tuple<tensor<1x64x112x112xf32>> {
    %0 = "mhlo.convolution"(%arg1, %arg0) {batch_group_count = 1 : i64, dimension_numbers = {input_batch_dimension = 0 : i64, input_feature_dimension = 1 : i64, input_spatial_dimensions = dense<[2, 3]> : tensor<2xi64>, kernel_input_feature_dimension = 1 : i64, kernel_output_feature_dimension = 0 : i64, kernel_spatial_dimensions = dense<[2, 3]> : tensor<2xi64>, output_batch_dimension = 0 : i64, output_feature_dimension = 1 : i64, output_spatial_dimensions = dense<[2, 3]> : tensor<2xi64>}, feature_group_count = 1 : i64, lhs_dilation = dense<1> : tensor<2xi64>, padding = dense<3> : tensor<2x2xi64>, precision_config = ["DEFAULT", "DEFAULT"], rhs_dilation = dense<1> : tensor<2xi64>, window_strides = dense<2> : tensor<2xi64>} : (tensor<1x3x224x224xf32>, tensor<64x3x7x7xf32>) -> tensor<1x64x112x112xf32>
    %1 = "mhlo.tuple"(%0) : (tensor<1x64x112x112xf32>) -> tuple<tensor<1x64x112x112xf32>>
    return %1 : tuple<tensor<1x64x112x112xf32>>
  }
}

I use "./mlir-hlo-opt ./conv2d.mlir -hlo-legalize-to-linalg -o conv2d_linalg.mlir" to do the transformation.
I traced the workflow and found out when it checks "HasCanonicalDimensionNumbers()", it returns false.
legalize_to_linalg.cc

  if (dimension_numbers.input_batch_dimension().getInt() != 0 ||
      dimension_numbers.input_feature_dimension().getInt() !=
          (input_spatial_rank + 1)) {
    return false;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant