I just published my version of .NET bindings for OpenCL over on Codeplex last night. Why another, you ask? There’s already so many out there … Cloo, OpenCL.NET from hoopoe and another OpenCL.Net over at Sourceforge (and more?). Well, …
- Every API out there has an object-oriented version of the API that’s easily usable from .NET. Sure, it’s easy … but looks very different from the raw OpenCL API if I wanted to use it, right? There’s reason #1 right there. I wanted a set of .NET bindings that look, feel and act like the C-style API so I (read: the users) could port existing samples or read books/tutorials and understand what’s going on.
- Which brings us to our second question: Don’t all of the mentioned bindings also have the C-style API exposed? Sure, they do. But some of them mark the exposed API as unsafe, use of which would force users to mark their own projects as unsafe too. Secondly, every set of bindings I saw had raw translations of the API transliterating <anything>* to IntPtr (and others along those lines) meaning we have to use their OO abstractions to get anything done easily. I wanted something more .NET friendly at the API level, however.
So I guess the reason I wrote my own bindings is: I wanted to strike the middle ground between OO + .NET friendly and raw API translation. You can find this over at Codeplex. The API isn’t complete yet, but some things I’m particularly happy about are:
- No unsafe code (yet).
- Everything is .NET friendly AND you can use it as you would the raw API (overloads).
- As little explicit marshaling as possible, in fact all the exposed methods that invoke the extern’d methods in OpenCL.dll are only one call/line.
Initially, I started with these bindings for my project Brahma, but decided it was a large enough effort to put up separately. I hope people find it useful alongside the other tools for OpenCL for .NET that are already available. I hope to have the API completed and released soon. Stay tuned.
Hi
Hi Ananth,
How can I reach you to your email id. ?
Are you from mumbai ?
Regards
JIGNESH.
Hello, could you be more specific? I don’t give away personal information.
Nice work man. Just what I was looking for. Thank you!
Stopforgetting
I’ve been watching your work eagerly! Do you have Brahma using these bindings yet?
Yes, I am working on Brahma as I work on these bindings. Unfortunately, I spent a lot of time debating if I wanted to move Brahma to F# (to use quotations) – and delayed the release, but I’ve decided it’s not quite time yet. I can still do a lot with LINQ.
I only wish the C# team had seen it fit to add expression from multiline lambda support. If anyone reading this has pull with that team, I would urge you to help make it happen. Brahma can REALLY go places then.
multi-line lambda
For multi-line lambda, have you checked C# 4.0? The dynamic languages are interpreted with the new LINQ Expressions V2.
-Fahad
AFAIK, C# 4.0 only has classes that allow creation of an expression tree from multi-line lambdas (BlockExpressions and stuff), but the C# 4.0 compiler will not accept a multiline lambda and implicitly convert it into an expression tree, which is what I envision.
“The C# and Visual Basic compilers can generate expression trees only from expression lambdas (or single-line lambdas). It cannot parse statement lambdas (or multi-line lambdas). For more information about lambda expressions in C#, see Lambda Expressions (C# Programming Guide); for Visual Basic, see Lambda Expressions (Visual Basic).”
from MSDN.
I did consider workarounds like the one outlined here, but dropped it for the time-being, opting to wait for the C# team to add it in, hopefully in C# 5.0.
Mr
Hi,
I have a question for you. In my current project at work place I have to compare bitmaps, and it has to be very fast so I am thinking of doing it on the GPU. Searching for solutions i came around Brahma.
My question is, can i compare 2 bitmaps on the GPU using this framework? And if so, cand u point me an example or something?I saw in the samples of the framework that u compared floats and some vectors.
Any help is really appreciated.
Thanks
Yes, you can definitely compare two bitmaps. All you’d need to do is to copy the data into a DataParallelArray2D using LockBits and Scan0 (look for Bitmap manipulation, you should find plenty of tips there) and then write a the comparison query as usual. Look at the Game of Life sample which, processes 2D images and extrapolate to compare two images like so: from p1 in image from p2 in image2 select (some similarity metric) – would process corresponding pixels in both images. Hope that helps.
Thank you for your answer,
I still have some question,is not very clear to me how to do the query.
I have created 2 DataParallelArray2D, one for each bitmap:
arrayNo1 = new DataParallelArray2D(provider, values)
arrayNo2 = new DataParallelArray2D(provider, values2)
(where values and values2 are byte[,] variables containing the bitmap ).
So at this point I have to create the query which compares the 2 arrays( and returns true/false) but is not very clear to me how to do it…