CUDA vs shaders


I am trying to determine if CUDA would be more efficient to use than shaders when working with a 512x512 floating point texture. Now, I am aware that CUDA cannot work directly with OpenGL textures, so a memory buffer would have to be created to read the data into.

Basically, I have three shaders that generate a histogram, smooth the histogram and apply it with an image manipulation algorithm, and finally display the results of the manipulated image.

As it stands, the shader implementation is rather quick, however there are additional filters we would like to add to the shaders. Unfortunately, the more filters that are generated, the more floating point textures we will have to use for fidelity. The additional shaders will also start to impede performance

I am hoping that I could utilize CUDA to streamline the algorithms so that additional filters could be written without impacting the overall performance (these computations need to be at a fast framerate – ~60FPS at least). However, if using vertex shaders to manipulate the imagery would be more efficient, by all means I would want to go that route.

Any thoughts?


This really depends on exactly what operations you’re performing. If you simply take shader code and port it directly to CUDA using texture fetches, the performance will probably not be any better.

But if you take advantage of CUDA features (shared memory, scattered writes etc.), the performance could be much higher.

For example, we have implementations of histograms in the CUDA SDK that are much faster than anything possible with shaders.

I’m not sure why you say that with more filters you need more textures. The temporary storage requirements should be the same for both methods, although with CUDA can read and write to the same buffer which might help. The maximum program length is also much greater with CUDA, which might help you perform more operations in a pass.

Probably because I’m relatively new to this type of programming, and it was my first stab. :)