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

No Transpose emission for 0 rank tensor #375

Merged
merged 5 commits into from
Dec 20, 2024

Conversation

glou-nes
Copy link
Contributor

@glou-nes glou-nes commented Dec 13, 2024

We emit transpose for 0 rank tensor.

> i = Reactant.ConcreteRNumber(5)
> @code_hlo optimize=false i<i
module {
  func.func @main(%arg0: tensor<i64>) -> (tensor<i1>, tensor<i64>) {
    %0 = stablehlo.transpose %arg0, dims = [] : (tensor<i64>) -> tensor<i64>
    %1 = stablehlo.compare  LT, %0, %0 : (tensor<i64>, tensor<i64>) -> tensor<i1>
    %2 = stablehlo.transpose %1, dims = [] : (tensor<i1>) -> tensor<i1>
    %3 = stablehlo.transpose %0, dims = [] : (tensor<i64>) -> tensor<i64>
    return %2, %3 : tensor<i1>, tensor<i64>
  }
}

Don't emit stablehlo.transpose operation for this case, and so simplify reading of unoptimized IR.

@code_hlo optimize=false i<i
module {
  func.func @main(%arg0: tensor<i64>) -> tensor<i1> {
    %0 = stablehlo.compare  LT, %arg0, %arg0 : (tensor<i64>, tensor<i64>) -> tensor<i1>
    return %0 : tensor<i1>
  }
}

@glou-nes glou-nes changed the title Transpose simplify No Transpose emission for 0 rank tensor Dec 13, 2024
Copy link
Member

@wsmoses wsmoses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should get optimized by enzyme-hlo-opt downstream later regardless, but I'm not opposed if this speeds up compiletime

@wsmoses
Copy link
Member

wsmoses commented Dec 18, 2024

@glou-nes can this be rebased (it merge conflicts)?

Copy link
Collaborator

@avik-pal avik-pal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test failures are unrelated

@wsmoses wsmoses merged commit 0a41c60 into EnzymeAD:main Dec 20, 2024
31 of 53 checks passed
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

Successfully merging this pull request may close these issues.

3 participants