Link MKL to an installed Numpy in Anaconda? - python

>>> numpy.__config__.show()
atlas_threads_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['f77blas', 'cblas', 'atlas']
library_dirs = ['/home/admin/anaconda/lib']
define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
language = c
atlas_blas_threads_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
library_dirs = ['/home/admin/anaconda/lib']
define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
language = f77
openblas_lapack_info:
NOT AVAILABLE
atlas_info:
libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
library_dirs = ['/home/admin/anaconda/lib']
define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
language = f77
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
atlas_blas_info:
libraries = ['f77blas', 'cblas', 'atlas']
library_dirs = ['/home/admin/anaconda/lib']
define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
language = c
mkl_info:
NOT AVAILABLE
This is numpy.config.show()
And this numpy is based on Anaconda.
in /home/admin/anaconda/lib/python2.7/site-packages/numpy
And meanwhile, I have installed MKL in /opt/intel/mkl.
Also it seems that, I can use MKL, when I used Theano with this Anaconda and this numpy.
Thank you~

To do this, you'll have to get the Numpy source code and create a site.cfg file in the main folder that tells Numpy where to look for the MKL libraries. Use the site.cfg.example file as a guide; there's a section in there on MKL that should tell you the exact lines you need.
Once you have a site.cfg file, run python setup.py config. This will spit out the configuration info (it looks like the output of numpy.config.show()). You should see the paths to your MKL libraries in there (if not, you'll have to play around with the site.cfg file until you do).
Then, you can build and install with python setup.py build and python setup.py install. You may want to uninstall your old Numpy first.
I have a blog post on installing Numpy with OpenBLAS. While your situation is a little different, a lot of steps are similar I think.

Related

How to build NumPy from source linked to Apple Accelerate framework?

It is my understanding that NumPy dropped support for using the Accelerate BLAS and LAPACK at version 1.20.0. According to the release notes for NumPy 1.21.1, these bugs have been resolved and building NumPy from source using the Accelerate framework on MacOS >= 11.3 is now possible again: https://numpy.org/doc/stable/release/1.21.0-notes.html, but I cannot find any documentation on how to do so. This seems like it would be an interesting thing to try and do because the Accelerate framework is supposed to be highly-optimized for M-series processors. I imagine the process is something like this:
Download numpy source code folder and navigate to this folder.
Make a site.cfg file that looks something like:
[DEFAULT]
library_dirs = /some/directory/
include_dirs = /some/other/directory/
[accelerate]
libraries = Accelerate, vecLib
Run python setup.py build
The problem is I do not know 1. what the variables library_dirs and include_dirs should be so that NumPy knows to use Accelerate BLAS and LAPACK and 2. if there are any other additional steps that need to be taken. If anyone knows how to do this or can provide any insight, it would be greatly appreciated.
I actually attempted this earlier today and these are the steps I used:
In the site.cfg file, put
[accelerate]
libraries = Accelerate, vecLib
Build with NPY_LAPACK_ORDER=accelerate python3 setup.py build
Install with pip3 install .
Afterwards, np.show_config() returned the following
blas_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
accelerate_info:
extra_compile_args = ['-I/System/Library/Frameworks/vecLib.framework/Headers']
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]
blas_opt_info:
extra_compile_args = ['-I/System/Library/Frameworks/vecLib.framework/Headers']
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]
lapack_mkl_info:
NOT AVAILABLE
openblas_lapack_info:
NOT AVAILABLE
openblas_clapack_info:
NOT AVAILABLE
flame_info:
NOT AVAILABLE
lapack_opt_info:
extra_compile_args = ['-I/System/Library/Frameworks/vecLib.framework/Headers']
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]
Supported SIMD extensions in this NumPy install:
baseline = NEON,NEON_FP16,NEON_VFPV4,ASIMD
found = ASIMDHP,ASIMDDP
not found =
and my quick test suggest significant performance boost relative to OpenBlas.
No it doesn't have to be that complicated. I used these two commands and was able to install numpy with Apple Accelerate on Mac M1.
pip install cython pybind11
pip install --no-binary :all: --no-use-pep517 numpy
Reference: How to install SciPy on Apple Silicon (ARM / M1)

Installing PyTorch on Jetson Nano Ubuntu 18

I am trying to install PyTorch on Jetson Nano Ruining Ubuntu 1804. My reference is https://dev.to/evanilukhin/guide-to-install-pytorch-with-cuda-on-ubuntu-18-04-5217
When I try the following command this is what I get:
(my_env) crigano#crigano-desktop:~$ python3.8 -m pip install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing
Collecting numpy
Using cached numpy-1.20.2-cp38-cp38-manylinux2014_aarch64.whl (12.7 MB)
Collecting ninja
Using cached ninja-1.10.0.post2.tar.gz (25 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting pyyaml
Using cached PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl (818 kB)
ERROR: Could not find a version that satisfies the requirement mkl
ERROR: No matching distribution found for mkl
If you just want to use PyTorch on the bare-metal Jetson Nano, simply install it with NVIDIA's pre-compiled binary wheel. Other packages can be found in the Jetson Zoo.
MKL is developed by Intel "to optimize code for current and future generations of Intel® CPUs and GPUs." [PyPI]. Apparently it does run on other x86-based chips like AMD's (although Intel has historically intentionally crippled the library for non-Intel chips [Wikipedia]), but unsurprisingly Intel is not interested in supporting ARM devices and has not ported MKL to ARM architectures.
If your goal is to use MKL for math optimization in numpy, openblas is a working alternative for ARM. libopenblas-base:arm64 and libopenblas-dev:arm64 come pre-installed on NVIDIA's "L4T PyTorch" Docker images. You can confirm that numpy detects them with numpy.__config__.show(). This is what I get using numpy 1.12 in python 3.69 on the l4t-pytorch:r32.5.0-pth1.6-py3 image:
blas_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
openblas_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib/aarch64-linux-gnu']
language = c
define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib/aarch64-linux-gnu']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
NOT AVAILABLE
openblas_lapack_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib/aarch64-linux-gnu']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib/aarch64-linux-gnu']
language = c
define_macros = [('HAVE_CBLAS', None)]
So presumably it will use openblas in place of MKL for math optimization. If your use case is also for numpy optimization, you can likewise use openblas and shouldn't need MKL... which is fortunate, since it isn't available anyway. 😅

Installing Keras over TensorFlow on Windows 10 (Python 3.5.3)

I'm trying to install Keras on Windows 10 but I get the following error while searching for the installed SciPy:
Installed c:\users\MY_USER\appdata\local\programs\python\python35\lib\site-packages\keras
Processing dependencies for Keras==2.0.4
Searching for scipy>=0.14
Reading https://pypi.python.org/simple/scipy/
Downloading https://pypi.python.org/packages/e5/93/9a8290e7eb5d4f7cb53b9a7ad7b92b9827ecceaddfd04c2a83f195d8767d/scipy-0.19.0.zip#md5=91b8396231eec780222a57703d3ec550
Best match: scipy 0.19.0
Processing scipy-0.19.0.zip
Writing c:\users\MY_USER\appdata\local\temp\easy_install-an2sfx\scipy-0.19.0\setup.cfg
Running scipy-0.19.0\setup.py -q bdist_egg --dist-dir c:\users\MY_USER\appdata\local\temp\easy_install-an2sfx\scipy-0.19.0\egg-dist-tmp-zy7oqf
c:\users\MY_USER\appdata\local\temp\easy_install-an2sfx\scipy-0.19.0\setup.py:323: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
warnings.warn("Unrecognized setuptools command, proceeding with "
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:639: UserWarning: Specified path C:\projects\numpy-wheels\windows-wheel-builder\atlas-builds\atlas-3.11.38-sse2-64\lib is invalid.
warnings.warn('Specified path %s is invalid.' % d)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:1532: UserWarning:
Atlas (http://math-atlas.sourceforge.net/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [atlas]) or by setting
the ATLAS environment variable.
warnings.warn(AtlasNotFoundError.__doc__)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:1543: UserWarning:
Lapack (http://www.netlib.org/lapack/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [lapack]) or by setting
the LAPACK environment variable.
warnings.warn(LapackNotFoundError.__doc__)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:1546: UserWarning:
Lapack (http://www.netlib.org/lapack/) sources not found.
Directories to search for the sources can be specified in the
numpy/distutils/site.cfg file (section [lapack_src]) or by setting
the LAPACK_SRC environment variable.
warnings.warn(LapackSrcNotFoundError.__doc__)
Running from scipy source directory.
non-existing path in 'scipy\\integrate': 'quadpack.h'
error: no lapack/blas resources found
Any idea what is wrong?
SciPy installation itself works perfectly.
Did you install any "lapack/blas" library??
If not, you should install it. You could try MKL from Intel. Or you could try just getting "Numpy" and "Scipy" from this link, which come with what is necessary: http://www.lfd.uci.edu/~gohlke/pythonlibs/
But:
Don't install anything in folders containing spaces in their names. User folders without spaces
.
If you already have blas/lapack installed in folders with spaces:
Check numpy configuration:
import numpy as np
np.__config__.show()
It should tell you where lapack/blas is installed.
You should see something like this:
lapack_opt_info:
library_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/lib/intel64_win']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/include']
libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_rt']
blas_opt_info:
library_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/lib/intel64_win']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/include']
libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_rt']
lapack_mkl_info:
library_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/lib/intel64_win']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/include']
libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_rt']
blas_mkl_info:
library_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/lib/intel64_win']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['C:/LinkToProgramFilesX86/IntelSWTools/compilers_and_libraries_2017/windows/mkl/include']
libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_rt']
Notice in my case I created a folder "LinkToProgramFilesX86". This folder is a symbolic link to the regular "Program Files" folder, which contains spaces. I have to create the symbolic link because of the space.
To create symbolic links, check here: Receive AssertionError while optimizing convolution in theano

ATLAS on a python virtualenv in Fedora for numpy/scipy/scikit-learn

I am struggeling to let python find and use the installed ATLAS libraries from my distribution when using virtualenv.
This is on Fedora 21, atlas, atlas-devel, blas, blas-devel are installed. Outside of a virtualenv, the command python -c 'import numpy; numpy.show_config()' shows that I have ATLAS:
atlas_3_10_blas_threads_info:
libraries = ['tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('HAVE_CBLAS', None), ('ATLAS_INFO', '"\\"3.10.1\\""')]
language = c
include_dirs = ['/usr/include']
lapack_opt_info:
libraries = ['tatlas', 'tatlas', 'tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('ATLAS_INFO', '"\\"3.10.1\\""')]
language = f77
include_dirs = ['/usr/include']
blas_opt_info:
libraries = ['tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('HAVE_CBLAS', None), ('ATLAS_INFO', '"\\"3.10.1\\""')]
language = c
include_dirs = ['/usr/include']
openblas_info:
NOT AVAILABLE
openblas_lapack_info:
NOT AVAILABLE
[...]
And ls /usr/lib64/atlas/ gives:
libatlas.a libsatlas.so libsatlas.so.3.10 libtatlas.so.3
libcblas.so libsatlas.so.3 libtatlas.so libtatlas.so.3.10
I also setup an environment variable, so that echo $ATLAS gives
/usr/lib64/atlas/libsatlas.so
But when I do the following:
virtualenv venv
source venv/bin/activate
pip install --upgrade pip
pip install numpy
pip install scipy
pip install scikit-learn
python -c 'import numpy; numpy.show_config()'
I get:
lapack_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
define_macros = [('HAVE_CBLAS', None)]
language = c
blas_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
define_macros = [('HAVE_CBLAS', None)]
language = c
openblas_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
define_macros = [('HAVE_CBLAS', None)]
language = c
openblas_lapack_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
define_macros = [('HAVE_CBLAS', None)]
language = c
blas_mkl_info:
NOT AVAILABLE
I would really appreciate help with how to get numpy and scipy simply find and use ATLAS from my distribution in a virtualenv.
You need to tell numpy's setup.py where to find your ATLAS libraries.
Try creating a .numpy-site.cfg file in your home folder before running pip install. Here's the template for this file.
You probably need to add the lines
[atlas]
library_dirs = /usr/lib64/atlas
include_dirs = /usr/include
Although, this has required a little bit of trial-and-error in my experience.
Using this file in conjunction with pip install seems to work reliably on RHEL and Ubuntu, at least within virtual environments where you don't need sudo.
If this fails for one or more of numpy, scipy and scikit-learn, consider installing from source instead, and modify the site.cfg file inside the source dir before running python setup.py install.

What is the easiest way to install numpy with LAPACK/BLAS?

I'm on an Ubuntu 14.04.
I would have expected doing:
sudo apt-get install python-numpy
would've worked but it isn't the case...
The way I tried to check is by doing locate blas and found nothing that seemed relevant.
I would like a solution that doesn't involve me compiling from source.
The ideal solution is something that uses the ubuntu repos.
In Ubuntu 14.04 and later, blas and lapack are installed as part of python-scipy and python3-scipy, so you need to install python-scipy. In Ubuntu 18.04 and earlier open the terminal and type:
sudo apt install python-scipy
This command will also install libblas3 (Basic Linear Algebra Subprograms reference implementations, shared library) and liblapack3 (Library of linear algebra routines 3 - shared version) as dependencies, and it will also install python-numpy as a dependency if you don't already have it installed.
numpy.show_config() revealed that I had no BLAS support even though python3-scipy was already installed. Uninstalling and re-installing python3-scipy and python3-numpy fixed it:
sudo apt-get remove python3-scipy python3-numpy
sudo apt-get install python3-scipy python3-numpy
Now I have LAPACK/BLAS support:
>>> numpy.show_config()
openblas_lapack_info:
NOT AVAILABLE
mkl_info:
NOT AVAILABLE
atlas_3_10_blas_threads_info:
NOT AVAILABLE
lapack_info:
libraries = ['lapack', 'lapack']
language = f77
library_dirs = ['/usr/lib']
atlas_3_10_blas_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['blas', 'blas']
define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
library_dirs = ['/usr/lib']
language = c
blas_info:
libraries = ['blas', 'blas']
language = c
library_dirs = ['/usr/lib']
define_macros = [('HAVE_CBLAS', None)]
blas_mkl_info:
NOT AVAILABLE
atlas_info:
NOT AVAILABLE
atlas_3_10_threads_info:
NOT AVAILABLE
lapack_mkl_info:
NOT AVAILABLE
atlas_blas_threads_info:
NOT AVAILABLE
atlas_3_10_info:
NOT AVAILABLE
atlas_threads_info:
NOT AVAILABLE
atlas_blas_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['lapack', 'lapack', 'blas', 'blas']
define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
library_dirs = ['/usr/lib']
language = c
Have your tried to use pip?
sudo pip install numpy
If you dont have pip install pip with instructions here
I have very good experience with the anaconda package manager (learning took me 1-2h). In my opinion it is easier to use than venv and more felixble than pip/env alone. After download and setup you have most of the package like numpy ready to go. So no problems like this anymore!

Categories