Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

11 Answers 11

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 (TiredPowerd) - 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 for a couple of months, which is a bad sign....

  • Cudafy (recommended) - 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.

  • Brahma - runs LINQ expressions via OpenCL (so supports AMD too). Not much documentation / examples.

  • C$ - last development was over 5 years ago...

  • Microsoft Accelerator - similarly doesn't look like it is being actively developed any longer.

  • some others (C++ AMP, OpenTK/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.

share|improve this answer
6  
+1 for updating a useful question in a kind of fast-developing subject. –  philologon Feb 19 '14 at 22:22

Microsoft Research Accelerator is a .NET GP GPU library. The paper is at ftp://ftp.research.microsoft.com/pub/tr/TR-2005-184.pdf.

share|improve this answer

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. :)

share|improve this answer

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!

share|improve this answer

How about http://www.tidepowerd.com/ GPU.NET ?

share|improve this answer
    
I love the idea, but they stopped responding to tech support questions about two years ago, and the site has been more-or-less down for about a year, so I think the project is dead. Apparently the author is on SO, though. –  BlueRaja - Danny Pflughoeft Apr 8 '13 at 21:34

In addition to Brahma, take a look at C$ (pronounced "C Bucks"). From their CodePlex site:

The aim of [C$] is creating a unified language and system for seamless parallel programming on modern GPU's and CPU's.

It's based on C#, evaluated lazily, and targets multiple accelerator models:

Currently the list of intended architectures includes GPU, Multi-core CPU, Multi-GPU (SLI, CrossFire), and Multi-GPU + Multi-CPU Hybrid Architecture.

share|improve this answer

Here's another one: CUDAfy. It sounds like GPU.Net, in that something as simple as a method-attribute can cause the entire method to run on the GPU. But unlike GPU.Net, CUDAfy is free and open-source.

GPU.Net appears to require no boilerplate code, though (According to their docs, it's "injected automatically by the build-tool"), while CUDAfy does.


Here is an example of building an application with CUDAfy.

share|improve this answer

There's a new Microsoft solution in town - C++ AMP (intro here).

Use from C# would be via P/Invoke, as demoed here for desktop apps, and here for (don't-call-it) Metro apps.

Edit: I should note that C++ AMP has an open specification, which means it's not necessarily just for the MS compiler, or just for Windows.

share|improve this answer

If your GPUs are all the same brand, you might be able to get GPGPU support from the vendor, either through Nvidia's CUDA or ATI's Stream. AFAIK, they provide DLLs, which you could use through P/Invoke.

share|improve this answer

Managed DirectX somehow, might work

share|improve this answer

WPF also uses the GPU and you can add custom shaders using HLSL.

share|improve this answer
    
WPF doesn't have GP GPU computation access, to my knowledge. When talking about WPF System.Windows.Media graphics, it isn't real DirectX. Very slow when compared to lower-level vertex programming with SharpDX or SlimDX. –  Pasi Tuomainen Jan 22 '14 at 10:42
    
I added a link to a series of articles on GPU-accelerated custom effects in WPF. –  Mark Cidade Jan 22 '14 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.