tikk3r / flocs

Containers recipes for software stacks used in LOFAR data reduction.
https://tikk3r.github.io/flocs/
GNU General Public License v3.0
6 stars 6 forks source link

Update MKL to One API MKL #57

Closed AlexKurek closed 1 year ago

AlexKurek commented 1 year ago

Hi, I just want to show you - are you aware that there is 2023 version of MKL called One API MKL? This is how I install numpy and scipi against that libraries.

sudo -s -H
export INSTALLDIR=/opt
export MKL_ONEAPI_VERSION=2023.1.0-46342
export NUMPY3_VERSION=1.19.5
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/intel/oneapi/mkl/latest/lib/intel64/

apt-get install -y python cython python-setuptools gfortran build-essential

cd /tmp/
wget -q --retry-connrefused https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sh -c 'echo deb https://apt.repos.intel.com/oneapi all main > /etc/apt/sources.list.d/oneAPI.list'
apt-get update
apt-get install -y intel-oneapi-mkl-devel

update-alternatives --install /usr/lib/x86_64-linux-gnu/libblas.so libblas.so-x86_64-linux-gnu /opt/intel/oneapi/mkl/${MKL_ONEAPI_VERSION}/lib/intel64/libmkl_rt.so 50
update-alternatives --install /usr/lib/x86_64-linux-gnu/libblas.so.3 libblas.so.3-x86_64-linux-gnu /opt/intel/oneapi/mkl/${MKL_ONEAPI_VERSION}/lib/intel64/libmkl_rt.so 50
update-alternatives --install /usr/lib/x86_64-linux-gnu/liblapack.so liblapack.so-x86_64-linux-gnu /opt/intel/oneapi/mkl/${MKL_ONEAPI_VERSION}/lib/intel64/libmkl_rt.so 50
update-alternatives --install /usr/lib/x86_64-linux-gnu/liblapack.so.3 liblapack.so.3-x86_64-linux-gnu /opt/intel/oneapi/mkl/${MKL_ONEAPI_VERSION}/lib/intel64/libmkl_rt.so 50
echo "/opt/intel/oneapi/mkl/latest/lib/intel64" >> /etc/ld.so.conf.d/mkl.conf
echo "MKL_THREADING_LAYER=GNU" >> /etc/environment
ldconfig
bash -c "source ${INSTALLDIR}/intel/oneapi/mkl/latest/env/vars.sh"

# Python 2.7 Numpy
cd /tmp/
wget -q --retry-connrefused https://github.com/numpy/numpy/archive/v1.16.6.tar.gz
tar xzf v1.16.6.tar.gz
cd numpy-1.16.6/
cp site.cfg.example site.cfg
echo "[mkl]" >> site.cfg
echo "library_dirs = /opt/intel/oneapi/mkl/latest/lib/intel64/" >> site.cfg
echo "include_dirs = /opt/intel/oneapi/mkl/latest/include" >> site.cfg
echo "mkl_libs = mkl_rt" >> site.cfg
echo "lapack_libs =" >> site.cfg
python setup.py config build_clib build_ext install
cd ..
# python -c "import numpy as np;np.__config__.show()"
rm -rf numpy-1.16.6/

# Python 2.7 SciPy
wget -q --retry-connrefused https://github.com/scipy/scipy/archive/v1.2.3.tar.gz
tar xzf v1.2.3.tar.gz
cd scipy-1.2.3/
python setup.py config build_clib build_ext install
cd ..
# python -c "import scipy as sp;sp.__config__.show()"
rm -rf scipy-1.2.3/

# Python 3.6 Numpy
apt-get install -y -q python3-pip
pip3 install cython
wget -q --retry-connrefused https://github.com/numpy/numpy/archive/v${NUMPY3_VERSION}.tar.gz
tar xzf v${NUMPY3_VERSION}.tar.gz
cd numpy-${NUMPY3_VERSION}/
cp site.cfg.example site.cfg
echo "[mkl]" >> site.cfg
echo "library_dirs = /opt/intel/oneapi/mkl/latest/lib/intel64/" >> site.cfg
echo "include_dirs = /opt/intel/oneapi/mkl/latest/include" >> site.cfg
echo "mkl_libs = mkl_rt" >> site.cfg
echo "lapack_libs =" >> site.cfg
python3 setup.py config build_clib build_ext install
cd ..
# python3 -c "import numpy as np;np.__config__.show()"
rm -rf numpy-${NUMPY3_VERSION}/
tikk3r commented 1 year ago

I was aware of the change of MKL to oneAPI MKL, but this made me notice that the switch to that never made it upstream (it is in my local dev recipe). Thanks for bringing that to light.

The recent addition of site.cfg to the repo was exactly to start linking NumPy etc. against the custom BLAS libraries, so good to see that suggestion as well.

tikk3r commented 1 year ago

Do you happen to know what happens internally when specifying multiple BLAS libraries for e.g. NumPy's site.cfg? It is not entirely clear to me from their documentation whether it link against both dynamically or if it picks what it considers the most efficient one.

AlexKurek commented 1 year ago

No, unfortunately I have no idea. I was always putting there mkl_rt.

tikk3r commented 1 year ago

Fixed in the latest release.