kunzmi / managedCuda

ManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.
Other
440 stars 79 forks source link

Problem in getting the right output #69

Closed N1vS closed 5 years ago

N1vS commented 5 years ago

Hello,

I tried launching a really simple kernel:

__global__ void kernel(double a, double *c)
{
    *c = a;
}

and used the following lines on the c# project:

CudaContext context = new CudaContext();
CUmodule module = context.LoadModule(@"C:\CUDAKernels\kernel.ptx");
myCudaKernel = new CudaKernel("_Z6kerneldPd", module, context);

CudaDeviceVariable<double> q_result=0;
double host_result=0;
myCudaKernel.Run(10, q_result.DevicePointer);
q_result.CopyToHost(ref host_result);

So in theory it should return 10 to the host variable but for some reason i get the result 4.94065645841247E-323 .

I tried to change all the double statements to int and it works. Can you help me understand why it does that?

Edit: never mind I found out that I needed to specify a decimal dot for the input and now it returns the right value.

Close this issue please.

kunzmi commented 5 years ago

managedCuda cannot derive the types needed for a kernel and just takes what it gets without any conversion. If you provide an int whereas a double is expected, C# or C++ would convert that for you, but managedCuda can't, hence the wrong result; you always must provide the correct type.