GCC fails to compile OpenMP offloading to GPU

  c++, gcc, gpu, offloading, openmp

I’m using GCC 9.3 on Ubuntu 20.04. I want to offload the famous SAXPY example to GPU using OpenMP. I installed GCC’s offloading capabilities by sudo apt install gcc-9-offload-nvptx . Then compiled the following code by g++ -fopenmp main.cpp:

int main()
    const size_t kNumel = 999999;

    float x[kNumel];
    float y[kNumel];

    for (size_t i=0 ;i <kNumel; i++)
        x[i] = i;
        y[i] = i;

    const float kCoef = 1.23f;

    #pragma omp target teams distribute parallel for
    for (size_t i=0; i < kNumel; i++)
        y[i] = kCoef*x[i] + y[i];

    return 0;

BUT it doesn’t compile and shows this error:

to1: error: ‘-fcf-protection=full’ is not supported for this target
mkoffload: fatal error: x86_64-linux-gnu-accel-nvptx-none-gcc-9 returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /usr/lib/gcc/x86_64-linux-gnu/9//accel/nvptx-none/mkoffload 
returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

I added -fno-stack-protector but the same error is reproduced.

Source: Windows Questions C++

One Reply to “GCC fails to compile OpenMP offloading to GPU”

  • I have never seen this error before, but the error seems to come from the offload compiler and I suppose that you have passed the flag to the host compiler. Does it help to add -foffload=-fno-stack-protector to your g++ invocation? This passes the flag to the offload compiler.