DirectCompute Mandelbrot Fractal Viewer
Following in the footsteps of other people on the Internet, I’ve written a GPGPU language Mandelbrot fractal viewer. Along with a DirectCompute implementation, I’ve also written a reference unoptimized cpu version and am really excited that the DirectCompute implementation is more than 50x times faster! (With the caveat that my cpu implementation can probably be optimized much more.)
Other People’s GPGPU language Mandelbrot Fractal Implementations
During the past year, a bunch of people have released GPGPU language Mandelbrot fractal implementations. It seems to be a popular first program for GPGPU language learning.
1) DX11 DirectCompute Mandelbrot and Julia viewer
I learned about this implementation from a Beyond3D forum post last year (http://forum.beyond3d.com/showthread.php?t=55330). The author has continued releasing DirectCompute demos after the release of the above Mandelbrot viewer demo. His latest DirectCompute fluid simulation demo blows my mind and looks amazing. Source code appears included with the demos.
2) A realtime Mandelbrot zoomer in SSE assembly and CUDA
I learned about this implementation from a VizWorld article (http://www.vizworld.com/2009/12/realtime-mandelbrot-zoomer-sse-assembly-cuda/). The author provides a multi-threaded, hand-optimized SIMD cpu implementation along with a Nvidia CUDA implementation. GPL-ed source code is provided.
3) MandelCPU vs MandelGPU
The author appears to be one of the main programmer behind the exciting developments in LuxRender’s OpenCL support (http://www.luxrender.net/wiki/index.php?title=Luxrender_and_OpenCL). This demos compares cpu and OpenCL implementations of a Mandelbrot fractal viewer. The author’s page http://davibu.interfree.it/index.html has other more advanced OpenCL demos with source code.
Explanation of the Mandelbrot Fractal
The above page provides a really good introduction to what the Mandelbrot fractal is. I had previously never written a Mandelbrot fractal program and the above page helped me a lot in my understanding and implementations.
Video of My Mandelbrot Fractal Viewer
The demo video starts off with the DirectCompute implementation running and toggles to my non-optimized cpu implementation midway through. As you can see by the VSync-disabled FPS at the top left-hand side of the screen, the DirectCompute implementation is much much faster.
The ghosting in the video is probably due to the fact that I don’t know how to use my free video editing software properly, but I’m too tired to try to fix it. Yay, fixed the ghosting problem in my video. Turns out I just needed to increase the CamStudio video options compressor quality setting to 100%.
My Mandelbrot Fractal Viewer Demo
As I wrote in the introduction, the DirectCompute version is over 50x faster! I have been reading about how fast GPGPU languages can be for the right algorithms, but experiencing huge performance gains first-hand really hits home. The caveat is, of course, that both cpu and gpu implementations are unoptimized, and the cpu implementation has more potential to be sped up (but not +50x, I don’t think). Currently, my cpu implementation is single-threaded with no SIMD-use. The cpu in my machine is an Intel Core2Quad Q6600 2.4ghz (not overclocked) and my gpu is a ATI Radeon HD5750. In the demo, I don’t use doubles, but use floats in my calculations because my gpu doesn’t support doubles. Unfortunately, the insufficient precisions limits how closely you can zoom into the fractal.
Source Code & Binary