- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I'm using Intel oneAPI 2022.1.3 from APT on Ubuntu 20.04 LTS x64 English (Linux-based).
I got example code of std::isfinite() from cppreference, compile them with DPC++ 2022.0.0.20211123 and it works incorrectly on Linux: not as C++ standard wants.
Linux build & execution log was attached.
Linux output:
isfinite(NaN) = true
isfinite(Inf) = true
isfinite(0.0) = true
isfinite(exp(800)) = true
isfinite(DBL_MIN/2.0) = true
Windows version of DPC++ generates correct output:
isfinite(NaN) = false
isfinite(Inf) = false
isfinite(0.0) = true
isfinite(exp(800)) = false
isfinite(DBL_MIN/2.0) = true
Example code was attached as a test.cpp file in test.zip too.
Code was compiled with command dpcpp test.cpp -o test
How can I fix that behavior?
With regards,
Alex
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for reaching out to us.
>>How can I fix that behavior?
Could you please try with below command as it worked (as expected) from our end.
dpcpp test.cpp -fp-model=precise -o test
Please find the below screenshot for more details.
"-fp-model=precise" disables the optimization for floating-point calculations, so that the result won't be changed.
Please refer to below link for more details.
Thanks & regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Noorjahan,
Yes, you are right, that flag was helpful for fixing behavior on Linux.
But I need to have maximum speed for Linux & Windows with equal & correct behaviour.
What about fixing an optimized version?
With regards,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I advice to test this version [1] as the original has the risk that everything is computed at compile time (try in godbolt for instance)
with Ofast (aka finite-math) one DOES expect isfinite(NAN) to be true
with latest gcc I get
c++ -O3 isfinite.cpp; ./a.out
isfinite(NaN) = false
isfinite(Inf) = false
isfinite(0.0) = true
isfinite(exp(800)) = false
isfinite(DBL_MIN/2.0) = true
x = 0
isfinite(0.f/x) = false
isfinite(1.f/x) = false
isfinite(x) = true
isfinite(exp(x)) = true
isfinite(DBL_MIN/x) = false
c++ -Ofast isfinite.cpp
./a.out
isfinite(NaN) = false
isfinite(Inf) = false
isfinite(0.0) = true
isfinite(exp(800)) = true
isfinite(DBL_MIN/2.0) = true
x = 0
isfinite(0.f/x) = true
isfinite(1.f/x) = true
isfinite(x) = true
isfinite(exp(x)) = true
isfinite(DBL_MIN/x) = true
[1]
#include <iostream>
#include <cmath>
#include <cfloat>
int main(int argc, char**)
{
float x = 1.f -float(argc);
std::cout << std::boolalpha
<< "isfinite(NaN) = " << std::isfinite(NAN) << '\n'
<< "isfinite(Inf) = " << std::isfinite(INFINITY) << '\n'
<< "isfinite(0.0) = " << std::isfinite(0.0) << '\n'
<< "isfinite(exp(800)) = " << std::isfinite(std::exp(800)) << '\n'
<< "isfinite(DBL_MIN/2.0) = " << std::isfinite(DBL_MIN/2.0) << '\n';
std::cout << std::boolalpha
<< "x = " << x << '\n'
<< "isfinite(0.f/x) = " << std::isfinite(0.f/x) << '\n'
<< "isfinite(1.f/x) = " << std::isfinite(1.f/x) << '\n'
<< "isfinite(x) = " << std::isfinite(0.0) << '\n'
<< "isfinite(exp(x)) = " << std::isfinite(std::exp(x)) << '\n'
<< "isfinite(DBL_MIN/x) = " << std::isfinite(DBL_MIN/x) << '\n';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We are working on your issue. We will get back to you soon.
Thanks & Regards,
Noorjahan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Alex,
I escalated this issue to development. I will update it as soon as I get any information.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Alex,
I got reply from developers:
"Use of dpcpp or icpx uses Intel defaults, which includes -fp-model=fast. This behavior is expected."
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The old compiler, icc, also had -fp-model=fast (or its equivalent) as the default, did it not? And yet isfinite does work on icc even in this mode.
I have a program that needs to have isfinite working. It runs about half as fast when I compile it with icx in precise mode as with icc in fast mode. I am eager to switch from icc to icx, but given this performance hit it is not an option for me right now.
Are there any prospects for fixing isfinite in icx in the fast mode?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...My apologies. This behavior is consistent with the most recent versions of gcc and clang in fast math mode. The solution is to add the compiler option -fno-finite-math-only, which is supported by gcc, clang, and icx.
![](/skins/images/D2683F18326913BBA0436CB7114DD569/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page