innuendo
innuendo

Reputation: 373

Declaring CPP objects inside cuda kernel

I am new to Cuda and I need to know its limits before running my C++ project via Cuda. Suppose I have a C++ class called MyClass. Knowing that Cuda uses C99, is it possible to declare an object of type MyClass inside a kernel? Would the below code snippet be appropriate?

_global__ void SolveBlaBlaBLa(int x, ...)
{

MyClass obj1;
.
.
.
}

Thanks in Advance, - Ruru

Upvotes: 0

Views: 1606

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 152164

Just providing an answer to get this off the unanswered list. I think @JaredHoberock will not mind.

In general, CUDA supports a large subset of C++ functionality, including support for objects in device code.

Any code that executes on the device, however, must be properly decorated. For ordinary individual functions (not kernels), the decorator that the compiler recognizes to create a device callable version of the code is __device__. This applies to any object method which may be used on the device, including constructors and destructors.

You may also wish to familiarize yourself with other restrictions on C++ classes used in the device code, as documented in the programming guide.

Upvotes: 4

Related Questions