Merge pull request #85636 from matthewbauer/blas-lapack-fix-fallout-from-83888

BLAS/LAPACK fix fallout from #83888
This commit is contained in:
Frederik Rietdijk 2020-04-21 19:59:16 +02:00 committed by GitHub
commit ec21df329a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 176 additions and 86 deletions

View File

@ -1290,32 +1290,9 @@ self: super: {
### How to use Intel's MKL with numpy and scipy?
A `site.cfg` is created that configures BLAS based on the `blas` parameter of
the `numpy` derivation. By passing in `mkl`, `numpy` and packages depending on
`numpy` will be built with `mkl`.
The following is an overlay that configures `numpy` to use `mkl`:
```nix
self: super: {
python37 = super.python37.override {
packageOverrides = python-self: python-super: {
numpy = python-super.numpy.override {
blas = super.pkgs.mkl;
};
};
};
}
```
`mkl` requires an `openmp` implementation when running with multiple processors.
By default, `mkl` will use Intel's `iomp` implementation if no other is
specified, but this is a runtime-only dependency and binary compatible with the
LLVM implementation. To use that one instead, Intel recommends users set it with
`LD_PRELOAD`.
Note that `mkl` is only available on `x86_64-{linux,darwin}` platforms;
moreover, Hydra is not building and distributing pre-compiled binaries using it.
MKL can be configured using an overlay. See the section “[Using
overlays to configure
alternatives](#sec-overlays-alternatives-blas-lapack)”.
### What inputs do `setup_requires`, `install_requires` and `tests_require` map to?

View File

@ -137,4 +137,118 @@ self: super:
Overlays are similar to other methods for customizing Nixpkgs, in particular the <literal>packageOverrides</literal> attribute described in <xref linkend="sec-modify-via-packageOverrides"/>. Indeed, <literal>packageOverrides</literal> acts as an overlay with only the <varname>super</varname> argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute.
</para>
</section>
<section xml:id="sec-overlays-alternatives">
<title>Using overlays to configure alternatives</title>
<para>
Certain software has different implementations of the same
interface. Other distributions have functionality to switch
between these. For example, Debian provides <link
xlink:href="https://wiki.debian.org/DebianAlternatives">DebianAlternatives</link>.
Nixpkgs has what we call <literal>alternatives</literal>, which
are configured through overlays.
</para>
<section xml:id="sec-overlays-alternatives-blas-lapack">
<title>BLAS/LAPACK</title>
<para>
In Nixpkgs, we have multiple implementations of the BLAS/LAPACK
numerical linear algebra interfaces. They are:
</para>
<itemizedlist>
<listitem>
<para>
<link xlink:href="https://www.openblas.net/">OpenBLAS</link>
</para>
<para>
The Nixpkgs attribute is <literal>openblas</literal> for
ILP64 and <literal>openblasCompat</literal> for LP64. This
is the default.
</para>
</listitem>
<listitem>
<para>
<link xlink:href="http://www.netlib.org/lapack/">LAPACK
reference</link> (also provides BLAS)
</para>
<para>
The Nixpkgs attribute is <literal>lapack-reference</literal>.
</para>
</listitem>
<listitem>
<para>
<link
xlink:href="https://software.intel.com/en-us/mkl">Intel
MKL</link> (only works on x86 architecture, unfree)
</para>
<para>
The Nixpkgs attribute is <literal>mkl</literal>.
</para>
</listitem>
</itemizedlist>
<para>
Introduced in <link
xlink:href="https://github.com/NixOS/nixpkgs/pull/83888">PR
#83888</link>, 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:
</para>
<programlisting>
self: super:
{
blas = super.blas.override {
blasProvider = self.mkl;
}
lapack = super.lapack.override {
lapackProvider = self.mkl;
}
}
</programlisting>
<para>
This overlay uses Intels MKL library for both BLAS and LAPACK
interfaces. Note that the same can be accomplished at runtime
using <literal>LD_PRELOAD</literal> of libblas.so.3 and
liblapack.so.3.
</para>
<para>
Intel MKL requires an <literal>openmp</literal> implementation
when running with multiple processors. By default,
<literal>mkl</literal> will use Intels <literal>iomp</literal>
implementation if no other is specified, but this is a
runtime-only dependency and binary compatible with the LLVM
implementation. To use that one instead, Intel recommends users
set it with <literal>LD_PRELOAD</literal>. Note that
<literal>mkl</literal> is only available on
<literal>x86_64-linux</literal> and
<literal>x86_64-darwin</literal>. Moreover, Hydra is not build
and distributing pre-compiled binaries using it.
</para>
<para>
For BLAS/LAPACK switching to work correctly, all packages must
depend on <literal>blas</literal> or <literal>lapack</literal>.
This ensures that only one BLAS/LAPACK library is used at one
time. There are two versions versions of BLAS/LAPACK currently
in the wild, <literal>LP64</literal> (integer size = 32 bits)
and <literal>ILP64</literal> (integer size = 64 bits). Some
software needs special flags or patches to work with
<literal>ILP64</literal>. You can check if
<literal>ILP64</literal> is used in Nixpkgs with
<varname>blas.isILP64</varname> and
<varname>lapack.isILP64</varname>. Some software does NOT work
with <literal>ILP64</literal>, and derivations need to specify
an assertion to prevent this. You can prevent
<literal>ILP64</literal> from being used with the following:
</para>
<programlisting>
{ stdenv, blas, lapack, ... }:
assert (!blas.isILP64) &amp;&amp; (!lapack.isILP64);
stdenv.mkDerivation {
...
}
</programlisting>
</section>
</section>
</chapter>

View File

@ -2,7 +2,7 @@
, libyaml, libxc, fftw, blas, lapack, gsl, netcdf, arpack, autoreconfHook
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "octopus";

View File

@ -13,7 +13,7 @@
assert pythonSupport -> pythonPackages != null;
assert opencvSupport -> opencv != null;
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
let
pname = "shogun";

View File

@ -9,7 +9,7 @@
, static ? false
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
name = "R-3.6.3";

View File

@ -5,7 +5,7 @@
}:
assert enableGUI -> libGLU != null && libGL != null && xorg != null && fltk != null;
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "giac${lib.optionalString enableGUI "-with-xcas"}";

View File

@ -1,7 +1,7 @@
{ stdenv, fetchurl, cmake, blas, lapack, gfortran, gmm, fltk, libjpeg
, zlib, libGL, libGLU, xorg, opencascade-occt }:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "gmsh";

View File

@ -54,7 +54,7 @@
, less
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
# This generates a `sage-env` shell file that will be sourced by sage on startup.
# It sets up various environment variables, telling sage where to find its

View File

@ -23,7 +23,7 @@
}:
# lots of segfaults with (64 bit) blas
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
# Wrapper that combined `sagelib` with `sage-env` to produce an actually
# executable sage. No tests are run yet and no documentation is built.

View File

@ -53,7 +53,7 @@
, pplpy
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
# This is the core sage python package. Everything else is just wrappers gluing
# stuff together. It is not very useful on its own though, since it will not

View File

@ -1,7 +1,7 @@
{ lib, stdenv
, lapack-reference, openblasCompat, openblas
, is64bit ? false
, blasProvider ? if is64bit then openblas else openblasCompat }:
, isILP64 ? false
, blasProvider ? if isILP64 then openblas else openblasCompat }:
let
blasFortranSymbols = [
@ -31,12 +31,12 @@ let
else stdenv.hostPlatform.extensions.sharedLibrary;
is64bit = blasProvider.blas64 or false;
isILP64 = blasProvider.blas64 or false;
blasImplementation = lib.getName blasProvider;
in
assert is64bit -> (blasImplementation == "openblas" && blasProvider.blas64) || blasImplementation == "mkl";
assert isILP64 -> (blasImplementation == "openblas" && blasProvider.blas64) || blasImplementation == "mkl";
stdenv.mkDerivation {
pname = "blas";
@ -49,7 +49,7 @@ stdenv.mkDerivation {
};
passthru = {
inherit is64bit;
inherit isILP64;
provider = blasProvider;
implementation = blasImplementation;
};
@ -58,6 +58,8 @@ stdenv.mkDerivation {
dontConfigure = true;
unpackPhase = "src=$PWD";
dontPatchELF = true;
installPhase = (''
mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
@ -132,6 +134,8 @@ Libs: -L$out/lib -lcblas
EOF
'' + stdenv.lib.optionalString (blasImplementation == "mkl") ''
mkdir -p $out/nix-support
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString is64bit "I"}LP64,GNU' > $out/nix-support/setup-hook
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
ln -s $out/lib/libblas${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
ln -sf ${blasProvider}/include/* $dev/include
'');
}

View File

@ -1,7 +1,7 @@
{ lib, stdenv
, lapack-reference, openblasCompat, openblas
, is64bit ? false
, lapackProvider ? if is64bit then openblas else openblasCompat }:
, isILP64 ? false
, lapackProvider ? if isILP64 then openblas else openblasCompat }:
let
@ -14,7 +14,7 @@ let
in
assert is64bit -> (lapackImplementation == "openblas" && lapackProvider.blas64) || lapackImplementation == "mkl";
assert isILP64 -> (lapackImplementation == "openblas" && lapackProvider.blas64) || lapackImplementation == "mkl";
stdenv.mkDerivation {
pname = "lapack";
@ -27,7 +27,7 @@ stdenv.mkDerivation {
};
passthru = {
inherit is64bit;
inherit isILP64;
provider = lapackProvider;
implementation = lapackImplementation;
};
@ -36,6 +36,8 @@ stdenv.mkDerivation {
dontConfigure = true;
unpackPhase = "src=$PWD";
dontPatchELF = true;
installPhase = (''
mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
@ -106,6 +108,8 @@ Libs: -L$out/lib -llapacke
EOF
'' + stdenv.lib.optionalString (lapackImplementation == "mkl") ''
mkdir -p $out/nix-support
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString is64bit "I"}LP64,GNU' > $out/nix-support/setup-hook
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
ln -s $out/lib/liblapack${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
ln -sf ${lapackProvider}/include/* $dev/include
'');
}

View File

@ -12,7 +12,7 @@
, CoreServices, ApplicationServices
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
with stdenv.lib;
@ -88,7 +88,7 @@ stdenv.mkDerivation rec {
"SHELL=${stdenv.shell}"
"USE_SYSTEM_BLAS=1"
"USE_BLAS64=${if blas.is64bit then "1" else "0"}"
"USE_BLAS64=${if blas.isILP64 then "1" else "0"}"
"USE_SYSTEM_LAPACK=1"

View File

@ -22,7 +22,7 @@
with stdenv.lib;
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
let
dsfmtVersion = "2.2.3";
@ -137,7 +137,7 @@ stdenv.mkDerivation rec {
"SHELL=${stdenv.shell}"
"USE_SYSTEM_BLAS=1"
"USE_BLAS64=${if blas.is64bit then "1" else "0"}"
"USE_BLAS64=${if blas.isILP64 then "1" else "0"}"
"USE_SYSTEM_LAPACK=1"

View File

@ -53,7 +53,7 @@
, darwin
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
version = "5.2.0";
@ -125,12 +125,12 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true;
# See https://savannah.gnu.org/bugs/?50339
F77_INTEGER_8_FLAG = if blas.is64bit then "-fdefault-integer-8" else "";
F77_INTEGER_8_FLAG = if blas.isILP64 then "-fdefault-integer-8" else "";
configureFlags = [
"--with-blas=blas"
"--with-lapack=lapack"
(if blas.is64bit then "--enable-64" else "--disable-64")
(if blas.isILP64 then "--enable-64" else "--disable-64")
]
++ (if stdenv.isDarwin then [ "--enable-link-all-dependencies" ] else [ ])
++ stdenv.lib.optionals enableReadline [ "--enable-readline" ]

View File

@ -2,7 +2,7 @@
, gmpxx
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "fflas-ffpack";

View File

@ -10,7 +10,7 @@
, withSage ? false # sage support
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "linbox";

View File

@ -18,7 +18,7 @@ stdenv.mkDerivation {
-e 's,^LAPACK=.*,LAPACK=-L${lapack}/lib -llapack,' \
Makeconf
''
+ stdenv.lib.optionalString blas.is64bit
+ stdenv.lib.optionalString blas.isILP64
''
sed -i Makeconf -e '/^FFLAGS=.*/ s/$/-fdefault-integer-8/'
'';

View File

@ -27,7 +27,7 @@ stdenv.mkDerivation {
cmakeFlags = [
"-DBUILD_SHARED_LIBS=ON"
"-DINTERFACE64=${optionalString blas.is64bit "1"}"
"-DINTERFACE64=${optionalString blas.isILP64 "1"}"
];
preCheck = if stdenv.isDarwin then ''

View File

@ -1,6 +1,6 @@
{ stdenv, fetchurl, unzip, blas, lapack, gfortran }:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "ipopt";

View File

@ -1,8 +1,4 @@
{ stdenv, fetchurl, cmake, gfortran, cudatoolkit, libpthreadstubs, lapack, blas
, mklSupport ? false, mkl ? null
}:
assert !mklSupport || mkl != null;
{ stdenv, fetchurl, cmake, gfortran, cudatoolkit, libpthreadstubs, lapack, blas }:
with stdenv.lib;
@ -17,13 +13,10 @@ in stdenv.mkDerivation {
name = "magma-${version}.tar.gz";
};
buildInputs = [ gfortran cudatoolkit libpthreadstubs cmake ]
++ (if mklSupport then [ mkl ] else [ lapack blas ]);
buildInputs = [ gfortran cudatoolkit libpthreadstubs cmake lapack blas ];
doCheck = false;
MKLROOT = optionalString mklSupport mkl;
preConfigure = ''
export CC=${cudatoolkit.cc}/bin/gcc CXX=${cudatoolkit.cc}/bin/g++
'';

View File

@ -2,7 +2,7 @@
, gfortran, mpi, blas, lapack
} :
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "scalapack";

View File

@ -1,6 +1,6 @@
{ stdenv, fetchFromGitHub, blas, lapack, gfortran, fixDarwinDylibNames }:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "scs";

View File

@ -1,7 +1,7 @@
{ stdenv, fetchurl, gfortran, blas, lapack }:
let
int_t = if blas.is64bit then "int64_t" else "int32_t";
int_t = if blas.isILP64 then "int64_t" else "int32_t";
in
stdenv.mkDerivation rec {
version = "4.2.1";

View File

@ -6,7 +6,7 @@ let
version = "4.4.4";
name = "suitesparse-${version}";
int_t = if blas.is64bit then "int64_t" else "int32_t";
int_t = if blas.isILP64 then "int64_t" else "int32_t";
SHLIB_EXT = stdenv.hostPlatform.extensions.sharedLibrary;
in
stdenv.mkDerivation {

View File

@ -44,7 +44,7 @@ stdenv.mkDerivation rec {
"BLAS=-lblas"
"LAPACK=-llapack"
"MY_METIS_LIB=-lmetis"
] ++ stdenv.lib.optionals blas.is64bit [
] ++ stdenv.lib.optionals blas.isILP64 [
"CFLAGS=-DBLAS64"
] ++ stdenv.lib.optionals enableCuda [
"CUDA_PATH=${cudatoolkit}"

View File

@ -1,7 +1,7 @@
{ stdenv, fetchurl, cmake,
gfortran, blas, lapack}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
version = "5.2.1";

View File

@ -8,7 +8,7 @@
, gfortran
, lapackSupport ? true }:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "sundials";

View File

@ -7,7 +7,7 @@
, gfortran
, lapackSupport ? true }:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "sundials";

View File

@ -1,7 +1,7 @@
{ stdenv, fetchFromGitHub, darwin, ocaml, findlib, dune, base, stdio, lapack, blas }:
assert stdenv.lib.versionAtLeast (stdenv.lib.getVersion ocaml) "4.05.0";
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "ocaml${ocaml.version}-lacaml";

View File

@ -11,7 +11,7 @@
, npy
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
assert blas.implementation == "openblas" && lapack.implementation == "openblas";
buildDunePackage rec {

View File

@ -14,7 +14,7 @@
, withFftw ? true
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
buildPythonPackage rec {
pname = "cvxopt";

View File

@ -12,18 +12,16 @@
, setuptoolsBuildHook
}:
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
let
cfg = writeTextFile {
name = "site.cfg";
text = (lib.generators.toINI {} {
${blas.implementation} = {
include_dirs = "${blas}/include:${lapack}/include";
include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include";
library_dirs = "${blas}/lib:${lapack}/lib";
} // lib.optionalAttrs (blas.implementation == "mkl") {
mkl_libs = "mkl_rt";
lapack_libs = "";
libraries = "lapack,lapacke,blas,cblas";
};
});
};

View File

@ -1,6 +1,6 @@
{ stdenv, fetchurl, blas, lapack, mpi } :
assert (!blas.is64bit) && (!lapack.is64bit);
assert (!blas.isILP64) && (!lapack.isILP64);
stdenv.mkDerivation rec {
pname = "hpl";

View File

@ -59,7 +59,7 @@ in
{
blas = mapListToAttrs supportedSystems (system': let system = lib.systems.elaborate { system = system'; };
in mapListToAttrs (blasProviders system) (provider: let
is64bit = builtins.elem provider (["mkl64"] ++ lib.optional system.is64bit "openblas");
isILP64 = builtins.elem provider (["mkl64"] ++ lib.optional system.is64bit "openblas");
pkgs = pkgsFun {
config = { inherit allowUnfree; };
system = system';
@ -68,13 +68,13 @@ in
lapackProvider = if provider == "mkl64"
then super.mkl
else builtins.getAttr provider super;
inherit is64bit;
inherit isILP64;
};
blas = super.blas.override {
blasProvider = if provider == "mkl64"
then super.mkl
else builtins.getAttr provider super;
inherit is64bit;
inherit isILP64;
};
})];
};