[Arith] Allow const folding on fp16 involving one and zero #13631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
return NullOpt
for fp16 cases and use the code path like above to simplify0h * 2.5h
to0h
etc.cc @vinx13 @wrongtest-intellif @Lunderberg