Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is numpy optimized for raspberry-pi automatically

The Raspberry Pi ( armv7l architecture ) has neon vfpv4 support which can be used for optimization.

Does the standard version of numpy include these optimizations when installing the command pip3 install numpy or apt-get python3-numpy?

I am not talking about blas and lapack. Native numpy.

like image 259
Dan Erez Avatar asked Dec 23 '22 04:12

Dan Erez


1 Answers

As Mark Setchell noted, numpy does not appear to have specific code that targets NEON intrinsics. However, that is not the full story. Modern compilers are frequently able to take serially written code and transform it to use SIMD intrinsics. For instance, GCC can partially unroll loops and use NEON's SIMD instructions to perform multiple iterations of the loop at the same time.

The next thing to note is that pip install and apt-get install will do different things. apt-get will fetch a prebuilt binary from the Raspbian/Debian repository (depending which you are using). Whereas pip can only fetch the source of numpy when on ARM architectures. This is because the Python Package Index (PyPI) does not store binaries for ARM architectures.

Debian and Raspbian both appear to have armhf versions of python3-numpy in their repositories. The hf stands for "hard float" -- floating point computations done in hardware as opposed to software. This debian page also appears to suggest that armhf packages have been compiled to take advantage of NEON intrinsics, but results have been limited. That is, GCC is using the NEON intrinsics, but isn't as finely tuned (yet) as it is when using SSE/SSE2 intrinsics.

pip would be the worse option in this case as it appears that GCC is a bit cautious when it comes to targeting ARM floating point instructions. That is, pip will download the numpy source and compile it on your Raspberry Pi, but might not optimise the code as much as it can by default. You will probably need to tell pip to use a few compiler options by using the --global-option argument. eg --global-option="-mfloat-abi=hard". You can find a comprehensive set of options to pass here.

like image 190
Dunes Avatar answered Dec 26 '22 11:12

Dunes