Questions tagged [fast-math]

The `-ffast-math` (or a similarly-named) compiler option trading precision and adherence to the IEEE 754 floating point standard in favor of execution speed

Most compilers have an option for turning floating-point-related optimizations which sacrifice computational precision and/or adherence to the costlier corner-cases of the IEEE 754 floating-point standard - in favor of better execution speed.

  • For gcc and clang, this option is named -ffast-math (and there are sub-options)
  • For nvcc, the name is --use-fast-math
  • For OpenCL compilation, the name is -cl-fast-relaxed-math

For more information: What does gcc's ffast-math actually do?

44 questions
2
votes
2 answers

Can I determine at compile time whether --use_fast_math was set?

I'm writing some CUDA code, and I want it to behave differently based on whether or not --use_fast_math was set or not. And - I want to make that decision at compile time, not at run time. It seems that NVCC does not add or change a preprocessor…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
1 answer

Curious result from the gcc linker behaviour around -ffast-math

I've noticed an interesting phenomenon around flags to the compiler linker affecting the running code in ways I cannot understand. I have a library that presents different implementations of the same algorithm in order to test the run speed of those…
Henry Gomersall
  • 8,434
  • 3
  • 31
  • 54
2
votes
1 answer

why -ffast-math option break my bool condition

This is critical section of the program that cause problem, and program is completely sequential. exist_ is a class bool private member, and dbl_num_ is a class double private member exist_ = false; dbl_num_ = 0; std::cout << dbl_num_ << " "…
Bryan Fok
  • 3,277
  • 2
  • 31
  • 59
1
vote
2 answers

Weird LTO behavior with -ffast-math

Summary Recently I encountered a weird issue regarding LTO and -ffast-math where I got inconsistent result for my "pow" ( in cmath ) calls depending on whether -flto is used. Environment: $ g++ --version g++ (GCC) 8.3.0 Copyright (C) 2018 Free…
Liu Wei
  • 77
  • 6
1
vote
0 answers

Is there a way to tell the compiler to compile with "fast-math" or something similar in C#?

In some other languages, you can allow the compiler to perform some floating point optimizations, one of which is rewriting your code into algebraically equivalent expressions. Here are some examples of what I mean: a = a * a * a * a * a * a * a * a…
Petrusion
  • 940
  • 4
  • 11
1
vote
1 answer

Does GCC's ffast-math have consistency guarantees across platforms or compiler versions?

I want to write cross-platform C/C++ which has reproducible behaviour across different environments. I understand that gcc's ffast-math enables various floating-point approximations. This is fine, but I need two separately-compiled binaries to…
spraff
  • 32,570
  • 22
  • 121
  • 229
1
vote
4 answers

gcc optimizations cause app to fail

I'm having a real strange problem using GCC for ARM with the optimizations turned on. Compiling my C++ application without the optimizations produces an executable that at runtime outputs the expected results. As soon as I turn on the…
celavek
  • 5,575
  • 6
  • 41
  • 69
1
vote
0 answers

Does gcc -Ofast enable vectorization?

I am currently compiling spec2000 art benchmark using following 2 flag settings: -Ofast -m32 -march=native -Ofast -m32 -march=native -fno-tree-vectorize The second setting just disable the vectorizer. However, when I checked the objdump of the 2…
1
vote
1 answer

AVX code segfaults when compiled with -ffast-math?

I'm experimenting with writing a couple kernels using GCCs builtin simd support. I've got this code benchmarking an AVX dot product kernel: #include #include #include #include #include #include…
gct
  • 14,100
  • 15
  • 68
  • 107
0
votes
0 answers

Assertion failure on isFast “getting fast-math flag on invalid op”, Trying to check if fast option is set for an instruction LLVM

Hi I am writing a transformation pass to check where on some conditional call instruction I would like to check If fast option is set for that call, instruction and disable it. For example on below call inst, I would like to disable the fast…
Pawan Nirpal
  • 565
  • 1
  • 12
  • 29
0
votes
1 answer

C++ gcc does associative-math flag disable float NAN values?

I'm working with statistic functions with a lot of float data. I want it to run faster but Ofast disable NAN (fno-finite-math-only flag), which is not allowed in my case. In this case, is it safe to turn on only associative-math ? I think this flag…
Huy Le
  • 1,439
  • 4
  • 19
0
votes
1 answer

__host__ __device__ functions calling overloaded functions

I do not understand whether there is function overloading in Cuda or not. I want to explain my problem on the following two functions, which I want to be able to use both on the GPU and the CPU, and I don't care about precision: __host__…
tommsch
  • 582
  • 4
  • 19
-1
votes
2 answers

Can this piece of code be modified such that it works with fast-math enabled?

Can the code below be modified such that it works correctly even when compiled by GCC with fast-math enabled? #include #include using namespace std; int main() { char divider = 2; float power = 1; float number = 1; …
Martin
  • 29
  • 5
-2
votes
1 answer

What exactly -ffast-math option does while compiling with gcc

Can any one help in making me understand what does -ffast-math option does when compiled with gcc. I see a difference of 20 sec in my programs execution time when executed with -O3 and -ffast-math compared to only use of -O3
pavan
  • 979
  • 3
  • 11
  • 21
1 2
3