2018-07-08 15:01:03 -07:00
|
|
|
{ stdenv, fetchFromGitHub, fetchpatch, gfortran, perl, which, config, coreutils
|
2016-12-10 14:49:45 -08: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 16:16:06 -07:00
|
|
|
, blas64 ? null
|
|
|
|
}:
|
2014-08-28 14:39:01 -07:00
|
|
|
|
2015-04-17 05:35:19 -07:00
|
|
|
with stdenv.lib;
|
2015-02-26 04:44:03 -08:00
|
|
|
|
2015-10-11 07:16:27 -07:00
|
|
|
let blas64_ = blas64; in
|
|
|
|
|
2016-12-10 14:49:45 -08:00
|
|
|
let
|
|
|
|
# To add support for a new platform, add an element to this set.
|
|
|
|
configs = {
|
2017-12-29 14:19:15 -08:00
|
|
|
armv6l-linux = {
|
|
|
|
BINARY = "32";
|
|
|
|
TARGET = "ARMV6";
|
|
|
|
DYNAMIC_ARCH = "0";
|
|
|
|
CC = "gcc";
|
|
|
|
USE_OPENMP = "1";
|
|
|
|
};
|
|
|
|
|
2016-12-10 14:49:45 -08:00
|
|
|
armv7l-linux = {
|
|
|
|
BINARY = "32";
|
|
|
|
TARGET = "ARMV7";
|
|
|
|
DYNAMIC_ARCH = "0";
|
|
|
|
CC = "gcc";
|
|
|
|
USE_OPENMP = "1";
|
|
|
|
};
|
2014-08-28 14:39:01 -07:00
|
|
|
|
2017-12-07 15:59:50 -08:00
|
|
|
aarch64-linux = {
|
|
|
|
BINARY = "64";
|
|
|
|
TARGET = "ARMV8";
|
|
|
|
DYNAMIC_ARCH = "1";
|
|
|
|
CC = "gcc";
|
|
|
|
USE_OPENMP = "1";
|
|
|
|
};
|
|
|
|
|
2016-12-10 14:49:45 -08:00
|
|
|
i686-linux = {
|
|
|
|
BINARY = "32";
|
|
|
|
TARGET = "P2";
|
|
|
|
DYNAMIC_ARCH = "1";
|
|
|
|
CC = "gcc";
|
|
|
|
USE_OPENMP = "1";
|
|
|
|
};
|
|
|
|
|
|
|
|
x86_64-darwin = {
|
|
|
|
BINARY = "64";
|
|
|
|
TARGET = "ATHLON";
|
|
|
|
DYNAMIC_ARCH = "1";
|
|
|
|
# Note that clang is available through the stdenv on OSX and
|
|
|
|
# thus is not an explicit dependency.
|
|
|
|
CC = "clang";
|
|
|
|
USE_OPENMP = "0";
|
|
|
|
MACOSX_DEPLOYMENT_TARGET = "10.7";
|
|
|
|
};
|
|
|
|
|
|
|
|
x86_64-linux = {
|
|
|
|
BINARY = "64";
|
|
|
|
TARGET = "ATHLON";
|
|
|
|
DYNAMIC_ARCH = "1";
|
|
|
|
CC = "gcc";
|
2018-03-14 17:25:20 -07:00
|
|
|
USE_OPENMP = if stdenv.hostPlatform.isMusl then "0" else "1";
|
2016-12-10 14:49:45 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
let
|
|
|
|
config =
|
2018-08-20 12:11:29 -07:00
|
|
|
configs.${stdenv.hostPlatform.system}
|
|
|
|
or (throw "unsupported system: ${stdenv.hostPlatform.system}");
|
2016-12-10 14:49:45 -08:00
|
|
|
in
|
|
|
|
|
|
|
|
let
|
|
|
|
blas64 =
|
|
|
|
if blas64_ != null
|
|
|
|
then blas64_
|
2018-08-20 12:11:29 -07:00
|
|
|
else hasPrefix "x86_64" stdenv.hostPlatform.system;
|
2015-10-11 07:16:27 -07:00
|
|
|
in
|
2018-03-12 10:40:49 -07:00
|
|
|
stdenv.mkDerivation rec {
|
2014-08-28 14:39:01 -07:00
|
|
|
name = "openblas-${version}";
|
2018-07-01 09:46:36 -07:00
|
|
|
version = "0.3.1";
|
2018-07-08 15:01:03 -07:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "xianyi";
|
|
|
|
repo = "OpenBLAS";
|
|
|
|
rev = "v${version}";
|
|
|
|
sha256 = "1dkwp4gz1hzpmhzks9y9ipb4c5h0r6c7yff62x3s8x9z6f8knaqc";
|
2014-08-28 14:39:01 -07:00
|
|
|
};
|
|
|
|
|
2015-10-11 07:16:27 -07:00
|
|
|
inherit blas64;
|
|
|
|
|
2016-10-20 14:37:50 -07: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 14:49:45 -08:00
|
|
|
# don't interfere with dynamic target detection
|
2016-10-20 14:37:50 -07:00
|
|
|
"relro" "bindnow"
|
|
|
|
];
|
|
|
|
|
2016-12-10 14:49:45 -08:00
|
|
|
nativeBuildInputs =
|
|
|
|
[gfortran perl which]
|
|
|
|
++ optionals stdenv.isDarwin [coreutils];
|
2015-04-17 05:35:19 -07:00
|
|
|
|
|
|
|
makeFlags =
|
|
|
|
[
|
|
|
|
"FC=gfortran"
|
|
|
|
''PREFIX="''$(out)"''
|
2016-12-10 14:49:45 -08:00
|
|
|
"NUM_THREADS=64"
|
2015-06-03 16:16:06 -07:00
|
|
|
"INTERFACE64=${if blas64 then "1" else "0"}"
|
2017-02-12 16:45:44 -08:00
|
|
|
"NO_STATIC=1"
|
2018-01-13 10:10:21 -08:00
|
|
|
] ++ stdenv.lib.optional (stdenv.hostPlatform.libc == "musl") "NO_AFFINITY=1"
|
2016-12-10 14:49:45 -08:00
|
|
|
++ mapAttrsToList (var: val: var + "=" + val) config;
|
2014-08-28 14:39:01 -07:00
|
|
|
|
2018-07-08 15:01:03 -07:00
|
|
|
patches = [
|
|
|
|
# Backport of https://github.com/xianyi/OpenBLAS/pull/1667, which
|
|
|
|
# is causing problems and was already accepted upstream.
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/xianyi/OpenBLAS/commit/5f2a3c05cd0e3872be3c5686b9da6b627658eeb7.patch";
|
|
|
|
sha256 = "1qvxhk92likrshw6z6hjqxvkblwzgsbzis2b2f71bsvx9174qfk1";
|
|
|
|
})
|
2018-07-12 09:48:29 -07:00
|
|
|
# Double "MAX_ALLOCATING_THREADS", fix with Go and Octave
|
|
|
|
# https://github.com/xianyi/OpenBLAS/pull/1663 (see also linked issue)
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/xianyi/OpenBLAS/commit/a49203b48c4a3d6f86413fc8c4b1fbfaa1946463.patch";
|
|
|
|
sha256 = "0v6kjkbgbw7hli6xkism48wqpkypxmcqvxpx564snll049l2xzq2";
|
|
|
|
})
|
2018-07-08 15:01:03 -07:00
|
|
|
];
|
2018-06-07 11:38:08 -07:00
|
|
|
|
2015-10-11 07:16:27 -07:00
|
|
|
doCheck = true;
|
|
|
|
checkTarget = "tests";
|
2015-06-03 16:16:06 -07:00
|
|
|
|
2018-08-17 05:49:52 -07:00
|
|
|
postInstall = ''
|
|
|
|
# Write pkgconfig aliases. Upstream report:
|
|
|
|
# https://github.com/xianyi/OpenBLAS/issues/1740
|
|
|
|
for alias in blas cblas lapack; do
|
|
|
|
cat <<EOF > $out/lib/pkgconfig/openblas-$alias.pc
|
|
|
|
Name: $alias
|
|
|
|
Version: ${version}
|
|
|
|
Description: $alias provided by the OpenBLAS package.
|
|
|
|
Cflags: -I$out/include
|
|
|
|
Libs: -L$out/lib -lopenblas
|
|
|
|
EOF
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2014-08-29 08:02:39 -07:00
|
|
|
meta = with stdenv.lib; {
|
2014-08-28 14:39:01 -07:00
|
|
|
description = "Basic Linear Algebra Subprograms";
|
2014-08-29 08:02:39 -07:00
|
|
|
license = licenses.bsd3;
|
2017-08-01 13:03:30 -07:00
|
|
|
homepage = https://github.com/xianyi/OpenBLAS;
|
2015-11-17 12:29:29 -08:00
|
|
|
platforms = platforms.unix;
|
2014-08-29 08:02:39 -07:00
|
|
|
maintainers = with maintainers; [ ttuegel ];
|
2014-08-28 14:39:01 -07:00
|
|
|
};
|
2018-08-13 23:00:54 -07:00
|
|
|
|
|
|
|
# We use linkName to pass a different name to --with-blas-libs for
|
|
|
|
# fflas-ffpack and linbox, because we use blas on darwin but openblas
|
|
|
|
# elsewhere.
|
|
|
|
# See see https://github.com/NixOS/nixpkgs/pull/45013.
|
|
|
|
passthru.linkName = "openblas";
|
2014-08-28 14:39:01 -07:00
|
|
|
}
|