Hi,
I was trying to reproduce the idea from pgcc compile error in OpenACC-CUDA interoperabily example of having CUDA kernels + OpenACC pragmas in the same file. Using NVCC as the main compiler with PGC++ as the host-compiler.
But I’m struggling to make it to work with cuda 8.0 and PGI 16.9.
#include <stdio.h>
#include <cuda_runtime.h>
__global__ void
vectorAdd(const float *A, const float *B, float *C, int numElements)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < numElements)
{
C[i] = A[i] + B[i];
}
}
/**
* Host main routine
*/
int
main(void)
{
cudaError_t err = cudaSuccess;
int numElements = 50000;
size_t size = numElements * sizeof(float);
printf("[Vector addition of %d elements]\n", numElements);
float *h_A = (float *)malloc(size);
float *h_B = (float *)malloc(size);
float *h_C = (float *)malloc(size);
for (int i = 0; i < numElements; ++i)
{
h_A[i] = rand()/(float)RAND_MAX;
h_B[i] = rand()/(float)RAND_MAX;
}
#pragma acc data copyin(h_A[0:numElements],h_B[0:numElements]), copyout(h_C[0:numElements])
{
#pragma acc host_data use_device(h_A,h_B,h_C)
{
// Launch the Vector Add CUDA Kernel
int threadsPerBlock = 256;
int blocksPerGrid =(numElements + threadsPerBlock - 1) / threadsPerBlock;
printf("CUDA kernel launch with %d blocks of %d threadsn\n", blocksPerGrid, threadsPerBlock);
vectorAdd<<<blocksPerGrid, threadsPerBlock>>>(h_A, h_B, h_C, numElements);
err = cudaGetLastError();
if (err != cudaSuccess)
{
exit(EXIT_FAILURE);
}
} // end host_data
} // end acc data region
for (int i = 0; i < numElements; ++i)
{
if (fabs(h_A[i] + h_B[i] - h_C[i]) > 1e-5)
{
exit(EXIT_FAILURE);
}
}
printf("Test PASSED\n");
// Free host memory
free(h_A);
free(h_B);
free(h_C);
printf("Done\n");
return 0;
}
Compiled with:
/usr/local/cuda-8.0/bin/nvcc -x cu -ccbin pgc++ -Xcompiler -ta=tesla:cuda8.0 -Xcompiler -Mcuda -Xcompiler -Minfo=accel -gencode arch=compute_35,code=sm_35 vecAdd.cpp
and error:
"/usr/local/cuda-8.0/bin/..//include/host_config.h", line 119: catastrophic
error: #error directive: -- unsupported GNU version! gcc versions
later than 5 are not supported!
#error -- unsupported GNU version! gcc versions later than 5 are not supported!
^
1 catastrophic error detected in the compilation of "vecAdd.cpp".
Compilation terminated.
It seems that pgc++ defines GNUC > 5. Is this behaviour correct? (It has any relation that my system has g++ 6.1.1 installed?)
Thanks.