From 771e403786d58bd48898b951de733e2d726b3e35 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 17 Sep 2017 18:03:00 +0300 Subject: [PATCH] python.pkgs.Theano: merge CUDA and non-CUDA versions --- .../python-modules/Theano/default.nix | 75 +++++++++++++++++++ .../Theano/theano-with-cuda/default.nix | 65 ---------------- .../Theano/theano-without-cuda/default.nix | 44 ----------- pkgs/top-level/python-packages.nix | 28 +++---- 4 files changed, 87 insertions(+), 125 deletions(-) create mode 100644 pkgs/development/python-modules/Theano/default.nix delete mode 100644 pkgs/development/python-modules/Theano/theano-with-cuda/default.nix delete mode 100644 pkgs/development/python-modules/Theano/theano-without-cuda/default.nix diff --git a/pkgs/development/python-modules/Theano/default.nix b/pkgs/development/python-modules/Theano/default.nix new file mode 100644 index 000000000000..e0ff839ce1b7 --- /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 f8b7a713d08e..000000000000 --- 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 e93af7436190..000000000000 --- 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 53469afd5931..a084abf9bedc 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";