2017-11-10 18:07:58 +01:00
|
|
|
{ stdenv, buildBazelPackage, lib, fetchFromGitHub, fetchpatch, symlinkJoin
|
|
|
|
, buildPythonPackage, isPy3k, pythonOlder, pythonAtLeast
|
|
|
|
, which, swig, binutils, glibcLocales
|
2017-10-15 14:23:56 +02:00
|
|
|
, python, jemalloc, openmpi
|
2017-11-10 18:07:58 +01:00
|
|
|
, numpy, six, protobuf, tensorflow-tensorboard, backports_weakref, mock, enum34, absl-py
|
2017-10-15 14:23:56 +02:00
|
|
|
, cudaSupport ? false, nvidia_x11 ? null, cudatoolkit ? null, cudnn ? null
|
2018-02-27 01:16:33 +01:00
|
|
|
# XLA without CUDA is broken
|
|
|
|
, xlaSupport ? cudaSupport
|
2017-10-15 14:23:56 +02:00
|
|
|
# Default from ./configure script
|
|
|
|
, cudaCapabilities ? [ "3.5" "5.2" ]
|
2017-10-25 10:56:51 +02:00
|
|
|
, sse42Support ? false
|
|
|
|
, avx2Support ? false
|
|
|
|
, fmaSupport ? false
|
2017-02-15 12:30:30 +01:00
|
|
|
}:
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
assert cudaSupport -> nvidia_x11 != null
|
|
|
|
&& cudatoolkit != null
|
2017-10-15 14:23:56 +02:00
|
|
|
&& cudnn != null;
|
2017-02-26 11:03:27 +01:00
|
|
|
|
|
|
|
# unsupported combination
|
|
|
|
assert ! (stdenv.isDarwin && cudaSupport);
|
|
|
|
|
2017-10-15 14:23:56 +02:00
|
|
|
let
|
2017-02-15 12:30:30 +01:00
|
|
|
|
2017-10-15 14:23:56 +02:00
|
|
|
withTensorboard = pythonOlder "3.6";
|
2017-02-15 12:30:30 +01:00
|
|
|
|
2017-10-03 15:50:39 +02:00
|
|
|
cudatoolkit_joined = symlinkJoin {
|
2017-10-15 14:23:56 +02:00
|
|
|
name = "${cudatoolkit.name}-unsplit";
|
|
|
|
paths = [ cudatoolkit.out cudatoolkit.lib ];
|
|
|
|
};
|
|
|
|
|
|
|
|
tfFeature = x: if x then "1" else "0";
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
version = "1.5.0";
|
|
|
|
|
|
|
|
pkg = buildBazelPackage rec {
|
|
|
|
name = "tensorflow-build-${version}";
|
2017-10-15 14:23:56 +02:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "tensorflow";
|
|
|
|
repo = "tensorflow";
|
|
|
|
rev = "v${version}";
|
2017-11-10 18:07:58 +01:00
|
|
|
sha256 = "1c4djsaip901nasm7a6dsimr02bsv70a7b1g0kysb4n39qpdh22q";
|
2017-10-15 14:23:56 +02:00
|
|
|
};
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
patches = [
|
|
|
|
# Fix build with Bazel >= 0.10
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/tensorflow/tensorflow/commit/6fcfab770c2672e2250e0f5686b9545d99eb7b2b.patch";
|
|
|
|
sha256 = "0p61za1mx3a7gj1s5lsps16fcw18iwnvq2b46v1kyqfgq77a12vb";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/tensorflow/tensorflow/commit/3f57956725b553d196974c9ad31badeb3eabf8bb.patch";
|
|
|
|
sha256 = "11dja5gqy0qw27sc9b6yw9r0lfk8dznb32vrqqfcnypk2qmv26va";
|
|
|
|
})
|
|
|
|
];
|
2017-10-15 14:23:56 +02:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
nativeBuildInputs = [ swig which ];
|
2017-10-15 14:23:56 +02:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
buildInputs = [ python jemalloc openmpi glibcLocales numpy ]
|
|
|
|
++ lib.optionals cudaSupport [ cudatoolkit cudnn nvidia_x11 ];
|
2017-10-15 14:23:56 +02:00
|
|
|
|
|
|
|
preConfigure = ''
|
|
|
|
patchShebangs configure
|
|
|
|
|
|
|
|
export PYTHON_BIN_PATH="${python.interpreter}"
|
2017-11-10 18:07:58 +01:00
|
|
|
export PYTHON_LIB_PATH="$NIX_BUILD_TOP/site-packages"
|
2017-10-15 14:23:56 +02:00
|
|
|
export TF_NEED_GCP=1
|
|
|
|
export TF_NEED_HDFS=1
|
|
|
|
export TF_ENABLE_XLA=${tfFeature xlaSupport}
|
2017-11-10 18:07:58 +01:00
|
|
|
export CC_OPT_FLAGS=" "
|
|
|
|
# https://github.com/tensorflow/tensorflow/issues/14454
|
|
|
|
export TF_NEED_MPI=${tfFeature cudaSupport}
|
|
|
|
export TF_NEED_CUDA=${tfFeature cudaSupport}
|
2017-10-15 14:23:56 +02:00
|
|
|
${lib.optionalString cudaSupport ''
|
|
|
|
export CUDA_TOOLKIT_PATH=${cudatoolkit_joined}
|
|
|
|
export TF_CUDA_VERSION=${cudatoolkit.majorVersion}
|
|
|
|
export CUDNN_INSTALL_PATH=${cudnn}
|
|
|
|
export TF_CUDNN_VERSION=${cudnn.majorVersion}
|
|
|
|
export GCC_HOST_COMPILER_PATH=${cudatoolkit.cc}/bin/gcc
|
|
|
|
export TF_CUDA_COMPUTE_CAPABILITIES=${lib.concatStringsSep "," cudaCapabilities}
|
|
|
|
''}
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
mkdir -p "$PYTHON_LIB_PATH"
|
2017-10-15 14:23:56 +02:00
|
|
|
'';
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
NIX_LDFLAGS = lib.optionals cudaSupport [ "-lcublas" "-lcudnn" "-lcuda" "-lcudart" ];
|
|
|
|
|
2017-10-15 14:23:56 +02:00
|
|
|
hardeningDisable = [ "all" ];
|
|
|
|
|
|
|
|
bazelFlags = [ "--config=opt" ]
|
2017-10-25 10:56:51 +02:00
|
|
|
++ lib.optional sse42Support "--copt=-msse4.2"
|
|
|
|
++ lib.optional avx2Support "--copt=-mavx2"
|
|
|
|
++ lib.optional fmaSupport "--copt=-mfma"
|
2017-10-15 14:23:56 +02:00
|
|
|
++ lib.optional cudaSupport "--config=cuda";
|
|
|
|
|
|
|
|
bazelTarget = "//tensorflow/tools/pip_package:build_pip_package";
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
fetchAttrs = {
|
|
|
|
preInstall = ''
|
|
|
|
rm -rf $bazelOut/external/{bazel_tools,\@bazel_tools.marker,local_*,\@local_*}
|
|
|
|
'';
|
2017-10-15 14:23:56 +02:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
sha256 = "1nc98aqrp14q7llypcwaa0kdn9xi7r0p1mnd3vmmn1m299py33ca";
|
|
|
|
};
|
2017-10-15 14:23:56 +02:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
buildAttrs = {
|
|
|
|
preBuild = ''
|
|
|
|
patchShebangs .
|
|
|
|
find -type f -name CROSSTOOL\* -exec sed -i \
|
|
|
|
-e 's,/usr/bin/ar,${binutils.bintools}/bin/ar,g' \
|
|
|
|
{} \;
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
sed -i 's,.*bdist_wheel.*,cp -rL . "$out"; exit 0,' bazel-bin/tensorflow/tools/pip_package/build_pip_package
|
|
|
|
bazel-bin/tensorflow/tools/pip_package/build_pip_package $PWD/dist
|
|
|
|
'';
|
|
|
|
};
|
2017-10-15 14:23:56 +02:00
|
|
|
|
|
|
|
dontFixup = true;
|
2017-11-10 18:07:58 +01:00
|
|
|
};
|
2017-10-15 14:23:56 +02:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
in buildPythonPackage rec {
|
|
|
|
pname = "tensorflow";
|
|
|
|
inherit version;
|
2017-10-15 14:23:56 +02:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
src = pkg;
|
2017-10-15 14:23:56 +02:00
|
|
|
|
|
|
|
installFlags = lib.optional (!withTensorboard) "--no-dependencies";
|
2017-02-15 12:30:30 +01:00
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
postPatch = lib.optionalString (pythonAtLeast "3.4") ''
|
|
|
|
sed -i '/enum34/d' setup.py
|
2017-10-15 14:23:56 +02:00
|
|
|
'';
|
|
|
|
|
2017-11-10 18:07:58 +01:00
|
|
|
propagatedBuildInputs = [ numpy six protobuf absl-py ]
|
|
|
|
++ lib.optional (!isPy3k) mock
|
|
|
|
++ lib.optionals (pythonOlder "3.4") [ backports_weakref enum34 ]
|
|
|
|
++ lib.optional withTensorboard tensorflow-tensorboard;
|
|
|
|
|
|
|
|
# Actual tests are slow and impure.
|
|
|
|
checkPhase = ''
|
2017-10-15 14:23:56 +02:00
|
|
|
${python.interpreter} -c "import tensorflow"
|
|
|
|
'';
|
2017-11-10 18:07:58 +01:00
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "Computation using data flow graphs for scalable machine learning";
|
2018-02-27 01:16:33 +01:00
|
|
|
homepage = http://tensorflow.org;
|
2017-11-10 18:07:58 +01:00
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ jyp abbradar ];
|
2018-03-15 01:08:06 +01:00
|
|
|
platforms = platforms.linux;
|
2018-02-27 01:16:33 +01:00
|
|
|
broken = !(xlaSupport -> cudaSupport);
|
2017-11-10 18:07:58 +01:00
|
|
|
};
|
|
|
|
}
|