# CUDA Mandelbrot Set effective bandwidth and optimization

I was reading through this article (very good article and excellent blog BTW) to do some measurements in my (very simple) implementation of the Mandelbrot Set.

I'm using a Quadro 2000D card which has a theoretical bandwidth of approximately 20 GB/s ( = 1304 MHz * 128 bit-bus).

Mandelbrot image has 700x700 pixels (uchar = 1 byte per pixel). Launching the kernel with a grid(44,44) and block(16,16) the time elapsed to compute it is 1.00026 ms.

Now if my calculations are good then I have the following

$$(490000~bytes)(10^{-9}~GB)~~\big/~~(1.00026)(10^{-3~}s)=0.4898~GB/s$$

How should I interpret this result? I am only using approx 2.5% of the bandwidth, which is bad but since the algorithm is doing only a write per pixel there's no way to improve this, is there? Is there something I am not taking into account?

UPDATE

I did three types of kernels to see what was going on and reduced the size of the image to 250x250.

First the very naive, 1 thread doing all the work: 125 ms + 3.1% Global efficiency store + 2% occupancy. This is BAD.

Second, one thread per row: 0.20 ms + 97.7% Global store efficiency + 16% occupancy. Much better.

Third, one thread per element: 0.25 ms with 50% Global store efficiency + 55% occupancy. Worst than the previous.

So, from here what can I do to improve? Is there way to do it? The only thing it occurs to me in the third type is to write inside the kernel to shared memory, then synchronize and after that all threads write to global memory so to have coalesced accesses.

• Have you considered how much arithmetic you are doing? Mandelbrot set is embarrassingly parallel (no dependencies between different pixels), so if you are bandwidth limited you are doing it wrong. Apr 22 '13 at 19:28
• Yes I know it is embarrassingly parallelizable. I'm sure there are many ways and things to do it very efficient but I'm not an expert, so telling me "You are doing it wrong" doesn't help much. When you say "Bandwidth limited" you mean that the efficient bandwidth used is low? in my case only 2.5%. BTW my calculations are well done? I mean I didn't miss something? Apr 22 '13 at 19:54
• No, bandwidth limited would usually mean you are using a lot of bandwidth. Since you are using a small amount, you are likely not bandwidth limited, which is why I suggested estimating how much arithmetic you are doing. Apr 22 '13 at 21:45
• We don't know how many FLOPs your Mandelbrot kernel requires or its arithmetic intensity, so we'd have to guess where on the roofline you are. As @GeoffreyIrving notes, you're working with what is considered a traditionally very arithmetically intense kernel, so it's not surprising that you're not seeing high memory bandwidth (because the code is likely instruction-bound). Apr 22 '13 at 21:50
• Thanks for clarifying @GeoffreyIrving. AronAdmadia It is indeed a instruction-bound algorithm, I made an update in my post. Apr 22 '13 at 22:02