下面这种结构体拷贝方法 我总觉得不对,但是结果却是正确的 ,为什么呢?
正确的使用方法是什么样的?
struct {int x1;
int x2;
int *p
} Dem;
Dem host;
host.p = new int[100];
host.p[1] = 1;
Dem* dev;
cudaMalloc( (void**)&dev, sizeof(Dem));
cudaMemcpy(dev, &host, sizeof(Dem), cudamemcpyhostodevice);
Dem temp;
cudaMemcpy(&temp, &dev, sizeof(Dem), cudamemcpyhostodevice);
printf("p = %d \n", temp.p[1]) ;
结果 是 p = 1;
|