Can Cuda work with c#?

Hi everyone,

Has anyone ever made cuda dll work with c#? I wrote a very simple example code and it failed in the very beginning when doing device check.

In c++ dll part:

extern “C” __declspec(dllexport) void TestCheckCudaDevice();
void TestCheckCudaDevice(void){
printf(“Checking CudaDevice…\n”);
printf(“CudaDevice check done!\n”);

In c# calling part:

[DllImport(“cudaBinoDll.dll”, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern void TestCheckCudaDevice();

static void Main(string args)

When I linked everything together and call the c# executable, I always got following error:

Checking CudaDevice…

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at testCSCudaBinoDll.Class1.TestCheckCudaDevice()
at testCSCudaBinoDll.Class1.Main(String args)

What do you think may be the problem of this error? Or how can I make it work?

PS: The c++ version of executable works well with the dll.


Just read from…655&hl=cuda+dll

Does that mean that cuda won’t work with dll for current version on windows xp?
But I have seen it worked well with a c++ caller… :geek:

Any idea?

CUDA works with DLLs as long as they are not loaded dynamically, so this should work. Just remember to export your DLL functions as extern “C” and don’t use C++ features in the interface. Then you should be able to use them from C# just like you can from C++.


hmm… Still no luck. I think I am wrapping things in dll using the very primitve c langurage. From the output you will find out that the printf() works fine. The CUD_CHECK_DEVICE will fail claiming null pointer some where.

Is there any way we can force c# to ‘not’ dynamically load those dll but brute forth load them?


Just find out that the c# caller failed at calling cudaSetDevice() function…

It seems that the coming 0.9 release will solve this problem.
Registering now…

Anyone know when the official release of 0.9 will come out? Or generally how long the approvment of registration take? O:)

I registered either Thursday or Friday last week (cant remember) and got in today, so I’d say not too long at the present time :)

That’s a good news :)

Another good news is that their 0.9 release solved the problem~~~ :magic: