Manolete
Manolete

Reputation: 3517

CUDA __device__ of type struct

CUDA experts, if I have defined in the host code a new type:

struct float_3{
 float x;
 float y;
 float z;
};

and I have transferred some data of this type to the device, can I create __device__ calls of that new type,i.e:

__device__ float_3 foo(float_3 r,float b,int a){
}

Can we create __device__ of any type? Or just int,float,dlouble,void, etc... And is it possible to return a pointer on __device__? i.e __device__ float_3* foo(){}

Upvotes: 5

Views: 6020

Answers (2)

jmsu
jmsu

Reputation: 2053

Yes, you can create __device__ of any type. It is just a qualifier that makes that function compile for running on the device and be callable from the device.

And by the way, CUDA has a float3 type. I have never used it but if I recall correctly it provides the same functionality of your float_3 and also comes with a constructor.

Upvotes: 9

Nickolas
Nickolas

Reputation: 790

Can we create __device__of any type?

The short answer is yes. The long answer is, yes, if it is a user-defined type as your float_3, you can define a __device__ variable pointer and allocate memory in device using cudaMalloc.

is it possible to return a pointer on device?

Yes, you can do it.

Upvotes: 2

Related Questions