nixpkgs/pkgs/development/libraries/science/math/mkl/default.nix

178 lines
6.7 KiB
Nix
Raw Normal View History

2021-01-27 05:50:30 +00:00
{ lib
, stdenv
, callPackage
, stdenvNoCC
, fetchurl
, rpmextract
, undmg
, darwin
2020-05-15 06:35:44 +00:00
, validatePkgConfig
, enableStatic ? stdenv.hostPlatform.isStatic
}:
/*
For details on using mkl as a blas provider for python packages such as numpy,
numexpr, scipy, etc., see the Python section of the NixPkgs manual.
*/
let
# Release notes and download URLs are here:
# https://registrationcenter.intel.com/en/products/
version = "${year}.${spot}.${rel}";
# Darwin is pinned to 2019.3 because the DMG does not unpack; see here for details:
# https://github.com/matthewbauer/undmg/issues/4
year = if stdenvNoCC.isDarwin then "2019" else "2020";
spot = if stdenvNoCC.isDarwin then "3" else "4";
rel = if stdenvNoCC.isDarwin then "199" else "304";
# Replace `openmpSpot` by `spot` after 2020.
openmpSpot = if stdenvNoCC.isDarwin then spot else "3";
rpm-ver = "${year}.${spot}-${rel}-${year}.${spot}-${rel}";
# Intel openmp uses its own versioning, but shares the spot release patch.
openmp = if stdenvNoCC.isDarwin then "19.0" else "19.1";
openmp-ver = "${openmp}.${openmpSpot}-${rel}-${openmp}.${openmpSpot}-${rel}";
shlibExt = stdenvNoCC.hostPlatform.extensions.sharedLibrary;
in stdenvNoCC.mkDerivation {
pname = "mkl";
inherit version;
2018-10-03 02:53:48 +00:00
src = if stdenvNoCC.isDarwin
then
(fetchurl {
2019-04-01 15:15:22 +00:00
url = "http://registrationcenter-download.intel.com/akdlm/irc_nas/tec/15235/m_mkl_${version}.dmg";
sha256 = "14b3ciz7995sqcd6jz7hc8g2x4zwvqxmgxgni46vrlb7n523l62f";
2018-10-03 02:53:48 +00:00
})
else
(fetchurl {
url = "https://registrationcenter-download.intel.com/akdlm/irc_nas/tec/16917/l_mkl_${version}.tgz";
hash = "sha256-IxTUZTaXTb0I8qTk+emhVdx+eeJ5jHTn3fqtAKWRfqU=";
2018-10-03 02:53:48 +00:00
});
2020-05-15 06:35:44 +00:00
nativeBuildInputs = [ validatePkgConfig ] ++ (if stdenvNoCC.isDarwin
then
[ undmg darwin.cctools ]
else
2020-05-15 06:35:44 +00:00
[ rpmextract ]);
2018-10-03 02:53:48 +00:00
buildPhase = if stdenvNoCC.isDarwin then ''
for f in Contents/Resources/pkg/*.tgz; do
tar xzvf $f
done
2018-10-03 02:53:48 +00:00
'' else ''
# Common stuff
rpmextract rpm/intel-mkl-core-${rpm-ver}.x86_64.rpm
rpmextract rpm/intel-mkl-common-c-${rpm-ver}.noarch.rpm
rpmextract rpm/intel-mkl-common-f-${rpm-ver}.noarch.rpm
# Dynamic libraries
rpmextract rpm/intel-mkl-cluster-rt-${rpm-ver}.x86_64.rpm
rpmextract rpm/intel-mkl-core-rt-${rpm-ver}.x86_64.rpm
rpmextract rpm/intel-mkl-gnu-f-rt-${rpm-ver}.x86_64.rpm
rpmextract rpm/intel-mkl-gnu-rt-${rpm-ver}.x86_64.rpm
# Intel OpenMP runtime
rpmextract rpm/intel-openmp-${openmp-ver}.x86_64.rpm
'' + (if enableStatic then ''
# Static libraries
rpmextract rpm/intel-mkl-cluster-${rpm-ver}.x86_64.rpm
rpmextract rpm/intel-mkl-gnu-${rpm-ver}.x86_64.rpm
rpmextract rpm/intel-mkl-gnu-f-${rpm-ver}.x86_64.rpm
'' else ''
# Take care of installing dynamic-only PkgConfig files during the installPhase
''
);
2019-09-16 15:05:54 +00:00
installPhase = ''
for f in $(find . -name 'mkl*.pc') ; do
bn=$(basename $f)
substituteInPlace $f \
--replace "prefix=<INSTALLDIR>/mkl" "prefix=$out" \
--replace $\{MKLROOT} "$out" \
--replace "lib/intel64_lin" "lib" \
--replace "lib/intel64" "lib"
2019-09-16 15:05:54 +00:00
done
for f in $(find opt/intel -name 'mkl*iomp.pc') ; do
substituteInPlace $f \
--replace "../compiler/lib" "lib"
done
'' +
(if stdenvNoCC.isDarwin then ''
2018-10-03 02:53:48 +00:00
mkdir -p $out/lib
2018-10-03 02:53:48 +00:00
cp -r compilers_and_libraries_${version}/mac/mkl/include $out/
2018-10-03 02:53:48 +00:00
cp -r compilers_and_libraries_${version}/licensing/mkl/en/license.txt $out/lib/
cp -r compilers_and_libraries_${version}/mac/compiler/lib/* $out/lib/
cp -r compilers_and_libraries_${version}/mac/mkl/lib/* $out/lib/
cp -r compilers_and_libraries_${version}/mac/tbb/lib/* $out/lib/
2019-09-16 15:05:54 +00:00
mkdir -p $out/lib/pkgconfig
cp -r compilers_and_libraries_${version}/mac/mkl/bin/pkgconfig/* $out/lib/pkgconfig
2018-10-03 02:53:48 +00:00
'' else ''
mkdir -p $out/lib
cp license.txt $out/lib/
2018-10-03 02:53:48 +00:00
cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/include $out/
mkdir -p $out/lib/pkgconfig
'') +
(if enableStatic then ''
cp -r opt/intel/compilers_and_libraries_${version}/linux/compiler/lib/intel64_lin/* $out/lib/
2018-10-03 02:53:48 +00:00
cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/lib/intel64_lin/* $out/lib/
2019-09-16 15:05:54 +00:00
cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/bin/pkgconfig/* $out/lib/pkgconfig
'' else ''
cp -r opt/intel/compilers_and_libraries_${version}/linux/compiler/lib/intel64_lin/*.so* $out/lib/
cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/lib/intel64_lin/*.so* $out/lib/
cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/bin/pkgconfig/*dynamic*.pc $out/lib/pkgconfig
blas/lapack: add wrapper for “alternative”s of BLAS/LAPACK provider This is based on previous work for switching between BLAS and LAPACK implementation in Debian[1] and Gentoo[2]. The goal is to have one way to depend on the BLAS/LAPACK libraries that all packages must use. The attrs “blas” and “lapack” are used to represent a wrapped BLAS/LAPACK provider. Derivations that don’t care how BLAS and LAPACK are implemented can just use blas and lapack directly. If you do care what you get (perhaps for some CPP), you should verify that blas and lapack match what you expect with an assertion. The “blas” package collides with the old “blas” reference implementation. This has been renamed to “blas-reference”. In addition, “lapack-reference” is also included, corresponding to “liblapack” from Netlib.org. Currently, there are 3 providers of the BLAS and LAPACK interfaces: - lapack-reference: the BLAS/LAPACK implementation maintained by netlib.org - OpenBLAS: an optimized version of BLAS and LAPACK - MKL: Intel’s unfree but highly optimized BLAS/LAPACK implementation By default, the above implementations all use the “LP64” BLAS and LAPACK ABI. This corresponds to “openblasCompat” and is the safest way to use BLAS/LAPACK. You may received some benefits from “ILP64” or 8-byte integer BLAS at the expense of breaking compatibility with some packages. This can be switched at build time with an override like: import <nixpkgs> { config.allowUnfree = true; overlays = [(self: super: { lapack = super.lapack.override { lapackProvider = super.lapack-reference; }; blas = super.blas.override { blasProvider = super.lapack-reference; }; })]; } or, switched at runtime via LD_LIBRARY_PATH like: $ LD_LIBRARY_PATH=$(nix-build -E '(with import <nixpkgs> {}).lapack.override { lapackProvider = pkgs.mkl; is64bit = true; })')/lib:$(nix-build -E '(with import <nixpkgs> {}).blas.override { blasProvider = pkgs.mkl; is64bit = true; })')/lib ./your-blas-linked-binary By default, we use OpenBLAS LP64 also known in Nixpkgs as openblasCompat. [1]: https://wiki.debian.org/DebianScience/LinearAlgebraLibraries [2]: https://wiki.gentoo.org/wiki/Blas-lapack-switch
2020-03-27 18:50:45 +00:00
'') + ''
# Setup symlinks for blas / lapack
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libblas${shlibExt}
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libcblas${shlibExt}
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapack${shlibExt}
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapacke${shlibExt}
2021-01-27 05:50:30 +00:00
'' + lib.optionalString stdenvNoCC.hostPlatform.isLinux ''
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libblas${shlibExt}".3"
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libcblas${shlibExt}".3"
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapack${shlibExt}".3"
ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapacke${shlibExt}".3"
blas/lapack: add wrapper for “alternative”s of BLAS/LAPACK provider This is based on previous work for switching between BLAS and LAPACK implementation in Debian[1] and Gentoo[2]. The goal is to have one way to depend on the BLAS/LAPACK libraries that all packages must use. The attrs “blas” and “lapack” are used to represent a wrapped BLAS/LAPACK provider. Derivations that don’t care how BLAS and LAPACK are implemented can just use blas and lapack directly. If you do care what you get (perhaps for some CPP), you should verify that blas and lapack match what you expect with an assertion. The “blas” package collides with the old “blas” reference implementation. This has been renamed to “blas-reference”. In addition, “lapack-reference” is also included, corresponding to “liblapack” from Netlib.org. Currently, there are 3 providers of the BLAS and LAPACK interfaces: - lapack-reference: the BLAS/LAPACK implementation maintained by netlib.org - OpenBLAS: an optimized version of BLAS and LAPACK - MKL: Intel’s unfree but highly optimized BLAS/LAPACK implementation By default, the above implementations all use the “LP64” BLAS and LAPACK ABI. This corresponds to “openblasCompat” and is the safest way to use BLAS/LAPACK. You may received some benefits from “ILP64” or 8-byte integer BLAS at the expense of breaking compatibility with some packages. This can be switched at build time with an override like: import <nixpkgs> { config.allowUnfree = true; overlays = [(self: super: { lapack = super.lapack.override { lapackProvider = super.lapack-reference; }; blas = super.blas.override { blasProvider = super.lapack-reference; }; })]; } or, switched at runtime via LD_LIBRARY_PATH like: $ LD_LIBRARY_PATH=$(nix-build -E '(with import <nixpkgs> {}).lapack.override { lapackProvider = pkgs.mkl; is64bit = true; })')/lib:$(nix-build -E '(with import <nixpkgs> {}).blas.override { blasProvider = pkgs.mkl; is64bit = true; })')/lib ./your-blas-linked-binary By default, we use OpenBLAS LP64 also known in Nixpkgs as openblasCompat. [1]: https://wiki.debian.org/DebianScience/LinearAlgebraLibraries [2]: https://wiki.gentoo.org/wiki/Blas-lapack-switch
2020-03-27 18:50:45 +00:00
'';
# fixDarwinDylibName fails for libmkl_cdft_core.dylib because the
# larger updated load commands do not fit. Use install_name_tool
# explicitly and ignore the error.
2021-01-27 05:50:30 +00:00
postFixup = lib.optionalString stdenvNoCC.isDarwin ''
for f in $out/lib/*.dylib; do
install_name_tool -id $out/lib/$(basename $f) $f || true
done
install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libmkl_intel_thread.dylib
install_name_tool -change @rpath/libtbb.dylib $out/lib/libtbb.dylib $out/lib/libmkl_tbb_thread.dylib
install_name_tool -change @rpath/libtbbmalloc.dylib $out/lib/libtbbmalloc.dylib $out/lib/libtbbmalloc_proxy.dylib
'';
# Per license agreement, do not modify the binary
dontStrip = true;
dontPatchELF = true;
passthru.tests.pkg-config = callPackage ./test { };
2021-01-27 05:50:30 +00:00
meta = with lib; {
description = "Intel Math Kernel Library";
longDescription = ''
Intel Math Kernel Library (Intel MKL) optimizes code with minimal effort
for future generations of Intel processors. It is compatible with your
choice of compilers, languages, operating systems, and linking and
threading models.
'';
homepage = "https://software.intel.com/en-us/mkl";
license = licenses.issl;
2018-10-03 02:53:48 +00:00
platforms = [ "x86_64-linux" "x86_64-darwin" ];
maintainers = with maintainers; [ bhipple ];
};
2019-09-16 15:05:54 +00:00
}