array of structs

Hi all,

I am trying to send an array of objects to the GPU and use them in my kernel. But I don’t get any data in the kernel. here is my code:

struct point{
float x;
float y;

}

in host code:

point *host_points = new point[length];

for(int i=0; i<length; i++)
{
point p;
p.x = 2;
p.y = 2.5;
host_points[i] = p;
}

point d_points;
cudaMalloc((void
*) &d_imaging_points, lengthsizeof(point));
cudaMemcpy(d_points, host_points, length
sizeof(point), cudaMemcpyHostToDevice));

Am I doing anything wrong here because in my kernel I cannot access d_points[bx].x. I get all zeros.

Thanks,
ngm

point d_points;
cudaMalloc((void
*) &d_imaging_points, lengthsizeof(point));
cudaMemcpy(d_points, host_points, length
sizeof(point), cudaMemcpyHostToDevice));

what is “d_imaging_points”
cudaMalloc((void**) &d_points, length*sizeof(point));
to get the speed of memory accessing you should use struct of array
not use array of struct
goodluck :biggrin:

May b you should use sizeof(struct points) instead of just “point”