-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Constant prop gives a different result in the presence of FMA #41450
Comments
julia> goo(x=1.0) = fma(1 + eps(x), 1 - eps(x), -1)
goo (generic function with 2 methods)
julia> goo()
-4.930380657631324e-32
julia> goo(1.0)
-4.930380657631324e-32 |
This is the documented behavior of muladd. The whole reason it exists is that the compiler can choose to use different operation based on the context and availabile hardware features. |
@yuyichao This isn't a bug per-se, so much as the compiler making a dumb choice. The compiler is free to choose whether to fold a |
No fma isn’t better or more correct at all and the compiler isn’t making any bad or dumb choice here. In terms of the results, both are equally good. This is only about performance and when things are constant folded both have the same performance. If some computation must be done at runtime, it should pick the one with higher performance, which isn’t necessarily fma even if such instruction exist (e.g. if a and b are both constants in |
I don't think it's fair to say that both results are equally good. The result of Also, since |
Which is not the definition of "good". Machine precision floating point math has well defined rounding rules, (edit:) and I've certainly seen algorithms that produces less accurate results when fused because of that. I.e., while mathematically speaking for this single operation, FMA is certainly more "correct", it is not always the case in context and the context is what
Which is not the case. Again,
No. that requires loading two floating point constants instead of one. |
The situation here seems to be:
It would therefore be nice to have the option to ensure that (for a block of code) |
I think the correct solution here is to finally go and implement the target capability query macros and if those indicate FMA support, force an |
In the meantime, I also don't think there's anything wrong with forcing FMA for the muladd constprop. |
So that we can get more accurate results when performance doesn't matter
Trying to solve by #41564 |
So that we can get more accurate results when performance doesn't matter
So that we can get more accurate results when performance doesn't matter
So that we can get more accurate results when performance doesn't matter
For reference, this is issue #9855. |
Oh, and #33011 |
The text was updated successfully, but these errors were encountered: