2019-10-05 14:17:37 +01:00
|
|
|
{ lib, stdenv, fetchgit, fetchFromGitHub, cmake
|
2021-01-10 12:40:19 +00:00
|
|
|
, openblas, blas, lapack, opencv3, libzip, boost, protobuf, mpi
|
2017-10-15 22:56:43 +01:00
|
|
|
, onebitSGDSupport ? false
|
2019-10-05 14:17:37 +01:00
|
|
|
, cudaSupport ? false, addOpenGLRunpath, cudatoolkit, nvidia_x11
|
2019-02-03 15:32:16 +00:00
|
|
|
, cudnnSupport ? cudaSupport, cudnn
|
2017-10-15 22:56:43 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert cudnnSupport -> cudaSupport;
|
2020-03-31 15:47:18 +01:00
|
|
|
assert blas.implementation == "openblas" && lapack.implementation == "openblas";
|
2017-10-15 22:56:43 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
# Old specific version required for CNTK.
|
|
|
|
cub = fetchFromGitHub {
|
|
|
|
owner = "NVlabs";
|
|
|
|
repo = "cub";
|
2018-02-25 16:58:21 +00:00
|
|
|
rev = "1.7.4";
|
|
|
|
sha256 = "0ksd5n1lxqhm5l5cd2lps4cszhjkf6gmzahaycs7nxb06qci8c66";
|
2017-10-15 22:56:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
2019-08-15 13:41:18 +01:00
|
|
|
pname = "CNTK";
|
2019-06-02 10:52:10 +01:00
|
|
|
version = "2.7";
|
2017-10-15 22:56:43 +01:00
|
|
|
|
|
|
|
# Submodules
|
|
|
|
src = fetchgit {
|
|
|
|
url = "https://github.com/Microsoft/CNTK";
|
|
|
|
rev = "v${version}";
|
2019-06-02 10:52:10 +01:00
|
|
|
sha256 = "18l9k7s966a26ywcf7flqyhm61788pcb9fj3wk61jrmgkhy2pcns";
|
2017-10-15 22:56:43 +01:00
|
|
|
};
|
|
|
|
|
2019-10-05 14:17:37 +01:00
|
|
|
nativeBuildInputs = [ cmake ] ++ lib.optional cudaSupport addOpenGLRunpath;
|
|
|
|
|
|
|
|
# Force OpenMPI to use g++ in PATH.
|
|
|
|
OMPI_CXX = "g++";
|
2017-10-15 22:56:43 +01:00
|
|
|
|
2021-05-17 00:52:25 +01:00
|
|
|
# Uses some deprecated tensorflow functions
|
|
|
|
NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations";
|
|
|
|
|
2021-01-10 12:40:19 +00:00
|
|
|
buildInputs = [ openblas opencv3 libzip boost protobuf mpi ]
|
2017-10-15 22:56:43 +01:00
|
|
|
++ lib.optional cudaSupport cudatoolkit
|
|
|
|
++ lib.optional cudnnSupport cudnn;
|
|
|
|
|
|
|
|
configureFlags = [
|
|
|
|
"--with-opencv=${opencv3}"
|
|
|
|
"--with-libzip=${libzip.dev}"
|
2021-05-17 00:52:25 +01:00
|
|
|
"--with-openblas=${openblas.dev}"
|
2017-10-15 22:56:43 +01:00
|
|
|
"--with-boost=${boost.dev}"
|
|
|
|
"--with-protobuf=${protobuf}"
|
2021-01-10 12:40:19 +00:00
|
|
|
"--with-mpi=${mpi}"
|
2018-02-25 19:49:59 +00:00
|
|
|
"--cuda=${if cudaSupport then "yes" else "no"}"
|
2018-02-25 16:58:21 +00:00
|
|
|
# FIXME
|
|
|
|
"--asgd=no"
|
2018-02-25 19:49:59 +00:00
|
|
|
] ++ lib.optionals cudaSupport [
|
2017-10-15 22:56:43 +01:00
|
|
|
"--with-cuda=${cudatoolkit}"
|
|
|
|
"--with-gdk-include=${cudatoolkit}/include"
|
|
|
|
"--with-gdk-nvml-lib=${nvidia_x11}/lib"
|
|
|
|
"--with-cub=${cub}"
|
|
|
|
] ++ lib.optional onebitSGDSupport "--1bitsgd=yes";
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
sed -i \
|
|
|
|
-e 's,^GIT_STATUS=.*,GIT_STATUS=,' \
|
|
|
|
-e 's,^GIT_COMMIT=.*,GIT_COMMIT=v${version},' \
|
|
|
|
-e 's,^GIT_BRANCH=.*,GIT_BRANCH=v${version},' \
|
|
|
|
-e 's,^BUILDER=.*,BUILDER=nixbld,' \
|
|
|
|
-e 's,^BUILDMACHINE=.*,BUILDMACHINE=machine,' \
|
|
|
|
-e 's,^BUILDPATH=.*,BUILDPATH=/homeless-shelter,' \
|
|
|
|
-e '/git does not exist/d' \
|
|
|
|
Tools/generate_build_info
|
|
|
|
|
|
|
|
patchShebangs .
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
${lib.optionalString cudnnSupport ''
|
|
|
|
mkdir cuda
|
|
|
|
ln -s ${cudnn}/include cuda
|
|
|
|
export configureFlags="$configureFlags --with-cudnn=$PWD"
|
|
|
|
''}
|
2019-10-05 14:17:37 +01:00
|
|
|
|
2017-10-15 22:56:43 +01:00
|
|
|
../configure $configureFlags
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
# Moving to make patchelf remove references later.
|
|
|
|
mv lib $out
|
|
|
|
cp bin/cntk $out/bin
|
|
|
|
'';
|
|
|
|
|
2019-10-05 14:17:37 +01:00
|
|
|
postFixup = lib.optionalString cudaSupport ''
|
|
|
|
for lib in $out/lib/*; do
|
|
|
|
addOpenGLRunpath "$lib"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2017-10-15 22:56:43 +01:00
|
|
|
meta = with lib; {
|
2019-10-05 14:17:37 +01:00
|
|
|
# Newer cub is included with cudatoolkit now and it breaks the build.
|
|
|
|
# https://github.com/Microsoft/CNTK/issues/3191
|
|
|
|
broken = cudaSupport;
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "https://github.com/Microsoft/CNTK";
|
2017-10-15 22:56:43 +01:00
|
|
|
description = "An open source deep-learning toolkit";
|
|
|
|
license = if onebitSGDSupport then licenses.unfreeRedistributable else licenses.mit;
|
2019-06-02 10:52:10 +01:00
|
|
|
platforms = [ "x86_64-linux" ];
|
2017-10-15 22:56:43 +01:00
|
|
|
maintainers = with maintainers; [ abbradar ];
|
|
|
|
};
|
|
|
|
}
|