Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and GDB*
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
260 Discussions

Big bug in oneAPI DPC++/C++ Compiler from Intel OneApi Developer Tools 2021.4 for arrays

JerzyP
Beginner
659 Views

Hi,

This post is an extension of my yesterday's post, which only covered valarrays and exp() functions. Because the error found is very important, I founded a new thread (as new subjects).

I found a big bug in oneAPI DPC++/C++ Compiler from Intel OneApi Developer Tools 2021 (versions w_BaseKit_p_2021.4.0.3421_offline.exe + w_HPCKit_p_2021.4.0.3340_offline.exe or earlier).
Try to compile the easy program given below with /O2:
----------

#include <iostream>
#include <cmath>

int main() {
using namespace std;
int size = 150;

double* x = new double[size];
double* y = new double[size];

for (int i = 0; i < size; ++i)
y[i] = x[i] = 1.0;

for (int i = 0; i < size; ++i)
y[i] *= exp(x[i]);

for (int i = 0; i < size; ++i)
cout << y[i] << endl;

delete[] y;
delete[] x;
return 0;
}

----------

I compiled this program as Release and for x64 platform using MS Visual Studio 2019 environment by oneAPI DPC++/C++ Compiler (on a PC with Windows 10 64-bit and Intel i7-2700 or i7-3770).

The all compilation option are: /GS /W3 /Gy /Zi /O2 /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Qipo /Zc:forScope /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" //fprofile-instr-use "x64\Release\" /Fp"x64\Release\bigbug.pch"
The all linker options are: /OUT:"C:\Users\Jerzy\source\repos\bigbug\x64\Release\bigbug.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Users\Jerzy\source\repos\bigbug\x64\Release\bigbug.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X64 /OPT:REF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\bigbug.exe.intermediate.manifest" /OPT:ICF /NOLOGO /TLBID:1

So, we expect to obtain: 2.71828, 2.71828, 2.71828, 2.71828,…(i.e. exp(1.0)),
but we get wrong results: 2.71828, 2.71828, 15.1543, 15.1543, 2.71828, 2.71828, 15.1543, 15.1543,…

Similar problem exist if we replace exp() function by sin(), cos(), tan(), log(), and many others.
This bug appears, when the program is optimized for favor speed (by options /O2, /Ox, or /O3) for variable size>127 or if the variable size is unknown during compilation time (i.e. appears as a calculated or given input variable).

Also, I got the same wrong results when I used valarray or arrays containers.

Please, help me, haw I can run around this problem in oneAPI DPC++/C++ Compiler to have the good-optimized program (this problem appeared in my numerical program which needs dozens of hours calculation time). So far I used Intel C++ Compiler Classic that gave a little less optimized execution code.

Thanks,
Jerzy

0 Kudos
11 Replies
JerzyP
Beginner
631 Views

The problem also exists with static arrays:
double x[150];
double y[150];

Jerzy

JerzyP
Beginner
614 Views

And also with single precision:
float x[150];
float y[150];

Jerzy

VarshaS_Intel
Moderator
590 Views

Hi,


Thanks for reporting us.


Could you please let us know which version of Microsoft Visual Studio you are using?


We are working on your issue internally and will get back to you soon.



Thanks & Regards

Varsha


JerzyP
Beginner
585 Views

Microsoft Visual Studio Enterprise 2019, ver. 16.11.4.

Jerzy

Jie_L_Intel
Employee
542 Views

Jerzy,

Does it work if build with "icpx test.cpp" in command line?


Jie_L_Intel
Employee
521 Views

i could not reproduce with your test code with VS16.3.6 and oneAPI 2021.4.

How did you create a VS project? i use "File"->"New" ->"Project" -> "Create a New Project" pop-up and select "DPC++ Console Application".



JerzyP
Beginner
511 Views

1. I use "File"->"New" ->"Project" -> "Create a New Project" pop-up and select "Empty Project".

2. I write the source code using VS.

3. In VS, I change the configuration from Debug to Release and platform from x86 to x64.

4. In VS, I change VS C++ compiler to Intel C++ Compiler 2021 ("Project" -> "Properties" pop-up and select  in General->Platform Toolset - > Intel C++ 2021). Next, I set in General -> C++ Language Standard -> "ISO C++17 Standard".

Jie_L_Intel
Employee
431 Views

With your detailed steps, i could reproduce the same sighting with you. i will submit this bug to developer team. And one work-around now is to select the "Intel oneAPI DPC++ Compiler" in "General" of project properties.


JerzyP
Beginner
401 Views

Jie_L_Intel, 

This method only partially solves the problem because if I select "Intel oneAPI DPC++ Compiler" in "General" of project properties then:
1) The “Project -> Properties -> Code Generation -> DPC++ -> Runtime Library -> Multi-threaded (/MT)” option disappears from VS Environment. How can I compile the program with static library linking?
2) The “Tools -> Intel Compiler -> Profile Guided Optimization” menu disappears from VS Environment. The PGO method that uses the “Compilation -> Profile Guided Optimization” does not work and when I use the -fprofile-instr-generate compilation option and next after running, the program the the -fprofile-instr-use compilation option also does not work. I get the information: “error: Could not read profile default.profdata: no such file or directory”.

Jerzy

Jie_L_Intel
Employee
386 Views

You are right that dpcpp and icx share some options but there are some options specific for icx and some for dpcpp only. i have conveyed the item 1 to developer team and item 2 could not apply to dpcpp. So the workaround could not solve all your problems, it could just solve the exp result value bugs. Let's wait for the bug-fixing.


Jie_L_Intel
Employee
340 Views

Primary analysis shows that the /O2 and IPO co-exist lead to this sighting. Lowering to /O1 with Intel Compiler 2021 could be one work around.

And for /MT with DPC++ project, it is not supported in DPC++ toolchain which means static library could not be supported. So you have to use "Intel Compiler 2021".


Reply