cuda compiler and abstract classes


I have an application compiled using cudas nvcc compiler. It exports one function which is called by the c++ part of the app compiled by visual studio. The function takes one parameter which is a pointer to an interface class. Sadly when I access its contents within the host side of the cuda code I get a memory error. Now if I define the implementation inside the *.cu file instead of only inlcuing the *.h file with the declaration all is fine. Is there any way to prevent having to define implementations on both the nvcc side as well as vvisual studio side?

You should really only export ‘extern “C”’ functions from code compiled by the current version of nvcc (we hope to have better C++ support in the future). By definition, extern “C” functions can’t take pointers to classes, since classes are a C++ feature.


Thanks for that reply, very helpfull!

I do however have one more question. Why is it that I can declare classes inside nvcc compiled code but not pass them. Is this because nvcc uses the visual studio compiler but has a different runtime?

It is using the preprocessor of the host compiler (VS or GCC) before actually compiling it with nvopencc. Run nvcc -v to see the processing chain.

So you can pass even template functions to it, if the preprocessor can resolve everything down to plain C functions. This is why a C++ class doesn’t work, because C++ specialization happens later in the compiler. As nvopencc is not a C++ compiler, there’s no way to make this work.


Thanks now I understand.