Pass C++ object to CUDA

I’m compiling CUDA separately and then linking to C++ with the g++ compiler.

The problem I’m faced with is that I can call my CUDA C functions from C++, but I want to be able to pass a class from C++ to CUDA C (a regular function, not a kernel). To do that I have to include my C++ header file which nvcc tries to compile and spits out a bunch of errors about how C++11 compilation is still experimental. I’m assuming it’s trying to compile the C++ code that I intend for it to be compiled by g++.

CUDA C/C++ is highly interoperable with C++, including modules compiled by g++ and linking using g++.
There are many CUDA sample codes that demonstrate using objects in both kinds of modules, as well as general integration with c++, such as the cpp integration sample code.

If you’re using CUDA 7.0 or 7.5RC, and compile (using nvcc) with -std=c++11, nvcc should handle c++11 constructs. This of course depends on having an appropriate version of g++ installed on your machine. g++ 4.8.2 works well, in my experience.

This will be entirely governed by what is in your C++ header file. If there is compilable code in it, then you should expect that code to be compiled in any modules that you include the header file in.

If you want to provide a short, specific example, I imagine someone can probably explain what is going on.

It worked after upgrading to 7.5 with -std=c++11. Thank you.

You mentioned: “There are many CUDA sample codes that demonstrate using objects in both kinds of modules…”
Can you direct me to these? I could only find examples where nvcc is used to compile C++ code directly. Any guidelines on how I should structure a large library would be great. I was only able to find short answers here and there through Google.

It worked after upgrading to 7.5 with -std=c++11. Thank you.

You mentioned: “There are many CUDA sample codes that demonstrate using objects in both kinds of modules…”
Can you direct me to these? I could only find examples where nvcc is used to compile C++ code directly. Any guidelines on how I should structure a large library would be great. I was only able to find short answers here and there through Google.