2019-06-16 19:59:06 +00:00
|
|
|
{ stdenv, fetchFromGitHub, perl, which
|
2016-12-10 22:49:45 +00:00
|
|
|
# Most packages depending on openblas expect integer width to match
|
|
|
|
# pointer width, but some expect to use 32-bit integers always
|
|
|
|
# (for compatibility with reference BLAS).
|
2015-06-03 23:16:06 +00:00
|
|
|
, blas64 ? null
|
2020-04-05 18:12:15 +00:00
|
|
|
# Multi-threaded applications must not call a threaded OpenBLAS
|
|
|
|
# (the only exception is when an application uses OpenMP as its
|
|
|
|
# *only* form of multi-threading). See
|
|
|
|
# https://github.com/xianyi/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
|
|
|
|
# https://github.com/xianyi/OpenBLAS/issues/2543
|
|
|
|
# This flag builds a single-threaded OpenBLAS using the flags
|
|
|
|
# stated in thre.
|
|
|
|
, singleThreaded ? false
|
2019-01-05 12:46:40 +00:00
|
|
|
, buildPackages
|
2019-02-01 08:22:29 +00:00
|
|
|
# Select a specific optimization target (other than the default)
|
2019-01-29 13:34:02 +00:00
|
|
|
# See https://github.com/xianyi/OpenBLAS/blob/develop/TargetList.txt
|
|
|
|
, target ? null
|
2019-05-17 02:45:42 +00:00
|
|
|
, enableStatic ? false
|
2020-01-02 17:53:00 +00:00
|
|
|
, enableShared ? true
|
2015-06-03 23:16:06 +00:00
|
|
|
}:
|
2014-08-28 21:39:01 +00:00
|
|
|
|
2015-04-17 12:35:19 +00:00
|
|
|
with stdenv.lib;
|
2015-02-26 12:44:03 +00:00
|
|
|
|
2015-10-11 14:16:27 +00:00
|
|
|
let blas64_ = blas64; in
|
|
|
|
|
2016-12-10 22:49:45 +00:00
|
|
|
let
|
2019-01-29 13:34:02 +00:00
|
|
|
setTarget = x: if target == null then x else target;
|
|
|
|
|
2016-12-10 22:49:45 +00:00
|
|
|
# To add support for a new platform, add an element to this set.
|
|
|
|
configs = {
|
2017-12-29 22:19:15 +00:00
|
|
|
armv6l-linux = {
|
2019-01-15 15:36:07 +00:00
|
|
|
BINARY = 32;
|
2019-01-29 13:34:02 +00:00
|
|
|
TARGET = setTarget "ARMV6";
|
2019-01-15 15:36:07 +00:00
|
|
|
DYNAMIC_ARCH = false;
|
|
|
|
USE_OPENMP = true;
|
2017-12-29 22:19:15 +00:00
|
|
|
};
|
|
|
|
|
2016-12-10 22:49:45 +00:00
|
|
|
armv7l-linux = {
|
2019-01-15 15:36:07 +00:00
|
|
|
BINARY = 32;
|
2019-01-29 13:34:02 +00:00
|
|
|
TARGET = setTarget "ARMV7";
|
2019-01-15 15:36:07 +00:00
|
|
|
DYNAMIC_ARCH = false;
|
|
|
|
USE_OPENMP = true;
|
2016-12-10 22:49:45 +00:00
|
|
|
};
|
2014-08-28 21:39:01 +00:00
|
|
|
|
2017-12-07 23:59:50 +00:00
|
|
|
aarch64-linux = {
|
2019-01-15 15:36:07 +00:00
|
|
|
BINARY = 64;
|
2019-01-29 13:34:02 +00:00
|
|
|
TARGET = setTarget "ARMV8";
|
2019-01-15 15:36:07 +00:00
|
|
|
DYNAMIC_ARCH = true;
|
|
|
|
USE_OPENMP = true;
|
2017-12-07 23:59:50 +00:00
|
|
|
};
|
|
|
|
|
2016-12-10 22:49:45 +00:00
|
|
|
i686-linux = {
|
2019-01-15 15:36:07 +00:00
|
|
|
BINARY = 32;
|
2019-01-29 13:34:02 +00:00
|
|
|
TARGET = setTarget "P2";
|
2019-01-15 15:36:07 +00:00
|
|
|
DYNAMIC_ARCH = true;
|
|
|
|
USE_OPENMP = true;
|
2016-12-10 22:49:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
x86_64-darwin = {
|
2019-01-15 15:36:07 +00:00
|
|
|
BINARY = 64;
|
2019-01-29 13:34:02 +00:00
|
|
|
TARGET = setTarget "ATHLON";
|
2019-01-15 15:36:07 +00:00
|
|
|
DYNAMIC_ARCH = true;
|
|
|
|
USE_OPENMP = false;
|
2016-12-10 22:49:45 +00:00
|
|
|
MACOSX_DEPLOYMENT_TARGET = "10.7";
|
|
|
|
};
|
|
|
|
|
|
|
|
x86_64-linux = {
|
2019-01-15 15:36:07 +00:00
|
|
|
BINARY = 64;
|
2019-01-29 13:34:02 +00:00
|
|
|
TARGET = setTarget "ATHLON";
|
2019-01-15 15:36:07 +00:00
|
|
|
DYNAMIC_ARCH = true;
|
2019-04-23 14:00:54 +00:00
|
|
|
NO_AVX512 = true;
|
2020-01-02 17:53:00 +00:00
|
|
|
USE_OPENMP = !stdenv.hostPlatform.isMusl;
|
2016-12-10 22:49:45 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
let
|
|
|
|
config =
|
2018-08-20 19:11:29 +00:00
|
|
|
configs.${stdenv.hostPlatform.system}
|
|
|
|
or (throw "unsupported system: ${stdenv.hostPlatform.system}");
|
2016-12-10 22:49:45 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
let
|
|
|
|
blas64 =
|
|
|
|
if blas64_ != null
|
|
|
|
then blas64_
|
2018-08-20 19:11:29 +00:00
|
|
|
else hasPrefix "x86_64" stdenv.hostPlatform.system;
|
2019-02-12 08:45:32 +00:00
|
|
|
# Convert flag values to format OpenBLAS's build expects.
|
|
|
|
# `toString` is almost what we need other than bools,
|
|
|
|
# which we need to map {true -> 1, false -> 0}
|
|
|
|
# (`toString` produces empty string `""` for false instead of `0`)
|
|
|
|
mkMakeFlagValue = val:
|
|
|
|
if !builtins.isBool val then toString val
|
|
|
|
else if val then "1" else "0";
|
|
|
|
mkMakeFlagsFromConfig = mapAttrsToList (var: val: "${var}=${mkMakeFlagValue val}");
|
2015-10-11 14:16:27 +00:00
|
|
|
in
|
2018-03-12 17:40:49 +00:00
|
|
|
stdenv.mkDerivation rec {
|
2019-08-15 12:41:18 +00:00
|
|
|
pname = "openblas";
|
2020-04-28 14:17:32 +00:00
|
|
|
version = "0.3.9";
|
2018-07-08 22:01:03 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "xianyi";
|
|
|
|
repo = "OpenBLAS";
|
|
|
|
rev = "v${version}";
|
2020-04-28 14:17:32 +00:00
|
|
|
sha256 = "0nq51j45shb32n6086xff3x374kx5qhr2cwjzvppx4s2z0ahflal";
|
2014-08-28 21:39:01 +00:00
|
|
|
};
|
|
|
|
|
2015-10-11 14:16:27 +00:00
|
|
|
inherit blas64;
|
|
|
|
|
2016-10-20 21:37:50 +00:00
|
|
|
# Some hardening features are disabled due to sporadic failures in
|
|
|
|
# OpenBLAS-based programs. The problem may not be with OpenBLAS itself, but
|
|
|
|
# with how these flags interact with hardening measures used downstream.
|
|
|
|
# In either case, OpenBLAS must only be used by trusted code--it is
|
|
|
|
# inherently unsuitable for security-conscious applications--so there should
|
|
|
|
# be no objection to disabling these hardening measures.
|
|
|
|
hardeningDisable = [
|
|
|
|
# don't modify or move the stack
|
|
|
|
"stackprotector" "pic"
|
|
|
|
# don't alter index arithmetic
|
|
|
|
"strictoverflow"
|
2016-12-10 22:49:45 +00:00
|
|
|
# don't interfere with dynamic target detection
|
2016-10-20 21:37:50 +00:00
|
|
|
"relro" "bindnow"
|
|
|
|
];
|
|
|
|
|
2019-02-11 01:16:16 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
perl
|
|
|
|
which
|
2019-12-19 12:14:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
depsBuildBuild = [
|
2019-02-11 01:16:16 +00:00
|
|
|
buildPackages.gfortran
|
|
|
|
buildPackages.stdenv.cc
|
|
|
|
];
|
2015-04-17 12:35:19 +00:00
|
|
|
|
2020-03-14 12:13:19 +00:00
|
|
|
# Disable an optimisation which seems to cause issues, pending an
|
|
|
|
# upstream fix: https://github.com/xianyi/OpenBLAS/issues/2496
|
|
|
|
patches = stdenv.lib.optionals stdenv.hostPlatform.isAarch64 [
|
|
|
|
./0001-Disable-optimised-aarch64-dgemm_beta-pending-fix.patch
|
|
|
|
];
|
|
|
|
|
2019-02-12 08:45:32 +00:00
|
|
|
makeFlags = mkMakeFlagsFromConfig (config // {
|
2019-01-15 15:36:07 +00:00
|
|
|
FC = "${stdenv.cc.targetPrefix}gfortran";
|
2019-02-10 23:49:04 +00:00
|
|
|
CC = "${stdenv.cc.targetPrefix}${if stdenv.cc.isClang then "clang" else "cc"}";
|
2019-01-15 15:36:07 +00:00
|
|
|
PREFIX = placeholder "out";
|
|
|
|
NUM_THREADS = 64;
|
|
|
|
INTERFACE64 = blas64;
|
2019-05-17 02:45:42 +00:00
|
|
|
NO_STATIC = !enableStatic;
|
2020-01-02 17:53:00 +00:00
|
|
|
NO_SHARED = !enableShared;
|
2019-01-15 15:36:07 +00:00
|
|
|
CROSS = stdenv.hostPlatform != stdenv.buildPlatform;
|
2019-02-10 23:49:04 +00:00
|
|
|
HOSTCC = "cc";
|
2019-02-22 18:46:58 +00:00
|
|
|
# Makefile.system only checks defined status
|
2019-03-30 16:55:24 +00:00
|
|
|
# This seems to be a bug in the openblas Makefile:
|
|
|
|
# on x86_64 it expects NO_BINARY_MODE=
|
|
|
|
# but on aarch64 it expects NO_BINARY_MODE=0
|
|
|
|
NO_BINARY_MODE = if stdenv.isx86_64
|
|
|
|
then toString (stdenv.hostPlatform != stdenv.buildPlatform)
|
|
|
|
else stdenv.hostPlatform != stdenv.buildPlatform;
|
2020-04-05 18:12:15 +00:00
|
|
|
} // (stdenv.lib.optionalAttrs singleThreaded {
|
|
|
|
# As described on https://github.com/xianyi/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
|
|
|
|
USE_THREAD = false;
|
|
|
|
USE_LOCKING = true; # available with openblas >= 0.3.7
|
|
|
|
USE_OPENMP = false; # openblas will refuse building with both USE_OPENMP=1 and USE_THREAD=0
|
|
|
|
}));
|
2019-01-15 15:36:07 +00:00
|
|
|
|
|
|
|
doCheck = true;
|
2015-10-11 14:16:27 +00:00
|
|
|
checkTarget = "tests";
|
2015-06-03 23:16:06 +00:00
|
|
|
|
2018-08-17 12:49:52 +00:00
|
|
|
postInstall = ''
|
|
|
|
# Write pkgconfig aliases. Upstream report:
|
|
|
|
# https://github.com/xianyi/OpenBLAS/issues/1740
|
|
|
|
for alias in blas cblas lapack; do
|
2018-09-03 21:56:40 +00:00
|
|
|
cat <<EOF > $out/lib/pkgconfig/$alias.pc
|
2018-08-17 12:49:52 +00:00
|
|
|
Name: $alias
|
|
|
|
Version: ${version}
|
|
|
|
Description: $alias provided by the OpenBLAS package.
|
|
|
|
Cflags: -I$out/include
|
|
|
|
Libs: -L$out/lib -lopenblas
|
|
|
|
EOF
|
|
|
|
done
|
2020-03-27 18:50:45 +00:00
|
|
|
|
|
|
|
# Setup symlinks for blas / lapack
|
2020-05-06 19:52:33 +00:00
|
|
|
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}
|
|
|
|
'' + stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
|
|
|
|
ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}.3
|
|
|
|
ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}.3
|
|
|
|
ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}.3
|
|
|
|
ln -s $out/lib/libopenblas${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/liblapacke${stdenv.hostPlatform.extensions.sharedLibrary}.3
|
|
|
|
'';
|
2018-08-17 12:49:52 +00:00
|
|
|
|
2014-08-29 15:02:39 +00:00
|
|
|
meta = with stdenv.lib; {
|
2014-08-28 21:39:01 +00:00
|
|
|
description = "Basic Linear Algebra Subprograms";
|
2014-08-29 15:02:39 +00:00
|
|
|
license = licenses.bsd3;
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "https://github.com/xianyi/OpenBLAS";
|
2015-11-17 20:29:29 +00:00
|
|
|
platforms = platforms.unix;
|
2014-08-29 15:02:39 +00:00
|
|
|
maintainers = with maintainers; [ ttuegel ];
|
2014-08-28 21:39:01 +00:00
|
|
|
};
|
|
|
|
}
|