somethih4nothing | 1 points | Apr 09 2021 02:59:35

有cuda老嗨吗?

为什么cudaMalloc要用二级指针(void **)啊?

[-] kky508 | 3 points | Apr 09 2021 03:11:35

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.

简单来说 C里面,当cudamalloc被调用时,将创建一个名为d_array的局部变量,并为其分配第一个函数参数的值。这个是无法在函数范围之外检索该局部变量中的值的。所以说要用双指针。

[-] somethih4nothing | 2 points | Apr 09 2021 03:36:45

所以cuda是developed based on C对吧,double pointer是为了这个d_array 能在函数范围之外被获取使用的

[-] Historical-Sample-14 | 2 points | Apr 09 2021 03:35:20

二级指针一律按指针数组处理

[-] kky508 | 1 points | Apr 09 2021 03:19:35

这个和c语言的一些特性也有关系,c和c++引用和函数重构都不太一样,我记得c++不用double pointer。

[-] Avocado19890604 | 1 points | Apr 09 2021 03:22:54

[-] Intelligent_Wish276 | 1 points | Apr 09 2021 06:13:40

这回不葱了,改chonglangoverflow了是吧

[-] FerretBorn9279 | 1 points | Apr 09 2021 11:26:39

都run出去18万美元了chonglangtv就可以转型了