Aussie AI
Floating-Point Optimizer Options
-
Book Excerpt from "Generative AI in C++"
-
by David Spuler, Ph.D.
Floating-Point Optimizer Options
Some C++ compilers have optimizations that you can use to speed up your Floating-Point Unit (FPU). Some of the options for GCC include:
- “
-ffast-math
” option — This option is a broad enabler of multiple floating-point speedups, such as-fno-math-errno
and-ffinite-math-only
. It also disables negative zero. - “
-fno-math-errno
” option — This allows the standard library math functions such assqrt
to run faster and also be more amenable to parallelization, simply by allowing them to never set the global “errno
” variable. The use oferrno
was once a great way to track error codes, but it's also a blocker for thread-safety and parallelization. And let's be frank: you weren't ever checkingerrno
anyway, so turn it off! - “
-ffinite-math-only
” — This mode allows GCC math library functions to skip any checks forInf
orNaN
, which can make them marginally faster.
Microsoft Visual Studio C++ also has its own set of FPU options:
- “Floating-Point Model” settings in a Project's Property Pages under “C++” for “Code Generation” has options “
/fp:precise
”, “/fp:strict
”, or “/fp:fast
” - “Enable Floating-Point Exceptions” can be turned off if you like.
• Next: • Up: Table of Contents |
The new AI programming book by Aussie AI co-founders:
Get your copy from Amazon: Generative AI in C++ |