CUDA and C++ ? Namespaces, classes, templates :(

hey guys

I get weird compile errors if I try to introduce any sort of C++ into my CUDA code.
I just included with NOTHING ELSE and it gave a compile error there.
If I include any special keyworded variables (such as device float *array) in namespaces or classes
I get compile errors. If I have them inside of namespaces, more errors arise (such as error C2065: ‘__shadow__ZN6s3cuda10output_devE’ : undeclared identifier). However, I use a CUDA class to wrap all my functionalty.

Basically what I’m doing now is I have all GPU specific variables/kernel code as globals outside of the class and namespace spaces, which are then called and used inside of the classes. However, I am going to be threading this app so I need an instace of these PER CLASS, so I need them inside of the class as local variables - is it possible?

Any help would be much appreciated!

Care to share which operating system and compiler version you are using? [my guess is gcc and in that case you need to do a little reading about the g++ obj/template instantiation model].

Hey, sorry about that.

Windows XP Service Pack 3 with Visual C++ 05 express. The project was created using the CUDA project wizard found on these forums. It might be useful to note that I am building it as a .LIB, to be linked in from another C++ program.

ON A SIDE NOTE: If I just include to my working program, I get a crash of cudafe++.exe, and the following error gets spewed out: internal error: assertion failed: gen_expr: bad expr node kind (D:/Bld/rel/gpgpu/toolkit/r2.1/compiler/edg/EDG_3.9/src/cp_gen_be.c, line 9510)

Very weird…

I haven’t tried it with the beta myself, but these issues are reportedly fixed in CUDA 2.2.

@Bluebit,

This is the first step in C+±CUDA misadventures.

I have faced this problem. VS 2005 SP1 - solved it. Also use CUDA 2.2, if possible.

i divided my code into 2 realms, one compiled with nvcc and one with g+±4.1 and because the abi is compatible

i could link the object files. this way i can use iostream and boost and whatnot. this is the case with gcc i have

no idea how well vc++ works.

i am quite sure you cannot have device or shared qualifiers for class members (it would not make sense

to store parts of the object in different memories), but you can

have a shared or device qualifier for objects of a class, making all members shared for example.

Try this after you include

[codebox]// Workaround for Cuda 2.1 bug: see http://forums.nvidia.com/index.php?showtopic=84283

// this should be fixed with 2.2

using namespace std;[/codebox]