about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/science/math/caffe
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-02-24 01:09:00 +0000
committerAlyssa Ross <hi@alyssa.is>2019-02-24 01:09:00 +0000
commit072c01a28f865e9487df09aed7ddff328252fb36 (patch)
tree6df6e652915940255f294ed8998cce1c4c7c2d40 /nixpkgs/pkgs/applications/science/math/caffe
parent024b46ff20027c15322e5d868ecec42632556d4b (diff)
parent969cff2691a02b3d7e5468beda26c482d8986644 (diff)
downloadnixlib-072c01a28f865e9487df09aed7ddff328252fb36.tar
nixlib-072c01a28f865e9487df09aed7ddff328252fb36.tar.gz
nixlib-072c01a28f865e9487df09aed7ddff328252fb36.tar.bz2
nixlib-072c01a28f865e9487df09aed7ddff328252fb36.tar.lz
nixlib-072c01a28f865e9487df09aed7ddff328252fb36.tar.xz
nixlib-072c01a28f865e9487df09aed7ddff328252fb36.tar.zst
nixlib-072c01a28f865e9487df09aed7ddff328252fb36.zip
Merge commit '969cff2691a02b3d7e5468beda26c482d8986644'
Diffstat (limited to 'nixpkgs/pkgs/applications/science/math/caffe')
-rw-r--r--nixpkgs/pkgs/applications/science/math/caffe/default.nix30
-rw-r--r--nixpkgs/pkgs/applications/science/math/caffe/python.patch70
2 files changed, 89 insertions, 11 deletions
diff --git a/nixpkgs/pkgs/applications/science/math/caffe/default.nix b/nixpkgs/pkgs/applications/science/math/caffe/default.nix
index e56c63e01bf0..9ee56041ed38 100644
--- a/nixpkgs/pkgs/applications/science/math/caffe/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/caffe/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, runCommand
+{ config, stdenv, lib, runCommand
 , fetchFromGitHub
 , fetchurl
 , cmake
@@ -13,10 +13,11 @@
 , Accelerate, CoreGraphics, CoreVideo
 , lmdbSupport ? true, lmdb
 , leveldbSupport ? true, leveldb, snappy
-, cudaSupport ? stdenv.isLinux, cudatoolkit
-, cudnnSupport ? false, cudnn ? null
+, cudaSupport ? config.cudaSupport or false, cudatoolkit
+, cudnnSupport ? cudaSupport, cudnn ? null
 , ncclSupport ? false, nccl ? null
 , pythonSupport ? false, python ? null, numpy ? null
+, substituteAll
 }:
 
 assert leveldbSupport -> (leveldb != null && snappy != null);
@@ -50,7 +51,9 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ cmake doxygen ];
 
   cmakeFlags =
-    [ (if pythonSupport then "-Dpython_version=${python.version}" else "-DBUILD_python=OFF")
+    # It's important that caffe is passed the major and minor version only because that's what
+    # boost_python expects
+    [ (if pythonSupport then "-Dpython_version=3${python.pythonVersion}" else "-DBUILD_python=OFF")
       "-DBLAS=open"
     ] ++ (if cudaSupport then [
            "-DCUDA_ARCH_NAME=All"
@@ -75,16 +78,21 @@ stdenv.mkDerivation rec {
   outputs = [ "bin" "out"];
   propagatedBuildOutputs = []; # otherwise propagates out -> bin cycle
 
-  patches = [ ./darwin.patch ];
+  patches = [
+    ./darwin.patch
+  ] ++ lib.optional pythonSupport (substituteAll {
+    src = ./python.patch;
+    inherit (python.sourceVersion) major minor;  # Should be changed in case of PyPy
+  });
 
-  preConfigure = lib.optionalString (cudaSupport && lib.versionAtLeast cudatoolkit.version "9.0") ''
+  postPatch = 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
+  '';
+
+  preConfigure = lib.optionalString pythonSupport ''
+    # We need this when building with Python bindings
+    export BOOST_LIBRARYDIR="${boost.out}/lib";
   '';
 
   postInstall = ''
diff --git a/nixpkgs/pkgs/applications/science/math/caffe/python.patch b/nixpkgs/pkgs/applications/science/math/caffe/python.patch
new file mode 100644
index 000000000000..b1bed6c174b8
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/caffe/python.patch
@@ -0,0 +1,70 @@
+commit b14ca23651d390fcae4a929dedc7c33a83453a66
+Author: Frederik Rietdijk <fridh@fridh.nl>
+Date:   Sun Feb 17 08:41:27 2019 +0100
+
+    Find boost_pythonXX
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 08f56a33..0a04592a 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -99,10 +99,10 @@ add_subdirectory(docs)
+ add_custom_target(lint COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
+ 
+ # ---[ pytest target
+-if(BUILD_python)
+-  add_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )
+-  add_dependencies(pytest pycaffe)
+-endif()
++# if(BUILD_python)
++#   add_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )
++#   add_dependencies(pytest pycaffe)
++# endif()
+ 
+ # ---[ uninstall target
+ configure_file(
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index 4a5bac47..be026d43 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -141,37 +141,14 @@ if(BUILD_python)
+     # use python3
+     find_package(PythonInterp 3.0)
+     find_package(PythonLibs 3.0)
+-    find_package(NumPy 1.7.1)
+-    # Find the matching boost python implementation
+-    set(version ${PYTHONLIBS_VERSION_STRING})
+-
+-    STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
+-    find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
+-    set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+-
+-    while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
+-      STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} )
+-
+-      STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
+-      find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
+-      set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+-
+-      STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
+-      if("${has_more_version}" STREQUAL "")
+-        break()
+-      endif()
+-    endwhile()
+-    if(NOT Boost_PYTHON_FOUND)
+-      find_package(Boost 1.46 COMPONENTS python)
+-    endif()
+   else()
+     # disable Python 3 search
+     find_package(PythonInterp 2.7)
+     find_package(PythonLibs 2.7)
+-    find_package(NumPy 1.7.1)
+-    find_package(Boost 1.46 COMPONENTS python)
+   endif()
+-  if(PYTHONLIBS_FOUND AND NUMPY_FOUND AND Boost_PYTHON_FOUND)
++  find_package(NumPy 1.7.1)
++  find_package(Boost 1.46 REQUIRED COMPONENTS python@major@@minor@)
++  if(PYTHONLIBS_FOUND AND NUMPY_FOUND AND BOOST_PYTHON@major@@minor@_FOUND)
+     set(HAVE_PYTHON TRUE)
+     if(BUILD_python_layer)
+       list(APPEND Caffe_DEFINITIONS PRIVATE -DWITH_PYTHON_LAYER)