You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

default.nix 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. { lib, stdenv, fetchgit, fetchFromGitHub, cmake
  2. , openblas, opencv3, libzip, boost, protobuf, openmpi
  3. , onebitSGDSupport ? false
  4. , cudaSupport ? false, addOpenGLRunpath, cudatoolkit, nvidia_x11
  5. , cudnnSupport ? cudaSupport, cudnn
  6. }:
  7. assert cudnnSupport -> cudaSupport;
  8. let
  9. # Old specific version required for CNTK.
  10. cub = fetchFromGitHub {
  11. owner = "NVlabs";
  12. repo = "cub";
  13. rev = "1.7.4";
  14. sha256 = "0ksd5n1lxqhm5l5cd2lps4cszhjkf6gmzahaycs7nxb06qci8c66";
  15. };
  16. in stdenv.mkDerivation rec {
  17. pname = "CNTK";
  18. version = "2.7";
  19. # Submodules
  20. src = fetchgit {
  21. url = "https://github.com/Microsoft/CNTK";
  22. rev = "v${version}";
  23. sha256 = "18l9k7s966a26ywcf7flqyhm61788pcb9fj3wk61jrmgkhy2pcns";
  24. };
  25. nativeBuildInputs = [ cmake ] ++ lib.optional cudaSupport addOpenGLRunpath;
  26. # Force OpenMPI to use g++ in PATH.
  27. OMPI_CXX = "g++";
  28. buildInputs = [ openblas opencv3 libzip boost protobuf openmpi ]
  29. ++ lib.optional cudaSupport cudatoolkit
  30. ++ lib.optional cudnnSupport cudnn;
  31. configureFlags = [
  32. "--with-opencv=${opencv3}"
  33. "--with-libzip=${libzip.dev}"
  34. "--with-openblas=${openblas}"
  35. "--with-boost=${boost.dev}"
  36. "--with-protobuf=${protobuf}"
  37. "--with-mpi=${openmpi}"
  38. "--cuda=${if cudaSupport then "yes" else "no"}"
  39. # FIXME
  40. "--asgd=no"
  41. ] ++ lib.optionals cudaSupport [
  42. "--with-cuda=${cudatoolkit}"
  43. "--with-gdk-include=${cudatoolkit}/include"
  44. "--with-gdk-nvml-lib=${nvidia_x11}/lib"
  45. "--with-cub=${cub}"
  46. ] ++ lib.optional onebitSGDSupport "--1bitsgd=yes";
  47. configurePhase = ''
  48. sed -i \
  49. -e 's,^GIT_STATUS=.*,GIT_STATUS=,' \
  50. -e 's,^GIT_COMMIT=.*,GIT_COMMIT=v${version},' \
  51. -e 's,^GIT_BRANCH=.*,GIT_BRANCH=v${version},' \
  52. -e 's,^BUILDER=.*,BUILDER=nixbld,' \
  53. -e 's,^BUILDMACHINE=.*,BUILDMACHINE=machine,' \
  54. -e 's,^BUILDPATH=.*,BUILDPATH=/homeless-shelter,' \
  55. -e '/git does not exist/d' \
  56. Tools/generate_build_info
  57. patchShebangs .
  58. mkdir build
  59. cd build
  60. ${lib.optionalString cudnnSupport ''
  61. mkdir cuda
  62. ln -s ${cudnn}/include cuda
  63. export configureFlags="$configureFlags --with-cudnn=$PWD"
  64. ''}
  65. ../configure $configureFlags
  66. '';
  67. installPhase = ''
  68. mkdir -p $out/bin
  69. # Moving to make patchelf remove references later.
  70. mv lib $out
  71. cp bin/cntk $out/bin
  72. '';
  73. postFixup = lib.optionalString cudaSupport ''
  74. for lib in $out/lib/*; do
  75. addOpenGLRunpath "$lib"
  76. done
  77. '';
  78. enableParallelBuilding = true;
  79. meta = with lib; {
  80. # Newer cub is included with cudatoolkit now and it breaks the build.
  81. # https://github.com/Microsoft/CNTK/issues/3191
  82. broken = cudaSupport;
  83. homepage = https://github.com/Microsoft/CNTK;
  84. description = "An open source deep-learning toolkit";
  85. license = if onebitSGDSupport then licenses.unfreeRedistributable else licenses.mit;
  86. platforms = [ "x86_64-linux" ];
  87. maintainers = with maintainers; [ abbradar ];
  88. };
  89. }