Uh oh!
There was an error while loading. Please reload this page.
feat: Add global fast_math flag to CudaBuilder - #331
Conversation
- Add fast_math field to CudaBuilder struct - Enables ftz, fast_sqrt, fast_div and fma_contraction(fmad) internally - Provides convenient parity with NVCC's --use_fast_math
nnethercote
left a comment
There was a problem hiding this comment.
The implementation is confused. How do the individual flags interact with the new flag? What happens if you specify fast_math and then also fast_sqrt(false)? Seems like either:
- CudaBuilder should handle all the fast_math stuff, and pass individual flags to NVCC, but not
--use_fast_math - CudaBuilder should just record fast_math and then pass
--use_fast_maththrough to NVCC
But currently it's doing a mixture of both.
Also, was this PR generated by AI? The description is very long, with subheadings and bullet points that are typical for AI.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
koreaygj
commented
Dec 2, 2025
Thank you for your review. Do you think delegating to NVCC would be the better approach? I need your advices. |
LegNeato
commented
Dec 5, 2025
How does this jive with https://simonbyrne.github.io/notes/fastmath/ ? |
Sorry to late! @nnethercote@LegNeato
Regarding IEEE 754 concerns — fast_math() doesn't add any new capability. It's a convenience wrapper over the same four individual flags (ftz, fast_sqrt, fast_div, fma_contraction) that already exist. |
Hi
I try to implemente a
fast_math()method to solve this issue. It provides a convenient way to enable fast math approximations globally, equivalent to NVCC's--use_fast_mathoption.Description
Implement a global
fast_mathflag for CudaBuilder as a convenience method equivalent to NVCC's--use_fast_mathoption.According to the NVCC official documentation, the
--use_fast_mathflag enables fast approximations for floating-point operations by internally settingftz,prec-sqrt, andprec-div.Implementation
I implemented a
fast_math()method that sets these three options internally:Usage
Users can now enable fast math globally with a single method call:
Instead of manually setting each flag:
Implementation Details
fast_math()method is a convenience wrapper that internally enablesftz,fast_sqrt, andfast_divinvoke_rustc()false)Relates to #262