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

[Arith] Allow const folding on fp16 involving one and zero #13631

Merged
merged 1 commit into from
Dec 16, 2022

Conversation

masahi
Copy link
Member

@masahi masahi commented Dec 16, 2022

Since #12515, const folding on fp16, when both lhs and rhs are constant, is disabled. This is the case even when one of the arguments are one or zero. This leads to a real problem described in #13532 (comment). So in practice, compiling winograd fp16 on GPU is currently broken.

This PR enables trivial algebraic simplification for fp16 const folding when (1) both arguments are constant and (2) one or both of the inputs are one or zero. Since we already do such simplification for any dtype when only one of the inputs are constant (for example

tvm/src/arith/const_fold.h

Lines 209 to 216 in 3a639a4

if (fa) {
if (fa->value == 1) return b;
if (fa->value == 0) return a;
}
if (fb) {
if (fb->value == 1) return a;
if (fb->value == 0) return b;
}
), I just removed all early exit return NullOpt for fp16 cases and use the code path like above to simplify 0h * 2.5h to 0h etc.

cc @vinx13 @wrongtest-intellif @Lunderberg

@tvm-bot
Copy link
Collaborator

tvm-bot commented Dec 16, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

Copy link
Contributor

@leandron leandron left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @masahi

@vinx13 vinx13 merged commit cded048 into apache:main Dec 16, 2022
fzi-peccia pushed a commit to fzi-peccia/tvm that referenced this pull request Mar 27, 2023
mikeseven pushed a commit to mikeseven/tvm that referenced this pull request Sep 27, 2023
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.

4 participants