开发者

cudaMemcpy - copy an int from host to device error

开发者 https://www.devze.com 2023-03-11 03:29 出处:网络
What is the difference between cudaMemcpy and cudaMemset?? How can I copy an int value from host to device?

What is the difference between

 cudaMemcpy and cudaMemset??

How can I copy an int value from host to device? This is the code I am using

int addXdir = 1;
int devAddXdir;
cudaMalloc((void**)&devAddXdir, sizeof(int));
cudaMemcpy(devAddXdir, addXdir, sizeof(int), cudaMem开发者_运维知识库cpyHostToDevice);

it gives the following errors error: argument of type "int" is incompatible with parameter of type "void *" error: argument of type "int" is incompatible with parameter of type "const void *"


devAddXdir must be a pointer for that code to work. Also, you must pass addXdir by reference to cudaMemcpy, not by value. Like this:

int addXdir = 1;
int * devAddXdir;
cudaMalloc((void**)&devAddXdir, sizeof(int));
cudaMemcpy(devAddXdir, &addXdir, sizeof(int), cudaMemcpyHostToDevice);
0

精彩评论

暂无评论...
验证码 换一张
取 消