如何将结构数组传递给GPU?

| 我有这个结构:
struct Node
{
     int *ptr;
     int k;   
}*d_ptr;
我如何声明一个Node数组并将其传递给GPU?问题是我必须先为ptr然后再为Node分配内存! 到目前为止,我有这个:
int N=100;
int NumbOfNodes=5;
cudaMalloc((void **) &d_NodeArr, sizeof(Node)*NumbOfNodes);
for(int i=0;i<NumbOfNodes;i++)
    cudaMalloc((void **) d_NodeArr[i].Degree, sizeof(int)*N);
如果我在一个数组中分配所有内容,这样会更快吗:
int N=100;
int NumbOfNodes=5;
int SIZE=(100*5)+5;//the +5 is for the k
cudaMalloc((void **) &d_ptr,sizeof(int)*SIZE);
    
已邀请:
只需首先在主机上构建结构。 也就是说,创建该结构,然后为int数组执行cudaMalloc。 随后,将结构本身从主机复制到设备。 这可以帮助您: http://forums.nvidia.com/index.php?showtopic=196084     

要回复问题请先登录注册