jonathanvdc / Flame

A compiler framework for managed code.
https://jonathanvdc.github.io/Flame
GNU General Public License v3.0
52 stars 4 forks source link

Create a GPU acceleration library #31

Closed jonathanvdc closed 5 years ago

jonathanvdc commented 5 years ago

As it turns out, GPUs are relatively easy to program when you have an LLVM back-end. This PR adds Turbo, a work-in-progress library that allows for transparent GPU programming from the comfort of C# code.

Turbo's main API is this method, defined in the Turbo.Parallel class:

public static Task ForAsync(int threadCount, Action kernel)

That is, you tell Turbo how many threads to launch and pass a delegate to specify the code that each of these threads should run. Turbo takes care of all the hard parts: it compiles the delegate to code suitable for execution on the GPU, it copies the delegate's call target to GPU memory, and it launches the kernel. Turbo wraps every kernel in aTask so you can easily manage kernel concurrency.