diff options
author | Nikolay Amiantov <ab@fmap.me> | 2019-07-13 22:38:41 +0300 |
---|---|---|
committer | Nikolay Amiantov <ab@fmap.me> | 2019-07-31 13:28:44 +0300 |
commit | 0a1bf4734fb93ebc7d2240a9d98babdacfcf6100 (patch) | |
tree | 16ddba766a2a896a449d3c957ac71e5e43555ac7 /pkgs/development/libraries/science/math | |
parent | 170dd558dffd2bb134e3001a93631fc71fe13f3c (diff) | |
download | nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.tar nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.tar.gz nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.tar.bz2 nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.tar.lz nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.tar.xz nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.tar.zst nixpkgs-0a1bf4734fb93ebc7d2240a9d98babdacfcf6100.zip |
libtensorflow: add binary build and add automatic generation
Diffstat (limited to 'pkgs/development/libraries/science/math')
3 files changed, 111 insertions, 0 deletions
diff --git a/pkgs/development/libraries/science/math/tensorflow/bin.nix b/pkgs/development/libraries/science/math/tensorflow/bin.nix new file mode 100644 index 00000000000..3db7a6f1d1e --- /dev/null +++ b/pkgs/development/libraries/science/math/tensorflow/bin.nix @@ -0,0 +1,72 @@ +{ stdenv +, fetchurl +, patchelf +, cudaSupport ? false, symlinkJoin, cudatoolkit, cudnn, nvidia_x11 +}: + +with stdenv.lib; +let + unavailable = throw "libtensorflow is not available for this platform!"; + + tfType = if cudaSupport then "gpu" else "cpu"; + + system = + if stdenv.isLinux then "linux" + else if stdenv.isDarwin then "darwin" + else unavailable; + + platform = + if stdenv.isx86_64 then "x86_64" + else unavailable; + + rpath = makeLibraryPath ([stdenv.cc.libc stdenv.cc.cc.lib] ++ + optionals cudaSupport [ cudatoolkit.out cudatoolkit.lib cudnn nvidia_x11 ]); + + packages = import ./binary-hashes.nix; + packageName = "${tfType}-${system}-${platform}"; + url = packages.${packageName} or unavailable; + + 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 + ''; + +in stdenv.mkDerivation rec { + pname = "libtensorflow"; + inherit (packages) version; + + src = fetchurl url; + + # Patch library to use our libc, libstdc++ and others + buildCommand = '' + 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/install/lang_c; + license = licenses.asl20; + platforms = [ "x86_64-linux" "x86_64-darwin" ]; + maintainers = with maintainers; [ basvandijk ]; + }; +} diff --git a/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix b/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix new file mode 100644 index 00000000000..892dfa2a609 --- /dev/null +++ b/pkgs/development/libraries/science/math/tensorflow/binary-hashes.nix @@ -0,0 +1,15 @@ +{ +version = "1.14.0"; +"cpu-linux-x86_64" = { + url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz"; + sha256 = "04bi3ijq4sbb8c5vk964zlv0j9mrjnzzxd9q9knq3h273nc1a36k"; +}; +"gpu-linux-x86_64" = { + url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz"; + sha256 = "1ffnpyj9jjgwxpjfiyjvq4dm3n6nwiksim5jld9zw7fdswh215x6"; +}; +"cpu-darwin-x86_64" = { + url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.14.0.tar.gz"; + sha256 = "0zsd5ils1a17j6jzh0c7q1z56fw46gkzybbnms7h2rgg8al0rh92"; +}; +} diff --git a/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh b/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh new file mode 100755 index 00000000000..515f25df4c1 --- /dev/null +++ b/pkgs/development/libraries/science/math/tensorflow/prefetcher.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +version=1.14.0 +hashfile=binary-hashes.nix +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 + |