Gentoo Archives: gentoo-commits

From: Mark Wright <gienah@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sci:master commit in: sci-libs/tensorflow/
Date: Tue, 01 May 2018 10:30:02
Message-Id: 1525169984.38fe3e1488bd82e32c16cc8d73de52cdb43149cc.gienah@gentoo
1 commit: 38fe3e1488bd82e32c16cc8d73de52cdb43149cc
2 Author: Mark Wright <gienah <AT> gentoo <DOT> org>
3 AuthorDate: Tue May 1 10:19:44 2018 +0000
4 Commit: Mark Wright <gienah <AT> gentoo <DOT> org>
5 CommitDate: Tue May 1 10:19:44 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/sci.git/commit/?id=38fe3e14
7
8 sci-libs/tensorflow: Bump to 1.8.0, build C and C++ APIs
9
10 Package-Manager: Portage-2.3.31, Repoman-2.3.9
11
12 sci-libs/tensorflow/tensorflow-1.8.0.ebuild | 171 ++++++++++++++++++++++++++++
13 1 file changed, 171 insertions(+)
14
15 diff --git a/sci-libs/tensorflow/tensorflow-1.8.0.ebuild b/sci-libs/tensorflow/tensorflow-1.8.0.ebuild
16 new file mode 100644
17 index 000000000..34d309cf4
18 --- /dev/null
19 +++ b/sci-libs/tensorflow/tensorflow-1.8.0.ebuild
20 @@ -0,0 +1,171 @@
21 +# Copyright 1999-2018 Gentoo Foundation
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +EAPI=6
25 +
26 +PYTHON_COMPAT=( python2_7 python3_{3,4,5,6} )
27 +
28 +inherit python-r1 distutils-r1 eutils versionator
29 +
30 +DESCRIPTION="Library for numerical computation using data flow graphs"
31 +HOMEPAGE="https://www.tensorflow.org
32 + https://github.com/tensorflow/tensorflow"
33 +SRC_URI="https://github.com/${PN}/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
34 + https://dev.gentoo.org/~gienah/snapshots/${P}-bazel-cache-repos.tar.xz"
35 +
36 +LICENSE="Apache-2.0"
37 +SLOT="0"
38 +KEYWORDS="~amd64"
39 +IUSE="cuda cxx mpi"
40 +
41 +# To create the cache repo tar file, temporarilly remove the
42 +# ${P}-bazel-cache-repos.tar.xz from SRC_URI and src_upack. Then build
43 +# it so that bazel will download the files:
44 +# FEATURES="noclean -network-sandbox" emerge -av sci-libs/tensorflow
45 +# cd /var/tmp/portage/sci-libs/${P}
46 +# tar --owner=portage --group=portage -cJvf \
47 +# /usr/portage/distfiles/${P}-bazel-cache-repos.tar.xz \
48 +# homedir/.cache/bazel/_bazel_portage/cache/repos/v1
49 +
50 +# TensorFlow 1.7 may be the last time we support Cuda versions below 8.0.
51 +# Starting with TensorFlow 1.8 release, 8.0 will be the minimum supported
52 +# version.
53 +# TensorFlow 1.7 may be the last time we support cuDNN versions below 6.0.
54 +# Starting with TensorFlow 1.8 release, 6.0 will be the minimum supported
55 +# version.
56 +# Possibly missing deps:
57 +# dev-python/gast
58 +DEPEND="
59 + cxx? ( dev-libs/protobuf )
60 + dev-python/absl-py
61 + dev-python/astor
62 + dev-python/numpy
63 + dev-python/protobuf-python
64 + dev-python/six
65 + dev-python/termcolor
66 + dev-python/wheel
67 + dev-libs/jemalloc
68 + dev-libs/protobuf-c
69 + dev-util/bazel
70 + media-libs/giflib
71 + virtual/jpeg:0
72 + cuda? ( >=dev-util/nvidia-cuda-toolkit-8.0[profiler] >=dev-libs/cudnn-6 )
73 + mpi? ( virtual/mpi )"
74 + #opencl? ( virtual/opencl )"
75 +RDEPEND="${DEPEND}"
76 +
77 +src_unpack() {
78 + unpack ${P}.tar.gz
79 + pushd .. || die
80 + unpack distdir/${P}-bazel-cache-repos.tar.xz
81 + popd || die
82 +}
83 +
84 +# TODO: seems it also supports some MPI implementations
85 +src_configure(){
86 + # there is no setup.py but there is configure
87 + # https://www.tensorflow.org/install/install_sources
88 + # https://www.tensorflow.org/install/install_linux#InstallingNativePip
89 + #
90 + # usage: configure.py [-h] [--workspace WORKSPACE]
91 + python_configure() {
92 + export PYTHON_BIN_PATH=${PYTHON}
93 + export PYTHON_LIB_PATH=${PYTHON_SITEDIR}
94 + export TF_NEED_JEMALLOC=1
95 + export TF_NEED_GCP=0
96 + export TF_NEED_HDFS=0
97 + export TF_NEED_S3=0
98 + export TF_NEED_KAFKA=0
99 + export TF_ENABLE_XLA=0
100 + export TF_NEED_GDR=0
101 + export TF_NEED_VERBS=0
102 + export TF_NEED_OPENCL=0
103 + if use cuda; then
104 + export TF_NEED_CUDA=1
105 + else
106 + export TF_NEED_CUDA=0
107 + fi
108 + if use mpi; then
109 + export TF_NEED_MPI=1
110 + else
111 + export TF_NEED_MPI=0
112 + fi
113 + export TF_NEED_OPENCL_SYCL=0
114 + export CC_OPT_FLAGS=${CFLAGS}
115 + export JAVA_HOME=$(java-config -O)
116 + # TODO: protect by a USE flag test --config=mkl
117 + ./configure || die
118 + }
119 + python_foreach_impl python_configure
120 +}
121 +
122 +src_compile() {
123 + # F: fopen_wr
124 + # S: deny
125 + # P: /proc/self/setgroups
126 + # A: /proc/self/setgroups
127 + # R: /proc/7712/setgroups
128 + # C: unable to read /proc/1/cmdline
129 + addpredict /proc
130 +
131 + local opt=$(usex cuda "--config=cuda" "")
132 + einfo ">>> Compiling ${PN} C"$(usex cxx " and C++" "")
133 + bazel build \
134 + --config=opt ${opt} \
135 + //tensorflow:libtensorflow.so \
136 + //tensorflow:libtensorflow_framework.so \
137 + $(usex cxx "//tensorflow:libtensorflow_cc.so" "") || die
138 +
139 + python_compile() {
140 + einfo ">>> Compiling ${PN} ${MULTIBUILD_VARIANT}"
141 + bazel build \
142 + --config=opt ${opt} \
143 + //tensorflow/tools/pip_package:build_pip_package || die
144 + bazel-bin/tensorflow/tools/pip_package/build_pip_package tensorflow_pkg || die
145 + unzip -o -d ${PN}_pkg_${MULTIBUILD_VARIANT} ${PN}_pkg/${P}-*.whl || die
146 + rm -f ${PN}_pkg_${MULTIBUILD_VARIANT}/lib${PN}_framework.so || die
147 + }
148 + python_foreach_impl python_compile
149 + bazel shutdown || die
150 +}
151 +
152 +src_test() {
153 + python_foreach_impl python_test
154 +}
155 +
156 +src_install() {
157 + local SO1=$(get_major_version)
158 + local SOVER=$(version_format_string '$1.$2')
159 + local tl="${PN} ${PN}_framework"
160 + dodir /usr/include/${PN}/${PN}/c
161 + insinto /usr/include/${PN}/${PN}/c
162 + doins ${PN}/c/c_api.h
163 + if use cxx; then
164 + for i in $(find ${PN}/cc ${PN}/core third_party/eigen3/unsupported \
165 + third_party/eigen3/Eigen \( -path third_party \
166 + -prune -o -type f -name \*.h -print \) -o \
167 + \( -path ${PN} -prune -o -type f -print \) ); do
168 + dodir $(dirname /usr/include/${PN}/${i})
169 + insinto $(dirname /usr/include/${PN}/${i})
170 + doins ${i}
171 + done
172 + tl+=" ${PN}_cc"
173 + fi
174 + for i in ${tl}; do
175 + dolib.so bazel-bin/${PN}/lib${i}.so
176 + dosym "lib${i}.so" \
177 + "/usr/$(get_libdir)/lib${i}.so.${SO1}" \
178 + || die "Could not create /usr/$(get_libdir)/lib${i}.so.${SO1} symlink"
179 + dosym "lib${i}.so" \
180 + "/usr/$(get_libdir)/lib${i}.so.${SOVER}" \
181 + || die "Could not create /usr/$(get_libdir)/lib${i}.so.${SOVER} symlink"
182 + done
183 + python_install() {
184 + python_domodule ${PN}_pkg_${MULTIBUILD_VARIANT}/${P}.data/purelib/${PN}
185 + dosym "../../../lib${PN}_framework.so" \
186 + "$(python_get_sitedir)/${PN}/lib${PN}_framework.so" \
187 + || die "Could not create $(python_get_sitedir)/lib${PN}_framework.so symlink for python module"
188 + }
189 + python_foreach_impl python_install
190 + einstalldocs
191 +}