4c3684c0460727223a9705655ea559a9b0e4b58e — DaniĆ«l de Kok 2 months ago 9e6a633 master
libtensorflow_1_15_0: init at 1.15.0

Also bring back libtensorflow 1.14.0. It's nice to have prebuilt
Tensorflow versions available with optimizations and multiple CUDA
capabilities. So, let's add them back to my package set.
3 files changed, 160 insertions(+), 0 deletions(-)

M default.nix
A pkgs/libtensorflow/1_14_0.nix
A pkgs/libtensorflow/1_15_0.nix
M default.nix => default.nix +12 -0
@@ 8,6 8,18 @@ rec {
   conllx-utils = pkgs.callPackage ./pkgs/conllx-utils {};
   dact = pkgs.libsForQt5.callPackage ./pkgs/dact { alpinocorpus = alpinocorpus; };
 
+  libtensorflow_1_14_0 = with pkgs; callPackage ./pkgs/libtensorflow/1_14_0.nix {
+    inherit (linuxPackages) nvidia_x11;
+    cudatoolkit = cudatoolkit_10_0;
+    cudnn = cudnn_cudatoolkit_10_0;
+  };
+
+  libtensorflow_1_15_0 = with pkgs; callPackage ./pkgs/libtensorflow/1_15_0.nix {
+    inherit (linuxPackages) nvidia_x11;
+    cudatoolkit = cudatoolkit_10_0;
+    cudnn = cudnn_cudatoolkit_10_0;
+  };
+
   # Python packages
   pythonPackages = python2Packages;
   python2Packages = python27Packages;

A pkgs/libtensorflow/1_14_0.nix => pkgs/libtensorflow/1_14_0.nix +76 -0
@@ 0,0 1,76 @@
+{ config, stdenv
+, fetchurl
+, patchelf
+, cudaSupport ? config.cudaSupport or 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.dylib $out/lib/libtensorflow.dylib
+      install_name_tool -id $out/lib/libtensorflow_framework.dylib $out/lib/libtensorflow_framework.dylib
+    ''
+    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 {
+  pname = "libtensorflow";
+  version = "1.14.0";
+
+  src = fetchurl {
+    url = "https://blob.danieldk.eu/${pname}/${pname}-${tfType}-${system}-avx-fma-${version}.tar.gz";
+    sha256 =
+      if system == "linux-x86_64" then
+        if cudaSupport
+        then "0ygq7ddjd4ahzkjgfjy01zxkczkxy6n5jp3bb75z02nlx87pw3d0"
+        else "1xcgkls4hrxgdhnap4ngnda3l8a0b6fp41xp2xpmmm51rbgfzs90"
+      else if system == "darwin-x86_64" then
+        if cudaSupport
+        then unavailable
+        else "120lr69f684lfcv5chivkq0xxaf0jjp0i7ms542mb971iji95cmv"
+      else unavailable;
+  };
+
+  # Patch library to use our libc, libstdc++ and others
+  buildCommand = ''
+    . $stdenv/setup
+    mkdir -pv $out
+    tar -C $out -xzf $src
+    chmod -R +w $out
+    ${patchLibs}
+
+    # 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
+  '';
+
+  meta = {
+    description = "C API for TensorFlow";
+    homepage = https://www.tensorflow.org/versions/master/install/install_c;
+    license = licenses.asl20;
+    platforms = with platforms; linux ++ darwin;
+  };
+}

A pkgs/libtensorflow/1_15_0.nix => pkgs/libtensorflow/1_15_0.nix +72 -0
@@ 0,0 1,72 @@
+{ config, stdenv
+, fetchurl
+, patchelf
+, cudaSupport ? config.cudaSupport or 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 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.dylib $out/lib/libtensorflow.dylib
+      install_name_tool -id $out/lib/libtensorflow_framework.dylib $out/lib/libtensorflow_framework.dylib
+    ''
+    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 {
+  pname = "libtensorflow";
+  version = "1.15.0";
+
+  src = fetchurl {
+    url = "https://blob.danieldk.eu/${pname}/${pname}-${tfType}-${system}-avx-fma-${version}.tar.gz";
+    sha256 =
+      if system == "linux-x86_64" then
+        if cudaSupport
+        then "1gkx76lc9zi8xcqxm1n2mmf44bb7nc59h9k6szlyas735d500q7f"
+        else "0yrm9jkb31a8y5brlmh0z2bwkh0z62x2yr4b8vwzlh4xicq3cll2"
+      else unavailable;
+  };
+
+  # Patch library to use our libc, libstdc++ and others
+  buildCommand = ''
+    . $stdenv/setup
+    mkdir -pv $out
+    tar -C $out -xzf $src
+    chmod -R +w $out
+    ${patchLibs}
+
+    # 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
+  '';
+
+  meta = {
+    description = "C API for TensorFlow";
+    homepage = https://www.tensorflow.org/versions/master/install/install_c;
+    license = licenses.asl20;
+    platforms = with platforms; linux ++ darwin;
+  };
+}