0

after edition: I wonder why the first argument of the cudaMalloc should be casted to void** , e.g (void**)&d_A where d_A is a pointer. I don't understand the syntax but content with its use especially cudaError_t cudaMalloc ( void ** devPtr, size_t size
)

Cheers

talonmies
  • 70,661
  • 34
  • 192
  • 269
S23
  • 21
  • 2
  • 1
    Did you actually mean `cudaMalloc`? (As pointed out in one answer: For `cudaMemcpy`, this question does not make sense...) – Marco13 Jan 28 '15 at 09:35
  • you are right, sorry...my question was about cudaMalloc – S23 Jan 28 '15 at 16:55
  • 2
    This is a direct duplicate of this: http://stackoverflow.com/q/12936986/681865 – talonmies Jan 28 '15 at 17:46
  • 1
    Your question remains unclear. Are you asking why it needs to be cast at all, or are you asking specifically why it is required to be a double-pointer (`**`) argument? If the first, it does not need to be cast in current versions of CUDA (try it.) If the second, it is a duplicate as @talonmies has stated. – Robert Crovella Jan 30 '15 at 14:52

2 Answers2

4

There has never been the need to cast to void** for cudaMemcpy, as it takes a void*. You may be confusing with cudaMalloc which does take a void**.

The conversion from any pointer type to void* is implicit in C, but not in C++ where a cast is required.

user703016
  • 37,307
  • 8
  • 87
  • 112
0

From the NVidia tutorial:

int main()
{
    int a[N], b[N], c[N];
    int *dev_a, *dev_b, *dev_c;
    // I deleted the code here, we don't need it
    cudaMemcpy(dev_a, a, N * sizeof(int), cudaMemcpyHostToDevice);
}

It seems that there is no need to cast the first argument of cudaMemcpy to void**. However, you may have to cast it to void*.

vincentp
  • 1,433
  • 9
  • 12