Porting a renderer from C++ to CUDA - the speed gains and their cost
users.softlab.ece.ntua.gr
users.softlab.ece.ntua.gr
But there were couple of problems (solvable, but might require changing of habits):
- Once you have CUDA running, you can't Remote Desktop to the machine (you can do VNC). We are still on Vista (and we stared trying this on XP). Things might be better with Windows 7.
Alternative: VNC
- The IT requires every unattended machine to be logged off after 15 minutes. This means that CUDA might stop working for you (no video driver). Same somtimes happen if you do Ctrl+Alt+Del and brought the Task Manager (that's inconsitent - it happens rarely).
- The biggest problem was that there were 2-3 models (DELL, then HP) machines. We always use Intel with NVIDIA, but now and then every machine would convert to DXT the texture data a little bit different. Visually no problem, but this was messing up MD5 sums of the produced image, and locally people were getting different results than the one stored on the cached asset server.
Alternative: Keep the MD5 sums of the source images + arguments for encoding (though this would not detect cases where bad images were encoded).
We had one very smart guy working for 6 months on new radiosity tool. He started with CUDA solution, but moved back to multithreaded/process solution with SSE code. For radisotiy (precomputed lighting for the levels) data we did not kept MD5 sums, so it did not matter.So for us what worked sanely was OpenMP - speeding up the nvidia compressor by processing blocks with height of 4, and length of the original image - another smart graphics programmer came up with the idea.
That to be said - it's still exciting, but too hard for a lot of common tasks.
full disclosure: I work on the CUDA driver stack and the dedicated compute driver for Vista/Win7 is my baby :)
Some interesting things to note, at least from my point of view:
* GPUs should not be considered like the next generation CPUs at this stage.
* Trying to take advantage of CUDA/OpenCL not only requires redesigning your algorithm and altering your data structures, but also the folly of implementing in software what is already available in hardware.
* Thread shared memory on nVidia cards isn't exactly similar to a cache. There's also a lot of papers in the last two years that speak of nothing else but altering algorithms to make better use of CUDA, because for anything else but the simplest of raytracers on a few objects, the situation gets really bad.
Very nice post, though. Neatly organized and well written, I really enjoyed it.
Blushing :-) Glad you enjoyed it, hope you have a chance to look at the GPL code, too.
What you can do is attempt to group up a bunch of secondary rays that appear to be pointing roughly the same direction (e.g., if their primary rays all reflected off the same flat, specular object), and do them in a batch, exploiting their spatial coherence. Whether the process of finding coherent secondary rays is less costly than just processing secondary rays in the same order as their primary rays, again, depends on scene geometry.
http://home.comcast.net/~tom_forsyth/larrabee/larrabee.html
"Rasterization on Larrabee and SIMD Programming With Larrabee: Michael Abrash and I doing our double-act. We both talk about the instruction sets, Michael talks about the hierarchical descent rasterisation algorithm, and I talk about how we do basic language structures such as conditionals and flow control with our 16-wide vector units. We were both absurdly proud to be able to finally talk about the architecture we'd worked on for so long - it's not every programmer that gets to design their own instruction set."
Also a presentation on OptiX shows how to implement ray tracer: http://www.nvidia.com/object/gtc2010-presentation-archive.ht...
Ray-tracing could be done well on GPU (see OptiX), but it is not trivial and needs some tricks (persistant threads, work donation etc. which are not that common on CPUs)
Real-time graphics does the best it can with a few big triangles (by e.g. texturing and bump-mapping them) out of necessity, but people are moving towards cases that are harder on the rasterizer.
As for my negative conclusions... I wouldn't describe them as "negative", just "objective". Some algorithms are easily adapted to CUDA, and you get an easy win of 10-40x. Others need a lot more work to offer speed gains, and finally, there are some that are simply hopeless (you have to redesign them from scratch).