nixpkgs/pkgs/applications/science/math/cntk/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

134 lines
3.9 KiB
Nix
Raw Normal View History

2022-03-15 10:26:37 +00:00
{ lib, stdenv, fetchFromGitHub, cmake
2021-09-23 08:40:27 +00:00
, fetchpatch
, openblas, blas, lapack, opencv3, libzip, boost, protobuf, mpi
2017-10-15 21:56:43 +00:00
, onebitSGDSupport ? false
, cudaSupport ? false, cudaPackages ? {}, addOpenGLRunpath, cudatoolkit, nvidia_x11
, cudnnSupport ? cudaSupport
2017-10-15 21:56:43 +00:00
}:
let
inherit (cudaPackages) cudatoolkit cudnn;
in
2017-10-15 21:56:43 +00:00
assert cudnnSupport -> cudaSupport;
assert blas.implementation == "openblas" && lapack.implementation == "openblas";
2017-10-15 21:56:43 +00:00
let
# Old specific version required for CNTK.
cub = fetchFromGitHub {
owner = "NVlabs";
repo = "cub";
rev = "1.7.4";
sha256 = "0ksd5n1lxqhm5l5cd2lps4cszhjkf6gmzahaycs7nxb06qci8c66";
2017-10-15 21:56:43 +00:00
};
in stdenv.mkDerivation rec {
pname = "CNTK";
version = "2.7";
2017-10-15 21:56:43 +00:00
2022-03-15 10:26:37 +00:00
src = fetchFromGitHub {
owner = "Microsoft";
repo = "CNTK";
2017-10-15 21:56:43 +00:00
rev = "v${version}";
2022-03-15 10:26:37 +00:00
sha256 = "sha256-2rIrPJyvZhnM5EO6tNhF6ARTocfUHce4N0IZk/SZiaI=";
fetchSubmodules = true;
2017-10-15 21:56:43 +00:00
};
2021-09-23 08:40:27 +00:00
patches = [
# Fix build with protobuf 3.18+
# Remove with onnx submodule bump to 1.9+
(fetchpatch {
url = "https://github.com/onnx/onnx/commit/d3bc82770474761571f950347560d62a35d519d7.patch";
extraPrefix = "Source/CNTKv2LibraryDll/proto/onnx/onnx_repo/";
stripLen = 1;
sha256 = "00raqj8wx30b06ky6cdp5vvc1mrzs7hglyi6h58hchw5lhrwkzxp";
})
];
postPatch = ''
# Fix build with protobuf 3.18+
substituteInPlace Source/CNTKv2LibraryDll/Serialization.cpp \
--replace 'SetTotalBytesLimit(INT_MAX, INT_MAX)' \
'SetTotalBytesLimit(INT_MAX)' \
--replace 'SetTotalBytesLimit(limit, limit)' \
'SetTotalBytesLimit(limit)'
'';
nativeBuildInputs = [ cmake ] ++ lib.optional cudaSupport addOpenGLRunpath;
# Force OpenMPI to use g++ in PATH.
OMPI_CXX = "g++";
2017-10-15 21:56:43 +00:00
2021-05-16 23:52:25 +00:00
# Uses some deprecated tensorflow functions
env.NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations";
2021-05-16 23:52:25 +00:00
buildInputs = [ openblas opencv3 libzip boost protobuf mpi ]
2017-10-15 21:56:43 +00:00
++ lib.optional cudaSupport cudatoolkit
++ lib.optional cudnnSupport cudnn;
configureFlags = [
"--with-opencv=${opencv3}"
"--with-libzip=${libzip.dev}"
2021-05-16 23:52:25 +00:00
"--with-openblas=${openblas.dev}"
2017-10-15 21:56:43 +00:00
"--with-boost=${boost.dev}"
"--with-protobuf=${protobuf}"
"--with-mpi=${mpi}"
2018-02-25 19:49:59 +00:00
"--cuda=${if cudaSupport then "yes" else "no"}"
# FIXME
"--asgd=no"
2018-02-25 19:49:59 +00:00
] ++ lib.optionals cudaSupport [
2017-10-15 21:56:43 +00: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"
''}
2017-10-15 21:56:43 +00:00
../configure $configureFlags
'';
installPhase = ''
mkdir -p $out/bin
# Moving to make patchelf remove references later.
mv lib $out
cp bin/cntk $out/bin
'';
postFixup = lib.optionalString cudaSupport ''
for lib in $out/lib/*; do
addOpenGLRunpath "$lib"
done
'';
2017-10-15 21:56:43 +00:00
meta = with lib; {
homepage = "https://github.com/Microsoft/CNTK";
2017-10-15 21:56:43 +00:00
description = "An open source deep-learning toolkit";
license = if onebitSGDSupport then licenses.unfreeRedistributable else licenses.mit;
platforms = [ "x86_64-linux" ];
2017-10-15 21:56:43 +00:00
maintainers = with maintainers; [ abbradar ];
2022-09-23 13:01:29 +00:00
# Newer cub is included with cudatoolkit now and it breaks the build.
# https://github.com/Microsoft/CNTK/issues/3191
# broken = cudaSupport;
broken = true; # at 2022-11-23
2017-10-15 21:56:43 +00:00
};
}