caffe: add darwin support (#44616)
This commit is contained in:
parent
995d005d84
commit
b7e50d52f0
47
pkgs/applications/science/math/caffe/darwin.patch
Normal file
47
pkgs/applications/science/math/caffe/darwin.patch
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
diff --git a/Makefile b/Makefile
|
||||||
|
index c823f66e..65b90c5e 100644
|
||||||
|
--- a/Makefile
|
||||||
|
+++ b/Makefile
|
||||||
|
@@ -32,9 +32,9 @@ SRC_DIRS := $(shell find * -type d -exec bash -c "find {} -maxdepth 1 \
|
||||||
|
LIBRARY_NAME := $(PROJECT)
|
||||||
|
LIB_BUILD_DIR := $(BUILD_DIR)/lib
|
||||||
|
STATIC_NAME := $(LIB_BUILD_DIR)/lib$(LIBRARY_NAME).a
|
||||||
|
-DYNAMIC_VERSION_MAJOR := 1
|
||||||
|
-DYNAMIC_VERSION_MINOR := 0
|
||||||
|
-DYNAMIC_VERSION_REVISION := 0
|
||||||
|
+DYNAMIC_VERSION_MAJOR := 1
|
||||||
|
+DYNAMIC_VERSION_MINOR := 0
|
||||||
|
+DYNAMIC_VERSION_REVISION := 0
|
||||||
|
DYNAMIC_NAME_SHORT := lib$(LIBRARY_NAME).so
|
||||||
|
#DYNAMIC_SONAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR)
|
||||||
|
DYNAMIC_VERSIONED_NAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR).$(DYNAMIC_VERSION_REVISION)
|
||||||
|
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
|
||||||
|
index c48255c8..cf4c580e 100644
|
||||||
|
--- a/cmake/Dependencies.cmake
|
||||||
|
+++ b/cmake/Dependencies.cmake
|
||||||
|
@@ -105,7 +105,6 @@ if(USE_OPENCV)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---[ BLAS
|
||||||
|
-if(NOT APPLE)
|
||||||
|
set(BLAS "Atlas" CACHE STRING "Selected BLAS library")
|
||||||
|
set_property(CACHE BLAS PROPERTY STRINGS "Atlas;Open;MKL")
|
||||||
|
|
||||||
|
@@ -123,17 +122,6 @@ if(NOT APPLE)
|
||||||
|
list(APPEND Caffe_LINKER_LIBS PUBLIC ${MKL_LIBRARIES})
|
||||||
|
list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_MKL)
|
||||||
|
endif()
|
||||||
|
-elseif(APPLE)
|
||||||
|
- find_package(vecLib REQUIRED)
|
||||||
|
- list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${vecLib_INCLUDE_DIR})
|
||||||
|
- list(APPEND Caffe_LINKER_LIBS PUBLIC ${vecLib_LINKER_LIBS})
|
||||||
|
-
|
||||||
|
- if(VECLIB_FOUND)
|
||||||
|
- if(NOT vecLib_INCLUDE_DIR MATCHES "^/System/Library/Frameworks/vecLib.framework.*")
|
||||||
|
- list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_ACCELERATE)
|
||||||
|
- endif()
|
||||||
|
- endif()
|
||||||
|
-endif()
|
||||||
|
|
||||||
|
# ---[ Python
|
||||||
|
if(BUILD_python)
|
@ -1,27 +1,39 @@
|
|||||||
{ stdenv, lib
|
{ stdenv, lib, runCommand
|
||||||
, fetchFromGitHub
|
, fetchFromGitHub
|
||||||
|
, fetchurl
|
||||||
, cmake
|
, cmake
|
||||||
, boost
|
, boost
|
||||||
, google-gflags
|
, google-gflags
|
||||||
, glog
|
, glog
|
||||||
, hdf5-cpp
|
, hdf5-cpp
|
||||||
, leveldb
|
|
||||||
, lmdb
|
|
||||||
, opencv3
|
, opencv3
|
||||||
, protobuf
|
, protobuf
|
||||||
, snappy
|
|
||||||
, doxygen
|
, doxygen
|
||||||
, openblas
|
, openblas
|
||||||
, cudaSupport ? true, cudatoolkit
|
, Accelerate, CoreGraphics, CoreVideo
|
||||||
|
, lmdbSupport ? true, lmdb
|
||||||
|
, leveldbSupport ? true, leveldb, snappy
|
||||||
|
, cudaSupport ? stdenv.isLinux, cudatoolkit
|
||||||
, cudnnSupport ? false, cudnn ? null
|
, cudnnSupport ? false, cudnn ? null
|
||||||
, ncclSupport ? false, nccl ? null
|
, ncclSupport ? false, nccl ? null
|
||||||
, pythonSupport ? false, python ? null, numpy ? null
|
, pythonSupport ? false, python ? null, numpy ? null
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
assert leveldbSupport -> (leveldb != null && snappy != null);
|
||||||
assert cudnnSupport -> cudaSupport;
|
assert cudnnSupport -> cudaSupport;
|
||||||
assert ncclSupport -> cudaSupport;
|
assert ncclSupport -> cudaSupport;
|
||||||
assert pythonSupport -> (python != null && numpy != null);
|
assert pythonSupport -> (python != null && numpy != null);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
name = "caffe-${version}";
|
name = "caffe-${version}";
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
@ -44,19 +56,27 @@ stdenv.mkDerivation rec {
|
|||||||
"-DCUDA_ARCH_NAME=All"
|
"-DCUDA_ARCH_NAME=All"
|
||||||
"-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc"
|
"-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc"
|
||||||
] else [ "-DCPU_ONLY=ON" ])
|
] else [ "-DCPU_ONLY=ON" ])
|
||||||
++ lib.optional ncclSupport "-DUSE_NCCL=ON";
|
++ ["-DUSE_NCCL=${toggle ncclSupport}"]
|
||||||
|
++ ["-DUSE_LEVELDB=${toggle leveldbSupport}"]
|
||||||
|
++ ["-DUSE_LMDB=${toggle lmdbSupport}"];
|
||||||
|
|
||||||
buildInputs = [ boost google-gflags glog protobuf hdf5-cpp lmdb leveldb snappy opencv3 openblas ]
|
buildInputs = [ boost google-gflags glog protobuf hdf5-cpp opencv3 openblas ]
|
||||||
++ lib.optional cudaSupport cudatoolkit
|
++ lib.optional cudaSupport cudatoolkit
|
||||||
++ lib.optional cudnnSupport cudnn
|
++ lib.optional cudnnSupport cudnn
|
||||||
|
++ lib.optional lmdbSupport lmdb
|
||||||
++ lib.optional ncclSupport nccl
|
++ lib.optional ncclSupport nccl
|
||||||
++ lib.optionals pythonSupport [ python numpy ];
|
++ lib.optionals leveldbSupport [ leveldb snappy ]
|
||||||
|
++ lib.optionals pythonSupport [ python numpy ]
|
||||||
|
++ lib.optionals stdenv.isDarwin [ Accelerate CoreGraphics CoreVideo ]
|
||||||
|
;
|
||||||
|
|
||||||
propagatedBuildInputs = lib.optional pythonSupport python.pkgs.protobuf;
|
propagatedBuildInputs = lib.optional pythonSupport python.pkgs.protobuf;
|
||||||
|
|
||||||
outputs = [ "bin" "out"];
|
outputs = [ "bin" "out"];
|
||||||
propagatedBuildOutputs = []; # otherwise propagates out -> bin cycle
|
propagatedBuildOutputs = []; # otherwise propagates out -> bin cycle
|
||||||
|
|
||||||
|
patches = [ ./darwin.patch ];
|
||||||
|
|
||||||
preConfigure = lib.optionalString (cudaSupport && lib.versionAtLeast cudatoolkit.version "9.0") ''
|
preConfigure = lib.optionalString (cudaSupport && lib.versionAtLeast cudatoolkit.version "9.0") ''
|
||||||
# CUDA 9.0 doesn't support sm_20
|
# CUDA 9.0 doesn't support sm_20
|
||||||
sed -i 's,20 21(20) ,,' cmake/Cuda.cmake
|
sed -i 's,20 21(20) ,,' cmake/Cuda.cmake
|
||||||
@ -71,6 +91,9 @@ stdenv.mkDerivation rec {
|
|||||||
# Internal static library.
|
# Internal static library.
|
||||||
rm $out/lib/libproto.a
|
rm $out/lib/libproto.a
|
||||||
|
|
||||||
|
# Install models
|
||||||
|
cp -a ../models $out/share/Caffe/models
|
||||||
|
|
||||||
moveToOutput "bin" "$bin"
|
moveToOutput "bin" "$bin"
|
||||||
'' + lib.optionalString pythonSupport ''
|
'' + lib.optionalString pythonSupport ''
|
||||||
mkdir -p $out/${python.sitePackages}
|
mkdir -p $out/${python.sitePackages}
|
||||||
@ -78,6 +101,16 @@ stdenv.mkDerivation rec {
|
|||||||
rm -rf $out/python
|
rm -rf $out/python
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
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}"
|
||||||
|
'';
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
description = "Deep learning framework";
|
description = "Deep learning framework";
|
||||||
longDescription = ''
|
longDescription = ''
|
||||||
@ -88,6 +121,6 @@ stdenv.mkDerivation rec {
|
|||||||
homepage = http://caffe.berkeleyvision.org/;
|
homepage = http://caffe.berkeleyvision.org/;
|
||||||
maintainers = with maintainers; [ jb55 ];
|
maintainers = with maintainers; [ jb55 ];
|
||||||
license = licenses.bsd2;
|
license = licenses.bsd2;
|
||||||
platforms = platforms.linux;
|
platforms = platforms.linux ++ platforms.darwin;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -20905,6 +20905,7 @@ with pkgs;
|
|||||||
cudnnSupport = cudaSupport;
|
cudnnSupport = cudaSupport;
|
||||||
# Used only for image loading.
|
# Used only for image loading.
|
||||||
opencv3 = opencv3WithoutCuda;
|
opencv3 = opencv3WithoutCuda;
|
||||||
|
inherit (darwin.apple_sdk.frameworks) Accelerate CoreGraphics CoreVideo;
|
||||||
};
|
};
|
||||||
|
|
||||||
caffe2 = callPackage ../development/libraries/science/math/caffe2 {
|
caffe2 = callPackage ../development/libraries/science/math/caffe2 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user