I encounter some weird crash (seg fault) when running my C++ code when built with nvc++ -O3. We have no issues with other compilers (GNU, Intel) and there is no valgrind error. It is hard to provide you a reproducer. So I would like to compile some specific files where crashes occurred (or specific part of the files) with -O0 cause when the code is built with nvc++ -O0, it is OK. I forgot to say that -Mnovect -Mnunrool has no effect too.
Unhappily, after reading the compiler doc, I don’t find any pragma to disable optimization locally. Am i wrong ?
Thanks
We use to document these, but I think due to Fortran sentinels being “!$pgi”, they removed them from the docs when we rebranded to nvhpc. Though the pragmas and directives are still there.
In this case you want the “opt” pragma which can either be applied to the whole file or a particular routine depending on the scope in which it’s use. For example:
#pragma opt 0 << this would apply -O0 to the whole file
void foo(float *Arr, int sze) {
#pragma opt 0 << this applies -O0 to a single routine
for (int i =0; i < sze; ++i) {
Arr[i] = i/10;
}
}
I didn’t succeed using #pragma opt 0 in my code. For your interest, I had a crash at the bold line (arithmetic exception). I solved it by adding a DMINFLOAT value (1.e-30) several lines after where the crash really happened to avoid the per 0 division by l variable despite the test on l variable. It is not the first time I saw that the compiler optimize (vectorize?) the code but omit the conditional test.
It is another workaround for us to disable it for the nvc++ compiler.
Yes, not enabling trapping will be your best option.
Trap safety is a known issue due to instruction selection by our back-end LLVM code generator. There are ways to force LLVM to be trap-safe, but the resulting performance is very poor, so much so that it’s highly unlikely you’d want to enable it.