I was searching how to create an array of pointers and copy it to CUDA memory. I found this post CUDA Double pointer memory copy but the following line in the accepted answer
int ** devicePointersStoredInDeviceMemory;
cudaMalloc( (void**)&devicePointersStoredInDeviceMemory, sizeof(int*)*N);
What's the meaning of passing the address of a double pointer and cast it to a void**? Wouldn't &devicePointerStoredInDeviceMemory be the same as int*** so why cast it to void** instead of void***?
cudaMalloc function takes a
void ** as its first parameter, so if we're going to call
cudaMalloc, that's the type we need. The purpose of the first parameter is to tell
codaMalloc where to store the pointer to the memory we allocated.
You could do this just as well:
void *j; cudaMalloc(&j, sizeof(int*)*N); // stores result in j int **devicePointersStoredInDeviceMemory = (int **) j;