2019-06-16 19:59:06 +00:00
|
|
|
{ config, stdenv, lib
|
2015-07-04 23:42:54 +00:00
|
|
|
, fetchFromGitHub
|
2018-08-16 11:46:51 +00:00
|
|
|
, fetchurl
|
2017-09-03 13:15:39 +00:00
|
|
|
, cmake
|
|
|
|
, boost
|
2019-07-25 09:04:55 +00:00
|
|
|
, gflags
|
2015-07-04 23:42:54 +00:00
|
|
|
, glog
|
2017-09-03 13:15:39 +00:00
|
|
|
, hdf5-cpp
|
2018-02-25 17:00:26 +00:00
|
|
|
, opencv3
|
2015-07-04 23:42:54 +00:00
|
|
|
, protobuf
|
2017-09-03 13:15:39 +00:00
|
|
|
, doxygen
|
2020-03-31 14:47:18 +00:00
|
|
|
, blas
|
2018-08-16 11:46:51 +00:00
|
|
|
, Accelerate, CoreGraphics, CoreVideo
|
|
|
|
, lmdbSupport ? true, lmdb
|
|
|
|
, leveldbSupport ? true, leveldb, snappy
|
2019-02-03 15:32:15 +00:00
|
|
|
, cudaSupport ? config.cudaSupport or false, cudatoolkit
|
|
|
|
, cudnnSupport ? cudaSupport, cudnn ? null
|
2018-02-25 17:02:10 +00:00
|
|
|
, ncclSupport ? false, nccl ? null
|
2017-09-03 13:15:39 +00:00
|
|
|
, pythonSupport ? false, python ? null, numpy ? null
|
2019-02-17 09:12:58 +00:00
|
|
|
, substituteAll
|
2015-07-04 23:42:54 +00:00
|
|
|
}:
|
|
|
|
|
2018-08-16 11:46:51 +00:00
|
|
|
assert leveldbSupport -> (leveldb != null && snappy != null);
|
2017-09-03 13:15:39 +00:00
|
|
|
assert cudnnSupport -> cudaSupport;
|
2018-02-25 17:02:10 +00:00
|
|
|
assert ncclSupport -> cudaSupport;
|
2017-09-03 13:15:39 +00:00
|
|
|
assert pythonSupport -> (python != null && numpy != null);
|
2015-07-04 23:42:54 +00:00
|
|
|
|
2018-08-16 11:46:51 +00:00
|
|
|
let
|
|
|
|
toggle = bool: if bool then "ON" else "OFF";
|
|
|
|
|
|
|
|
test_model_weights = fetchurl {
|
|
|
|
url = "http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel";
|
|
|
|
sha256 = "472d4a06035497b180636d8a82667129960371375bd10fcb6df5c6c7631f25e0";
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2017-09-03 13:15:39 +00:00
|
|
|
stdenv.mkDerivation rec {
|
2019-08-15 12:41:18 +00:00
|
|
|
pname = "caffe";
|
2017-09-17 04:08:22 +00:00
|
|
|
version = "1.0";
|
2015-07-04 23:42:54 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "BVLC";
|
|
|
|
repo = "caffe";
|
2017-09-17 04:08:22 +00:00
|
|
|
rev = version;
|
|
|
|
sha256 = "104jp3cm823i3cdph7hgsnj6l77ygbwsy35mdmzhmsi4jxprd9j3";
|
2015-07-04 23:42:54 +00:00
|
|
|
};
|
|
|
|
|
2017-09-03 13:15:39 +00:00
|
|
|
nativeBuildInputs = [ cmake doxygen ];
|
2015-07-04 23:42:54 +00:00
|
|
|
|
2018-02-25 17:00:26 +00:00
|
|
|
cmakeFlags =
|
2019-02-17 09:12:58 +00:00
|
|
|
# It's important that caffe is passed the major and minor version only because that's what
|
|
|
|
# boost_python expects
|
2019-06-17 09:42:04 +00:00
|
|
|
[ (if pythonSupport then "-Dpython_version=${python.pythonVersion}" else "-DBUILD_python=OFF")
|
2018-02-25 17:00:26 +00:00
|
|
|
"-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" ])
|
2018-08-16 11:46:51 +00:00
|
|
|
++ ["-DUSE_NCCL=${toggle ncclSupport}"]
|
|
|
|
++ ["-DUSE_LEVELDB=${toggle leveldbSupport}"]
|
|
|
|
++ ["-DUSE_LMDB=${toggle lmdbSupport}"];
|
2017-09-03 11:55:57 +00:00
|
|
|
|
2020-03-31 14:47:18 +00:00
|
|
|
buildInputs = [ boost gflags glog protobuf hdf5-cpp opencv3 blas ]
|
2017-09-03 13:15:39 +00:00
|
|
|
++ lib.optional cudaSupport cudatoolkit
|
|
|
|
++ lib.optional cudnnSupport cudnn
|
2018-08-16 11:46:51 +00:00
|
|
|
++ lib.optional lmdbSupport lmdb
|
2018-02-25 17:02:10 +00:00
|
|
|
++ lib.optional ncclSupport nccl
|
2018-08-16 11:46:51 +00:00
|
|
|
++ lib.optionals leveldbSupport [ leveldb snappy ]
|
|
|
|
++ lib.optionals pythonSupport [ python numpy ]
|
|
|
|
++ lib.optionals stdenv.isDarwin [ Accelerate CoreGraphics CoreVideo ]
|
|
|
|
;
|
2017-09-03 13:15:39 +00:00
|
|
|
|
2019-06-17 12:16:13 +00:00
|
|
|
propagatedBuildInputs = lib.optionals pythonSupport (
|
|
|
|
# requirements.txt
|
|
|
|
let pp = python.pkgs; in ([
|
|
|
|
pp.numpy pp.scipy pp.scikitimage pp.h5py
|
|
|
|
pp.matplotlib pp.ipython pp.networkx pp.nose
|
2021-07-03 11:37:24 +00:00
|
|
|
pp.pandas pp.python-dateutil pp.protobuf pp.gflags
|
2019-06-17 12:16:13 +00:00
|
|
|
pp.pyyaml pp.pillow pp.six
|
|
|
|
] ++ lib.optional leveldbSupport pp.leveldb)
|
|
|
|
);
|
|
|
|
|
|
|
|
outputs = [ "bin" "out" ];
|
2017-09-26 21:39:55 +00:00
|
|
|
propagatedBuildOutputs = []; # otherwise propagates out -> bin cycle
|
2015-07-04 23:42:54 +00:00
|
|
|
|
2019-02-17 09:12:58 +00:00
|
|
|
patches = [
|
|
|
|
./darwin.patch
|
|
|
|
] ++ lib.optional pythonSupport (substituteAll {
|
|
|
|
src = ./python.patch;
|
|
|
|
inherit (python.sourceVersion) major minor; # Should be changed in case of PyPy
|
|
|
|
});
|
2018-08-16 11:46:51 +00:00
|
|
|
|
2019-02-17 09:12:58 +00:00
|
|
|
postPatch = lib.optionalString (cudaSupport && lib.versionAtLeast cudatoolkit.version "9.0") ''
|
2017-09-17 04:08:22 +00:00
|
|
|
# CUDA 9.0 doesn't support sm_20
|
|
|
|
sed -i 's,20 21(20) ,,' cmake/Cuda.cmake
|
2019-02-17 09:12:58 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
preConfigure = lib.optionalString pythonSupport ''
|
|
|
|
# We need this when building with Python bindings
|
|
|
|
export BOOST_LIBRARYDIR="${boost.out}/lib";
|
2017-09-17 04:08:22 +00:00
|
|
|
'';
|
|
|
|
|
2017-09-03 13:15:39 +00:00
|
|
|
postInstall = ''
|
|
|
|
# Internal static library.
|
|
|
|
rm $out/lib/libproto.a
|
2015-07-04 23:42:54 +00:00
|
|
|
|
2018-08-16 11:46:51 +00:00
|
|
|
# Install models
|
|
|
|
cp -a ../models $out/share/Caffe/models
|
|
|
|
|
2017-09-03 13:15:39 +00: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-04 23:42:54 +00:00
|
|
|
'';
|
|
|
|
|
2018-08-16 11:46:51 +00:00
|
|
|
doInstallCheck = false; # build takes more than 30 min otherwise
|
|
|
|
installCheckPhase = ''
|
|
|
|
model=bvlc_reference_caffenet
|
|
|
|
m_path="$out/share/Caffe/models/$model"
|
|
|
|
$bin/bin/caffe test \
|
|
|
|
-model "$m_path/deploy.prototxt" \
|
|
|
|
-solver "$m_path/solver.prototxt" \
|
|
|
|
-weights "${test_model_weights}"
|
|
|
|
'';
|
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2015-07-04 23:42:54 +00:00
|
|
|
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.
|
|
|
|
'';
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "http://caffe.berkeleyvision.org/";
|
2015-07-04 23:42:54 +00:00
|
|
|
maintainers = with maintainers; [ jb55 ];
|
|
|
|
license = licenses.bsd2;
|
2018-08-16 11:46:51 +00:00
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
2015-07-04 23:42:54 +00:00
|
|
|
};
|
|
|
|
}
|