DirectX11 Interop CUDA Mandelbrot Fractal
Introduction
I updated my DirectCompute Mandelbrot fractal demo to be able to render using both CUDA and DirectCompute. The program is a simple Mandelbrot renderer, but you can dynamically switch between a CUDA and DirectCompute render.
Relevant Links
http://developer.download.nvidia.com/compute/cuda/sdk/website/Graphics_Interop.html#simpleD3D11Texture
The NVIDIA CUDA 3.2 SDK includes a DirectX11 interop sample “Simple D3D11 Texture” which I used as reference. For the 3.2 SDK, I think this is the only CUDA sample using D3D11. The SDK sample uses a ID3D11Texture3D as a CUDA resource while my Mandelbrot fractal program uses a ID3D11Buffer as a CUDA resource.
http://developer.nvidia.com/object/cuda-by-example.html
I mainly used the CUDA 3.2 SDK programming manual to learn CUDA, but I also read the NVIDIA “Cuda by Example” book on Safari Informit. The book is very easy to follow and I read it in one sitting. This book teaches the basics of CUDA in a simple language and I thought it was a good first book.
http://www.yakiimo3d.com/2010/02/02/directcompute-mandelbrot-fractal-viewer/
My old DirectCompute Mandelbrot fractal viewer. The program has a bug (oh no!) when the screen size dimensions are not divisible by the thread group size dimensions, which I fixed in my new CUDA interop demo.
Demo Notes
Took some timings to compare the CUDA DirectX11 interop and DirectCompute performances. Timings were taken on my Geforce GTX 460, Driver 266.58, Vista 64-bit SP2, CUDA SDK 3.2. Neither the CUDA nor DirectCompute implementations have been optimized. With better documentation, better tools and finer control over the program, I think the CUDA program has a better chance of good optimization.
| Num Iterations | DirectCompute | CUDA |
| 8 | 0.588ms/frame (1700fps) | 0.749ms/frame (1335fps) |
| 256 | 1.439ms/frame (695fps) | 1.639ms/frame (610fps) |
| 624 | 3.185ms/frame (314fps) | 2.907ms/frame (344fps) |
| 1024 | 4.878ms/frame (205fps) | 4.274ms/frame (234fps) |
The higher the iteration count, the more work that the compute shader has to do. When the iteration count is low, DirectCompute is faster. When the iteration count becomes higher, CUDA becomes faster than DirectCompute. I’m assuming this means that with my current code, the CUDA kernel execution is faster, but that there is a fixed cost for DirectX11 interop that makes CUDA initially slower.
http://nvidia.fullviewmedia.com/gdc2011/agenda.html
On Friday, I watched the NVIDIA GDC2011 “GPU Radiosity: Porting the Enlighten runtime to CUDA” presentation, and around 28:23, the speaker mentions that “Switching between D3D and CUDA is expensive (it’s a power cycle!)”. I’m guessing this power mode switch cost is what makes CUDA initially slower in my Mandelbrot fractal program. I watched the entire Enlighten presentation and it was very interesting. The stream had some technical info, but if you are curious about Enlighten tech, there is a DICE&Geomerics Siggraph 2010 presentation that contains even more detailed technical information about Enlighten http://advances.realtimerendering.com/s2010/index.html.
Demo
Source Code & Binary
http://yakiimo3d.codeplex.com/releases/view/62087
. This entry was posted on Sunday, March 6th, 2011 at 11:36 PM and is filed under Cuda, Demo, DirectCompute, DirectX11. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>It may take some time for your comment to appear, it is not necessary to submit it again.