diff --git a/temporary/python-packages.nix b/temporary/python-packages.nix index 8e18a36..91bc7bd 100644 --- a/temporary/python-packages.nix +++ b/temporary/python-packages.nix @@ -16,4 +16,29 @@ pkgs: self: super: with self; { cudnn = pkgs.cudnn_cudatoolkit90; inherit (pkgs.linuxPackages) nvidia_x11; }; + + # https://github.com/NixOS/nixpkgs/pull/26580 (Cuda definitions are backwards too) + libgpuarray = callPackage ./theano-libgpuarray.nix { + clblas = pkgs.clblas.override { inherit boost; }; + cudaSupport = pkgs.config.cudaSupport or false; + inherit (pkgs.linuxPackages) nvidia_x11; + }; + + Theano = callPackage ./theano.nix rec { + cudaSupport = pkgs.config.cudaSupport or false; + cudnnSupport = cudaSupport; + cudatoolkit = pkgs.cudatoolkit8; + cudnn = pkgs.cudnn_cudatoolkit8; + inherit (pkgs.linuxPackages) nvidia_x11; + }; + + TheanoWithoutCuda = super.TheanoWithoutCuda.override { + cudaSupport = false; + cudnnSupport = false; + }; + + TheanoWithCuda = super.TheanoWithCuda.override { + cudaSupport = true; + cudnnSupport = true; + }; } diff --git a/temporary/theano-libgpuarray.nix b/temporary/theano-libgpuarray.nix new file mode 100644 index 0000000..ef01fde --- /dev/null +++ b/temporary/theano-libgpuarray.nix @@ -0,0 +1,83 @@ +{ stdenv +, lib +, buildPythonPackage +, fetchFromGitHub +, cmake +, cython +, numpy +, six +, nose +, Mako +, cudaSupport ? false, cudatoolkit , nvidia_x11 +, openclSupport ? true, ocl-icd, clblas +}: + +assert cudaSupport -> nvidia_x11 != null + && cudatoolkit != null; + +buildPythonPackage rec { + pname = "libgpuarray"; + version = "0.7.5"; + name = pname + "-" + version; + + src = fetchFromGitHub { + owner = "Theano"; + repo = "libgpuarray"; + rev = "v${version}"; + sha256 = "0zkdwjq3k6ciiyf8y5w663fbsnmzhgy27yvpxfhkpxazw9vg3l5v"; + }; + + # requires a GPU + doCheck = false; + + configurePhase = "cmakeConfigurePhase"; + + libraryPath = lib.makeLibraryPath ( + [] + ++ lib.optionals cudaSupport [ cudatoolkit.lib cudatoolkit.out nvidia_x11 ] + ++ lib.optionals openclSupport ([ clblas ] ++ lib.optional (!stdenv.isDarwin) ocl-icd) + ); + + preBuild = '' + make -j$NIX_BUILD_CORES + make install + + export NIX_CFLAGS_COMPILE="-L $out/lib -I $out/include $NIX_CFLAGS_COMPILE" + + cd .. + ''; + + postFixup = '' + rm $out/lib/libgpuarray-static.a + '' + stdenv.lib.optionalString (!stdenv.isDarwin) '' + function fixRunPath { + p=$(patchelf --print-rpath $1) + patchelf --set-rpath "$p:$libraryPath" $1 + } + + fixRunPath $out/lib/libgpuarray.so + ''; + + propagatedBuildInputs = [ + numpy + six + Mako + ]; + + enableParallelBuilding = true; + + buildInputs = [ + cmake + cython + nose + ]; + + meta = with stdenv.lib; { + homepage = "https://github.com/Theano/libgpuarray"; + description = "Library to manipulate tensors on GPU."; + license = licenses.free; + maintainers = with maintainers; [ artuuge ]; + platforms = platforms.unix; + }; + +} diff --git a/temporary/theano.nix b/temporary/theano.nix new file mode 100644 index 0000000..793488f --- /dev/null +++ b/temporary/theano.nix @@ -0,0 +1,88 @@ +{ stdenv +, runCommandCC +, lib +, fetchPypi +, gcc +, buildPythonPackage +, isPyPy +, pythonOlder +, isPy3k +, nose +, numpy +, scipy +, six +, libgpuarray +, cudaSupport ? false, cudatoolkit +, cudnnSupport ? false, cudnn +, nvidia_x11 +}: + +assert cudnnSupport -> cudaSupport; + +assert cudaSupport -> nvidia_x11 != null + && cudatoolkit != null + && cudnn != null; + +let + wrapped = command: buildTop: buildInputs: + runCommandCC "${command}-wrapped" { inherit buildInputs; } '' + type -P '${command}' || { echo '${command}: not found'; exit 1; } + cat > "$out" <