2020-02-11 19:02:43 +00:00
|
|
|
{ stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, gfortran
|
|
|
|
, openblas
|
|
|
|
, cmake
|
|
|
|
, fixDarwinDylibNames
|
2019-01-01 14:47:55 +00:00
|
|
|
, gnum4
|
2020-02-11 19:02:43 +00:00
|
|
|
, enableCuda ? false
|
|
|
|
, cudatoolkit
|
2017-03-29 13:47:51 +00:00
|
|
|
}:
|
2014-12-15 17:29:30 +00:00
|
|
|
|
2020-02-11 19:02:43 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "suitesparse";
|
2020-02-12 06:23:00 +00:00
|
|
|
version = "5.7.1";
|
2015-06-03 22:33:11 +00:00
|
|
|
|
2020-02-11 19:02:43 +00:00
|
|
|
outputs = [ "out" "dev" "doc" ];
|
2014-12-15 17:29:30 +00:00
|
|
|
|
2020-02-11 19:02:43 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "DrTimothyAldenDavis";
|
|
|
|
repo = "SuiteSparse";
|
|
|
|
rev = "v${version}";
|
2020-02-12 06:23:00 +00:00
|
|
|
sha256 = "SA9SQKRDKUI1GilNMuCXljcvovLUwRKBUi/tiQ4dl5w=";
|
2014-12-15 17:29:30 +00:00
|
|
|
};
|
|
|
|
|
2020-02-11 19:02:43 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
gnum4
|
|
|
|
] ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames;
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
openblas
|
|
|
|
gfortran.cc.lib
|
|
|
|
] ++ stdenv.lib.optional enableCuda cudatoolkit;
|
|
|
|
|
2018-02-20 08:05:24 +00:00
|
|
|
dontUseCmakeConfigure = true;
|
|
|
|
|
2014-12-15 17:29:30 +00:00
|
|
|
preConfigure = ''
|
|
|
|
mkdir -p $out/lib
|
2020-02-11 19:02:43 +00:00
|
|
|
mkdir -p $dev/include
|
|
|
|
mkdir -p $doc/share/doc/${pname}-${version}
|
2015-06-03 22:33:11 +00:00
|
|
|
|
|
|
|
sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
|
2020-02-11 19:02:43 +00:00
|
|
|
-e '/CHOLMOD_CONFIG ?=/ s/$/ -DNPARTITION/'
|
2016-03-12 23:44:31 +00:00
|
|
|
''
|
|
|
|
+ stdenv.lib.optionalString stdenv.isDarwin ''
|
|
|
|
sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
|
|
|
|
-e 's/^[[:space:]]*\(LIB = -lm\) -lrt/\1/'
|
2017-03-29 13:47:51 +00:00
|
|
|
''
|
|
|
|
+ stdenv.lib.optionalString enableCuda ''
|
|
|
|
sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
|
|
|
|
-e 's|^[[:space:]]*\(CUDA_ROOT =\)|CUDA_ROOT = ${cudatoolkit}|' \
|
|
|
|
-e 's|^[[:space:]]*\(GPU_BLAS_PATH =\)|GPU_BLAS_PATH = $(CUDA_ROOT)|' \
|
|
|
|
-e 's|^[[:space:]]*\(GPU_CONFIG =\)|GPU_CONFIG = -I$(CUDA_ROOT)/include -DGPU_BLAS -DCHOLMOD_OMP_NUM_THREADS=$(NIX_BUILD_CORES) |' \
|
|
|
|
-e 's|^[[:space:]]*\(CUDA_PATH =\)|CUDA_PATH = $(CUDA_ROOT)|' \
|
|
|
|
-e 's|^[[:space:]]*\(CUDART_LIB =\)|CUDART_LIB = $(CUDA_ROOT)/lib64/libcudart.so|' \
|
|
|
|
-e 's|^[[:space:]]*\(CUBLAS_LIB =\)|CUBLAS_LIB = $(CUDA_ROOT)/lib64/libcublas.so|' \
|
|
|
|
-e 's|^[[:space:]]*\(CUDA_INC_PATH =\)|CUDA_INC_PATH = $(CUDA_ROOT)/include/|' \
|
2017-04-04 15:23:20 +00:00
|
|
|
-e 's|^[[:space:]]*\(NV20 =\)|NV20 = -arch=sm_20 -Xcompiler -fPIC|' \
|
|
|
|
-e 's|^[[:space:]]*\(NV30 =\)|NV30 = -arch=sm_30 -Xcompiler -fPIC|' \
|
|
|
|
-e 's|^[[:space:]]*\(NV35 =\)|NV35 = -arch=sm_35 -Xcompiler -fPIC|' \
|
2017-03-29 13:47:51 +00:00
|
|
|
-e 's|^[[:space:]]*\(NVCC =\) echo|NVCC = $(CUDA_ROOT)/bin/nvcc|' \
|
|
|
|
-e 's|^[[:space:]]*\(NVCCFLAGS =\)|NVCCFLAGS = $(NV20) -O3 -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_60,code=sm_60|'
|
2014-12-15 17:29:30 +00:00
|
|
|
'';
|
|
|
|
|
2020-02-11 19:02:43 +00:00
|
|
|
NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-DNTIMER";
|
2015-06-03 22:33:11 +00:00
|
|
|
|
2018-02-20 08:05:24 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
# Build individual shared libraries
|
|
|
|
make library \
|
2020-03-10 16:16:17 +00:00
|
|
|
JOBS=$NIX_BUILD_CORES \
|
2018-02-20 08:05:24 +00:00
|
|
|
BLAS=-lopenblas \
|
|
|
|
LAPACK="" \
|
|
|
|
${stdenv.lib.optionalString openblas.blas64 "CFLAGS=-DBLAS64"}
|
|
|
|
|
|
|
|
# Build libsuitesparse.so which bundles all the individual libraries.
|
|
|
|
# Bundling is done by building the static libraries, extracting objects from
|
|
|
|
# them and combining the objects into one shared library.
|
|
|
|
mkdir -p static
|
2020-03-10 16:16:17 +00:00
|
|
|
make static JOBS=$NIX_BUILD_CORES AR_TARGET=$(pwd)/static/'$(LIBRARY).a'
|
2015-06-04 12:09:29 +00:00
|
|
|
(
|
2018-02-20 08:05:24 +00:00
|
|
|
cd static
|
|
|
|
for i in lib*.a; do
|
2015-06-04 12:09:29 +00:00
|
|
|
ar -x $i
|
|
|
|
done
|
|
|
|
)
|
2018-02-20 08:05:24 +00:00
|
|
|
${if enableCuda then "${cudatoolkit}/bin/nvcc" else "${stdenv.cc.outPath}/bin/cc"} \
|
|
|
|
static/*.o \
|
|
|
|
${if stdenv.isDarwin then "-dynamiclib" else "--shared"} \
|
2020-02-11 19:02:43 +00:00
|
|
|
-o "lib/libsuitesparse${stdenv.hostPlatform.extensions.sharedLibrary}" \
|
2018-02-20 08:05:24 +00:00
|
|
|
-lopenblas \
|
|
|
|
${stdenv.lib.optionalString enableCuda "-lcublas"}
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
cp -r lib $out/
|
2020-02-11 19:02:43 +00:00
|
|
|
cp -r include $dev/
|
|
|
|
cp -r share $doc/
|
|
|
|
''
|
|
|
|
+ stdenv.lib.optionalString stdenv.isDarwin ''
|
2018-12-19 01:05:33 +00:00
|
|
|
# The fixDarwinDylibNames in nixpkgs can't seem to fix all the libraries.
|
|
|
|
# We manually fix them up here.
|
|
|
|
fixDarwinDylibNames() {
|
|
|
|
local flags=()
|
|
|
|
local old_id
|
|
|
|
|
|
|
|
for fn in "$@"; do
|
|
|
|
flags+=(-change "$PWD/lib/$(basename "$fn")" "$fn")
|
|
|
|
done
|
|
|
|
|
|
|
|
for fn in "$@"; do
|
|
|
|
if [ -L "$fn" ]; then continue; fi
|
|
|
|
echo "$fn: fixing dylib"
|
|
|
|
install_name_tool -id "$fn" "''${flags[@]}" "$fn"
|
|
|
|
done
|
|
|
|
}
|
2018-02-20 08:05:24 +00:00
|
|
|
|
2018-12-19 01:05:33 +00:00
|
|
|
fixDarwinDylibNames $(find "$out" -name "*.dylib")
|
2020-02-11 19:02:43 +00:00
|
|
|
''
|
|
|
|
+ stdenv.lib.optionalString (!stdenv.isDarwin) ''
|
2018-02-20 08:05:24 +00:00
|
|
|
# Fix rpaths
|
|
|
|
cd $out
|
|
|
|
find -name \*.so\* -type f -exec \
|
|
|
|
patchelf --set-rpath "$out/lib:${stdenv.lib.makeLibraryPath buildInputs}" {} \;
|
2020-02-11 19:02:43 +00:00
|
|
|
''
|
|
|
|
+ ''
|
2018-02-20 08:05:24 +00:00
|
|
|
runHook postInstall
|
2020-02-11 19:02:43 +00:00
|
|
|
'';
|
2014-12-15 17:29:30 +00:00
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
2020-02-11 19:02:43 +00:00
|
|
|
homepage = "http://faculty.cse.tamu.edu/davis/suitesparse.html";
|
2014-12-15 17:29:30 +00:00
|
|
|
description = "A suite of sparse matrix algorithms";
|
|
|
|
license = with licenses; [ bsd2 gpl2Plus lgpl21Plus ];
|
|
|
|
maintainers = with maintainers; [ ttuegel ];
|
2016-08-02 17:50:55 +00:00
|
|
|
platforms = with platforms; unix;
|
2014-12-15 17:29:30 +00:00
|
|
|
};
|
|
|
|
}
|