blob: 1531b4d40ab916b161def3feb16af641aaf3be65 [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() {
Jonathan Hseu1b5235f2017-06-09 10:37:18 -070016 [[ "${PLATFORM}" == "linux" ]]
Jonathan Hseuc058a012017-01-17 15:06:43 -080017}
18
19function is_macos() {
Jonathan Hseu1b5235f2017-06-09 10:37:18 -070020 [[ "${PLATFORM}" == "darwin" ]]
Jonathan Hseuc058a012017-01-17 15:06:43 -080021}
22
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080023function is_windows() {
24 # On windows, the shell script is actually running in msys
Jonathan Hseu1b5235f2017-06-09 10:37:18 -070025 [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080026}
27
Dan Ringwalt692fad22017-05-05 09:09:05 -080028function sed_in_place() {
29 sed -e $1 $2 > "$2.bak"
30 mv "$2.bak" $2
Dandelion Mané0386a012017-03-10 14:43:23 -080031}
32
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080033function write_to_bazelrc() {
34 echo "$1" >> .tf_configure.bazelrc
35}
36
37function write_action_env_to_bazelrc() {
38 write_to_bazelrc "build --action_env $1=\"$2\""
39}
40
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080041function python_path {
42 "$PYTHON_BIN_PATH" - <<END
43from __future__ import print_function
44import site
45import os
46
47try:
48 input = raw_input
49except NameError:
50 pass
51
52python_paths = []
53if os.getenv('PYTHONPATH') is not None:
54 python_paths = os.getenv('PYTHONPATH').split(':')
55try:
56 library_paths = site.getsitepackages()
57except AttributeError:
58 from distutils.sysconfig import get_python_lib
59 library_paths = [get_python_lib()]
60all_paths = set(python_paths + library_paths)
61
62paths = []
63for path in all_paths:
64 if os.path.isdir(path):
65 paths.append(path)
66
67print(",".join(paths))
68END
69}
70
71function setup_python {
72 ## Set up python-related environment settings:
73 while true; do
74 fromuser=""
75 if [ -z "$PYTHON_BIN_PATH" ]; then
76 default_python_bin_path=$(which python || which python3 || true)
77 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
78 fromuser="1"
79 if [ -z "$PYTHON_BIN_PATH" ]; then
80 PYTHON_BIN_PATH=$default_python_bin_path
81 fi
82 fi
83 if [ -e "$PYTHON_BIN_PATH" ]; then
84 break
85 fi
86 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
87 if [ -z "$fromuser" ]; then
88 exit 1
89 fi
90 PYTHON_BIN_PATH=""
91 # Retry
92 done
93
94 if [ -z "$PYTHON_LIB_PATH" ]; then
95 # Split python_path into an array of paths, this allows path containing spaces
Jonathan Hseu1b5235f2017-06-09 10:37:18 -070096 IFS=',' read -r -a python_lib_path <<< "$(python_path)"
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080097
98 if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then
99 PYTHON_LIB_PATH=${python_lib_path[0]}
100 echo "Using python library path: $PYTHON_LIB_PATH"
101
102 else
103 echo "Found possible Python library paths:"
104 for x in "${python_lib_path[@]}"; do
105 echo " $x"
106 done
107 set -- "${python_lib_path[@]}"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700108 echo "Please input the desired Python library path to use. Default is [$1]"
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800109 read b || true
110 if [ "$b" == "" ]; then
111 PYTHON_LIB_PATH=${python_lib_path[0]}
112 echo "Using python library path: $PYTHON_LIB_PATH"
113 else
114 PYTHON_LIB_PATH="$b"
115 fi
116 fi
117 fi
118
119 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
120 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
121 exit 1
122 fi
123
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700124 local python_major_version
125 python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);' | head -c1)
126 if [ -z "$python_major_version" ]; then
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800127 echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?"
128 exit 1
129 fi
130
131 # Convert python path to Windows style before writing into bazel.rc
132 if is_windows; then
133 PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700134 PYTHON_LIB_PATH="$(cygpath -m "$PYTHON_LIB_PATH")"
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800135 fi
136
137 # Set-up env variables used by python_configure.bzl
138 write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
139 write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH"
Benoit Steineree112cf2017-05-10 21:12:21 -0700140 write_to_bazelrc "build --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
141 write_to_bazelrc "build --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800142 write_to_bazelrc "build --force_python=py$python_major_version"
143 write_to_bazelrc "build --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700144 write_to_bazelrc "build --python${python_major_version}_path=\"$PYTHON_BIN_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800145 write_to_bazelrc "test --force_python=py$python_major_version"
146 write_to_bazelrc "test --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700147 write_to_bazelrc "test --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
148 write_to_bazelrc "test --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
149 write_to_bazelrc "run --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
150 write_to_bazelrc "run --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800151
152 # Write tools/python_bin_path.sh
153 echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh
154}
155
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700156function version {
157 echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }';
158}
159
160
161bazel version > bazel.version
162curr_bazel_version=$(head -n 1 bazel.version | cut -d ' ' -f3)
163rm -f bazel.version
164
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700165
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700166echo "You have bazel $curr_bazel_version installed."
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700167if [ -z "$curr_bazel_version" ]; then
168 echo "WARNING: current bazel installation is not a release version."
169 echo "Make sure you are running at least bazel $MIN_BAZEL_VERSION."
170elif [ "$(version "$MIN_BAZEL_VERSION")" -gt "$(version "$curr_bazel_version")" ]; then
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700171 echo "Please upgrade your bazel installation to version $MIN_BAZEL_VERSION or higher to build TensorFlow!"
172 echo "Exiting..."
173 exit 1
174fi
175
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800176# This file contains customized config settings.
177rm -f .tf_configure.bazelrc
178touch .tf_configure.bazelrc
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700179if [[ ! -e .bazelrc ]]; then
180 if [[ -e "${HOME}/.bazelrc" ]]; then
181 echo "import ${HOME}/.bazelrc" >.bazelrc
182 else
183 touch .bazelrc
184 fi
185fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800186sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800187echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800188
Andrew Harp51dbc462017-01-27 14:42:30 -0800189# Delete any leftover BUILD files from the Makefile build, which would interfere
190# with Bazel parsing.
191MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
192if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
193 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
194fi
195
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800196setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800197
Benoit Steiner639b4e72017-02-08 09:25:09 -0800198## Set up MKL related environment settings
Benoit Steineree112cf2017-05-10 21:12:21 -0700199while [ "$TF_NEED_MKL" == "" ]; do
200 fromuser=""
201 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
202 fromuser="1"
203 case $INPUT in
204 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
205 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
206 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
207 * ) echo "Invalid selection: " $INPUT;;
208 esac
209done
210
211OSNAME=`uname -s`
212
213if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
214 while [ "$TF_DOWNLOAD_MKL" == "" ]; do
Benoit Steiner639b4e72017-02-08 09:25:09 -0800215 fromuser=""
Benoit Steineree112cf2017-05-10 21:12:21 -0700216 read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800217 fromuser="1"
218 case $INPUT in
Benoit Steineree112cf2017-05-10 21:12:21 -0700219 [Yy]* ) TF_DOWNLOAD_MKL=1;;
220 [Nn]* ) TF_DOWNLOAD_MKL=0;;
221 "" ) TF_DOWNLOAD_MKL=1;;
222 * ) echo "Invalid selection: " $INPUT; exit 1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800223 esac
224 done
225
Benoit Steineree112cf2017-05-10 21:12:21 -0700226 if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800227 DST=`dirname $0`
Benoit Steineree112cf2017-05-10 21:12:21 -0700228 ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
229 GITHUB_RELEASE_TAG=v0.7
Benoit Steiner639b4e72017-02-08 09:25:09 -0800230 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
Benoit Steineree112cf2017-05-10 21:12:21 -0700231 if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
232 curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800233 fi
234 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
235 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
236 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
237 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
238
Benoit Steineree112cf2017-05-10 21:12:21 -0700239 else
240 default_mkl_path=/opt/intel/mklml
241 fromuser=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700242 if [ -z "$MKL_INSTALL_PATH" ]; then
243 read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
244 fromuser="1"
245 fi
Benoit Steineree112cf2017-05-10 21:12:21 -0700246 if [ -z "$MKL_INSTALL_PATH" ]; then
247 MKL_INSTALL_PATH=$default_mkl_path
248 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700249 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Benoit Steineree112cf2017-05-10 21:12:21 -0700250 # 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
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700484 read -p "Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: " 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
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800527 break
528 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800529 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
530
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800531 if [ -z "$fromuser" ]; then
532 exit 1
533 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800534 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800535 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800536 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800537done
538
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700539# Set default CUDA version if not set
540if [ -z "$TF_CUDA_VERSION" ]; then
541 TF_CUDA_VERSION="8.0"
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700542 export TF_CUDA_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700543fi
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700544write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700545
Dan Ringwalt692fad22017-05-05 09:09:05 -0800546# Set up which gcc nvcc should use as the host compiler
547# No need to set this on Windows
548while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
549 fromuser=""
550 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
551 default_gcc_host_compiler_path=$(which gcc || true)
552 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
553 if [ -L "$cuda_bin_symlink" ]; then
554 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
555 fi
556 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
557 fromuser="1"
558 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
559 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
560 fi
561 fi
562 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
563 export GCC_HOST_COMPILER_PATH
564 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
565 break
566 fi
567 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
568 if [ -z "$fromuser" ]; then
569 exit 1
570 fi
571 GCC_HOST_COMPILER_PATH=""
572 # Retry
573done
574
Martin Wicke916776a2016-01-14 07:30:00 -0800575# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800576while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800577 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800578 if [ -z "$TF_CUDNN_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700579 read -p "Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: " TF_CUDNN_VERSION
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800580 fi
581
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800582 fromuser=""
583 if [ -z "$CUDNN_INSTALL_PATH" ]; then
584 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800585 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 -0800586 fromuser="1"
587 if [ -z "$CUDNN_INSTALL_PATH" ]; then
588 CUDNN_INSTALL_PATH=$default_cudnn_path
589 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700590 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800591 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800592 CUDNN_INSTALL_PATH=`"${PYTHON_BIN_PATH}" -c "import os; print(os.path.realpath(os.path.expanduser('${CUDNN_INSTALL_PATH}')))"`
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700593 if is_windows; then
594 CUDNN_INSTALL_PATH="$(cygpath -m "$CUDNN_INSTALL_PATH")"
595 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800596 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800597
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800598 if [[ -z "$TF_CUDNN_VERSION" ]]; then
599 TF_CUDNN_EXT=""
600 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800601 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800602 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800603
Andrew Harp1cb96892016-12-08 20:05:49 -0800604 if is_windows; then
605 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
606 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800607 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800608 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
609 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800610 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800611 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
612 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800613 fi
614
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700615 if [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_ALT_PATH}" ] || [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_PATH}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800616 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800617 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800618 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800619 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800620 break
621 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800622
Jonathan Hseuc058a012017-01-17 15:06:43 -0800623 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800624 if ! type ldconfig > /dev/null 2>&1; then
625 LDCONFIG_BIN=/sbin/ldconfig
626 else
627 LDCONFIG_BIN=ldconfig
628 fi
629 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800630 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800631 export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700632 export CUDNN_INSTALL_PATH
633 CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800634 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800635 break
636 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800637 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800638 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
639 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
640 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800641 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800642 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
643 fi
644
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800645 if [ -z "$fromuser" ]; then
646 exit 1
647 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800648 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800649 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800650 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800651done
652
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700653# Set default CUDNN version if not set
654if [ -z "$TF_CUDNN_VERSION" ]; then
655 TF_CUDNN_VERSION="6"
656 export TF_CUDNN_VERSION
657fi
658write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
659
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800660# Configure the compute capabilities that TensorFlow builds for.
661# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700662function get_native_cuda_compute_capabilities {
663 device_query_bin="$CUDA_TOOLKIT_PATH/extras/demo_suite/deviceQuery" # Also works on Windows without .exe
664 "$device_query_bin" | grep 'Capability' | grep -o '[0-9]*\.[0-9]*' | sed ':a;{N;s/\n/,/};ba'
665 exit 0 # ensure that this function always exit success even if device detection fails, to prevent the whole configure from aborting
666}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800667while true; do
668 fromuser=""
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700669 native_cuda_compute_capabilities=$(get_native_cuda_compute_capabilities)
670 default_cuda_compute_capabilities=${native_cuda_compute_capabilities:-"3.5,5.2"}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800671 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800672cat << EOF
673Please specify a list of comma-separated Cuda compute capabilities you want to build with.
674You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
675Please note that each additional compute capability significantly increases your build time and binary size.
676EOF
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700677 read -p "[Default is: \"$default_cuda_compute_capabilities\"]: " TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800678 fromuser=1
679 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800680 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
681 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
682 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800683 # Check whether all capabilities from the input is valid
684 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
685 ALL_VALID=1
686 for CAPABILITY in $COMPUTE_CAPABILITIES; do
687 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
688 echo "Invalid compute capability: " $CAPABILITY
689 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800690 break
691 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800692 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800693 if [ "$ALL_VALID" == "0" ]; then
694 if [ -z "$fromuser" ]; then
695 exit 1
696 fi
697 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800698 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800699 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800700 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800701 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800702 TF_CUDA_COMPUTE_CAPABILITIES=""
703done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800704
Andrew Harp1cb96892016-12-08 20:05:49 -0800705if is_windows; then
706 # The following three variables are needed for MSVC toolchain configuration in Bazel
707 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
708 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
709 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800710 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
711 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
712 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Gunhan Gulsoy3cf88d32017-06-06 22:34:30 -0700713 write_to_bazelrc "build --config=win-cuda"
714 write_to_bazelrc "test --config=win-cuda"
715else
716 # If CUDA is enabled, always use GPU during build and test.
717 write_to_bazelrc "build --config=cuda"
718 write_to_bazelrc "test --config=cuda"
Andrew Harp1cb96892016-12-08 20:05:49 -0800719fi
720
Benoit Steinera7715982016-11-09 13:14:03 -0800721# end of if "$TF_NEED_CUDA" == "1"
722fi
723
724# OpenCL configuration
725
726if [ "$TF_NEED_OPENCL" == "1" ]; then
727
728# Determine which C++ compiler should be used as the host compiler
729while true; do
730 fromuser=""
731 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700732 default_cxx_host_compiler=$(which g++ || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800733 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
734 fromuser="1"
735 if [ -z "$HOST_CXX_COMPILER" ]; then
736 HOST_CXX_COMPILER=$default_cxx_host_compiler
737 fi
738 fi
739 if [ -e "$HOST_CXX_COMPILER" ]; then
740 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800741 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800742 break
743 fi
744 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
745 if [ -z "$fromuser" ]; then
746 exit 1
747 fi
748 HOST_CXX_COMPILER=""
749 # Retry
750done
751
752# Determine which C compiler should be used as the host compiler
753while true; do
754 fromuser=""
755 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700756 default_c_host_compiler=$(which gcc || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800757 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
758 fromuser="1"
759 if [ -z "$HOST_C_COMPILER" ]; then
760 HOST_C_COMPILER=$default_c_host_compiler
761 fi
762 fi
763 if [ -e "$HOST_C_COMPILER" ]; then
764 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800765 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800766 break
767 fi
768 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
769 if [ -z "$fromuser" ]; then
770 exit 1
771 fi
772 HOST_C_COMPILER=""
773 # Retry
774done
775
776while true; do
777 # Configure the OPENCL version to use.
778 TF_OPENCL_VERSION="1.2"
779
780 # Point to ComputeCpp root
781 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
782 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800783 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 -0800784 fromuser="1"
785 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
786 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
787 fi
788 fi
789
Jonathan Hseuc058a012017-01-17 15:06:43 -0800790 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800791 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
792 fi
793
794 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
795 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800796 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800797 break
798 fi
799 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
800
801 if [ -z "$fromuser" ]; then
802 exit 1
803 fi
804 # Retry
805 TF_OPENCL_VERSION=""
806 COMPUTECPP_TOOLKIT_PATH=""
807done
808
Benoit Steinera7715982016-11-09 13:14:03 -0800809# end of if "$TF_NEED_OPENCL" == "1"
810fi
811
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700812
813while [ "$TF_NEED_MPI" == "" ]; do
814 read -p "Do you wish to build TensorFlow with "\
815"MPI support? [y/N] " INPUT
816 case $INPUT in
817 [Yy]* ) echo "MPI support will be enabled for "\
818"TensorFlow"; TF_NEED_MPI=1;;
819 [Nn]* ) echo "MPI support will not be enabled for "\
820"TensorFlow"; TF_NEED_MPI=0;;
821 "" ) echo "MPI support will not be enabled for "\
822"TensorFlow"; TF_NEED_MPI=0;;
823 * ) echo "Invalid selection: " $INPUT;;
824 esac
825done
826
827# Find out where the MPI toolkit is installed
828while true; do
829 if [ "$TF_NEED_MPI" == "0" ]; then
830 break;
831 fi
832
833 fromuser=""
834 if [ -z "$MPI_HOME" ]; then
835 #Get the base folder by removing the bin path
836 default_mpi_path=$(dirname $(dirname $(which mpirun)) || dirname $(dirname $(which mpiexec)) || true)
837 read -p "Please specify the MPI toolkit folder. [Default is $default_mpi_path]: " MPI_HOME
838 fromuser="1"
839 if [ -z "$MPI_HOME" ]; then
840 MPI_HOME=$default_mpi_path
841 fi
842 fi
843
844 #Check that the include and library folders are where we expect them to be
845 if [ -e "$MPI_HOME/include" ] && [ -e "$MPI_HOME/lib" ]; then
846 break
847 fi
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700848
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700849 echo "Invalid path to the MPI Toolkit. ${MPI_HOME}/include or ${MPI_HOME}/lib cannot be found."
850 if [ -z "$fromuser" ]; then
851 exit 1
852 fi
853
854 # Retry
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700855 MPI_HOME=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700856done
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700857
858
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700859if [ "$TF_NEED_MPI" == "1" ]; then
860 write_to_bazelrc 'build --define with_mpi_support=true'
861
862 #Link the MPI header files
863 ln -sf "${MPI_HOME}/include/mpi.h" third_party/mpi/mpi.h
864
865
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700866 #Determine if we use OpenMPI or MVAPICH, these require different header files
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700867 #to be included here to make bazel dependency checker happy
868
869 if [ -e "${MPI_HOME}/include/mpi_portable_platform.h" ]; then
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700870 #OpenMPI
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700871 ln -sf "${MPI_HOME}/include/mpi_portable_platform.h" third_party/mpi/
872 sed -i -e "s/MPI_LIB_IS_OPENMPI=False/MPI_LIB_IS_OPENMPI=True/" third_party/mpi/mpi.bzl
873 else
874 #MVAPICH / MPICH
875 ln -sf "${MPI_HOME}/include/mpio.h" third_party/mpi/
876 ln -sf "${MPI_HOME}/include/mpicxx.h" third_party/mpi/
877 sed -i -e "s/MPI_LIB_IS_OPENMPI=True/MPI_LIB_IS_OPENMPI=False/" third_party/mpi/mpi.bzl
878 fi
879
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700880
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700881 if [ -e "${MPI_HOME}/lib/libmpi.so" ]; then
882 ln -sf "${MPI_HOME}/lib/libmpi.so" third_party/mpi/
883 else
884 echo "Cannot find the MPI library file in ${MPI_HOME}/lib "
885 exit 1
886 fi
887fi
888
889
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800890echo "Configuration finished"