not able to use cudaMemcpy() in openacc

Here is the code:
#include <cuda_runtime.h>

const int GL=100000;
Particle particles[GL];
int cp01[2][GL];
#pragma acc declare create(particles,cp01)

#pragma acc update self(cp01)
#pragma acc host_data use_device(particles)
{
cudaMemcpy(&particles[cp01[0][0]],&particles[cp01[1][0]],cp*sizeof(Particle),cudaMemcpyDeviceToDevice);
}
I build the project with compiler options “-acc -Minfo=all”, but the compiler gives:
[100%] Linking CXX executable AOS_GPU_LIFE
CMakeFiles/AOS_GPU_LIFE.dir/nbody.cpp.o: In function function_device()': /home/70- gaa/source/GPU/AOS_GPU_LIFE_map_sort_new/nbody.cpp:175: undefined reference to cudaMemcpy’
pgacclnk: child process exit status 1: /usr/bin/ld
CMakeFiles/AOS_GPU_LIFE.dir/build.make:94: recipe for target ‘AOS_GPU_LIFE’ failed
make[2]: *** [AOS_GPU_LIFE] Error 2
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/AOS_GPU_LIFE.dir/all’ failed
make[1]: *** [CMakeFiles/AOS_GPU_LIFE.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
How to solve the problem? Should I use the compiler option -Mcuda=8.0 to enable usage of CUDA 8.0 in the application?

Hi Andrey,

Yes, whenever you mix OpenACC with CUDA, you need to add the “-Mcuda” flag. Optionally you can use “cuda8.0” if you want to link with the CUDA 8.0 libraries rather than the current default for PGI 2071 which is CUDA 7.5. The “-Mcuda” flag will add the CUDA runtime libraries to your link, which is the cause of your linking error.

-Mat