c# and cuda dll

I’ve been doing a lot of research, but I am new enough to where it doesn’t make much sense. I understand that in order to use CUDA with C#, one has to compile a CUDA program as a DLL, and then call the dll from within C#. I can’t find any good sample code for doing so.

Does any one have a Visual Studio example for doing this? I’m normally a linux developer, so I’m a bit lost with Visual Studio.

Any help would be very appreciated.

P.S I looked into CUDA.NET but I read many reports of it being very unreliable, so it might just be simpler to write my own wrapper of sorts.

Heres a quick and dirty example on how to do it.

Indeed, set the C/CUDA program to compile to a dll.

extern "C" __declspec(dllexport) void doCuda( int width, int height, unsigned char* stuff)


cuda C code... call your kernel in here somewhere



And then in the C# project, something like :

In the class scope


		public unsafe static extern int doCuda(int width, int height, byte[] stuff);

And then from some function in your c# code:

doCuda(bmp.Width, bmp.Height, bytesleft);

Hope this helps!