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 as sqrt to run faster and also be more amenable to parallelization, simply by allowing them to never set the global “errno” variable. The use of errno 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 checking errno anyway, so turn it off!
  • -ffinite-math-only” — This mode allows GCC math library functions to skip any checks for Inf or NaN, 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

Buy: Generative AI in C++: Coding Transformers and LLMs

Generative AI in C++ The new AI programming book by Aussie AI co-founders:
  • AI coding in C++
  • Transformer engine speedups
  • LLM models
  • Phone and desktop AI
  • Code examples
  • Research citations

Get your copy from Amazon: Generative AI in C++