Hi, I’m new to CUDA programming, and I’d like to get some help to make a program that would take an array, modify it and return it back to host.
public static CUDA cuda;
public static CUfunction myFunction;
int[] myArray = new int[4];
myArray[0] = 10;
myArray[1] = 20;
myArray[2] = 30;
myArray[3] = 40;
cuda = new CUDA(0, true);
cuda.LoadModule("test.cubin");
myFunction = cuda.GetModuleFunction("myFunction");
CUdeviceptr dpt = cuda.CopyHostToDevice<int>(myArray);
cuda.SetParameter(myFunction, 0, myArray);
cuda.Launch(myFunction);
cuda.CopyDeviceToHost<int>(dpt, myArray);
/* I'd like the CUDA program to add 10 to every item
in the array, so i would get myArray[0] = 20, myArray[1] = 30, etc
*/
I’ve been trying this code, but I get a cudaUnknownError in my code at this line.
cuda.CopyDeviceToHost(dpt, myArray);
Is there something I’m doing wrong in my code (well, it’s obvious there is something External Media ). I’d like to get some help, I can’t pass pointers on C#, so that’s why I try to pass the whole array as a parameter. Is that wrong?
Thanks again :rolleyes:
EDIT
Even if I pass the pointer instead of the array it still won’t work.
I have never used CUDA.net, but I know of both, used independently… I guess the problem is that in cuda.SetParameter you are passing “myArray”, that is a C# managed array. I guess you need to pass instead the device pointer there - dpt.
Easy to try - let us know whether I’ve got it correctly.