CudaMemcpy - copying int from host error to device

What's the difference between

cudaMemcpy and cudaMemset?? 

How to copy int value from host to device? This is the code I'm using.

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

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

+7
source share
1 answer

devAddXdir should be a pointer to the operation of this code. In addition, you should pass addXdir at the cudaMemcpy link, and not by value. Like this:

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

All Articles