cudaMalloc

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:

[codebox]

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

[/codebox]

Thanks a lot! It makes sense