about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/science/math/tensorflow
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/science/math/tensorflow')
-rw-r--r--nixpkgs/pkgs/development/libraries/science/math/tensorflow/bin.nix71
-rw-r--r--nixpkgs/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix15
-rwxr-xr-xnixpkgs/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh26
3 files changed, 112 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/science/math/tensorflow/bin.nix b/nixpkgs/pkgs/development/libraries/science/math/tensorflow/bin.nix
new file mode 100644
index 000000000000..d42026c13cf9
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/science/math/tensorflow/bin.nix
@@ -0,0 +1,71 @@
+{ lib, stdenv
+, fetchurl
+, addOpenGLRunpath
+, cudaSupport ? false, symlinkJoin, cudatoolkit, cudnn, nvidia_x11
+}:
+
+with lib;
+let
+  broken = !stdenv.isLinux && !stdenv.isDarwin;
+
+  tfType = if cudaSupport then "gpu" else "cpu";
+
+  system =
+    if stdenv.isLinux then "linux"
+    else "darwin";
+
+  platform =  "x86_64";
+
+  rpath = makeLibraryPath ([stdenv.cc.libc stdenv.cc.cc.lib]
+                           ++ optionals cudaSupport [ cudatoolkit.out cudatoolkit.lib cudnn nvidia_x11 ]);
+
+  packages = import ./binary-hashes.nix;
+
+  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 --set-rpath "${rpath}:$out/lib" $out/lib/libtensorflow.so
+      patchelf --set-rpath "${rpath}" $out/lib/libtensorflow_framework.so
+      ${optionalString cudaSupport ''
+        addOpenGLRunpath $out/lib/libtensorflow.so $out/lib/libtensorflow_framework.so
+      ''}
+    '';
+
+in stdenv.mkDerivation rec {
+  pname = "libtensorflow";
+  inherit (packages) version;
+
+  src = fetchurl packages."${tfType}-${system}-${platform}";
+
+  nativeBuildInputs = optional cudaSupport addOpenGLRunpath;
+
+  # Patch library to use our libc, libstdc++ and others
+  buildCommand = ''
+    mkdir -pv $out
+    tar -C $out -xzf $src
+    chmod -R +w $out
+    ${patchLibs}
+
+    # Write pkg-config 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/install/lang_c";
+    license = licenses.asl20;
+    platforms = [ "x86_64-linux" "x86_64-darwin" ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix b/nixpkgs/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix
new file mode 100644
index 000000000000..b606e45477a9
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix
@@ -0,0 +1,15 @@
+{
+version = "2.4.0";
+"cpu-linux-x86_64" = {
+  url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz";
+  sha256 = "022p5jjwmb8rhyyis3cpk2lw45apl2vz49m2rgxmd75h783x1gjk";
+};
+"gpu-linux-x86_64" = {
+  url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.4.0.tar.gz";
+  sha256 = "1fclvbrn3fs8qmhmh3lzni7s7wl1w30a071b4gzh9ifnxdhip6lq";
+};
+"cpu-darwin-x86_64" = {
+  url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.4.0.tar.gz";
+  sha256 = "09x096nslg04c8sr7bd5v68a5gfinc0f1h36lbzn8bahs8b1agi3";
+};
+}
diff --git a/nixpkgs/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh b/nixpkgs/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh
new file mode 100755
index 000000000000..d571d38f7719
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+# ./prefetcher.sh 2.4.0 binary-hashes.nix
+
+version="$1"
+hashfile="$2"
+rm -f $hashfile
+echo "{" >> $hashfile
+echo "version = \"$version\";" >> $hashfile
+for sys in "linux" "darwin"; do
+    for tfpref in "cpu" "gpu"; do
+        for platform in "x86_64"; do
+            if [ $sys = "darwin" ] && [ $tfpref = "gpu" ]; then
+               continue
+            fi
+            url=https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-$tfpref-$sys-$platform-$version.tar.gz
+            hash=$(nix-prefetch-url $url)
+            echo "\"${tfpref}-${sys}-${platform}\" = {" >> $hashfile
+            echo "  url = \"$url\";" >> $hashfile
+            echo "  sha256 = \"$hash\";" >> $hashfile
+            echo "};" >> $hashfile
+        done
+    done
+done
+echo "}" >> $hashfile
+