-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Runtime intrinsics: fix fpext and fptrunc behaviour on Float16/BFloat16 #57160
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
Runtime intrinsics: fix fpext and fptrunc behaviour on Float16/BFloat16 #57160
Conversation
I'm still not sure what the right thing to do is when doing
|
29628b6
to
d4ad742
Compare
I believe the correct behavior would be for fpext to allow going from Float16 or Bfloat16 to Float32/Float64 but not from Float16 to BFloat16 (or from Bfloat16 to Float16). I think that fpext is supposed to only allow transitions from src to dest if all possible src values are losslessly encodable in dest. See also https://discourse.llvm.org/t/converting-between-different-but-same-sized-floating-point-types/59538 which suggests that there might not be any general understanding of what should happen here. |
LLVM seems to prohibit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (superficially at least, it's been a while since I looked at this code).
For BFloat16s.jl it'd be fine to reject fpext/fptrunc between f16 and bf16, it currently should go through f32 anyway.
else | ||
jl_error("fptrunc: runtime floating point intrinsics are not implemented for bit sizes other than 16, 32 and 64"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are changing the permitted combination of behaviors, you will also need to update Compiler/src/tfuncs.jl and src/intrinsics.cpp to match these new rules, so that they all agree on exactly which errors are thrown and for what cases they can occur
We also throw an exception when using fpext/fptrunc on integer types, because with the addition of BFloat16, there is no unambiguous floating point format with which to interpret the input when it is 16 bits wide.
BFloat16 tests that trigger codegen are disabled for now, pending an LLVM fix.
I decided to leave the incorrect handling of NaNs for later, since what to do is not entirely clear (#49353). |
double_to_half, float/double_to_bfloat TODO
cdbda7c
to
7431a86
Compare
Co-authored-by: Jameson Nash <[email protected]>
7431a86
to
e2d3cd9
Compare
86d3070
to
fa82f94
Compare
The `fptrunc`/`fpext` intrinsics were modified in #57160 to throw on non-float arguments. - The arithmetic and math float intrinsics now require all their arguments to be floats - `fptosi`/`fptoui` require their source to be a float - `sitofp`/`uitofp` require their destination type to be a float Also fixes #57384.
The `fptrunc`/`fpext` intrinsics were modified in #57160 to throw on non-float arguments. - The arithmetic and math float intrinsics now require all their arguments to be floats - `fptosi`/`fptoui` require their source to be a float - `sitofp`/`uitofp` require their destination type to be a float Also fixes #57384. (cherry picked from commit 0bcc9cd)
…16 (JuliaLang#57160) This makes two changes `fpext` and `fptrunc` to match the behaviour specified in their error strings: -`fpext` works when converting from Float16 => Float16, -`fptrunc` is prevented from truncating Float16 => Float16 Both are re-written to make it explicit what conversions are possible, and how they are done. Closes JuliaLang#57130. --------- Co-authored-by: Jameson Nash <[email protected]>
) The `fptrunc`/`fpext` intrinsics were modified in JuliaLang#57160 to throw on non-float arguments. - The arithmetic and math float intrinsics now require all their arguments to be floats - `fptosi`/`fptoui` require their source to be a float - `sitofp`/`uitofp` require their destination type to be a float Also fixes JuliaLang#57384.
This makes two changes
fpext
andfptrunc
to match the behaviour specified in their error strings:-
fpext
works when converting from Float16 => Float16,-
fptrunc
is prevented from truncating Float16 => Float16Both are re-written to make it explicit what conversions are possible, and how they are done.
Closes #57130.