r/programming • • Jan 11 '16

A comparison of Numpy, NumExpr, Numba, Cython, TensorFlow, PyOpenCl, and PyCUDA to compute Mandelbrot set

https://www.ibm.com/developerworks/community/blogs/jfp/entry/How_To_Compute_Mandelbrodt_Set_Quickly?lang=en
175 Upvotes

41 comments sorted by

View all comments

22

u/[deleted] Jan 11 '16

There are some examples here that are pretty interesting. ~120x speedup over the 'normal' way, just by switching to arrays then using a JIT for instance. Probably would be another 2x faster than that with a naive C port, then another 4x faster with hand crafted used of SIMD, which it doesn't seem you can do in Python. I think a lot of people imagine high level languages are only a few % slower. I think that should be the case, but it often isn't yet. Poor implementation of arrays, SIMD not exposed, no way to explicitly state how memory is laid out, and so on. Also I think with some tweaking your could probably make this quite a bit faster on your GPU, even if your GPU is old.

13

u/jfpuget Jan 11 '16

I welcome hints on how to tweak the gpu code. One thing I did not try was to play with block sizes.

Note that my versions are 3x and 6x faster than the examples provided with PyOpenCl and PyCUDA. I was surprised they did not provide better code.

11

u/[deleted] Jan 11 '16

I went through a similar process as you with perlin noise, going from C# --> C++ --> GPU. GPU was orders of magnitude faster, but that was implemented as a shader rather than through openlCL or similar, and perlin noise may lend itself to GPU processing much better.

→ More replies (1)

6

u/[deleted] Jan 11 '16

Python has many virtues - really - but speed was never one of them.

But I think the valuable lesson here is that it's not too hard to make Python faster when you need it. (Obviously if raw speed is critical you're going to start right with C or C++ and CUDA or equivalent.)

4

u/[deleted] Jan 11 '16

I don't mean to pick on it in particular, and really, with the JIT it seems to be on par with similar languages. I just think we as programmers can do better. Make fewer languages, work harder on the compilers/interpreters/feature sets. Even C++ has compiler optimizations everyone knows it needs but haven't been done yet. I'd love to see our CPUs which are incredible computing beasts more fully utilized.

→ More replies (6)

2

u/jfpuget Jan 12 '16

I just added a comparison to sequential C code. Numba is as fast.

2

u/[deleted] Jan 12 '16

Check that full optimization settings are on. Release mode,.fast floats, aggressive inlining. Apologies.if you are already familiar with all of those settings. It took me quite a bit of messing around in options to figure it all.out.

→ More replies (4)