c# - How to do CudaMemcpy using CUdeviceptr -
i'm trying wrapper in С++ dll cuda, able use in c# (yeah, know there's managedcuda , cudafy, still try this)
the thing is, able pass pointer reference c#, cant usual , cuda malloc float*. trying manage cudeviceptr, but, though cudamalloc apparently works (no error given cudagetlasterror), when cudamemcpy using cudevicptr variable breaks , gives "invalid argument" error.
extern "c" __declspec(dllexport) void __cdecl allocatedevicememory(float*, cudeviceptr, unsigned int); extern void allocatedevicememory(float* data, cudeviceptr device_pointer, unsigned int numelements){ cudamalloc((void**)&device_pointer,numelements * sizeof(float)); cudaerror_t error = cudagetlasterror(); printf("cudaerror.... 1 %s\n", cudageterrorstring(error)); cudamemcpy((void*)&device_pointer ,data,numelements * sizeof(float), cudamemcpyhosttodevice); error = cudagetlasterror(); printf("cudaerror.... 2 %s\n", cudageterrorstring(error)); }
does have ideas how can done?
change
cudamemcpy((void*)&device_pointer ,data,numelements * sizeof(float), cudamemcpyhosttodevice)
to
cudamemcpy((void *)device_pointer ,data,numelements * sizeof(float), cudamemcpyhosttodevice
cudeviceptr
device pointer. when doing &device_pointer
, sending in pointer device pointer. cudamalloc
expects pointer pointer , works fine. cudamemcpy
expects device pointer (not pointer pointer).
if want use driver api (i.e. use
cudeviceptr
), usecumemalloc
,cumemcpyhtod
if want use runtime api use
void *
memory pointers , cast them required type. can usecudamalloc
,cudamemcpy
runtime api.
edit: added edit explicitly cast cudeviceptr
void *
. added information driver , device api.
Comments
Post a Comment