I am a newbie to CUDA. I don’t quite understand the function cudaMalloc as to why we are typecasting to void**,

so we invoke it as cudaMalloc((void**) &A, size); we are casting address of A to (void**). Am a little confused.

The idea is that you pass cudaMalloc the address of a pointer so that it can modify it:


int *ptr = 0;

void **ptr_to_ptr = &ptr;

cudaMalloc(ptr_to_ptr, sizeof(int));

assert(ptr != 0);

// ptr now points to a segment of device memory


Thanks a lot! It makes sense