error C2065: 'add': undeclared identifier
This error is not related to CUDA. The add function belongs to one compilation unit ( kernelAdd.cu ), and the other compilation unit ( mainFunc.cpp ) knows nothing about this. To provide this information, you must create an additional kernelAdd.h header kernelAdd.h with a function declaration:
__global__ void add(int a, int b, int *c);
And include it in mainFunc.cpp :
#include "kernelAdd.h"
Each cu or cpp file is compiled separately and knows only about the functions that it sees in the header files that it includes.
error C2059: syntax error: '<'
Now I'm guessing here (don't check VS or even Windows), but it looks like VS selects a compiler for each of the files in the project based on its extension. Thus, mainFunc.cpp compiled using the general C ++ compiler, but the syntax <<<>>> for kernel calls does not apply to standard C ++ - it is from CUDA. All CUDA syntax should be used only in files that are going to be compiled using nvcc .
Thus, one way to solve your problem is to rename mainFunc.cpp to mainFunc.cu . You can still save your main .cpp file, of course, but then you have to move the kernel call to some normal C ++ function inside the cu file and put it in the standard C ++ header file that your .cpp file will include.
source share