2018-07-23 10:07:09 +01:00
|
|
|
{ stdenv
|
|
|
|
, fetchurl
|
|
|
|
, patchelf
|
|
|
|
, cudaSupport ? false, symlinkJoin, cudatoolkit, cudnn, nvidia_x11
|
|
|
|
}:
|
|
|
|
with stdenv.lib;
|
|
|
|
let
|
|
|
|
tfType = if cudaSupport then "gpu" else "cpu";
|
|
|
|
system =
|
|
|
|
if stdenv.isx86_64
|
|
|
|
then if stdenv.isLinux then "linux-x86_64"
|
|
|
|
else if stdenv.isDarwin then "darwin-x86_64" else unavailable
|
|
|
|
else unavailable;
|
|
|
|
unavailable = throw "libtensorflow is not available for this platform!";
|
|
|
|
cudatoolkit_joined = symlinkJoin {
|
|
|
|
name = "unsplit_cudatoolkit";
|
|
|
|
paths = [ cudatoolkit.out
|
|
|
|
cudatoolkit.lib ];};
|
|
|
|
rpath = makeLibraryPath ([stdenv.cc.libc stdenv.cc.cc.lib] ++
|
|
|
|
optionals cudaSupport [ cudatoolkit_joined cudnn nvidia_x11 ]);
|
|
|
|
patchLibs =
|
|
|
|
if stdenv.isDarwin
|
|
|
|
then ''
|
|
|
|
install_name_tool -id $out/lib/libtensorflow.so $out/lib/libtensorflow.so
|
|
|
|
install_name_tool -id $out/lib/libtensorflow_framework.so $out/lib/libtensorflow_framework.so
|
|
|
|
''
|
|
|
|
else ''
|
|
|
|
${patchelf}/bin/patchelf --set-rpath "${rpath}:$out/lib" $out/lib/libtensorflow.so
|
|
|
|
${patchelf}/bin/patchelf --set-rpath "${rpath}" $out/lib/libtensorflow_framework.so
|
|
|
|
'';
|
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
2018-07-21 01:21:30 +01:00
|
|
|
pname = "libtensorflow";
|
2018-09-06 07:56:09 +01:00
|
|
|
version = "1.9.0";
|
2018-07-21 01:21:30 +01:00
|
|
|
name = "${pname}-${version}";
|
|
|
|
src = fetchurl {
|
2018-07-23 10:07:09 +01:00
|
|
|
url = "https://storage.googleapis.com/tensorflow/${pname}/${pname}-${tfType}-${system}-${version}.tar.gz";
|
|
|
|
sha256 =
|
|
|
|
if system == "linux-x86_64" then
|
|
|
|
if cudaSupport
|
2018-09-06 07:54:12 +01:00
|
|
|
then "1q3mh06x344im25z7r3vgrfksfdsi8fh8ldn6y2mf86h4d11yxc3"
|
2018-09-06 07:56:09 +01:00
|
|
|
else "0l9ps115ng5ffzdwphlqmj3jhidps2v5afppdzrbpzmy41xz0z21"
|
2018-07-23 10:07:09 +01:00
|
|
|
else if system == "darwin-x86_64" then
|
|
|
|
if cudaSupport
|
|
|
|
then unavailable
|
2018-09-06 07:54:12 +01:00
|
|
|
else "1qj0v1706w6mczycdsh38h2glyv5d25v62kdn98wxd5rw8f9v657"
|
2018-07-23 10:07:09 +01:00
|
|
|
else unavailable;
|
2018-07-21 01:21:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# Patch library to use our libc, libstdc++ and others
|
|
|
|
buildCommand = ''
|
|
|
|
. $stdenv/setup
|
|
|
|
mkdir -pv $out
|
|
|
|
tar -C $out -xzf $src
|
|
|
|
chmod +w $out/lib/libtensorflow.so
|
|
|
|
chmod +w $out/lib/libtensorflow_framework.so
|
2018-07-23 10:07:09 +01:00
|
|
|
${patchLibs}
|
2018-07-21 01:21:30 +01:00
|
|
|
chmod -w $out/lib/libtensorflow.so
|
|
|
|
chmod -w $out/lib/libtensorflow_framework.so
|
2018-10-19 13:10:14 +01:00
|
|
|
|
|
|
|
# Write pkgconfig file.
|
|
|
|
mkdir $out/lib/pkgconfig
|
|
|
|
cat > $out/lib/pkgconfig/tensorflow.pc << EOF
|
|
|
|
Name: TensorFlow
|
|
|
|
Version: ${version}
|
|
|
|
Description: Library for computation using data flow graphs for scalable machine learning
|
|
|
|
Requires:
|
|
|
|
Libs: -L$out/lib -ltensorflow
|
|
|
|
Cflags: -I$out/include/tensorflow
|
|
|
|
EOF
|
2018-07-21 01:21:30 +01:00
|
|
|
'';
|
|
|
|
|
2018-07-23 10:07:09 +01:00
|
|
|
meta = {
|
2018-07-21 01:21:30 +01:00
|
|
|
description = "C API for TensorFlow";
|
2018-07-23 10:07:09 +01:00
|
|
|
homepage = https://www.tensorflow.org/versions/master/install/install_c;
|
2018-07-21 01:21:30 +01:00
|
|
|
license = licenses.asl20;
|
2018-07-23 10:07:09 +01:00
|
|
|
platforms = with platforms; linux ++ darwin;
|
2018-07-21 01:21:30 +01:00
|
|
|
maintainers = [maintainers.basvandijk];
|
|
|
|
};
|
|
|
|
}
|