0

when we want to allocate memory on device we use following syntax:

float *device_array;
error = cudaMalloc((void *)&device_array,
   sizeof(float) * N);

what is that "&" for? we dont use it in cudaMemCpy.

shayan
  • 29
  • 6
  • 1
    To *change* the pointer value inside cudaMalloc, it must be passed by address, rather than by value. C has no pass by reference symantics and the CUDA APIs are all notionally C APIs. – talonmies Jan 18 '16 at 20:22
  • "cudaMalloc((void *)device_array, sizeof(float)*N);" since device_array is a pointer , isnt (void *)device_array an address? @talonmies – shayan Jan 18 '16 at 20:28
  • No, it isn't and address, it is a value, and it is not possible to change the value at the caller's scope like that. Don't confuse assigning a value to a pointer and pointer indirection. They are not the same thing – talonmies Jan 18 '16 at 20:30
  • I feel dumb talkin to you ,thanks a bunch @talonmies – shayan Jan 18 '16 at 20:42

0 Answers0