blob: 71c14345f50d92ed6b21a5ff264d58be7e03bb2f [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
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -07006MIN_BAZEL_VERSION=0.4.5
7
Andrew Selle09045e42016-09-06 08:19:04 -08008# Find out the absolute path to where ./configure resides
A. Unique TensorFlower46d2c282017-01-02 22:19:48 -08009pushd `dirname $0` > /dev/null
Andrew Selle09045e42016-09-06 08:19:04 -080010SOURCE_BASE_DIR=`pwd -P`
11popd > /dev/null
12
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080013PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
Jonathan Hseuc058a012017-01-17 15:06:43 -080014
15function is_linux() {
16 if [[ "${PLATFORM}" == "linux" ]]; then
17 true
18 else
19 false
20 fi
21}
22
23function is_macos() {
24 if [[ "${PLATFORM}" == "darwin" ]]; then
25 true
26 else
27 false
28 fi
29}
30
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080031function is_windows() {
32 # On windows, the shell script is actually running in msys
Shanqing Cai56fc8832017-01-23 18:25:25 -080033 if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080034 true
35 else
36 false
37 fi
38}
39
Dan Ringwalt692fad22017-05-05 09:09:05 -080040function sed_in_place() {
41 sed -e $1 $2 > "$2.bak"
42 mv "$2.bak" $2
Dandelion Mané0386a012017-03-10 14:43:23 -080043}
44
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080045function write_to_bazelrc() {
46 echo "$1" >> .tf_configure.bazelrc
47}
48
49function write_action_env_to_bazelrc() {
50 write_to_bazelrc "build --action_env $1=\"$2\""
51}
52
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080053function python_path {
54 "$PYTHON_BIN_PATH" - <<END
55from __future__ import print_function
56import site
57import os
58
59try:
60 input = raw_input
61except NameError:
62 pass
63
64python_paths = []
65if os.getenv('PYTHONPATH') is not None:
66 python_paths = os.getenv('PYTHONPATH').split(':')
67try:
68 library_paths = site.getsitepackages()
69except AttributeError:
70 from distutils.sysconfig import get_python_lib
71 library_paths = [get_python_lib()]
72all_paths = set(python_paths + library_paths)
73
74paths = []
75for path in all_paths:
76 if os.path.isdir(path):
77 paths.append(path)
78
79print(",".join(paths))
80END
81}
82
83function setup_python {
84 ## Set up python-related environment settings:
85 while true; do
86 fromuser=""
87 if [ -z "$PYTHON_BIN_PATH" ]; then
88 default_python_bin_path=$(which python || which python3 || true)
89 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
90 fromuser="1"
91 if [ -z "$PYTHON_BIN_PATH" ]; then
92 PYTHON_BIN_PATH=$default_python_bin_path
93 fi
94 fi
95 if [ -e "$PYTHON_BIN_PATH" ]; then
96 break
97 fi
98 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
99 if [ -z "$fromuser" ]; then
100 exit 1
101 fi
102 PYTHON_BIN_PATH=""
103 # Retry
104 done
105
106 if [ -z "$PYTHON_LIB_PATH" ]; then
107 # Split python_path into an array of paths, this allows path containing spaces
108 IFS=','
109 python_lib_path=($(python_path))
110 unset IFS
111
112 if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then
113 PYTHON_LIB_PATH=${python_lib_path[0]}
114 echo "Using python library path: $PYTHON_LIB_PATH"
115
116 else
117 echo "Found possible Python library paths:"
118 for x in "${python_lib_path[@]}"; do
119 echo " $x"
120 done
121 set -- "${python_lib_path[@]}"
122 echo "Please input the desired Python library path to use. Default is ["$1"]"
123 read b || true
124 if [ "$b" == "" ]; then
125 PYTHON_LIB_PATH=${python_lib_path[0]}
126 echo "Using python library path: $PYTHON_LIB_PATH"
127 else
128 PYTHON_LIB_PATH="$b"
129 fi
130 fi
131 fi
132
133 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
134 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
135 exit 1
136 fi
137
138 local python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);')
139 if [ "$python_major_version" == "" ]; then
140 echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?"
141 exit 1
142 fi
143
144 # Convert python path to Windows style before writing into bazel.rc
145 if is_windows; then
146 PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
147 fi
148
149 # Set-up env variables used by python_configure.bzl
150 write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
151 write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH"
Benoit Steineree112cf2017-05-10 21:12:21 -0700152 write_to_bazelrc "build --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
153 write_to_bazelrc "build --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800154 write_to_bazelrc "build --force_python=py$python_major_version"
155 write_to_bazelrc "build --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700156 write_to_bazelrc "build --python${python_major_version}_path=\"$PYTHON_BIN_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800157 write_to_bazelrc "test --force_python=py$python_major_version"
158 write_to_bazelrc "test --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700159 write_to_bazelrc "test --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
160 write_to_bazelrc "test --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
161 write_to_bazelrc "run --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
162 write_to_bazelrc "run --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800163
164 # Write tools/python_bin_path.sh
165 echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh
166}
167
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700168function version {
169 echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }';
170}
171
172
173bazel version > bazel.version
174curr_bazel_version=$(head -n 1 bazel.version | cut -d ' ' -f3)
175rm -f bazel.version
176
177echo "You have bazel $curr_bazel_version installed."
178if [ "$(version "$MIN_BAZEL_VERSION")" -gt "$(version "$curr_bazel_version")" ]; then
179 echo "Please upgrade your bazel installation to version $MIN_BAZEL_VERSION or higher to build TensorFlow!"
180 echo "Exiting..."
181 exit 1
182fi
183
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800184# This file contains customized config settings.
185rm -f .tf_configure.bazelrc
186touch .tf_configure.bazelrc
187touch .bazelrc
Dan Ringwalt692fad22017-05-05 09:09:05 -0800188sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800189echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800190
Andrew Harp51dbc462017-01-27 14:42:30 -0800191# Delete any leftover BUILD files from the Makefile build, which would interfere
192# with Bazel parsing.
193MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
194if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
195 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
196fi
197
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800198setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800199
Benoit Steiner639b4e72017-02-08 09:25:09 -0800200## Set up MKL related environment settings
Benoit Steineree112cf2017-05-10 21:12:21 -0700201while [ "$TF_NEED_MKL" == "" ]; do
202 fromuser=""
203 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
204 fromuser="1"
205 case $INPUT in
206 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
207 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
208 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
209 * ) echo "Invalid selection: " $INPUT;;
210 esac
211done
212
213OSNAME=`uname -s`
214
215if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
216 while [ "$TF_DOWNLOAD_MKL" == "" ]; do
Benoit Steiner639b4e72017-02-08 09:25:09 -0800217 fromuser=""
Benoit Steineree112cf2017-05-10 21:12:21 -0700218 read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800219 fromuser="1"
220 case $INPUT in
Benoit Steineree112cf2017-05-10 21:12:21 -0700221 [Yy]* ) TF_DOWNLOAD_MKL=1;;
222 [Nn]* ) TF_DOWNLOAD_MKL=0;;
223 "" ) TF_DOWNLOAD_MKL=1;;
224 * ) echo "Invalid selection: " $INPUT; exit 1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800225 esac
226 done
227
Benoit Steineree112cf2017-05-10 21:12:21 -0700228 if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800229 DST=`dirname $0`
Benoit Steineree112cf2017-05-10 21:12:21 -0700230 ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
231 GITHUB_RELEASE_TAG=v0.7
Benoit Steiner639b4e72017-02-08 09:25:09 -0800232 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
Benoit Steineree112cf2017-05-10 21:12:21 -0700233 if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
234 curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800235 fi
236 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
237 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
238 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
239 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
240
Benoit Steineree112cf2017-05-10 21:12:21 -0700241 else
242 default_mkl_path=/opt/intel/mklml
243 fromuser=""
244 read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
245 fromuser="1"
246 if [ -z "$MKL_INSTALL_PATH" ]; then
247 MKL_INSTALL_PATH=$default_mkl_path
248 fi
249 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
250 # Going through one more level of expansion to handle that.
251 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
252 fi
253
254 if [ "$OSNAME" == "Linux" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800255 # Full MKL configuration
256 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
257 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
258
259 # MKL-ML configuration
260 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
261 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
Benoit Steineree112cf2017-05-10 21:12:21 -0700262 elif [ "$OSNAME" == "Darwin" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800263 echo "Darwin is unsupported yet";
264 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700265 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800266
Benoit Steineree112cf2017-05-10 21:12:21 -0700267 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800268 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
269 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
270 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
271 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
Benoit Steineree112cf2017-05-10 21:12:21 -0700272 loc=$(locate -e libdl.so.2 | sed -n 1p)
273 ln -sf $loc third_party/mkl/libdl.so.2
274 elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then
275 ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/
276 ln -sf $MKL_INSTALL_PATH/${MKL_RT_OMP_LIB_PATH} third_party/mkl/
277 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
278 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
279 loc=$(locate -e libdl.so.2 | sed -n 1p)
280 ln -sf $loc third_party/mkl/libdl.so.2
281 else
282 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 -0800283 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700284 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800285
286cat > third_party/mkl/mkl.config <<EOF
287# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
288# files can be either in this directory, or under include/ and lib64/
289MKL_INSTALL_PATH=$MKL_INSTALL_PATH
290EOF
291
Benoit Steineree112cf2017-05-10 21:12:21 -0700292fi # TF_NEED_MKL
293## End MKL setup
Benoit Steiner639b4e72017-02-08 09:25:09 -0800294
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800295## Set up architecture-dependent optimization flags.
296if [ -z "$CC_OPT_FLAGS" ]; then
297 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800298 read -p "Please specify optimization flags to use during compilation when bazel option "\
299"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800300 if [ -z "$CC_OPT_FLAGS" ]; then
301 CC_OPT_FLAGS=$default_cc_opt_flags
302 fi
303fi
304
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800305if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800306 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800307 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800308 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800309 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800310 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800311fi
312
Jonathan Hseuc058a012017-01-17 15:06:43 -0800313if is_linux; then
314 while [ "$TF_NEED_JEMALLOC" == "" ]; do
315 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
316 INPUT
317 case $INPUT in
318 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
319 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
320 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
321 * ) echo "Invalid selection: " $INPUT;;
322 esac
323 done
324else
325 TF_NEED_JEMALLOC=0
326fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800327
Martin Wickebc456e32017-03-23 12:31:16 -0800328if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800329 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800330fi
331
Martin Wickebc456e32017-03-23 12:31:16 -0800332while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800333 read -p "Do you wish to build TensorFlow with "\
334"Google Cloud Platform support? [y/N] " INPUT
335 case $INPUT in
336 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
337"TensorFlow"; TF_NEED_GCP=1;;
338 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
339"TensorFlow"; TF_NEED_GCP=0;;
340 "" ) echo "No Google Cloud Platform support will be enabled for "\
341"TensorFlow"; TF_NEED_GCP=0;;
342 * ) echo "Invalid selection: " $INPUT;;
343 esac
344done
345
Martin Wickebc456e32017-03-23 12:31:16 -0800346if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800347 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800348fi
349
Martin Wickebc456e32017-03-23 12:31:16 -0800350while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800351 read -p "Do you wish to build TensorFlow with "\
352"Hadoop File System support? [y/N] " INPUT
353 case $INPUT in
354 [Yy]* ) echo "Hadoop File System support will be enabled for "\
355"TensorFlow"; TF_NEED_HDFS=1;;
356 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
357"TensorFlow"; TF_NEED_HDFS=0;;
358 "" ) echo "No Hadoop File System support will be enabled for "\
359"TensorFlow"; TF_NEED_HDFS=0;;
360 * ) echo "Invalid selection: " $INPUT;;
361 esac
362done
363
Martin Wickebc456e32017-03-23 12:31:16 -0800364if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800365 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800366fi
367
Peter Hawkins1e67c902017-01-09 12:04:37 -0800368## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800369while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800370 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
371 case $INPUT in
372 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
373 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
374 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
375 * ) echo "Invalid selection: " $INPUT;;
376 esac
377done
378
Martin Wickebc456e32017-03-23 12:31:16 -0800379if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800380 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800381fi
382
Shanqing Cai32694232017-04-22 06:08:17 -0800383# Verbs configuration
384while [ "$TF_NEED_VERBS" == "" ]; do
385 read -p "Do you wish to build TensorFlow with "\
386"VERBS support? [y/N] " INPUT
387 case $INPUT in
388 [Yy]* ) echo "VERBS support will be enabled for "\
389"TensorFlow"; TF_NEED_VERBS=1;;
390 [Nn]* ) echo "No VERBS support will be enabled for "\
391"TensorFlow"; TF_NEED_VERBS=0;;
392 "" ) echo "No VERBS support will be enabled for "\
393"TensorFlow"; TF_NEED_VERBS=0;;
394 * ) echo "Invalid selection: " $INPUT;;
395 esac
396done
397
398if [[ "$TF_NEED_VERBS" == "1" ]]; then
399 write_to_bazelrc 'build --define with_verbs_support=true'
400fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800401
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800402# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800403for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800404 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800405done
406
Andrew Selle09045e42016-09-06 08:19:04 -0800407# Run the gen_git_source to create links where bazel can track dependencies for
408# git hash propagation
409GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
410chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800411"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800412
Benoit Steinera7715982016-11-09 13:14:03 -0800413## Set up SYCL-related environment settings
414while [ "$TF_NEED_OPENCL" == "" ]; do
415 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
416 case $INPUT in
417 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
418 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
419 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
420 * ) echo "Invalid selection: " $INPUT;;
421 esac
422done
423
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800424## Set up Cuda-related environment settings
425
426while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800427 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800428 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800429 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
430 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
431 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800432 * ) echo "Invalid selection: " $INPUT;;
433 esac
434done
435
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800436export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800437write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800438
Rohan Jainaab09972017-01-05 14:39:17 -0800439export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800440write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800441
Benoit Steinera7715982016-11-09 13:14:03 -0800442if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800443while [[ "$TF_CUDA_CLANG" == "" ]]; do
444 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
445 case $INPUT in
446 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
447 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
448 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
449 * ) echo "Invalid selection: " $INPUT;;
450 esac
451done
452
453export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800454write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800455
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800456# Set up which clang we should use as the cuda / host compiler.
457while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
458 fromuser=""
459 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
460 default_clang_host_compiler_path=$(which clang || true)
461 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
462 fromuser="1"
463 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
464 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
465 fi
466 fi
467 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
468 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800469 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800470 break
471 fi
472 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
473 if [ -z "$fromuser" ]; then
474 exit 1
475 fi
476 CLANG_CUDA_COMPILER_PATH=""
477 # Retry
478done
479
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800480# Find out where the CUDA toolkit is installed
481while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800482 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800483 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800484 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 -0800485 fi
486
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800487 fromuser=""
488 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
489 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800490 if is_windows; then
491 if [ -z "$CUDA_PATH" ]; then
492 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
493 else
494 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
495 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800496 elif is_linux; then
497 # If the default doesn't exist, try an alternative default.
498 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
499 default_cuda_path=/opt/cuda
500 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800501 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800502 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 -0800503 fromuser="1"
504 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800505 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800506 fi
507 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800508
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800509 if [[ -z "$TF_CUDA_VERSION" ]]; then
510 TF_CUDA_EXT=""
511 else
512 TF_CUDA_EXT=".$TF_CUDA_VERSION"
513 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800514
Andrew Harp1cb96892016-12-08 20:05:49 -0800515 if is_windows; then
516 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800517 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800518 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800519 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800520 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
521 fi
522
523 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800524 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800525 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800526 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800527 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800528 break
529 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800530 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
531
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800532 if [ -z "$fromuser" ]; then
533 exit 1
534 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800535 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800536 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800537 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800538done
539
Dan Ringwalt692fad22017-05-05 09:09:05 -0800540# Set up which gcc nvcc should use as the host compiler
541# No need to set this on Windows
542while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
543 fromuser=""
544 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
545 default_gcc_host_compiler_path=$(which gcc || true)
546 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
547 if [ -L "$cuda_bin_symlink" ]; then
548 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
549 fi
550 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
551 fromuser="1"
552 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
553 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
554 fi
555 fi
556 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
557 export GCC_HOST_COMPILER_PATH
558 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
559 break
560 fi
561 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
562 if [ -z "$fromuser" ]; then
563 exit 1
564 fi
565 GCC_HOST_COMPILER_PATH=""
566 # Retry
567done
568
Martin Wicke916776a2016-01-14 07:30:00 -0800569# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800570while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800571 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800572 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800573 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 -0800574 fi
575
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800576 fromuser=""
577 if [ -z "$CUDNN_INSTALL_PATH" ]; then
578 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800579 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 -0800580 fromuser="1"
581 if [ -z "$CUDNN_INSTALL_PATH" ]; then
582 CUDNN_INSTALL_PATH=$default_cudnn_path
583 fi
584 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
585 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800586 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 -0800587 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800588
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800589 if [[ -z "$TF_CUDNN_VERSION" ]]; then
590 TF_CUDNN_EXT=""
591 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800592 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800593 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800594
Andrew Harp1cb96892016-12-08 20:05:49 -0800595 if is_windows; then
596 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
597 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800598 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800599 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
600 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800601 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800602 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
603 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800604 fi
605
606 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 -0800607 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800608 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800609 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800610 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800611 break
612 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800613
Jonathan Hseuc058a012017-01-17 15:06:43 -0800614 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800615 if ! type ldconfig > /dev/null 2>&1; then
616 LDCONFIG_BIN=/sbin/ldconfig
617 else
618 LDCONFIG_BIN=ldconfig
619 fi
620 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800621 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800622 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800623 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800624 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800625 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800626 break
627 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800628 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800629 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
630 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
631 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800632 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800633 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
634 fi
635
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800636 if [ -z "$fromuser" ]; then
637 exit 1
638 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800639 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800640 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800641 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800642done
643
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800644# Configure the compute capabilities that TensorFlow builds for.
645# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
646while true; do
647 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800648 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800649 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800650cat << EOF
651Please specify a list of comma-separated Cuda compute capabilities you want to build with.
652You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
653Please note that each additional compute capability significantly increases your build time and binary size.
654EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800655 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
656 fromuser=1
657 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800658 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
659 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
660 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800661 # Check whether all capabilities from the input is valid
662 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
663 ALL_VALID=1
664 for CAPABILITY in $COMPUTE_CAPABILITIES; do
665 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
666 echo "Invalid compute capability: " $CAPABILITY
667 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800668 break
669 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800670 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800671 if [ "$ALL_VALID" == "0" ]; then
672 if [ -z "$fromuser" ]; then
673 exit 1
674 fi
675 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800676 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800677 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800678 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800679 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800680 TF_CUDA_COMPUTE_CAPABILITIES=""
681done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800682
Andrew Harp1cb96892016-12-08 20:05:49 -0800683if is_windows; then
684 # The following three variables are needed for MSVC toolchain configuration in Bazel
685 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
686 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
687 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800688 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
689 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
690 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Gunhan Gulsoy3cf88d32017-06-06 22:34:30 -0700691 write_to_bazelrc "build --config=win-cuda"
692 write_to_bazelrc "test --config=win-cuda"
693else
694 # If CUDA is enabled, always use GPU during build and test.
695 write_to_bazelrc "build --config=cuda"
696 write_to_bazelrc "test --config=cuda"
Andrew Harp1cb96892016-12-08 20:05:49 -0800697fi
698
Benoit Steinera7715982016-11-09 13:14:03 -0800699# end of if "$TF_NEED_CUDA" == "1"
700fi
701
702# OpenCL configuration
703
704if [ "$TF_NEED_OPENCL" == "1" ]; then
705
706# Determine which C++ compiler should be used as the host compiler
707while true; do
708 fromuser=""
709 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800710 default_cxx_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_cxx_host_compiler]: " HOST_CXX_COMPILER
712 fromuser="1"
713 if [ -z "$HOST_CXX_COMPILER" ]; then
714 HOST_CXX_COMPILER=$default_cxx_host_compiler
715 fi
716 fi
717 if [ -e "$HOST_CXX_COMPILER" ]; then
718 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800719 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800720 break
721 fi
722 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
723 if [ -z "$fromuser" ]; then
724 exit 1
725 fi
726 HOST_CXX_COMPILER=""
727 # Retry
728done
729
730# Determine which C compiler should be used as the host compiler
731while true; do
732 fromuser=""
733 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800734 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800735 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
736 fromuser="1"
737 if [ -z "$HOST_C_COMPILER" ]; then
738 HOST_C_COMPILER=$default_c_host_compiler
739 fi
740 fi
741 if [ -e "$HOST_C_COMPILER" ]; then
742 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800743 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800744 break
745 fi
746 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
747 if [ -z "$fromuser" ]; then
748 exit 1
749 fi
750 HOST_C_COMPILER=""
751 # Retry
752done
753
754while true; do
755 # Configure the OPENCL version to use.
756 TF_OPENCL_VERSION="1.2"
757
758 # Point to ComputeCpp root
759 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
760 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800761 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 -0800762 fromuser="1"
763 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
764 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
765 fi
766 fi
767
Jonathan Hseuc058a012017-01-17 15:06:43 -0800768 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800769 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
770 fi
771
772 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
773 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800774 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800775 break
776 fi
777 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
778
779 if [ -z "$fromuser" ]; then
780 exit 1
781 fi
782 # Retry
783 TF_OPENCL_VERSION=""
784 COMPUTECPP_TOOLKIT_PATH=""
785done
786
Benoit Steinera7715982016-11-09 13:14:03 -0800787# end of if "$TF_NEED_OPENCL" == "1"
788fi
789
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800790# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
791bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800792echo "Configuration finished"