Utilizing the GPU with c# [closed]
I am trying to get more processing power out of my grid.
I am using all cpus/cores, is it possible to utilize the GPU with C#.
Anyone know any libraries or got any sample code?
[Edit OCT 2017 as even this answer gets quite old]
Most of these answers are quite old, so I thought I'd give an updated summary of where I think each project is:
GPU.Net (TidePowerd) - I tried this 6 months ago or so, and did get it working though it took a little bit of work. Converts C# kernel code to cuda at compile time. Unfortunately their website has been down and their github hasn't been updated for a couple of years, which might indicate the project is dead....
Cudafy - Open source and very easy to use. Converts C# kernel code to cuda at runtime (with ability to serialize and cache). Can easily run the same kernel code on the CPU (mostly for debugging). Supports multiple GPUs. More examples available than others here. The boilerplate code referred to by other answers is minimal, and in my case at least helped with my understanding of how the code works. Cuda/Nvidia only though. Unfortunately, it seems that they didn't update their solutions for a couple of years too (latest commit in 2015 -- support of cuda 7.0).
Hybridizer. Commercial solution compiling C# to CUDA. Provides a free community edition on visual studio marketplace and samples on github.
AleaGPU Commercial solution with a free community edition for consumer GPUS. See Daniel's comments for details.
Brahma - runs LINQ expressions via OpenCL (so supports AMD too). Not much documentation / examples. Last update in 2011.
C$ - last development was over 10 years ago...
Microsoft Accelerator - similarly doesn't look like it is being actively developed any longer.
some others (C++ AMP, OpenTK -- dead/Cloo) - many of these are just bindings - ie enable you to call the GPU from C#, but your kernel code (code which is actually run on the GPU) needs to be written in C or OpenCL, meaning you must use (and learn) another language.
As I said, I would recommend Cudafy over all the others - if it could run on OpenCL as well as Cuda it would be perfect.
EDIT SEP 2013 Cudafy now allows you to compile for both CUDA and OpenCL, so will run the same C# code on on all GPUs. This sounds fantastic, though I haven't tested the OpenCL compiling yet.
Microsoft Research Accelerator was a .NET GP GPU library.
I found Brahma... It also has a GPGPU provider that allows methods to run on the GPU... Thanks for the question... Learnt something new today. :)
Could I recommend XNA Game Studio as a possible avenue for exploration? It is obviously geared up for writing games, but gives you managed access to your graphics card and much better access to capability enumeration functions and shader development than was previously available in, say, Managed DirectX. There are also ways of combining WinForms and XNA into hybrid applications:
http://www.ziggyware.com/news.php?readmore=866
You'll have to put some effort into learning shader programming (XNA supports HLSL), but this may be a simpler approach than learning a vendor-specific solution such as nVidia's CUDA. The advantage is that you can program in a 100% managed environment. Here are some HLSL links:
http://www.ziggyware.com/weblinks.php?cat_id=9
The GPGPU site is also a recommended destination for general purpose GPU programming:
http://gpgpu.org/
Best of luck!