summary refs log tree commit diff
path: root/pkgs/applications/science/math/caffe/default.nix
blob: 5c6fe9c573d5e107987009556f6f06e08ce3fc5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ stdenv, lib
, fetchFromGitHub
, cmake
, boost
, google-gflags
, glog
, hdf5-cpp
, leveldb
, lmdb
, opencv
, protobuf
, snappy
, atlas
, doxygen
, cudaSupport ? true, cudatoolkit
, cudnnSupport ? false, cudnn ? null
, pythonSupport ? false, python ? null, numpy ? null
}:

assert cudnnSupport -> cudaSupport;
assert pythonSupport -> (python != null && numpy != null);

stdenv.mkDerivation rec {
  name = "caffe-${version}";
  version = "1.0-rc5";

  src = fetchFromGitHub {
    owner = "BVLC";
    repo = "caffe";
    rev = "rc5";
    sha256 = "0lfmmc0n6xvkpygvxclzrvd0zigb4yfc5612anv2ahlxpfi9031c";
  };

  enableParallelBuilding = true;

  nativeBuildInputs = [ cmake doxygen ];

  cmakeFlags = [ "-DCUDA_ARCH_NAME=All" ]
               ++ lib.optional (!cudaSupport) "-DCPU_ONLY=ON"
               ++ lib.optional (!pythonSupport) "-DBUILD_python=OFF";

  buildInputs = [ boost google-gflags glog protobuf hdf5-cpp lmdb leveldb snappy opencv atlas ]
                ++ lib.optional cudaSupport cudatoolkit
                ++ lib.optional cudnnSupport cudnn
                ++ lib.optionals pythonSupport [ python numpy ];

  propagatedBuildInputs = lib.optional pythonSupport python.pkgs.protobuf;

  outputs = [ "out" "bin" ];
  # Don't propagate bin.
  outputBin = "out";

  postInstall = ''
    # Internal static library.
    rm $out/lib/libproto.a

    moveToOutput "bin" "$bin"
  '' + lib.optionalString pythonSupport ''
    mkdir -p $out/${python.sitePackages}
    mv $out/python/caffe $out/${python.sitePackages}
    rm -rf $out/python
  '';

  meta = with stdenv.lib; {
    description = "Deep learning framework";
    longDescription = ''
      Caffe is a deep learning framework made with expression, speed, and
      modularity in mind. It is developed by the Berkeley Vision and Learning
      Center (BVLC) and by community contributors.
    '';
    homepage = http://caffe.berkeleyvision.org/;
    maintainers = with maintainers; [ jb55 ];
    license = licenses.bsd2;
    platforms = platforms.linux;
  };
}