When I build the code with kernelAdd() function and main() function in the same file mainFunc.cu, it\'s ok.
But when I separate the kernelAdd() function in the kerne
The only addition to C to make CUDA C is the triple angle-bracket syntax to launch a kernel (<<<>>>). Everything else uses existing C features. Specifying a function as __global__ will cause nvcc to compile it for the device and create the symbols etc. so that it can be called from the host.
This means that:
__global__ function etc.) must be in a .cu file.<<<>>> syntax to launch a kernel must be in a .cu file.You can still have all your other host code in .cpp files, you just need to put a stub in the .cu file to call the kernel, e.g. void launch_add(...) { add<<<...>>>(...); }.