From 5a500ff0babbb1c5adf58389a774b28b97da7459 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 22 Apr 2020 12:37:04 -0500 Subject: [PATCH 1/4] blas,lapack: use correct name for library To match the soname, we need to use libblas.so.3, liblapack.so.3. --- pkgs/build-support/alternatives/blas/default.nix | 4 ++-- pkgs/build-support/alternatives/lapack/default.nix | 4 ++-- pkgs/development/libraries/science/math/mkl/default.nix | 8 ++++---- .../libraries/science/math/openblas/default.nix | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/alternatives/blas/default.nix b/pkgs/build-support/alternatives/blas/default.nix index 8bba49b4550..bdee6688a74 100644 --- a/pkgs/build-support/alternatives/blas/default.nix +++ b/pkgs/build-support/alternatives/blas/default.nix @@ -63,7 +63,7 @@ stdenv.mkDerivation { installPhase = ('' mkdir -p $out/lib $dev/include $dev/lib/pkgconfig - libblas="${lib.getLib blasProvider}/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}" + libblas="${lib.getLib blasProvider}/lib/libblas${canonicalExtension}" if ! [ -e "$libblas" ]; then echo "$libblas does not exist, ${blasProvider.name} does not provide libblas." @@ -100,7 +100,7 @@ Libs: -L$out/lib -lblas Cflags: -I$dev/include EOF - libcblas="${lib.getLib blasProvider}/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}" + libcblas="${lib.getLib blasProvider}/lib/libcblas${canonicalExtension}" if ! [ -e "$libcblas" ]; then echo "$libcblas does not exist, ${blasProvider.name} does not provide libcblas." diff --git a/pkgs/build-support/alternatives/lapack/default.nix b/pkgs/build-support/alternatives/lapack/default.nix index e260ad1bd93..5a19916f83e 100644 --- a/pkgs/build-support/alternatives/lapack/default.nix +++ b/pkgs/build-support/alternatives/lapack/default.nix @@ -41,7 +41,7 @@ stdenv.mkDerivation { installPhase = ('' mkdir -p $out/lib $dev/include $dev/lib/pkgconfig - liblapack="${lib.getLib lapackProvider}/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}" + liblapack="${lib.getLib lapackProvider}/lib/liblapack${canonicalExtension}" if ! [ -e "$liblapack" ]; then echo "$liblapack does not exist, ${lapackProvider.name} does not provide liblapack." @@ -74,7 +74,7 @@ Cflags: -I$dev/include Libs: -L$out/lib -llapack EOF - liblapacke="${lib.getLib lapackProvider}/lib/liblapacke${stdenv.hostPlatform.extensions.sharedLibrary}" + liblapacke="${lib.getLib lapackProvider}/lib/liblapacke${canonicalExtension}" if ! [ -e "$liblapacke" ]; then echo "$liblapacke does not exist, ${lapackProvider.name} does not provide liblapacke." diff --git a/pkgs/development/libraries/science/math/mkl/default.nix b/pkgs/development/libraries/science/math/mkl/default.nix index f9026ec7b99..ee861c14ab4 100644 --- a/pkgs/development/libraries/science/math/mkl/default.nix +++ b/pkgs/development/libraries/science/math/mkl/default.nix @@ -114,10 +114,10 @@ in stdenvNoCC.mkDerivation { '') + '' # Setup symlinks for blas / lapack - ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/libblas${stdenvNoCC.hostPlatform.extensions.sharedLibrary} - ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/libcblas${stdenvNoCC.hostPlatform.extensions.sharedLibrary} - ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/liblapack${stdenvNoCC.hostPlatform.extensions.sharedLibrary} - ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/liblapacke${stdenvNoCC.hostPlatform.extensions.sharedLibrary} + ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/libblas${stdenvNoCC.hostPlatform.extensions.sharedLibrary}${stdenvNoCC.lib.optionalString stdenvNoCC.hostPlatform.isLinux ".3"} + ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/libcblas${stdenvNoCC.hostPlatform.extensions.sharedLibrary}${stdenvNoCC.lib.optionalString stdenvNoCC.hostPlatform.isLinux ".3"} + ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/liblapack${stdenvNoCC.hostPlatform.extensions.sharedLibrary}${stdenvNoCC.lib.optionalString stdenvNoCC.hostPlatform.isLinux ".3"} + ln -s $out/lib/libmkl_rt${stdenvNoCC.hostPlatform.extensions.sharedLibrary} $out/lib/liblapacke${stdenvNoCC.hostPlatform.extensions.sharedLibrary}${stdenvNoCC.lib.optionalString stdenvNoCC.hostPlatform.isLinux ".3"} ''; # fixDarwinDylibName fails for libmkl_cdft_core.dylib because the diff --git a/pkgs/development/libraries/science/math/openblas/default.nix b/pkgs/development/libraries/science/math/openblas/default.nix index c55a5cb7878..f6a40204587 100644 --- a/pkgs/development/libraries/science/math/openblas/default.nix +++ b/pkgs/development/libraries/science/math/openblas/default.nix @@ -178,10 +178,10 @@ EOF done # Setup symlinks for blas / lapack - ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary} - ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary} - ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary} - ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/liblapacke${stdenv.hostPlatform.extensions.sharedLibrary} + ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}${stdenv.lib.optionalString stdenv.hostPlatform.isLinux ".3"} + ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}${stdenv.lib.optionalString stdenv.hostPlatform.isLinux ".3"} + ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}${stdenv.lib.optionalString stdenv.hostPlatform.isLinux ".3"} + ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/liblapacke${stdenv.hostPlatform.extensions.sharedLibrary}${stdenv.lib.optionalString stdenv.hostPlatform.isLinux ".3"} ''; meta = with stdenv.lib; { From 3d18975478e4f2cc9bd92fd44b7e9d8c331fcec1 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 22 Apr 2020 12:38:28 -0500 Subject: [PATCH 2/4] python.pkgs.scipy: set SCIPY_USE_G77_ABI_WRAPPER=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid segmentation fault on MKL, we need to use the CBLAS ABI. Normally, scipy will autodetect this, but here we don’t link using the ‘libmkl_rt.so’ name. So we need to manually set this. See https://github.com/scipy/scipy/blob/50012918db47f0ec3418dd53f0277daa589f82e3/doc/source/building/linux.rst#fortran-abi-mismatch --- pkgs/development/python-modules/scipy/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/python-modules/scipy/default.nix b/pkgs/development/python-modules/scipy/default.nix index a9947e7e689..ace6c248ab2 100644 --- a/pkgs/development/python-modules/scipy/default.nix +++ b/pkgs/development/python-modules/scipy/default.nix @@ -53,6 +53,8 @@ in buildPythonPackage rec { setupPyBuildFlags = [ "--fcompiler='gnu95'" ]; + SCIPY_USE_G77_ABI_WRAPPER = 1; + meta = { description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering. "; homepage = "https://www.scipy.org/"; From 4238b2b943f0e49fb00588b7080bc848382db36f Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 22 Apr 2020 12:43:14 -0500 Subject: [PATCH 3/4] doc/overlays.xml: fix missing documentation for blas/lapack This adds some more information to the documentation as well as addressing review from https://github.com/NixOS/nixpkgs/pull/85636. --- doc/using/overlays.xml | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/doc/using/overlays.xml b/doc/using/overlays.xml index 5f808839dd0..ada9ab38932 100644 --- a/doc/using/overlays.xml +++ b/doc/using/overlays.xml @@ -140,8 +140,8 @@ self: super:
Using overlays to configure alternatives - Certain software has different implementations of the same - interface. Other distributions have functionality to switch + Certain software packages have different implementations of the + same interface. Other distributions have functionality to switch between these. For example, Debian provides DebianAlternatives. Nixpkgs has what we call alternatives, which @@ -160,8 +160,9 @@ self: super: The Nixpkgs attribute is openblas for - ILP64 and openblasCompat for LP64. This - is the default. + ILP64 (integer width = 64 bits) and + openblasCompat for LP64 (integer width = + 32 bits). openblasCompat is the default. @@ -190,8 +191,15 @@ self: super: #83888, we are able to override the ‘blas’ and ‘lapack’ packages to use different implementations, through the ‘blasProvider’ and ‘lapackProvider’ argument. This can be used - to select a different provider. For example, an overlay can be - created that looks like: + to select a different provider. BLAS providers will have + symlinks in $out/lib/libblas.so.3 and + $out/lib/libcblas.so.3 to their respective + BLAS libraries. Likewise, LAPACK providers will have symlinks + in $out/lib/liblapack.so.3 and + $out/lib/liblapacke.so.3 to their respective + LAPCK libraries. For example, Intel MKL is both a BLAS and + LAPACK provider. An overlay can be created to use Intel MKL + that looks like: self: super: @@ -208,9 +216,12 @@ self: super: This overlay uses Intel’s MKL library for both BLAS and LAPACK interfaces. Note that the same can be accomplished at runtime - using LD_PRELOAD of libblas.so.3 and - liblapack.so.3. + using LD_LIBRARY_PATH of libblas.so.3 and + liblapack.so.3. For instance: + +$ LD_LIBRARY_PATH=$(nix-build -A mkl):$LD_LIBRARY_PATH nix-shell -p octave --run octave + Intel MKL requires an openmp implementation when running with multiple processors. By default, @@ -221,8 +232,8 @@ self: super: set it with LD_PRELOAD. Note that mkl is only available on x86_64-linux and - x86_64-darwin. Moreover, Hydra is not build - and distributing pre-compiled binaries using it. + x86_64-darwin. Moreover, Hydra is not + building and distributing pre-compiled binaries using it. For BLAS/LAPACK switching to work correctly, all packages must From 480a55a6b695939a2e8b1cadc3205080a404c814 Mon Sep 17 00:00:00 2001 From: Benjamin Hipple Date: Wed, 22 Apr 2020 21:54:41 -0400 Subject: [PATCH 4/4] doc/using/overlays.xml: update LD_LIBRARY_PATH example --- doc/using/overlays.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/using/overlays.xml b/doc/using/overlays.xml index ada9ab38932..3fa68e32a3c 100644 --- a/doc/using/overlays.xml +++ b/doc/using/overlays.xml @@ -220,7 +220,7 @@ self: super: liblapack.so.3. For instance: -$ LD_LIBRARY_PATH=$(nix-build -A mkl):$LD_LIBRARY_PATH nix-shell -p octave --run octave +$ LD_LIBRARY_PATH=$(nix-build -A mkl)/lib:$LD_LIBRARY_PATH nix-shell -p octave --run octave Intel MKL requires an openmp implementation