2018-05-04 23:00:50 +01:00
|
|
|
|
{ buildPythonPackage, pythonOlder,
|
2018-05-04 15:19:31 +01:00
|
|
|
|
cudaSupport ? false, cudatoolkit ? null, cudnn ? null,
|
2018-07-21 01:44:44 +01:00
|
|
|
|
fetchFromGitHub, lib, numpy, pyyaml, cffi, typing, cmake,
|
|
|
|
|
linkFarm, symlinkJoin,
|
2018-05-04 15:19:31 +01:00
|
|
|
|
utillinux, which }:
|
2017-07-16 20:15:05 +01:00
|
|
|
|
|
2018-05-04 15:19:31 +01:00
|
|
|
|
assert cudnn == null || cudatoolkit != null;
|
|
|
|
|
assert !cudaSupport || cudatoolkit != null;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cudatoolkit_joined = symlinkJoin {
|
|
|
|
|
name = "${cudatoolkit.name}-unsplit";
|
|
|
|
|
paths = [ cudatoolkit.out cudatoolkit.lib ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Normally libcuda.so.1 is provided at runtime by nvidia-x11 via
|
|
|
|
|
# LD_LIBRARY_PATH=/run/opengl-driver/lib. We only use the stub
|
|
|
|
|
# libcuda.so from cudatoolkit for running tests, so that we don’t have
|
|
|
|
|
# to recompile pytorch on every update to nvidia-x11 or the kernel.
|
|
|
|
|
cudaStub = linkFarm "cuda-stub" [{
|
|
|
|
|
name = "libcuda.so.1";
|
|
|
|
|
path = "${cudatoolkit}/lib/stubs/libcuda.so";
|
|
|
|
|
}];
|
|
|
|
|
cudaStubEnv = lib.optionalString cudaSupport
|
|
|
|
|
"LD_LIBRARY_PATH=${cudaStub}\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ";
|
|
|
|
|
|
|
|
|
|
in buildPythonPackage rec {
|
2018-08-30 16:30:29 +01:00
|
|
|
|
version = "0.4.1";
|
2017-07-16 20:15:05 +01:00
|
|
|
|
pname = "pytorch";
|
|
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2017-08-19 02:22:23 +01:00
|
|
|
|
owner = "pytorch";
|
|
|
|
|
repo = "pytorch";
|
|
|
|
|
rev = "v${version}";
|
2018-05-04 15:19:31 +01:00
|
|
|
|
fetchSubmodules = true;
|
2018-08-30 16:30:29 +01:00
|
|
|
|
sha256 = "1cr8h47jxgfar5bamyvlayvqymnb2qvp7rr0ka2d2d4rdldf9lrp";
|
2017-07-16 20:15:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-05-04 15:19:31 +01:00
|
|
|
|
preConfigure = lib.optionalString cudaSupport ''
|
2018-05-04 23:00:50 +01:00
|
|
|
|
export CC=${cudatoolkit.cc}/bin/gcc CXX=${cudatoolkit.cc}/bin/g++
|
2018-05-04 15:19:31 +01:00
|
|
|
|
'' + lib.optionalString (cudaSupport && cudnn != null) ''
|
|
|
|
|
export CUDNN_INCLUDE_DIR=${cudnn}/include
|
2017-07-16 20:15:05 +01:00
|
|
|
|
'';
|
|
|
|
|
|
2018-09-12 08:22:52 +01:00
|
|
|
|
preFixup = ''
|
|
|
|
|
function join_by { local IFS="$1"; shift; echo "$*"; }
|
|
|
|
|
function strip2 {
|
|
|
|
|
IFS=':'
|
|
|
|
|
read -ra RP <<< $(patchelf --print-rpath $1)
|
|
|
|
|
IFS=' '
|
|
|
|
|
RP_NEW=$(join_by : ''${RP[@]:2})
|
|
|
|
|
patchelf --set-rpath \$ORIGIN:''${RP_NEW} "$1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for f in $(find ''${out} -name 'libcaffe2*.so')
|
|
|
|
|
do
|
|
|
|
|
strip2 $f
|
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
|
2017-07-16 20:15:05 +01:00
|
|
|
|
buildInputs = [
|
|
|
|
|
cmake
|
|
|
|
|
numpy.blas
|
2018-05-04 15:19:31 +01:00
|
|
|
|
utillinux
|
|
|
|
|
which
|
|
|
|
|
] ++ lib.optionals cudaSupport [cudatoolkit_joined cudnn];
|
2017-11-22 22:02:34 +00:00
|
|
|
|
|
2017-07-16 20:15:05 +01:00
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
|
cffi
|
|
|
|
|
numpy
|
|
|
|
|
pyyaml
|
2018-05-04 23:00:50 +01:00
|
|
|
|
] ++ lib.optional (pythonOlder "3.5") typing;
|
2017-07-16 20:15:05 +01:00
|
|
|
|
|
2018-05-04 15:19:31 +01:00
|
|
|
|
checkPhase = ''
|
2018-09-12 08:22:52 +01:00
|
|
|
|
${cudaStubEnv}python test/run_test.py --exclude dataloader sparse torch utils
|
2017-07-16 20:15:05 +01:00
|
|
|
|
'';
|
2017-11-22 22:02:34 +00:00
|
|
|
|
|
2017-07-16 20:15:05 +01:00
|
|
|
|
meta = {
|
|
|
|
|
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration.";
|
2018-06-27 21:12:57 +01:00
|
|
|
|
homepage = https://pytorch.org/;
|
2017-07-16 20:15:05 +01:00
|
|
|
|
license = lib.licenses.bsd3;
|
|
|
|
|
platforms = lib.platforms.linux;
|
|
|
|
|
maintainers = with lib.maintainers; [ teh ];
|
|
|
|
|
};
|
|
|
|
|
}
|