title: How to do CudaMemcpy using CUdeviceptr
body: <p>I'm trying to do a wrapper in a С++ DLL for CUDA, to be able to use it in C# (yeah, I know there's managedCuda and cudafy, but I still would like to try this)</p>
  
  <p>The thing is, to be able to pass the pointer reference back to c#, i cant just do as usual and do the cuda malloc with float*. I was trying to manage everything with CUdeviceptr, but, even though cudaMalloc apparently works (no error given by cudaGetLastError), when I do the cudaMemcpy using the CUdevicptr variable it breaks and gives the "Invalid argument" error.</p>
  
  <pre><code>extern "C" __declspec(dllexport) void __cdecl allocateDeviceMemory(float*, CUdeviceptr,     unsigned int);
  
  extern void allocateDeviceMemory(float* data, CUdeviceptr device_pointer, unsigned int numElements){
  cudaMalloc((void**)&amp;device_pointer,numElements * sizeof(float));
  cudaError_t error = cudaGetLastError();
  printf("CudaError.... 1  %s\n", cudaGetErrorString(error));
  
  cudaMemcpy((void*)&amp;device_pointer ,data,numElements * sizeof(float), cudaMemcpyHostToDevice);
  error = cudaGetLastError();
  printf("CudaError.... 2  %s\n", cudaGetErrorString(error));
  }
  </code></pre>
  
  <p>Does anybody have any ideas about how can this be done?</p>