Coding CUDA with C#?

Viewed 66210

I've been looking for some information on coding CUDA (the nvidia gpu language) with C#. I have seen a few of the libraries, but it seems that they would add a bit of overhead (because of the p/invokes, etc).

  • How should I go about using CUDA in my C# applications? Would it be better to code it in say C++ and compile that into a dll?
  • Would this overhead of using a wrapper kill any advantages I would get from using CUDA?
  • And are there any good examples of using CUDA with C#?
4 Answers

There are several alternatives you can use to use CUDA in your C# applications.

  • Write a C++/CUDA library in a separate project, and use P/Invoke. The overhead of P/invokes over native calls will likely be negligible.
  • Use a CUDA wrapper such as ManagedCuda(which will expose entire CUDA API). You won't have to write your DLLImports by hand for the entire CUDA runtime API (which is convenient). Unfortunely, you will still have to write your own CUDA code in a separate project.
  • (recommended) You can use free/opensource/proprietary compilers (which will generate cuda (either source or binary) from your c# code.

You can find several of them online : have a look at this answer for example.

Related