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

Failure to compile broadcast_in_dim #50

Open
jpienaar opened this issue Oct 5, 2022 · 4 comments
Open

Failure to compile broadcast_in_dim #50

jpienaar opened this issue Oct 5, 2022 · 4 comments

Comments

@jpienaar
Copy link
Member

jpienaar commented Oct 5, 2022

The following fails to compile

module @jit_encode_batch {
  func.func public @main(%arg0: tensor<i32>, %arg293: tensor<?x1024xi32>) -> tensor<?x1024xi32> {
    %0 = mhlo.constant dense<0> : tensor<i32>
    %1 = mhlo.convert %arg0 : tensor<i32>
    %2 = mhlo.reshape %1 : (tensor<i32>) -> tensor<1xi32>
    %3 = mhlo.constant dense<1024> : tensor<1xi32>
    %4 = "mhlo.concatenate"(%2, %3) {dimension = 0 : i64} : (tensor<1xi32>, tensor<1xi32>) -> tensor<2xi32>
    %5 = "mhlo.dynamic_broadcast_in_dim"(%arg293, %4) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor<?x1024xi32>, tensor<2xi32>) -> tensor<?x1024xi32>
    return %5 : tensor<?x1024xi32>
 }
}

while the following does

module @jit_encode_batch {
  func.func public @main(%arg0: tensor<i32>, %arg293: tensor<?x1024xi32>) -> tensor<?x1024xi32> {
    %0 = mhlo.constant dense<0> : tensor<i32>
    %1 = mhlo.convert %arg0 : tensor<i32>
    %2 = mhlo.reshape %1 : (tensor<i32>) -> tensor<1xi32>
    %3 = mhlo.constant dense<1024> : tensor<1xi32>
    %4 = "mhlo.concatenate"(%2, %3) {dimension = 0 : i64} : (tensor<1xi32>, tensor<1xi32>) -> tensor<2xi32>
    %5 = "mhlo.dynamic_broadcast_in_dim"(%arg293, %4) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>,
      known_expanding_dimensions = dense<[0]> : tensor<1xi64>,
      known_nonexpanding_dimensions = dense<[1]> : tensor<1xi64>
    } : (tensor<?x1024xi32>, tensor<2xi32>) -> tensor<?x1024xi32>
    return %5 : tensor<?x1024xi32>
 }
}

Not sure if this is a frontend issue (the first form shouldn't have been produced with those attributes), luck that it compiles with those attributes, or expected that it compiles without those.

@jpienaar
Copy link
Member Author

jpienaar commented Oct 5, 2022

@d0k @sherhut if you are able to direct

@d0k
Copy link
Member

d0k commented Oct 5, 2022

Fails to compile using what pipeline? The first one is a lot harder to codegen because you don't know if the first dimension expands or not, we also can't derive this from the IR alone.

As far as I know kernelgen can compile the unannotated version into slow code, while IREE doesn't support this fully dynamic case. Ideally the frontend would produce the attributes, but it might not be possible depending on the input.

@jpienaar
Copy link
Member Author

jpienaar commented Oct 5, 2022

SG, so if one wants any performance here, you should be using the attributed form?

@jpienaar
Copy link
Member Author

jpienaar commented Oct 5, 2022

Ah, and while we have this question: what is the tool/config for the different pipelines here? (e.g., is it xla-opt with pipeline foo that captures all the passes)

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

2 participants