2

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);
1
  • Yes it will be faster to allocate everything in a single array. That is the common practice. Commented Apr 14, 2011 at 18:19

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.