如何将struct数组传递给GPU?

我有这个结构:

struct Node { int *ptr; int k; }*d_ptr; 

我如何声明一个Node数组并将其传递给GPU? 问题是我必须先为ptr分配内存然后再分配节点!

我有这个到现在为止:

 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。 随后将struct本身从主机复制到设备。

这可以帮助您: http : //forums.nvidia.com/index.php?showtopic = 196084