Generate C++ code from CUDA code

Hi I am new to PGI.

In my project I want to compile .cu files into cpp files first, then use g++ later on. When I was using nvcc, I could do the following:

nvcc -cuda -arch=sm_20 -o a.cpp
g++ -L/usr/local/cuda/lib64/ -lcuda -lcudart a.cpp -o a

However, I am not sure how to achieve this with pgCC compiler. Could anybody help?

Hi timnth,

You should be able to use “pgc++” instead of “pgCC”. “pgc++” is our GNU compatible C++ compiler which will be required since nvcc uses “g++” as the host side compiler.

% nvcc -cuda -arch=sm_20 -o vectorAdd.cpp
% pgc++ -L/opt/cuda-6.5/lib64/ -lcuda -lcudart vectorAdd.cpp
% a.out
[Vector addition of 50000 elements]
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
Copy output data from the CUDA device to the host memory

Hope this helps,

Thanks very much for the answer!
In addition to compiling to .cpp first, I also want to use the cuda x86, how should I do the compilation?

Hi timhth,

For Cuda x86, use the flag “-Mcudax86” with pgc++ directly on the .cu file. Note that Cuda x86 only supports Cuda 3.2 features.

  • Mat