问题描述
正如其他问题和链接所述,您不能再为此功能使用符号名称.现在这个功能已经消失了,什么时候想要在 cudaMemCpy
上使用它?您什么时候想使用它?权衡或好处是什么?
As stated by other questions and according to the link, you can no longer use the symbol name for this function. Now that the feature is gone, when would ever want to use this over cudaMemCpy
? When would you ever want to use it at all? What is the tradeoff or benefit?
推荐答案
简而言之,因为 cudaMemcpy
不能在没有额外 API 调用的情况下做与 cudaMemcpyToSymbol
相同的事情.考虑一个常量内存数组:
In short, because cudaMemcpy
can't do the same thing as cudaMemcpyToSymbol
without an additional API call. Consider a constant memory array:
__constant__ float coeffs[8];
要使用 cudaMemcpyToSymbol
将值复制到此数组,只需这样做
To copy values to this array using cudaMemcpyToSymbol
, just do
cudaMemcpyToSymbol(coeffs, hostData, 8*sizeof(float));
要对 cudaMemcpy
做同样的事情,需要这样做:
To do the same with cudaMemcpy
requires this:
float *dcoeffs;
cudaGetSymbolAddress((void **)&dcoeffs, coeffs);
cudaMemcpy(dcoeffs, hostData, 8*sizeof(float), cudaMemcpyHostToDevice);
直接调用 cudaMemcpy
未经事先符号查找是非法的.
A direct call to cudaMemcpy
is illegal without prior symbol lookup.
[标准免责声明:所有代码在浏览器中编写,无需访问文档或编译器,使用风险自负]
[standard disclaimer: all code written in browser without access to documentation or compiler, use at own risk]
这篇关于cudaMemcpyToSymbol vs. cudaMemcpy 为什么它仍然存在 (cudaMemcpyToSymbol)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!