CUDA __device__ of type struct

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

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

and I transferred some data of this type to the device, can I make __device__ calls of this new type, ie:

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

Is it possible to create __device__ any type? Or just int , float , dlouble , void , etc. .... And is it possible to return a pointer to __device__? those. __device__ float_3* foo(){}

+4
source share
2 answers

Yes, you can create __device__ any type. It is simply a qualifier that makes this function compiled to work on the device and can be called from the device.

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

+7
source

Can we create __device__ any type?

The short answer is yes. Long answer: yes, if it is a user-defined type, like your float_3 , you can define the pointer to the __device__ variable and allocate memory on the device using cudaMalloc .

Can I return a pointer to the device?

Yes you can do it.

+2
source

All Articles