4 ms·
I'm a bit surprised to see that GPU Mandelbrot is only at best x75 faster than (sequential?) CPU. Does Julia just generate really fast (multicore/vectorized?)
by Athas 8y ago
I'm a bit surprised to see that GPU Mandelbrot is only at best x75 faster than (sequential?) CPU. Does Julia just generate really fast (multicore/vectorized?) CPU code? Does it also count communication costs? Fractal computations like that are extremely GPU friendly because they involve no memory accesses at all, except for writing the final result. I would expect at least two orders of magnitude improvement over a straightforwardly written C implementation.
- ummonk 8y agoIt does autovectorize quite often.
- Athas 8y agoI had a suspicion that the problem was that maxiters was set fairly low (16). For the Mandelbrot sets I'm used to, this would result in relatively little computation (over a hundred iterations is more common). To investigate this hunch, I wrote a Futhark program as a proxy for a hand-written GPU implementation (didn't quite have the patience for that this evening): import "lib/github.com/diku-dk/complex/complex" module c32 = mk_complex f32 type c32 = c32.complex let juliaset (maxiter: i32) (z0: c32) = let c = c32.mk (-0.5) 0.75 let (_, i) = loop (z, i) = (z0, 0) while i < maxiter && c32.mag z <= 4 do (c32.(z * z + c), i+1) in i let main (n: i32) (maxiter: i32) = let N = 2**n let (w, h) = (N, N) let q = tabulate_2d w h (\i j -> let i = 1 - r32 i*(2/r32 w) let j = -1.5 + r32 j*(3/r32 h) in c32.mk i j) in map (map (juliaset maxiter)) q I don't have the tools or skills to easily generate nice graphs, but I get about a x271 speedup when this code is compiled to OpenCL and run on a Vega 64 GPU, versus when it is compiled to C. The C code runs in 272ms, which is very close to the number reported for Julia here[0] (I assume that the page has a typo and that the N=2²⁴ column actually means N=2¹², because an N=2²⁴ image would take up dozens of TiB in GPU memory. Also, the benchmark code linked only goes up to N=2¹².) Unfortunately, if I change maxiters to 256, the speedup actually drops, to x182. So much for that theory. Edit: also tried on an NVIDIA GTX 780Ti, and the results are the same. My new theory is that the Julia code also counts the cost of moving the resulting array back to the host (which can easily be dominant for a kernel that runs for just a millisecond or two). [0]: https://github.com/JuliaGPU/GPUBenchmarks.jl/blob/master/results/results.md#juliaset-1 https://github.com/JuliaGPU/GPUBenchmarks.jl/blob/master/res...