-
Notifications
You must be signed in to change notification settings - Fork 11
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
Would it make sense to enable ffast-math for simd types? #19
Comments
This won't be much of a response, but I personally don't know. I don't know anything about I think I'd need to see a lot more detail on this before I'd personally be comfortable doing anything. |
I'm far from an expert on the topic but my understanding is that the normal IEEE754 precision guarantees don't allow doing certain arithmetic reorderings. This limits LLVM in generating more effective code even with normal floating point instructions and can severely limit it's ability to auto-vectorize. Enabling |
I feel like there is a much larger design space. For example, instead of duplicating all of the floating point vector types, we could just expose "fast" arithmetic operations as normal functions, kind of like how we have Another design point is to add a Finally, I'm not exactly sure why @pedrocr My intuition here is that someone will need to champion this and propose an addition to the standard library that gives you access to |
This would work but makes for really ugly code.
This would be a much better solution indeed from the code clarity standpoint.
Doing it for normal types is indeed also useful. I see two reasons this connects with SIMD though. The first (and circunstancial) is that the vector API is already a wrapper around the underlying types so it's already naturally easier to implement these things than with
I've been following this issue: I don't really understand the rust design process. Are you suggesting that the next step should be to take that discussion and try and do an RFC? I don't think I know enough about the rust conventions and this problem to write an RFC but I can try and start a pre-RFC discussion in internals to get the ball going. |
Could you expand on this? It still seems to me like
A pre-RFC would be good. I should have suggested that first. :-) I'd encourage you to give lots of examples. |
It's zero cost in execution but quite costly in programming time creating quite ugly code. Here's what getting rid of OrderedFloat bought me in code simplification:
Yeah, I think I'll do that. I have 2 or 3 options of how |
Created a pre-RFC here: https://internals.rust-lang.org/t/pre-rfc-whats-the-best-way-to-implement-ffast-math/5740 |
As discussed here:
rust-lang/rust#21690
-ffast-math
can be very useful to speedup floating point operations, particularly allowing easier vectorization. I'm seeing a ~30% runtime reduction for matrix multiplication in clang from doing-ffast-math
in this benchmark:https://github.com/pedrocr/rustc-math-bench
As mentioned in the rust issue the intrinsics already allow a part of this and a wrapper type for
f32/f64
can already be implemented. Since SIMD types are already aimed at vectorization and the cost of wrapping/unwrapping is already there would it make sense to enable-ffast-math
for them anyway? Alternatively if there are cases where that doesn't make sense would it be useful to duplicate slow and fast versions of all the types for convenience?The text was updated successfully, but these errors were encountered: