-1

Whether its is using OpenCV (prefer not to), DirectX, Direct3D, OpenGL, etc., I want know if it is possible to get the difference of two images using the GPU. So not caring about whether the target machine has a Nvidia CUDA card installed or not, this library would simply utilize whatever GPU was present to perform operations on an image. I've looked, and looked but cannot find a library that does this for C#.

The question is very straightforward and very specific: What C# library has a function/API-call that compares two images using the GPU?

(I can already do this quickly using pointers and unsafe code in C#, but it can be much faster if done on the GPU somehow)

John
  • 775
  • 3
  • 11
  • 25
  • 1
    Flagged to close as this question is off-topic as per the rules disallowing: Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – Adam Miles Nov 17 '15 at 14:48

1 Answers1

2

Think very carefully if you want to solve this problem on the GPU. You have to transfer the data to the GPU and configure and start a GPU program. This costs some time. And since the GPU program will be very small, the overhead might be larger than the performance gain. So first try to parallelize your comparison on the CPU. A GPU implementation might be even slower (but could also be faster).

There are lots of APIs which let you program the GPU. None of them contain directly usable C# code as far as I know.

Firstly, there are the graphics libraries (DirectX, OpenGL). They let you program the GPU via Compute Shaders. There are C# bindings for these APIs, such as SharpDX, SlimDX, OpenTK. However, Compute Shaders require a graphics card that is capable of these shader stages.

And then there are the pure computation APIs, such as CUDA or OpenCL. CUDA is restricted to nVidia GPUs. OpenCL should run on most hardware. But there are also some limitations on the graphics device. Though, they are usually lower than for Compute Shaders. OpenTK is also a C# wrapper for OpenCL.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • To expand on this, if the *only* thing you're doing to the images is `for each pixel { x[i][j] = a[i][j] - b[i][j] }` moving it to the GPU will almost *always* be slower. This is because this kind of task will be massively [IO-bound](https://en.wikipedia.org/wiki/I/O_bound), and moving the image to GPU-visible memory will just add to the IO cost. You won't be taking advantage of the massive data-parallelism and huge memory bandwidth of the GPU itself. If you're going to do multiple operations to the image though, it could be worth the transfer cost. – MooseBoys Nov 17 '15 at 18:59