blob: 308369efd32a2c12e0da5d818b1a704b755bff7f [file] [log] [blame]
Geoffrey Irving4c85a082016-03-16 12:20:34 -08001#!/usr/bin/env bash
Manjunath Kudlurf41959c2015-11-06 16:27:58 -08002
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -08003set -e
4set -o pipefail
5
Andrew Selle09045e42016-09-06 08:19:04 -08006# Find out the absolute path to where ./configure resides
A. Unique TensorFlower46d2c282017-01-02 22:19:48 -08007pushd `dirname $0` > /dev/null
Andrew Selle09045e42016-09-06 08:19:04 -08008SOURCE_BASE_DIR=`pwd -P`
9popd > /dev/null
10
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080011PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
Jonathan Hseuc058a012017-01-17 15:06:43 -080012
13function is_linux() {
14 if [[ "${PLATFORM}" == "linux" ]]; then
15 true
16 else
17 false
18 fi
19}
20
21function is_macos() {
22 if [[ "${PLATFORM}" == "darwin" ]]; then
23 true
24 else
25 false
26 fi
27}
28
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080029function is_windows() {
30 # On windows, the shell script is actually running in msys
Shanqing Cai56fc8832017-01-23 18:25:25 -080031 if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080032 true
33 else
34 false
35 fi
36}
37
Dan Ringwalt692fad22017-05-05 09:09:05 -080038function sed_in_place() {
39 sed -e $1 $2 > "$2.bak"
40 mv "$2.bak" $2
Dandelion Mané0386a012017-03-10 14:43:23 -080041}
42
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080043function write_to_bazelrc() {
44 echo "$1" >> .tf_configure.bazelrc
45}
46
47function write_action_env_to_bazelrc() {
48 write_to_bazelrc "build --action_env $1=\"$2\""
49}
50
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080051function python_path {
52 "$PYTHON_BIN_PATH" - <<END
53from __future__ import print_function
54import site
55import os
56
57try:
58 input = raw_input
59except NameError:
60 pass
61
62python_paths = []
63if os.getenv('PYTHONPATH') is not None:
64 python_paths = os.getenv('PYTHONPATH').split(':')
65try:
66 library_paths = site.getsitepackages()
67except AttributeError:
68 from distutils.sysconfig import get_python_lib
69 library_paths = [get_python_lib()]
70all_paths = set(python_paths + library_paths)
71
72paths = []
73for path in all_paths:
74 if os.path.isdir(path):
75 paths.append(path)
76
77print(",".join(paths))
78END
79}
80
81function setup_python {
82 ## Set up python-related environment settings:
83 while true; do
84 fromuser=""
85 if [ -z "$PYTHON_BIN_PATH" ]; then
86 default_python_bin_path=$(which python || which python3 || true)
87 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
88 fromuser="1"
89 if [ -z "$PYTHON_BIN_PATH" ]; then
90 PYTHON_BIN_PATH=$default_python_bin_path
91 fi
92 fi
93 if [ -e "$PYTHON_BIN_PATH" ]; then
94 break
95 fi
96 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
97 if [ -z "$fromuser" ]; then
98 exit 1
99 fi
100 PYTHON_BIN_PATH=""
101 # Retry
102 done
103
104 if [ -z "$PYTHON_LIB_PATH" ]; then
105 # Split python_path into an array of paths, this allows path containing spaces
106 IFS=','
107 python_lib_path=($(python_path))
108 unset IFS
109
110 if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then
111 PYTHON_LIB_PATH=${python_lib_path[0]}
112 echo "Using python library path: $PYTHON_LIB_PATH"
113
114 else
115 echo "Found possible Python library paths:"
116 for x in "${python_lib_path[@]}"; do
117 echo " $x"
118 done
119 set -- "${python_lib_path[@]}"
120 echo "Please input the desired Python library path to use. Default is ["$1"]"
121 read b || true
122 if [ "$b" == "" ]; then
123 PYTHON_LIB_PATH=${python_lib_path[0]}
124 echo "Using python library path: $PYTHON_LIB_PATH"
125 else
126 PYTHON_LIB_PATH="$b"
127 fi
128 fi
129 fi
130
131 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
132 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
133 exit 1
134 fi
135
136 local python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);')
137 if [ "$python_major_version" == "" ]; then
138 echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?"
139 exit 1
140 fi
141
142 # Convert python path to Windows style before writing into bazel.rc
143 if is_windows; then
144 PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
145 fi
146
147 # Set-up env variables used by python_configure.bzl
148 write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
149 write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH"
Benoit Steineree112cf2017-05-10 21:12:21 -0700150 write_to_bazelrc "build --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
151 write_to_bazelrc "build --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800152 write_to_bazelrc "build --force_python=py$python_major_version"
153 write_to_bazelrc "build --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700154 write_to_bazelrc "build --python${python_major_version}_path=\"$PYTHON_BIN_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800155 write_to_bazelrc "test --force_python=py$python_major_version"
156 write_to_bazelrc "test --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700157 write_to_bazelrc "test --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
158 write_to_bazelrc "test --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
159 write_to_bazelrc "run --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
160 write_to_bazelrc "run --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800161
162 # Write tools/python_bin_path.sh
163 echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh
164}
165
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800166# This file contains customized config settings.
167rm -f .tf_configure.bazelrc
168touch .tf_configure.bazelrc
169touch .bazelrc
Dan Ringwalt692fad22017-05-05 09:09:05 -0800170sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800171echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800172
Andrew Harp51dbc462017-01-27 14:42:30 -0800173# Delete any leftover BUILD files from the Makefile build, which would interfere
174# with Bazel parsing.
175MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
176if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
177 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
178fi
179
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800180setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800181
Benoit Steiner639b4e72017-02-08 09:25:09 -0800182## Set up MKL related environment settings
Benoit Steineree112cf2017-05-10 21:12:21 -0700183while [ "$TF_NEED_MKL" == "" ]; do
184 fromuser=""
185 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
186 fromuser="1"
187 case $INPUT in
188 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
189 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
190 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
191 * ) echo "Invalid selection: " $INPUT;;
192 esac
193done
194
195OSNAME=`uname -s`
196
197if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
198 while [ "$TF_DOWNLOAD_MKL" == "" ]; do
Benoit Steiner639b4e72017-02-08 09:25:09 -0800199 fromuser=""
Benoit Steineree112cf2017-05-10 21:12:21 -0700200 read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800201 fromuser="1"
202 case $INPUT in
Benoit Steineree112cf2017-05-10 21:12:21 -0700203 [Yy]* ) TF_DOWNLOAD_MKL=1;;
204 [Nn]* ) TF_DOWNLOAD_MKL=0;;
205 "" ) TF_DOWNLOAD_MKL=1;;
206 * ) echo "Invalid selection: " $INPUT; exit 1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800207 esac
208 done
209
Benoit Steineree112cf2017-05-10 21:12:21 -0700210 if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800211 DST=`dirname $0`
Benoit Steineree112cf2017-05-10 21:12:21 -0700212 ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
213 GITHUB_RELEASE_TAG=v0.7
Benoit Steiner639b4e72017-02-08 09:25:09 -0800214 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
Benoit Steineree112cf2017-05-10 21:12:21 -0700215 if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
216 curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800217 fi
218 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
219 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
220 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
221 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
222
Benoit Steineree112cf2017-05-10 21:12:21 -0700223 else
224 default_mkl_path=/opt/intel/mklml
225 fromuser=""
226 read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
227 fromuser="1"
228 if [ -z "$MKL_INSTALL_PATH" ]; then
229 MKL_INSTALL_PATH=$default_mkl_path
230 fi
231 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
232 # Going through one more level of expansion to handle that.
233 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
234 fi
235
236 if [ "$OSNAME" == "Linux" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800237 # Full MKL configuration
238 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
239 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
240
241 # MKL-ML configuration
242 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
243 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
Benoit Steineree112cf2017-05-10 21:12:21 -0700244 elif [ "$OSNAME" == "Darwin" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800245 echo "Darwin is unsupported yet";
246 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700247 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800248
Benoit Steineree112cf2017-05-10 21:12:21 -0700249 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800250 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
251 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
252 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
253 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
Benoit Steineree112cf2017-05-10 21:12:21 -0700254 loc=$(locate -e libdl.so.2 | sed -n 1p)
255 ln -sf $loc third_party/mkl/libdl.so.2
256 elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then
257 ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/
258 ln -sf $MKL_INSTALL_PATH/${MKL_RT_OMP_LIB_PATH} third_party/mkl/
259 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
260 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
261 loc=$(locate -e libdl.so.2 | sed -n 1p)
262 ln -sf $loc third_party/mkl/libdl.so.2
263 else
264 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} nor $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} exists";
Benoit Steiner639b4e72017-02-08 09:25:09 -0800265 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700266 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800267
268cat > third_party/mkl/mkl.config <<EOF
269# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
270# files can be either in this directory, or under include/ and lib64/
271MKL_INSTALL_PATH=$MKL_INSTALL_PATH
272EOF
273
Benoit Steineree112cf2017-05-10 21:12:21 -0700274fi # TF_NEED_MKL
275## End MKL setup
Benoit Steiner639b4e72017-02-08 09:25:09 -0800276
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800277## Set up architecture-dependent optimization flags.
278if [ -z "$CC_OPT_FLAGS" ]; then
279 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800280 read -p "Please specify optimization flags to use during compilation when bazel option "\
281"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800282 if [ -z "$CC_OPT_FLAGS" ]; then
283 CC_OPT_FLAGS=$default_cc_opt_flags
284 fi
285fi
286
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800287if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800288 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800289 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800290 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800291 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800292 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800293fi
294
Jonathan Hseuc058a012017-01-17 15:06:43 -0800295if is_linux; then
296 while [ "$TF_NEED_JEMALLOC" == "" ]; do
297 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
298 INPUT
299 case $INPUT in
300 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
301 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
302 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
303 * ) echo "Invalid selection: " $INPUT;;
304 esac
305 done
306else
307 TF_NEED_JEMALLOC=0
308fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800309
Martin Wickebc456e32017-03-23 12:31:16 -0800310if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800311 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800312fi
313
Martin Wickebc456e32017-03-23 12:31:16 -0800314while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800315 read -p "Do you wish to build TensorFlow with "\
316"Google Cloud Platform support? [y/N] " INPUT
317 case $INPUT in
318 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
319"TensorFlow"; TF_NEED_GCP=1;;
320 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
321"TensorFlow"; TF_NEED_GCP=0;;
322 "" ) echo "No Google Cloud Platform support will be enabled for "\
323"TensorFlow"; TF_NEED_GCP=0;;
324 * ) echo "Invalid selection: " $INPUT;;
325 esac
326done
327
Martin Wickebc456e32017-03-23 12:31:16 -0800328if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800329 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800330fi
331
Martin Wickebc456e32017-03-23 12:31:16 -0800332while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800333 read -p "Do you wish to build TensorFlow with "\
334"Hadoop File System support? [y/N] " INPUT
335 case $INPUT in
336 [Yy]* ) echo "Hadoop File System support will be enabled for "\
337"TensorFlow"; TF_NEED_HDFS=1;;
338 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
339"TensorFlow"; TF_NEED_HDFS=0;;
340 "" ) echo "No Hadoop File System support will be enabled for "\
341"TensorFlow"; TF_NEED_HDFS=0;;
342 * ) echo "Invalid selection: " $INPUT;;
343 esac
344done
345
Martin Wickebc456e32017-03-23 12:31:16 -0800346if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800347 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800348fi
349
Peter Hawkins1e67c902017-01-09 12:04:37 -0800350## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800351while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800352 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
353 case $INPUT in
354 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
355 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
356 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
357 * ) echo "Invalid selection: " $INPUT;;
358 esac
359done
360
Martin Wickebc456e32017-03-23 12:31:16 -0800361if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800362 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800363fi
364
Shanqing Cai32694232017-04-22 06:08:17 -0800365# Verbs configuration
366while [ "$TF_NEED_VERBS" == "" ]; do
367 read -p "Do you wish to build TensorFlow with "\
368"VERBS support? [y/N] " INPUT
369 case $INPUT in
370 [Yy]* ) echo "VERBS support will be enabled for "\
371"TensorFlow"; TF_NEED_VERBS=1;;
372 [Nn]* ) echo "No VERBS support will be enabled for "\
373"TensorFlow"; TF_NEED_VERBS=0;;
374 "" ) echo "No VERBS support will be enabled for "\
375"TensorFlow"; TF_NEED_VERBS=0;;
376 * ) echo "Invalid selection: " $INPUT;;
377 esac
378done
379
380if [[ "$TF_NEED_VERBS" == "1" ]]; then
381 write_to_bazelrc 'build --define with_verbs_support=true'
382fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800383
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800384# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800385for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800386 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800387done
388
Andrew Selle09045e42016-09-06 08:19:04 -0800389# Run the gen_git_source to create links where bazel can track dependencies for
390# git hash propagation
391GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
392chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800393"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800394
Benoit Steinera7715982016-11-09 13:14:03 -0800395## Set up SYCL-related environment settings
396while [ "$TF_NEED_OPENCL" == "" ]; do
397 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
398 case $INPUT in
399 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
400 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
401 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
402 * ) echo "Invalid selection: " $INPUT;;
403 esac
404done
405
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800406## Set up Cuda-related environment settings
407
408while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800409 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800410 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800411 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
412 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
413 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800414 * ) echo "Invalid selection: " $INPUT;;
415 esac
416done
417
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800418export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800419write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800420
Rohan Jainaab09972017-01-05 14:39:17 -0800421export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800422write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800423
Benoit Steinera7715982016-11-09 13:14:03 -0800424if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800425while [[ "$TF_CUDA_CLANG" == "" ]]; do
426 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
427 case $INPUT in
428 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
429 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
430 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
431 * ) echo "Invalid selection: " $INPUT;;
432 esac
433done
434
435export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800436write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800437
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800438# Set up which clang we should use as the cuda / host compiler.
439while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
440 fromuser=""
441 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
442 default_clang_host_compiler_path=$(which clang || true)
443 read -p "Please specify which clang should be used as device and host compiler. [Default is $default_clang_host_compiler_path]: " CLANG_CUDA_COMPILER_PATH
444 fromuser="1"
445 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
446 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
447 fi
448 fi
449 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
450 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800451 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800452 break
453 fi
454 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
455 if [ -z "$fromuser" ]; then
456 exit 1
457 fi
458 CLANG_CUDA_COMPILER_PATH=""
459 # Retry
460done
461
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800462# Find out where the CUDA toolkit is installed
463while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800464 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800465 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800466 read -p "Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: " TF_CUDA_VERSION
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800467 fi
468
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800469 fromuser=""
470 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
471 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800472 if is_windows; then
473 if [ -z "$CUDA_PATH" ]; then
474 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
475 else
476 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
477 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800478 elif is_linux; then
479 # If the default doesn't exist, try an alternative default.
480 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
481 default_cuda_path=/opt/cuda
482 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800483 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800484 read -p "Please specify the location where CUDA $TF_CUDA_VERSION toolkit is installed. Refer to README.md for more details. [Default is $default_cuda_path]: " CUDA_TOOLKIT_PATH
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800485 fromuser="1"
486 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800487 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800488 fi
489 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800490
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800491 if [[ -z "$TF_CUDA_VERSION" ]]; then
492 TF_CUDA_EXT=""
493 else
494 TF_CUDA_EXT=".$TF_CUDA_VERSION"
495 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800496
Andrew Harp1cb96892016-12-08 20:05:49 -0800497 if is_windows; then
498 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800499 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800500 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800501 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800502 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
503 fi
504
505 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800506 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800507 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800508 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800509 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800510 break
511 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800512 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
513
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800514 if [ -z "$fromuser" ]; then
515 exit 1
516 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800517 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800518 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800519 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800520done
521
Dan Ringwalt692fad22017-05-05 09:09:05 -0800522# Set up which gcc nvcc should use as the host compiler
523# No need to set this on Windows
524while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
525 fromuser=""
526 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
527 default_gcc_host_compiler_path=$(which gcc || true)
528 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
529 if [ -L "$cuda_bin_symlink" ]; then
530 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
531 fi
532 read -p "Please specify which gcc should be used by nvcc as the host compiler. [Default is $default_gcc_host_compiler_path]: " GCC_HOST_COMPILER_PATH
533 fromuser="1"
534 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
535 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
536 fi
537 fi
538 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
539 export GCC_HOST_COMPILER_PATH
540 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
541 break
542 fi
543 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
544 if [ -z "$fromuser" ]; then
545 exit 1
546 fi
547 GCC_HOST_COMPILER_PATH=""
548 # Retry
549done
550
Martin Wicke916776a2016-01-14 07:30:00 -0800551# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800552while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800553 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800554 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800555 read -p "Please specify the cuDNN version you want to use. [Leave empty to use system default]: " TF_CUDNN_VERSION
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800556 fi
557
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800558 fromuser=""
559 if [ -z "$CUDNN_INSTALL_PATH" ]; then
560 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800561 read -p "Please specify the location where cuDNN $TF_CUDNN_VERSION library is installed. Refer to README.md for more details. [Default is $default_cudnn_path]: " CUDNN_INSTALL_PATH
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800562 fromuser="1"
563 if [ -z "$CUDNN_INSTALL_PATH" ]; then
564 CUDNN_INSTALL_PATH=$default_cudnn_path
565 fi
566 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
567 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800568 CUDNN_INSTALL_PATH=`"${PYTHON_BIN_PATH}" -c "import os; print(os.path.realpath(os.path.expanduser('${CUDNN_INSTALL_PATH}')))"`
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800569 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800570
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800571 if [[ -z "$TF_CUDNN_VERSION" ]]; then
572 TF_CUDNN_EXT=""
573 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800574 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800575 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800576
Andrew Harp1cb96892016-12-08 20:05:49 -0800577 if is_windows; then
578 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
579 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800580 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800581 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
582 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800583 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800584 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
585 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800586 fi
587
588 if [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_ALT_PATH}" -o -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_PATH}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800589 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800590 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800591 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800592 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800593 break
594 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800595
Jonathan Hseuc058a012017-01-17 15:06:43 -0800596 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800597 if ! type ldconfig > /dev/null 2>&1; then
598 LDCONFIG_BIN=/sbin/ldconfig
599 else
600 LDCONFIG_BIN=ldconfig
601 fi
602 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800603 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800604 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800605 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800606 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800607 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800608 break
609 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800610 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800611 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
612 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
613 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800614 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800615 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
616 fi
617
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800618 if [ -z "$fromuser" ]; then
619 exit 1
620 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800621 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800622 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800623 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800624done
625
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800626# Configure the compute capabilities that TensorFlow builds for.
627# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
628while true; do
629 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800630 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800631 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800632cat << EOF
633Please specify a list of comma-separated Cuda compute capabilities you want to build with.
634You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
635Please note that each additional compute capability significantly increases your build time and binary size.
636EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800637 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
638 fromuser=1
639 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800640 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
641 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
642 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800643 # Check whether all capabilities from the input is valid
644 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
645 ALL_VALID=1
646 for CAPABILITY in $COMPUTE_CAPABILITIES; do
647 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
648 echo "Invalid compute capability: " $CAPABILITY
649 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800650 break
651 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800652 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800653 if [ "$ALL_VALID" == "0" ]; then
654 if [ -z "$fromuser" ]; then
655 exit 1
656 fi
657 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800658 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800659 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800660 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800661 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800662 TF_CUDA_COMPUTE_CAPABILITIES=""
663done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800664
Andrew Harp1cb96892016-12-08 20:05:49 -0800665if is_windows; then
666 # The following three variables are needed for MSVC toolchain configuration in Bazel
667 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
668 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
669 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800670 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
671 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
672 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800673fi
674
Benoit Steinera7715982016-11-09 13:14:03 -0800675# end of if "$TF_NEED_CUDA" == "1"
676fi
677
678# OpenCL configuration
679
680if [ "$TF_NEED_OPENCL" == "1" ]; then
681
682# Determine which C++ compiler should be used as the host compiler
683while true; do
684 fromuser=""
685 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800686 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800687 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
688 fromuser="1"
689 if [ -z "$HOST_CXX_COMPILER" ]; then
690 HOST_CXX_COMPILER=$default_cxx_host_compiler
691 fi
692 fi
693 if [ -e "$HOST_CXX_COMPILER" ]; then
694 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800695 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800696 break
697 fi
698 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
699 if [ -z "$fromuser" ]; then
700 exit 1
701 fi
702 HOST_CXX_COMPILER=""
703 # Retry
704done
705
706# Determine which C compiler should be used as the host compiler
707while true; do
708 fromuser=""
709 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800710 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800711 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
712 fromuser="1"
713 if [ -z "$HOST_C_COMPILER" ]; then
714 HOST_C_COMPILER=$default_c_host_compiler
715 fi
716 fi
717 if [ -e "$HOST_C_COMPILER" ]; then
718 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800719 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800720 break
721 fi
722 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
723 if [ -z "$fromuser" ]; then
724 exit 1
725 fi
726 HOST_C_COMPILER=""
727 # Retry
728done
729
730while true; do
731 # Configure the OPENCL version to use.
732 TF_OPENCL_VERSION="1.2"
733
734 # Point to ComputeCpp root
735 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
736 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800737 read -p "Please specify the location where ComputeCpp for SYCL $TF_OPENCL_VERSION is installed. [Default is $default_computecpp_toolkit_path]: " COMPUTECPP_TOOLKIT_PATH
Benoit Steinera7715982016-11-09 13:14:03 -0800738 fromuser="1"
739 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
740 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
741 fi
742 fi
743
Jonathan Hseuc058a012017-01-17 15:06:43 -0800744 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800745 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
746 fi
747
748 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
749 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800750 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800751 break
752 fi
753 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
754
755 if [ -z "$fromuser" ]; then
756 exit 1
757 fi
758 # Retry
759 TF_OPENCL_VERSION=""
760 COMPUTECPP_TOOLKIT_PATH=""
761done
762
Benoit Steinera7715982016-11-09 13:14:03 -0800763# end of if "$TF_NEED_OPENCL" == "1"
764fi
765
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800766# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
767bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800768echo "Configuration finished"