summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2017-09-17 18:03:00 +0300
committerNikolay Amiantov <ab@fmap.me>2017-10-19 12:47:30 +0300
commit771e403786d58bd48898b951de733e2d726b3e35 (patch)
treedc80c187be3239ac2daa31d20a96288b7ad3124d /pkgs
parentefd2444de5663df1cad443f41d4bfec4a1745f28 (diff)
downloadnixpkgs-771e403786d58bd48898b951de733e2d726b3e35.tar
nixpkgs-771e403786d58bd48898b951de733e2d726b3e35.tar.gz
nixpkgs-771e403786d58bd48898b951de733e2d726b3e35.tar.bz2
nixpkgs-771e403786d58bd48898b951de733e2d726b3e35.tar.lz
nixpkgs-771e403786d58bd48898b951de733e2d726b3e35.tar.xz
nixpkgs-771e403786d58bd48898b951de733e2d726b3e35.tar.zst
nixpkgs-771e403786d58bd48898b951de733e2d726b3e35.zip
python.pkgs.Theano: merge CUDA and non-CUDA versions
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/python-modules/Theano/default.nix75
-rw-r--r--pkgs/development/python-modules/Theano/theano-with-cuda/default.nix65
-rw-r--r--pkgs/development/python-modules/Theano/theano-without-cuda/default.nix44
-rw-r--r--pkgs/top-level/python-packages.nix28
4 files changed, 87 insertions, 125 deletions
diff --git a/pkgs/development/python-modules/Theano/default.nix b/pkgs/development/python-modules/Theano/default.nix
new file mode 100644
index 00000000000..e0ff839ce1b
--- /dev/null
+++ b/pkgs/development/python-modules/Theano/default.nix
@@ -0,0 +1,75 @@
+{ stdenv
+, lib
+, fetchPypi
+, gcc
+, writeScriptBin
+, buildPythonPackage
+, isPyPy
+, pythonOlder
+, isPy3k
+, nose
+, numpy
+, pydot_ng
+, scipy
+, six
+, libgpuarray
+, cudaSupport ? false, cudatoolkit
+, cudnnSupport ? false, cudnn
+}:
+
+assert cudnnSupport -> cudaSupport;
+
+let
+  extraFlags =
+    lib.optionals cudaSupport [ "-I ${cudatoolkit}/include" "-L ${cudatoolkit}/lib" ]
+    ++ lib.optionals cudnnSupport [ "-I ${cudnn}/include" "-L ${cudnn}/lib" ];
+
+  gcc_ = writeScriptBin "g++" ''
+    #!${stdenv.shell}
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${toString extraFlags}"
+    exec ${gcc}/bin/g++ "$@"
+  '';
+
+  libgpuarray_ = libgpuarray.override { inherit cudaSupport; };
+
+in buildPythonPackage rec {
+  name = "${pname}-${version}";
+  pname = "Theano";
+  version = "0.9.0";
+
+  disabled = isPyPy || pythonOlder "2.6" || (isPy3k && pythonOlder "3.3");
+
+  src = fetchPypi {
+    inherit pname version;
+    sha256 = "05xwg00da8smkvkh6ywbywqzj8dw7x840jr74wqhdy9icmqncpbl";
+  };
+
+  postPatch = ''
+    sed -i 's,g++,${gcc_}/bin/g++,g' theano/configdefaults.py
+  '' + lib.optionalString cudnnSupport ''
+    sed -i \
+      -e "s,ctypes.util.find_library('cudnn'),'${cudnn}/lib/libcudnn.so',g" \
+      -e "s/= _dnn_check_compile()/= (True, None)/g" \
+      theano/gpuarray/dnn.py
+  '';
+
+  preCheck = ''
+    mkdir -p check-phase
+    export HOME=$(pwd)/check-phase
+  '';
+  doCheck = false;
+  # takes far too long, also throws "TypeError: sort() missing 1 required positional argument: 'a'"
+  # when run from the installer, and testing with Python 3.5 hits github.com/Theano/Theano/issues/4276,
+  # the fix for which hasn't been merged yet.
+
+  # keep Nose around since running the tests by hand is possible from Python or bash
+  checkInputs = [ nose ];
+  propagatedBuildInputs = [ numpy numpy.blas scipy six libgpuarray_ ];
+
+  meta = with stdenv.lib; {
+    homepage = http://deeplearning.net/software/theano/;
+    description = "A Python library for large-scale array computation";
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ maintainers.bcdarwin ];
+  };
+}
diff --git a/pkgs/development/python-modules/Theano/theano-with-cuda/default.nix b/pkgs/development/python-modules/Theano/theano-with-cuda/default.nix
deleted file mode 100644
index f8b7a713d08..00000000000
--- a/pkgs/development/python-modules/Theano/theano-with-cuda/default.nix
+++ /dev/null
@@ -1,65 +0,0 @@
-{ buildPythonPackage
-, fetchFromGitHub
-, pythonOlder
-, future
-, numpy
-, six
-, scipy
-, nose
-, nose-parameterized
-, pydot_ng
-, sphinx
-, pygments
-, libgpuarray
-, python
-, pycuda
-, cudatoolkit
-, cudnn
-, stdenv
-}:
-
-buildPythonPackage rec {
-  name = "Theano-cuda-${version}";
-  version = "0.8.2";
-
-  src = fetchFromGitHub {
-    owner = "Theano";
-    repo = "Theano";
-    rev = "46fbfeb628220b5e42bf8277a5955c52d153e874";
-    sha256 = "1sl91gli3jaw5gpjqqab4fiq4x6282spqciaid1s65pjsf3k55sc";
-  };
-
-  doCheck = false;
-
-  patchPhase = ''
-    pushd theano/sandbox/gpuarray
-    sed -i -re '2s/^/from builtins import bytes\n/g' subtensor.py
-    sed -i -re "s/(b'2')/int(bytes(\1))/g" subtensor.py
-    sed -i -re "s/(ctx.bin_id\[\-2\])/int(\1)/g" subtensor.py
-
-    sed -i -re '2s/^/from builtins import bytes\n/g' dnn.py
-    sed -i -re "s/(b'30')/int(bytes(\1))/g" dnn.py
-    sed -i -re "s/(ctx.bin_id\[\-2:\])/int(\1)/g" dnn.py
-    popd
-  '';
-
-  dontStrip = true;
-
-  propagatedBuildInputs = [
-    numpy.blas
-    numpy
-    six
-    scipy
-    nose
-    nose-parameterized
-    pydot_ng
-    sphinx
-    pygments
-    pycuda
-    cudatoolkit
-    libgpuarray
-    cudnn
-  ] ++ (stdenv.lib.optional (pythonOlder "3.0") future);
-
-  passthru.cudaSupport = true;
-}
diff --git a/pkgs/development/python-modules/Theano/theano-without-cuda/default.nix b/pkgs/development/python-modules/Theano/theano-without-cuda/default.nix
deleted file mode 100644
index e93af743619..00000000000
--- a/pkgs/development/python-modules/Theano/theano-without-cuda/default.nix
+++ /dev/null
@@ -1,44 +0,0 @@
-{ stdenv
-, fetchurl
-, buildPythonPackage
-, isPyPy
-, pythonOlder
-, isPy3k
-, nose
-, numpy
-, pydot_ng
-, scipy
-, six
-}:
-
-buildPythonPackage rec {
-  name = "Theano-0.9.0";
-
-  disabled = isPyPy || pythonOlder "2.6" || (isPy3k && pythonOlder "3.3");
-
-  src = fetchurl {
-    url = "mirror://pypi/T/Theano/${name}.tar.gz";
-    sha256 = "05xwg00da8smkvkh6ywbywqzj8dw7x840jr74wqhdy9icmqncpbl";
-  };
-
-  #preCheck = ''
-  #  mkdir -p check-phase
-  #  export HOME=$(pwd)/check-phase
-  #'';
-  doCheck = false;
-  # takes far too long, also throws "TypeError: sort() missing 1 required positional argument: 'a'"
-  # when run from the installer, and testing with Python 3.5 hits github.com/Theano/Theano/issues/4276,
-  # the fix for which hasn't been merged yet.
-
-  # keep Nose around since running the tests by hand is possible from Python or bash
-  propagatedBuildInputs = [ nose numpy numpy.blas pydot_ng scipy six ];
-
-  meta = {
-    homepage = http://deeplearning.net/software/theano/;
-    description = "A Python library for large-scale array computation";
-    license = stdenv.lib.licenses.bsd3;
-    maintainers = [ stdenv.lib.maintainers.bcdarwin ];
-  };
-
-  passthru.cudaSupport = false;
-}
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 53469afd593..a084abf9bed 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -19833,24 +19833,20 @@ in {
 
   stevedore = callPackage ../development/python-modules/stevedore {};
 
-  Theano = self.TheanoWithoutCuda;
+  Theano = callPackage ../development/python-modules/Theano rec {
+    cudaSupport = pkgs.config.cudaSupport or false;
+    cudnnSupport = cudaSupport;
+  };
 
-  TheanoWithoutCuda = callPackage ../development/python-modules/Theano/theano-without-cuda { };
+  TheanoWithoutCuda = self.Theano.override {
+    cudaSupport = true;
+    cudnnSupport = true;
+  };
 
-  TheanoWithCuda = callPackage ../development/python-modules/Theano/theano-with-cuda (
-  let
-    boost = pkgs.boost159.override {
-      inherit (self) python numpy scipy;
-    };
-  in rec {
-    cudatoolkit = pkgs.cudatoolkit75;
-    cudnn = pkgs.cudnn5_cudatoolkit75;
-    inherit (self) numpy scipy;
-    pycuda = self.pycuda.override { inherit boost; };
-    libgpuarray = self.libgpuarray-cuda.override {
-      clblas = pkgs.clblas-cuda.override { inherit boost; };
-    };
-  });
+  TheanoWithCuda = self.Theano.override {
+    cudaSupport = false;
+    cudnnSupport = false;
+  };
 
   tidylib = buildPythonPackage rec {
     version = "0.2.4";