56

I've recently read a lot about software (mostly scientific/math and encryption related) that moves part of their calculation onto the GPU which causes a 100-1000 (!) fold increase in speed for supported operations.

Is there a library, API or other way to run something on the GPU via C#? I'm thinking of simple Pi calculation. I have a GeForce 8800 GTX if that's relevant at all (would prefer card independent solution though).

JAL
  • 41,701
  • 23
  • 172
  • 300
Alex
  • 75,813
  • 86
  • 255
  • 348
  • 1
    I don't think you need the GPU for a "simple Pi calculation" unless you're doing it thousands of times a second... – Sasha Chedygov Aug 08 '09 at 21:05
  • 23
    It's not about 'needing' it. I just suggested it as a proof of concept example. – Alex Aug 08 '09 at 21:06
  • I really liked multiple answers, including CUDA, CUDA.NET, Accellerator, Brahma and OpenCL. So FYI for everybody who looks at this question later - take a look at all the answers. – Alex Aug 09 '09 at 00:38
  • @Alex as far as i know you can not do it in c# you need to know 7/10 c++, all the libraries(cudafy,aleagpu,...) are just invokers for c++ codes – Hichem Dec 06 '17 at 12:53

7 Answers7

25

It's a very new technology, but you might investigate CUDA. Since your question is tagged with C#, here is a .Net wrapper.

As a bonus, it appears that your 8800 GTX supports CUDA.

Charlie Salts
  • 13,109
  • 7
  • 49
  • 78
16

Another option that hasn't been mentioned for GPU calculation from C# is Brahma.

Brahma provides a LINQ-based abstraction for GPU calculations - it's basically LINQ to GPU. It works over OpenGL and DirectX without extra libraries (but requires SM3). Some of the samples are fairly amazing.

boop
  • 7,413
  • 13
  • 50
  • 94
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
8

You might want to look at this question

You're probably looking for Accelerator, but if you are interested in game development in general I'll suggest you take a look at XNA

Community
  • 1
  • 1
Tchami
  • 4,647
  • 1
  • 32
  • 45
  • I had not heard of this one - interesting! I worry that it's still a research project though. Is it ready for commercial applications? – Charlie Salts Aug 08 '09 at 21:33
  • To be perfectly honest I haven't tried it out and I don't know how stable it is. I do some graphics programming and had it in my bookmarks for future reference, and it seemed to be easier to approach than CUDA for this problem. – Tchami Aug 08 '09 at 21:47
  • I've got an ATI card so maybe I'll give Accelerator a try. – Charlie Salts Aug 09 '09 at 03:24
4

CUDA.NET should be exactly what you're looking for, and it seems to support your specific graphics card.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
4

You can access the latest Direct3D APIs from .NET using the Windows API Code Pack. Direct3D 11 comes with Compute Shaders. These are roughly comparable to CUDA, but work also on non-NVIDIA GPUs.

Note that Managed DirectX and XNA are limited to the Direct3D 9 feature set, which is somewhat difficult to use for GPGPU.

Malte Clasen
  • 5,637
  • 1
  • 23
  • 28
2

There is a set of .Net bindings for Nvidia's CUDA api, it's called CUDA.net. You can refer to the reference guide to look at some sample C# code.

The preferred way to access your co-proccesor (GPU) would be using OpenCL so that your code would be portable with ATI cards, but I believe there may be additional coding required and I'm not sure how much support OpenCL has for the .Net platform.

If you want to use C++, here's a quick overview on how to get some sample code compiling with Visual Studio.

Darwyn
  • 4,696
  • 3
  • 25
  • 26
0

FYI: Accelerator (http://research.microsoft.com/en-us/projects/Accelerator/) was working great for a couple of tests.

Alex
  • 75,813
  • 86
  • 255
  • 348