cuda - Allocating more memory to an existing Global memory array -


is possible add memory allocated array in global memory?

what need this:

//cudamalloc memory d_a int n=0;int n=100; {  kernel<<< , >>> (d_a,n++);  //add n memory d_a  while(n!=5)} 

does doing cudamalloc removes values of allocated array? in case values of previous allocated array should kept...

first, cudamalloc behaves malloc, not realloc. means cudamalloc allocate totally new device memory @ new location. there no realloc function in cuda api.

secondly, workaround, can use cudamalloc again allocate more more memory. remember free device pointer cudafree before assign new address d_a. following code functionally want.

int n=0;int n=100;  //set initial memory size size = <something>;  {     //allocate enough memory     cudamalloc((void**) &d_a, size);      kernel<<< ... >>> (d_a,n++);         //free memory allocated d_a     cudafree(d_a);      //increase memory size     size+=n;  while(n!=5)} 

thirdly, cudamalloc can expensive operation, , expect above code rather slow. think should consider why want grow array. can allocate memory d_a 1 time enough memory largest use case? there no reason allocate 100 bytes if know need 1,000 bytes later on!

//calculate max memory requirement max_size = <something>;  //allocate once cudamalloc((void**) &d_a, max_size);  //use loops when appropriate for(n=0; n<5; n++) {     kernel<<< ... >>> (d_a,n); } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -