15

Maybe a crazy question but is it possible to run threads on the GPU?

Reason I ask is I have some quite complicated computation to execute (it's mostly maths and arrays) and would like to see if I can get any improvement in speed using the GPU.

Oh and I'd like to do this in C# or F# :)

Thanks

Ash
  • 754
  • 1
  • 10
  • 18

4 Answers4

4

There is an abstract on the topic here:

http://microsoft.cs.msu.su/Projects/Documents/ILShaders/ilshaders.pdf -- [[dead link]]

But I've yet to find a link to source. Here is the Google translated project page:

http://translate.google.co.uk/translate?hl=en&sl=ru&u=http://microsoft.cs.msu.su/Projects/Pages/ILShaders.aspx&ei=QuieTu_tGsTD8QPk-tmmCQ&sa=X&oi=translate&ct=result&resnum=2&ved=0CCYQ7gEwAQ&prev=/search%3Fq%3DILShaders%26hl%3Den%26prmd%3Dimvns -- [[deak link]]

I've looked at this topic before and haven't found anything previously that actually took a compliant language and compiled it down onto the GPU.

There are plenty of libraries that expose GPU parts but you need to understand how to express your problem in a parallel data structure kind of way. These libraries can then be referenced in C#.

Some libraries:

CUDA.NET -- dead link

Microsoft Accelerator -- dead link

Various other Q/A sources:

Utilizing the GPU with c#

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/239fd75b-05c3-4e4b-9835-6807940dc492

Update: SK-logic commented on tidepowerd, I've linked the "How It Works" section:

http://www.tidepowerd.com/product/howitworks -- [[dead link]]

This looks like a good starting point to me. Not sure if it handles the MSIL directly, it initially looks like a post build step to generate custom code under the hood.

Community
  • 1
  • 1
Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
2

Alea GPU compiles MSIL at run-time to LLVM IR and then to CUBIN so that it can execute on the GPU. As opposed to CUDAFy it is a true fully fledged compiler and not just a CUDA C code generator, which relies on the NVIDIA CUDA C++ compiler in the back end.

Their technology also allows to compile a delegate at run-time to GPU code and execute it on the GPU.

They also implemented automatic memory management with IL code instrumentation, so that the programmer does not need to copy forth and back data between the CPU and the GPU. More details on the features is on their product page.

Daniel
  • 1,522
  • 1
  • 12
  • 25
2

If you're using a recent NVidia GPU, you can take a look at CUDAfy.

Haven't used it, but I took at long look at them before when I was writing a .NET program for Beale's Conjecture. Good luck.

Tim P.
  • 2,903
  • 24
  • 26
1

Probably your best bet is to use C++ AMP and then call that code from .NET in the usual way. You'll need Visual Studio 11 Developer Preview (Ultimate or Express) to get access to C++ AMP. (Never heard of C++ AMP? I have a blog post full of links.)

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
  • +1, I'd recommend this if you are doing something involving large numbers and obviously performance is crucial if you're trying to run on the GPU. Native C++ is always going to be faster than MSIL in almost every case when running these large performance-intensive applications. – Tim P. Oct 19 '11 at 15:18
  • 3
    That runs MSIL on the GPU? If it doesn't, thus not actually answering the question, why is AMP preferable over other solutions? "Read my blog" is not an answer of course, it is blog spam. – Hans Passant Oct 19 '11 at 15:50
  • @HansPassant and to think I said nice things about you just yesterday to a client. I considered eliminating the parenthetical but it is a good answer to "what is C++ AMP?" and leaving it out would just trigger comments asking what C++ AMP was. The answer as a whole answers "how can I leverage the GPU from managed code" and I stand by it. – Kate Gregory Oct 19 '11 at 16:07
  • @Kate the question can be taken two ways, what was put on the question itself (MSIL) and what is in the content (libraries from C#). However, I don't agree that people would go asking about C++ AMP, it seems like an immediately usable Google search term, which is consequently what I did before clicking on your link. Even if it isn't spam, the way you presented your link does sound like a sales pitch lol – Adam Houldsworth Oct 19 '11 at 16:09
  • 2
    Guys chill out, all your answers were great! It freaks me out sometimes how quickly people reply with such great useful answers. C++ AMP looks cool, may do that and call into via .NET or use CUDA.NET just weighing it all up. Thanks for the answers and stop arguing :) – Ash Oct 19 '11 at 19:23
  • To use C++ AMP from .NET follow these links: http://www.danielmoth.com/Blog/NET-Access-To-The-GPU-For-Compute-Purposes.aspx – Daniel Moth Feb 14 '12 at 01:53