summary refs log tree commit diff
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2017-10-16 00:56:43 +0300
committerNikolay Amiantov <ab@fmap.me>2017-10-19 13:24:24 +0300
commit94dc37d6223ff6e47745afa92d2fb0efcb3df44f (patch)
tree4444c0b64d43b426b1d3fa102b5aeb78e3b95280
parentcf2cc8b1d370a51af431ffdb77ab0dc53f1107b1 (diff)
downloadnixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.tar
nixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.tar.gz
nixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.tar.bz2
nixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.tar.lz
nixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.tar.xz
nixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.tar.zst
nixlib-94dc37d6223ff6e47745afa92d2fb0efcb3df44f.zip
cntk: init at 2.2
-rw-r--r--pkgs/applications/science/math/cntk/default.nix98
-rw-r--r--pkgs/top-level/all-packages.nix8
-rw-r--r--pkgs/top-level/python-packages.nix21
3 files changed, 127 insertions, 0 deletions
diff --git a/pkgs/applications/science/math/cntk/default.nix b/pkgs/applications/science/math/cntk/default.nix
new file mode 100644
index 000000000000..80a5f6f032b7
--- /dev/null
+++ b/pkgs/applications/science/math/cntk/default.nix
@@ -0,0 +1,98 @@
+{ lib, stdenv, fetchgit, fetchFromGitHub, fetchpatch, cmake
+, openblas, opencv3, libzip, boost, protobuf, openmpi
+, onebitSGDSupport ? false
+, cudaSupport ? false, cudatoolkit, nvidia_x11
+, cudnnSupport ? false, cudnn
+}:
+
+assert cudnnSupport -> cudaSupport;
+
+let
+  # Old specific version required for CNTK.
+  cub = fetchFromGitHub {
+    owner = "NVlabs";
+    repo = "cub";
+    rev = "1.4.1";
+    sha256 = "1lcdwblz03c0yq1lxndg566kg14b5qm14x5qixjbmz6wq85kgmqc";
+  };
+
+in stdenv.mkDerivation rec {
+  name = "CNTK-${version}";
+  version = "2.2";
+
+  # Submodules
+  src = fetchgit {
+    url = "https://github.com/Microsoft/CNTK";
+    rev = "v${version}";
+    sha256 = "0q4knrwiyphb2fbqf9jzqvkz2jzj6jmbmang3lavdvsh7z0n8zz9";
+  };
+
+  patches = [
+    # Fix "'exp' was not declared"
+    (fetchpatch {
+      url = "https://github.com/imriss/CNTK/commit/ef1cca6df95cc507deb8471df2c0dd8cbfeef23b.patch";
+      sha256 = "0z7xyrxwric0c4h7rfs05f544mcq6d10wgs0vvfcyd2pcf410hy7";
+    })
+  ];
+
+  nativeBuildInputs = [ cmake ];
+
+  buildInputs = [ openblas opencv3 libzip boost protobuf openmpi ]
+             ++ lib.optional cudaSupport cudatoolkit
+             ++ lib.optional cudnnSupport cudnn;
+
+  configureFlags = [
+    "--with-opencv=${opencv3}"
+    "--with-libzip=${libzip.dev}"
+    "--with-openblas=${openblas}"
+    "--with-boost=${boost.dev}"
+    "--with-protobuf=${protobuf}"
+    "--with-mpi=${openmpi}"
+  ] ++ lib.optionals cudaSupport [
+    "--cuda=yes"
+    "--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"
+    ''}
+    ../configure $configureFlags
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    # Moving to make patchelf remove references later.
+    mv lib $out
+    cp bin/cntk $out/bin
+  '';
+
+  hardeningDisable = [ "format" ];
+
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    homepage = "https://github.com/Microsoft/CNTK";
+    description = "An open source deep-learning toolkit";
+    license = if onebitSGDSupport then licenses.unfreeRedistributable else licenses.mit;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index a290783fe7df..90890e0f2d07 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -18744,6 +18744,14 @@ with pkgs;
     cudnnSupport = cudaSupport;
   };
 
+  cntk = callPackage ../applications/science/math/cntk rec {
+    cudaSupport = pkgs.config.cudaSupport or false;
+    cudnnSupport = cudaSupport;
+    inherit (linuxPackages) nvidia_x11;
+    cudatoolkit = cudatoolkit8;
+    cudnn = cudnn6_cudatoolkit8;
+  };
+
   ecm = callPackage ../applications/science/math/ecm { };
 
   eukleides = callPackage ../applications/science/math/eukleides {
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 60946e8e8dd0..4e8c4add1677 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -2578,6 +2578,27 @@ in {
     };
   };
 
+  cntk = buildPythonPackage rec {
+    inherit (pkgs.cntk) name version src meta;
+
+    buildInputs = [ pkgs.cntk pkgs.swig pkgs.openmpi ];
+    propagatedBuildInputs = with self; [ numpy scipy enum34 protobuf pip ];
+
+    CNTK_LIB_PATH = "${pkgs.cntk}/lib";
+    CNTK_COMPONENT_VERSION = pkgs.cntk.version;
+
+    postPatch = ''
+      cd bindings/python
+    '';
+
+    postInstall = ''
+      rm -rf $out/${python.sitePackages}/cntk/libs
+      ln -s ${pkgs.cntk}/lib $out/${python.sitePackages}/cntk/libs
+      # It's not installed for some reason.
+      cp cntk/cntk_py.py $out/${python.sitePackages}/cntk
+    '';
+  };
+
   celery = buildPythonPackage rec {
     name = "celery-${version}";
     version = "4.0.2";