如何通过结构的阵列到GPU? [英] how to pass array of struct to GPU?
问题描述
我有这样的结构:
结构节点
{
INT * PTR;
时int k;
} *应将d_ptr;
我怎么可以声明节点的数组并把它传递到GPU?问题是,我必须先分配的内存ptr的节点!
我有这个至今:
INT N = 100;
INT NumbOfNodes = 5;
cudaMalloc((无效**)及d_NodeArr,sizeof的(节点)* NumbOfNodes);
的for(int i = 0; I< NumbOfNodes;我++)
cudaMalloc((无效**)d_NodeArr [I] .Degree,sizeof的(INT)* N);
这将是更快,如果我喜欢这种在单个阵列中分配的一切:
INT N = 100;
INT NumbOfNodes = 5;
INT SIZE =(100 * 5)+5; // +5为第k
cudaMalloc((无效**)及应将d_ptr,sizeof的(INT)* SIZE);
就构建结构主机上的第一位。
也就是说,创建结构,然后做了int数组cudaMalloc。
随后,结构本身从主机复制到设备上。
这会一起帮助你:
http://forums.nvidia.com/index.php?showtopic=196084
i have this struct:
struct Node
{
int *ptr;
int k;
}*d_ptr;
how can i declare an array of Node and pass it to the GPU? the problem is that i have to allocate memory for ptr first and then Node!
i have this till now:
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);
would it be faster if i allocated everything within a single array like this:
int N=100;
int NumbOfNodes=5;
int SIZE=(100*5)+5;//the +5 is for the k
cudaMalloc((void **) &d_ptr,sizeof(int)*SIZE);
Just construct the structure on the host first. That is, create the struct and then do a cudaMalloc for the int array. Subsequently copy the struct itself from host to device.
This could help you along: http://forums.nvidia.com/index.php?showtopic=196084
这篇关于如何通过结构的阵列到GPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!