Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cudaMemcpy - copy an int from host to device error

Tags:

cuda

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), cudaMemcpyHostToDevice);

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 *"

like image 713
user570593 Avatar asked Jun 06 '11 08:06

user570593


1 Answers

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);
like image 153
talonmies Avatar answered Oct 22 '22 13:10

talonmies