Using Brahma to perform LINQ on the GPU

Source: Internet
Author: User
Keywords Execute run value target statement
Tags code computing cpu data example graphics graphics processor open source

Brahma is an open source library for parallel computing, written by C # and supported to run on a variety of processors. Currently, Brahma contains only one graphics processor (GPU) module, but its modular structure can support more kinds of processors. With Brahma, statements in the same C # method can run on both the CPU and the GPU without the need for additional code.

Brahma performs parallel computations by converting LINQ statements into target processor code, and the generated code differs according to the target processor. For example, for DirectX, a high level shading Language is generated, and OpenGL shading Language is generated for OpenGL. To improve performance, LINQ queries are compiled only once, and then run as many times as needed

The following code multiplies the elements of an array by 2 in parallel:

Create a calculated object
var computationprovider = new Computationprovider ();

Create a parallel array and populate the data
var data = new Dataparallelarray (Computationprovider,
New[] {0f, 1f, 2f, 3f, 4f, 5f, 6f});

Compiling LINQ Queries
CompiledQuery query = computationprovider.compile>
(
D => from value in D
Select value * 2f
);

Executing queries on data
IQueryable result = Computationprovider.run (query, data);

Print results
foreach (float value in result)
Console.WriteLine (Result[i]);

Releasing resources
Computationprovider.dispose ();
Data. Dispose ();
Result. Dispose ();

Brahma source code and binaries follow Eclipse public License 1.0.

View English Original: LINQ on GPU with Brahma

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.