Use of cudamalloc(). Why the double pointer?

前端 未结 5 1619
滥情空心
滥情空心 2020-11-28 23:59

I am currently going through the tutorial examples on http://code.google.com/p/stanford-cs193g-sp2010/ to learn CUDA. The code which demostrates __global__ func

5条回答
  •  不知归路
    2020-11-29 00:26

    All CUDA API functions return an error code (or cudaSuccess if no error occured). All other parameters are passed by reference. However, in plain C you cannot have references, that's why you have to pass an address of the variable that you want the return information to be stored. Since you are returning a pointer, you need to pass a double-pointer.

    Another well-known function which operates on addresses for the same reason is the scanf function. How many times have you forgotten to write this & before the variable that you want to store the value to? ;)

    int i;
    scanf("%d",&i);
    

提交回复
热议问题