Jun 19, 2010

CUDA and Fractals

After making some fractal videos of Julia sets, I ran into issues because for certain Julia sets, the image would take a long time to process and I couldn't just do a screen capture to show you a nice animated video (which is what I did for the last video). I decided to sit down and try to figure out how to make it faster. I first tried using shaders, but it didn't work and I got bored (shaders just aren't really something I'm interested in!), so that project failed and the plan to speed up the program faded into the background like most of my projects do.

Recently though I was in Toronto at the Trends in Computing Symposium where a UofT grad student by the name of Duy Minh Dang gave a presentation on using CUDA for computational finance. CUDA is an extension to C released by Nvidia which lets you use the GPU in addition to the CPU for computation. I thought that was a pretty sweet idea, and decided to give it a go to speed up my rendering.

It worked very well, I can render pretty much any Julia set very quickly, so I can make some very interesting videos. Unfortunately running a screen capture program while running the video generator is more than my machine can handle at once, so the fractal video frame rate drops dramatically - if anybody knows a good way for me to pipe the array of raw pixel data to something that encodes to a video file let me know, I've been wanting to figure it out for myself but haven't had the time to figure it out for myself.

So if you want to see the video, you'll need to compile the code yourself. I put up a gist here with the code and compilation command, you need SDL and CUDA in order to compile it. I think you also need an Nvidia card for this, if you have an ATI card you might be able to use Stream to do the same thing. Obviously you'll have to modify the code to whatever Stream uses.

No comments: