I ran into the problem of copying structure data from the host to the device in the CUDA architecture.
The following is a snippet of code.
struct point { double x,y; }; int main() { point * a = (point*)malloc(sizeof(point)); a->x=10.0; a->y=10.0; point * d_a; cudaMalloc((void**)d_a,sizeof(point)); cudaMemcpy((void**)d_a,a,sizeof(point),cudaMemcpyHostToDevice); dim3 dimblock(16,16); dim3 dimgrid(1,1); MyFunc<<<dimgrid,dimblock>>>(d_a); cudaMemcpy((void**)a,d_a,sizeof(point),cudaMemcpyDeviceToHost); printf("%lf %lf\n",a->x,a->y); } __global__ void MyFunc(point* d_a) { if(threadIdx.x == 0 && threadIdx.y == 0) { d_a->x=100.0; d_a->y = 100.0; } }
The fields x and y of point a must be changed to 100. Instead, it is still 10 initialized. What's going on here? Please, help.
source share