Error Compiling CUDA

Hi Everyone,

I got on this project where a bunch of C++ code was written, and my job is to distribute the work across the many processors of a GPU. So, the code is broken up as follows:

Main.cpp --> does CPU calculations for a while

passData() --> change format from vectors, classes, etc., to fit in C-style CUDA code (i.e. going C++ --> C)

Kernel.cu --> allocate GPU, etc.

I have a method called kernelCall() inside Kernel.cu, but I get the errors:

“error: identifier “kernelCall” is undefined”

I think that’s because I have had to use a Kernel.h method to the prototype of my extern “C” method passData() inside it. So, the compiler seems to complain that there’s no prototype definition of “kernelCall” inside Kernel.h.

If I do add a prototype definition to kernelCall to Kernel.h, then I get the following error:

“error C2144: syntax error : ‘void’ should be preceded by ‘;’”

I suppose this makes sense. How would regular C/C++ style code recognize the CUDA-specific command like global? It can’t.

What am I supposed to do?

EDIT: I excluded Kernel.h from the code, and it literally made no difference. Exact same error. For some reason, my function kernelCall inside of passData(), all of which is in Kernel.cu, cannot be found by the compiler. I don’t know what is up with this. I can’t make any kernel calls.

BTW, I’m running Windows XP Professional 32-bit, CUDA 3.0, Visual Studio 2008. I use the CUDA wizard to setup the project, and several days ago I setup the program to do a dummy test call from inside Kernel.cu to access the GPU, and it worked fine then. I haven’t changed anything in the .cu file until today, but that shouldn’t affect whether or not I can even call the GPU.

EDIT 2: Oh, wow… I didn’t know that the global function had to literally be before the passData() function inside Kernel.cu. Apparently, the order of appearance of code really matters. No one told me this. Oh well, it works!

Thanks in advance,
Daniel

Is kernelCall a host or device/global function? I would suggest the following:

main.cpp

  • include kernel.h

  • Do high level C++ stuff

  • (maybe) implement prepareParameters here

  • call prepareParameters()

  • call hostKernelCall()

kernel.h

  • declare all CUDA types

  • declare hostKernelCall() function

  • if you want classes (CUDA do support classes) and you want them to work both on host and device code you can try the following:

#ifdef __CUDACC__

#define HOST __host__

#define DEVICE __device__

#else

#define HOST

#define DEVICE

#endif

and declare all functions with HOST and/or DEVICE when applicable. During compilation of main.cpp all functions will be compiled as host functions only.

make all functions inline!

kernel.cu

  • Implement host function hostKernelCall() which will call the CUDA kernel

There are other ways to do it, e.g. you can call kernel directly from cpp file using special functions (without <<< >>> syntax) but it is more complicated.

It is a global function, so it was called on the host in Kernel.cu, but the work was to be done inside kernelCall on the GPU. I have my program setup much how you recommended it to be, so I appreciate the advice. The program is working. Just note to self: all global functions come before extern “C” functions in the .cu file.

Why do you need extern “C” functions at all?
CUDA host code is compiled by full C++ with all its stuff, including function naming and overloading.