hi all
how can i use struct in cuda
thanks
hi all
how can i use struct in cuda
thanks
It’s the same as C or C++.
struct Ray
{
float x, y, z;
float dx, dy, dz;
};
Ray view;
view.x=0.2345f;
view.y=1.3233f;
typedef struct
{
double x;
double y;
double z;
} vector;
global void
cross_product(vector *v1,vector *v2,vector *result,int size)
{
int i;
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if(idx<size)
{
result[i].x = cuda_abs((v1[i].y*v2[i].z)-(v1[i].z*v2[i].y));
result[i].y = -1 * cuda_abs((v1[i].x*v2[i].z)-(v1[i].z*v2[i].x));
result[i].z = cuda_abs((v1[i].x*v2[i].y)-(v1[i].y*v2[i].x));
}
}
this is my sample
result[i].x,result[i].y and result[i].z always return 0.0
it should be different value for each step
Remember that you are using “double”, so what your device Capability. 1.3 is it right?
:)
How can i learn my device Capability??
Run the deviceQuery example from the SDK, or just look it up in the Appendix of the programming guide.