I have an array of pointers unsigned char *dev_src[2];
. Actually those pointers have to point the memory allocated by cudaMalloc()
.
I am able to get the address of allocated memory if I do it inside the main()
using the following code:
//Inside the same function
int memsize = 100;
int main()
{
unsigned char *dev_src[2];
//Allocate memomry
for (int i = 0; i < numCudaStreams; i++)
{
cudaMalloc((void**)&dev_src[i], memsize);
}
return 0;
}
PROBLEM: I want to get the addresses of allocated memories inside an another function for which I need to pass this array of pointer to that function. I already know how to pass an array to an another function and make changes inside it but in this case, I am not able to get the correct way.
//Inside another function
int memsize = 100;
void memallocation(unsigned char ????)
{
//Allocate memomry
for (int i = 0; i < numCudaStreams; i++)
{
cudaMalloc((void**)??????????, memsize);
}
}
int main()
{
unsigned char *dev_src[2];
//Initialization of pointers before passing them to a function
for (int i = 0; i < 2; i++)
*dev_src[i] = NULL;
memallocation(&dev_src);
return 0;
}
UPDATE: It is not a duplicate of this question. I have already mentioned that I know how to pass an array by reference to change its elements but in this case the element itself have to be the pointers assigned by cudaMalloc()
.