joe_coolish
joe_coolish

Reputation: 7259

Using XNA to access GPGPU for image processing

I'm working on some real-time image processing projects in C# and I want to utilize the GPU as much as possible.

Specifically I have several byte[] that contain raw bitmap data, and I need to do things like high/low pass filters, edge detection, masking, dilation, hole filling, median filters, etc. on those byte[] as close to 30 fps as possible (the images are pretty small, no larger that 640x480)

I know that there are other GPGPU libraries out there (Like Cudafy, GPU.net, and Accelerator) but their EULAs either prohibit "for profit" usage of the library, or you need to purchase a license.

At the moment there are no funds for a license, so I'm trying to explore options that allow for commercial production while not costing anything, and XNA seemed to be the only option I could find that fits both criteria.

Are there any resources available on how to utilize XNA to access the GPU in a non-game setting? Are there any other options available to access the GPU via C#?

Upvotes: 4

Views: 1485

Answers (2)

Ani
Ani

Reputation: 10896

As the author of this library, might I suggest Brahma - which is a open-source, free for commercial use library (under the Eclipse public license) on CodePlex and automagically translates/runs LINQ as OpenCL?

Of course, if you wish to use RAW OpenCL, I also have a .NET friendly but raw-API version of OpenCL here on Codeplex and as a Nuget package.

Look here for an example of Brahma code (this one is for FFT).

Upvotes: 4

3Dave
3Dave

Reputation: 29041

I'd have a look at OpenCL via Cloo. It is open source and released under the MIT license, meaning you can happily include it in proprietary packages.

OpenCL is a bit more flexible than CUDA in that kernels can run on the GPU, CPU and (in theory) cell processor on a system where it's available - think running Mono+Linux+PS3, though I haven't tried that combination.

(GPU.NET is nice in that it allows you to write kernels in C#, but at the moment they only run on NVidia GPUs. This was a deal-breaker for me since my dev laptop has an AMD chipset.)

OpenCL kernels are written in the OpenCL language, which is basically C. It's also actively supported by Intel, AMD, and NVidia.

I'm using Cloo/OpenCL+XNA for an FDTD (optics/wave physics simulation) project and it works very well. The OpenCL code operates on a 3D array on the GPU; periodically I copy the buffer back to the host for visualization in the XNA code.

There may be a way to share that data without going back and forth to the CPU, but I haven't found it and for visualization purposes the impact, at least in my application, is minimal.

Upvotes: 1

Related Questions