CUDA - 将CPU变量传输到GPU __constant__变量 [英] CUDA - Transfering CPU variables to GPU __constant__ variables
问题描述
与CUDA一样,最基本的东西有时是最难的...
As anything with CUDA, the most basic things are sometimes the hardest...
所以...我只想将一个变量从CPU复制到
So...I just want to copy a variable from the CPU to a GPU's constant variable, and I am having a hard time.
这是我所拥有的:
__constant__ int contadorlinhasx_d;
int main(){
(...)
int contadorlinhasx=100;
status=cudaMemcpyToSymbol(contadorlinhasx_d,contadorlinhasx,1*sizeof(int),0,cudaMemcpyHostToDevice);
我收到此错误
presortx.cu(222): error: no instance of overloaded function "cudaMemcpyToSymbol" matches the argument list
argument types are: (int, int, unsigned long, int, cudaMemcpyKind)
有人可以帮助我吗?我知道这是一个愚蠢的错误,但我厌倦了谷歌,我花了差不多30分钟只是试图复制一个愚蠢的变量:/
Could anyone help me? I know it is some stupid error, but I am tired of googling it, and I have spent almost 30 minutes just trying to copy a stupid variable :/
提前感谢
推荐答案
您需要执行
cudaMemcpyToSymbol("contadorlinhasx_d",
&contadorlinhasx,
1*sizeof(int),
0,
cudaMemcpyHostToDevice);
[请注意,这是旧的API调用,现在已在CUDA 4.0及更高版本中弃用]
[Note this is the old API call, now deprecated in CUDA 4.0 and newer]
或
cudaMemcpyToSymbol(contadorlinhasx_d,
&contadorlinhasx,
1*sizeof(int),
0,
cudaMemcpyHostToDevice);
如果您查看 API文档,前两个参数是指针。第一个可以是字符串,这将强制在API内部(CUDA 4之前)或设备符号地址(CUDA 4及更高版本)的符号查找。第二个参数是副本的主机源内存的地址。编译器错误消息非常明确 - 您传递的参数类型错误,编译器无法在库中找到匹配的实例。
If you look at the API documentation, the first two arguments are pointers. The first can either be a string, which will force a symbol lookup internally in the API (pre CUDA 4), or a device symbol address (CUDA 4 and later). The second argument is the address of the host source memory for the copy. The compiler error message is pretty explicit - you are passing the wrong types of argument and the compiler can't find an instance in the library which matches.
这篇关于CUDA - 将CPU变量传输到GPU __constant__变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!