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

[Unity] Ignore R.ExternFunc in EliminateCommonSubexpr #15900

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, relax::ExternFunc nodes would be de-duplicated as part of the EliminateCommonSubexpr pass. This commit instead ignores the relax::ExternFunc nodes, retaining the in-line definitions.

Prior to this commit, `relax::ExternFunc` nodes would be de-duplicated
as part of the `EliminateCommonSubexpr` pass.  This commit instead
ignores the `relax::ExternFunc` nodes, retaining the in-line
definitions.
@R.function(pure=False)
def foo(x: R.Tensor((2, 3), dtype="float32")):
y = R.call_packed("extern_func_name", x, sinfo_args=R.Tensor([2, 3]))
z = R.call_packed("extern_func_name", y, sinfo_args=R.Tensor([2, 3]))
Copy link
Contributor

Choose a reason for hiding this comment

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

If this was commoned before, then something else is probably wrong. This is equivalent to extern_func(extern_func(x)), so there is no opportunity to common anything even if the external function was known to be pure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, it wasn't a computational step that was being extracted as the common subexpression, but the R.ExternFunc object itself.

@I.ir_module
class Module:
    @R.function(pure=False)
    def foo(x: R.Tensor((2, 3), dtype="float32")):
        gv = R.ExternFunc("extern_func_name")
        y = gv(x, sinfo_args=(R.Tensor((2, 3)),))
        z = gv(y, sinfo_args=(R.Tensor((2, 3)),))
        return z

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Yeah, that seems unnecessary.

@Hzfengsy Hzfengsy merged commit 465d691 into apache:unity Oct 11, 2023
5 checks passed
@Lunderberg Lunderberg deleted the unity_avoid_cse_of_extern_func branch October 11, 2023 18:53
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