Fast floating point model broken on next-generation intel compiler
Asked Answered
P

1

8

Description

I'm trying to switch over from using the classic intel compiler from the Intel OneAPI toolkit to the next-generation DPC/C++ compiler, but the default behaviour for handling floating point operations appears broken or different, in that comparison with infinity always evaluates to false in fast floating point modes. The above is both a compiler warning and the behaviour I now experience with ICX, but not a behaviour experienced with the classic compiler (for the same minimal set of compiler flags used).

Minimally reproducible example

#include <iostream>
#include <cmath>

int main()
{
    double a = 1.0/0.0;
    if (std::isinf(a))
        std::cout << "is infinite";
    else
        std::cout << "is not infinite;";
}

Compiler Flags: -O3 -Wall -fp-model=fast

ICC 2021.5.0 Output: is infinite (also tested on several older versions)

ICX 2022.0.0 Output: is not infinite (also tested on 2022.0.1)

Live demo on compiler-explorer: https://godbolt.org/z/vzeYj1Wa3

By default -fp-model=fast is enabled on both compilers. If I manually specify -fp-model=precise I can recover the behaviour but not the performance.

Does anyone know of a potential solution to both maintain the previous behaviour & performance of the fast floating point model using the next-gen compiler?

Parity answered 29/8, 2022 at 20:11 Comment(4)
GCC has a similar option: -ffinite-math-only, enabled by -ffast-math, enabled by -Ofast, godbolt. It makes optimisations based on the assumption that NaNs do not ever occur.Rectum
@AveMilia -ffinite-math-only assumes that arguments and results are not NaNs or Infs.Hadria
@Hadria sorry, I misread the source code and replaced the inf check for a nan check. You are right.Rectum
@Parity Unless -fp-model=fast is defined to include IEEE-754 compliant handling of Infs (and I can find no such guarantee in the Intel docs, but may be looking in the wrong place), nothing seems broken.Hadria
R
7

If you add -fp-speculation=safe to -fp-model=fast, you will still get the warning that you shouldn't use -fp-model=fast if you want to check for infinity, but the condition will evaluate correctly: godbolt.

In the Intel Porting Guide for ICC Users to DPCPP or ICX it is stated that:

FP Strictness: Nothing stricter than the default is supported. There is no support for -fp-model strict, -fp-speculation=safe, #pragma fenv_access, etc. Implementing support for these is a work-in-progress in the open source community.

Even though it works for the current version of the tested compiler (icx 2022.0.0), there is a discrepancy: either the documentation is outdated (more probable), or this feature is working by accident (less probable).

Rectum answered 29/8, 2022 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.