2017-09-03 14:15:39 +01:00
|
|
|
{ stdenv, lib
|
2015-07-05 00:42:54 +01:00
|
|
|
, fetchFromGitHub
|
2017-09-03 14:15:39 +01:00
|
|
|
, cmake
|
|
|
|
, boost
|
2015-07-05 00:42:54 +01:00
|
|
|
, google-gflags
|
|
|
|
, glog
|
2017-09-03 14:15:39 +01:00
|
|
|
, hdf5-cpp
|
2015-07-05 00:42:54 +01:00
|
|
|
, leveldb
|
|
|
|
, lmdb
|
2018-02-25 17:00:26 +00:00
|
|
|
, opencv3
|
2015-07-05 00:42:54 +01:00
|
|
|
, protobuf
|
|
|
|
, snappy
|
2017-09-03 14:15:39 +01:00
|
|
|
, doxygen
|
2018-02-25 17:00:26 +00:00
|
|
|
, openblas
|
2017-09-03 14:15:39 +01:00
|
|
|
, cudaSupport ? true, cudatoolkit
|
|
|
|
, cudnnSupport ? false, cudnn ? null
|
2018-02-25 17:02:10 +00:00
|
|
|
, ncclSupport ? false, nccl ? null
|
2017-09-03 14:15:39 +01:00
|
|
|
, pythonSupport ? false, python ? null, numpy ? null
|
2015-07-05 00:42:54 +01:00
|
|
|
}:
|
|
|
|
|
2017-09-03 14:15:39 +01:00
|
|
|
assert cudnnSupport -> cudaSupport;
|
2018-02-25 17:02:10 +00:00
|
|
|
assert ncclSupport -> cudaSupport;
|
2017-09-03 14:15:39 +01:00
|
|
|
assert pythonSupport -> (python != null && numpy != null);
|
2015-07-05 00:42:54 +01:00
|
|
|
|
2017-09-03 14:15:39 +01:00
|
|
|
stdenv.mkDerivation rec {
|
2017-09-03 12:55:57 +01:00
|
|
|
name = "caffe-${version}";
|
2017-09-17 05:08:22 +01:00
|
|
|
version = "1.0";
|
2015-07-05 00:42:54 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "BVLC";
|
|
|
|
repo = "caffe";
|
2017-09-17 05:08:22 +01:00
|
|
|
rev = version;
|
|
|
|
sha256 = "104jp3cm823i3cdph7hgsnj6l77ygbwsy35mdmzhmsi4jxprd9j3";
|
2015-07-05 00:42:54 +01:00
|
|
|
};
|
|
|
|
|
2017-09-03 14:15:39 +01:00
|
|
|
enableParallelBuilding = true;
|
2015-07-05 00:42:54 +01:00
|
|
|
|
2017-09-03 14:15:39 +01:00
|
|
|
nativeBuildInputs = [ cmake doxygen ];
|
2015-07-05 00:42:54 +01:00
|
|
|
|
2018-02-25 17:00:26 +00:00
|
|
|
cmakeFlags =
|
|
|
|
[ (if pythonSupport then "-Dpython_version=${python.version}" else "-DBUILD_python=OFF")
|
|
|
|
"-DBLAS=open"
|
|
|
|
] ++ (if cudaSupport then [
|
|
|
|
"-DCUDA_ARCH_NAME=All"
|
|
|
|
"-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc"
|
2018-02-25 17:02:10 +00:00
|
|
|
] else [ "-DCPU_ONLY=ON" ])
|
|
|
|
++ lib.optional ncclSupport "-DUSE_NCCL=ON";
|
2017-09-03 12:55:57 +01:00
|
|
|
|
2018-02-25 17:00:26 +00:00
|
|
|
buildInputs = [ boost google-gflags glog protobuf hdf5-cpp lmdb leveldb snappy opencv3 openblas ]
|
2017-09-03 14:15:39 +01:00
|
|
|
++ lib.optional cudaSupport cudatoolkit
|
|
|
|
++ lib.optional cudnnSupport cudnn
|
2018-02-25 17:02:10 +00:00
|
|
|
++ lib.optional ncclSupport nccl
|
2017-09-03 14:15:39 +01:00
|
|
|
++ lib.optionals pythonSupport [ python numpy ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = lib.optional pythonSupport python.pkgs.protobuf;
|
2015-07-05 00:42:54 +01:00
|
|
|
|
2017-09-26 22:39:55 +01:00
|
|
|
outputs = [ "bin" "out"];
|
|
|
|
propagatedBuildOutputs = []; # otherwise propagates out -> bin cycle
|
2015-07-05 00:42:54 +01:00
|
|
|
|
2017-09-17 05:08:22 +01:00
|
|
|
preConfigure = lib.optionalString (cudaSupport && lib.versionAtLeast cudatoolkit.version "9.0") ''
|
|
|
|
# CUDA 9.0 doesn't support sm_20
|
|
|
|
sed -i 's,20 21(20) ,,' cmake/Cuda.cmake
|
|
|
|
'' + lib.optionalString (python.isPy3 or false) ''
|
|
|
|
sed -i \
|
|
|
|
-e 's,"python-py''${boost_py_version}",python3,g' \
|
|
|
|
-e 's,''${Boost_PYTHON-PY''${boost_py_version}_FOUND},''${Boost_PYTHON3_FOUND},g' \
|
|
|
|
cmake/Dependencies.cmake
|
|
|
|
'';
|
|
|
|
|
2017-09-03 14:15:39 +01:00
|
|
|
postInstall = ''
|
|
|
|
# Internal static library.
|
|
|
|
rm $out/lib/libproto.a
|
2015-07-05 00:42:54 +01:00
|
|
|
|
2017-09-03 14:15:39 +01:00
|
|
|
moveToOutput "bin" "$bin"
|
|
|
|
'' + lib.optionalString pythonSupport ''
|
|
|
|
mkdir -p $out/${python.sitePackages}
|
|
|
|
mv $out/python/caffe $out/${python.sitePackages}
|
|
|
|
rm -rf $out/python
|
2015-07-05 00:42:54 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|