Using C++ CUDA Functions in C# as a DLL

Hi all,
Currently I start a practical project with CUDA. As I mentioned in the title I want to write some computational functions with VC++ and CUDA, then get a DLL on that and add/call it to a C# GUI project.
Thank you for taking time to visit.

People who are interested in using CUDA with C# are often interested in libraries such as managedCuda and cudafy (just google those). Both cudafy and managedCuda have examples and tutorials available.

Of course, as you say, you can implement your own unmanaged library of C/C++ wrapper functions (calling CUDA routines from within the wrappers) and provide that as an unmanaged DLL for use in C# if you want.

Thank you txbob
Can you give me an example or useful link
(for ‘How to use unmanaged cuda DLL in C#?’)

I will try this solutions and comment the result.
Thanks again dear txbob :smile:

Try this.

I used this setup to integrate CUDA in my Unity game.
From my experience, you can’t call functions from a .DLL that was created by nvcc, so I created a .LIB from nvcc and an additional pure C++ .DLL that calls wrappers in the CUDA .LIB.
Could be that it was just a problem with my setup, but if you have trouble down the road you can try what I did.

Hey, would you mind describing your workflow a bit? I intend to write .Net code that uses cuda via a C++/CLI layer. But I can’t find a good work flow / best practice guide, especially in terms of debugging.
I can either use the VS debugger that ignores CUDA code or use Nsight debugging which doesn’t support managed code. So it’s extremely tedious to catch bugs / write test applications. Do you have some good hints or could explain your workflow?