问题描述
我对 CUDA
相当陌生,并且熟悉 cudaMalloc
和 cudaMemcpy
的常规用法以及 cudaMemcpyToSymbol 代码>复制到常量存储器.
I am fairly new to CUDA
and am familiar with the normal usage of cudaMalloc
and cudaMemcpy
and also with cudaMemcpyToSymbol
for copying to constant memory.
但是,我刚刚得到了一些代码,这些代码经常使用 cudaGetSymbolAddress
和 cudaMemcpyToSymbol
复制到全局内存中,我不确定为什么他们选择了代替 cudaMalloc
/ cudaMemcpy
来执行此操作.
However, I have just been given some code which makes frequent use of cudaGetSymbolAddress
and cudaMemcpyToSymbol
to copy to global memory and I'm not sure why they have chosen to do this instead of cudaMalloc
/cudaMemcpy
.
有人能够解释使用 cudaGetSymbolAddress
和 cudaMemcpyToSymbol
何时合适吗?
Would somebody be able to explain when it is advantageous and appropriate to use cudaGetSymbolAddress
and cudaMemcpyToSymbol
?
谢谢!
推荐答案
使用 cudaMalloc
动态分配全局内存时,要使用的正确复制API是 cudaMemcpy
.
When global memory is allocated dynamically using cudaMalloc
, then the correct copying API to use is cudaMemcpy
.
分配了全局内存后,静态地:
__device__ int my_data[DSIZE];
然后正确使用的API是 cudaMemcpyToSymbol
或 cudaMemcpyFromSymbol
then the correct API to use is cudaMemcpyToSymbol
or cudaMemcpyFromSymbol
这篇关于是否将cudaGetSymbolAddress和cudaMemcpyToSymbol与全局内存一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!