blob: e1aaddabdac5fa2e731a8360e568920e7c48943a [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
165echo "You have bazel $curr_bazel_version installed."
A. Unique TensorFlower1fa73c52017-06-26 14:00:17 -0700166if [ "$(version "$MIN_BAZEL_VERSION")" -gt "$(version "$curr_bazel_version")" ]; then
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700167 echo "Please upgrade your bazel installation to version $MIN_BAZEL_VERSION or higher to build TensorFlow!"
168 echo "Exiting..."
169 exit 1
170fi
171
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800172# This file contains customized config settings.
173rm -f .tf_configure.bazelrc
174touch .tf_configure.bazelrc
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700175if [[ ! -e .bazelrc ]]; then
176 if [[ -e "${HOME}/.bazelrc" ]]; then
177 echo "import ${HOME}/.bazelrc" >.bazelrc
178 else
179 touch .bazelrc
180 fi
181fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800182sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800183echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800184
Andrew Harp51dbc462017-01-27 14:42:30 -0800185# Delete any leftover BUILD files from the Makefile build, which would interfere
186# with Bazel parsing.
187MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
188if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
189 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
190fi
191
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800192setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800193
Benoit Steiner639b4e72017-02-08 09:25:09 -0800194## Set up MKL related environment settings
Benoit Steineree112cf2017-05-10 21:12:21 -0700195while [ "$TF_NEED_MKL" == "" ]; do
196 fromuser=""
197 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
198 fromuser="1"
199 case $INPUT in
200 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
201 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
202 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
203 * ) echo "Invalid selection: " $INPUT;;
204 esac
205done
206
207OSNAME=`uname -s`
208
209if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
210 while [ "$TF_DOWNLOAD_MKL" == "" ]; do
Benoit Steiner639b4e72017-02-08 09:25:09 -0800211 fromuser=""
Benoit Steineree112cf2017-05-10 21:12:21 -0700212 read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800213 fromuser="1"
214 case $INPUT in
Benoit Steineree112cf2017-05-10 21:12:21 -0700215 [Yy]* ) TF_DOWNLOAD_MKL=1;;
216 [Nn]* ) TF_DOWNLOAD_MKL=0;;
217 "" ) TF_DOWNLOAD_MKL=1;;
218 * ) echo "Invalid selection: " $INPUT; exit 1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800219 esac
220 done
221
Benoit Steineree112cf2017-05-10 21:12:21 -0700222 if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800223 DST=`dirname $0`
Benoit Steineree112cf2017-05-10 21:12:21 -0700224 ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
225 GITHUB_RELEASE_TAG=v0.7
Benoit Steiner639b4e72017-02-08 09:25:09 -0800226 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
Benoit Steineree112cf2017-05-10 21:12:21 -0700227 if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
228 curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800229 fi
230 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
231 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
232 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
233 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
234
Benoit Steineree112cf2017-05-10 21:12:21 -0700235 else
236 default_mkl_path=/opt/intel/mklml
237 fromuser=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700238 if [ -z "$MKL_INSTALL_PATH" ]; then
239 read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
240 fromuser="1"
241 fi
Benoit Steineree112cf2017-05-10 21:12:21 -0700242 if [ -z "$MKL_INSTALL_PATH" ]; then
243 MKL_INSTALL_PATH=$default_mkl_path
244 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700245 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Benoit Steineree112cf2017-05-10 21:12:21 -0700246 # Going through one more level of expansion to handle that.
247 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
248 fi
249
250 if [ "$OSNAME" == "Linux" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800251 # Full MKL configuration
252 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
253 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
254
255 # MKL-ML configuration
256 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
257 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
Benoit Steineree112cf2017-05-10 21:12:21 -0700258 elif [ "$OSNAME" == "Darwin" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800259 echo "Darwin is unsupported yet";
260 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700261 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800262
Benoit Steineree112cf2017-05-10 21:12:21 -0700263 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800264 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
265 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
266 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
267 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
Benoit Steineree112cf2017-05-10 21:12:21 -0700268 loc=$(locate -e libdl.so.2 | sed -n 1p)
269 ln -sf $loc third_party/mkl/libdl.so.2
270 elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then
271 ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/
272 ln -sf $MKL_INSTALL_PATH/${MKL_RT_OMP_LIB_PATH} third_party/mkl/
273 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
274 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
275 loc=$(locate -e libdl.so.2 | sed -n 1p)
276 ln -sf $loc third_party/mkl/libdl.so.2
277 else
278 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 -0800279 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700280 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800281
282cat > third_party/mkl/mkl.config <<EOF
283# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
284# files can be either in this directory, or under include/ and lib64/
285MKL_INSTALL_PATH=$MKL_INSTALL_PATH
286EOF
287
Benoit Steineree112cf2017-05-10 21:12:21 -0700288fi # TF_NEED_MKL
289## End MKL setup
Benoit Steiner639b4e72017-02-08 09:25:09 -0800290
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800291## Set up architecture-dependent optimization flags.
292if [ -z "$CC_OPT_FLAGS" ]; then
293 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800294 read -p "Please specify optimization flags to use during compilation when bazel option "\
295"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800296 if [ -z "$CC_OPT_FLAGS" ]; then
297 CC_OPT_FLAGS=$default_cc_opt_flags
298 fi
299fi
300
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800301if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800302 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800303 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800304 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800305 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800306 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800307fi
308
Jonathan Hseuc058a012017-01-17 15:06:43 -0800309if is_linux; then
310 while [ "$TF_NEED_JEMALLOC" == "" ]; do
311 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
312 INPUT
313 case $INPUT in
314 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
315 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
316 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
317 * ) echo "Invalid selection: " $INPUT;;
318 esac
319 done
320else
321 TF_NEED_JEMALLOC=0
322fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800323
Martin Wickebc456e32017-03-23 12:31:16 -0800324if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800325 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800326fi
327
Martin Wickebc456e32017-03-23 12:31:16 -0800328while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800329 read -p "Do you wish to build TensorFlow with "\
330"Google Cloud Platform support? [y/N] " INPUT
331 case $INPUT in
332 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
333"TensorFlow"; TF_NEED_GCP=1;;
334 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
335"TensorFlow"; TF_NEED_GCP=0;;
336 "" ) echo "No Google Cloud Platform support will be enabled for "\
337"TensorFlow"; TF_NEED_GCP=0;;
338 * ) echo "Invalid selection: " $INPUT;;
339 esac
340done
341
Martin Wickebc456e32017-03-23 12:31:16 -0800342if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800343 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800344fi
345
Martin Wickebc456e32017-03-23 12:31:16 -0800346while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800347 read -p "Do you wish to build TensorFlow with "\
348"Hadoop File System support? [y/N] " INPUT
349 case $INPUT in
350 [Yy]* ) echo "Hadoop File System support will be enabled for "\
351"TensorFlow"; TF_NEED_HDFS=1;;
352 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
353"TensorFlow"; TF_NEED_HDFS=0;;
354 "" ) echo "No Hadoop File System support will be enabled for "\
355"TensorFlow"; TF_NEED_HDFS=0;;
356 * ) echo "Invalid selection: " $INPUT;;
357 esac
358done
359
Martin Wickebc456e32017-03-23 12:31:16 -0800360if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800361 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800362fi
363
Peter Hawkins1e67c902017-01-09 12:04:37 -0800364## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800365while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800366 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
367 case $INPUT in
368 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
369 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
370 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
371 * ) echo "Invalid selection: " $INPUT;;
372 esac
373done
374
Martin Wickebc456e32017-03-23 12:31:16 -0800375if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800376 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800377fi
378
Shanqing Cai32694232017-04-22 06:08:17 -0800379# Verbs configuration
380while [ "$TF_NEED_VERBS" == "" ]; do
381 read -p "Do you wish to build TensorFlow with "\
382"VERBS support? [y/N] " INPUT
383 case $INPUT in
384 [Yy]* ) echo "VERBS support will be enabled for "\
385"TensorFlow"; TF_NEED_VERBS=1;;
386 [Nn]* ) echo "No VERBS support will be enabled for "\
387"TensorFlow"; TF_NEED_VERBS=0;;
388 "" ) echo "No VERBS support will be enabled for "\
389"TensorFlow"; TF_NEED_VERBS=0;;
390 * ) echo "Invalid selection: " $INPUT;;
391 esac
392done
393
394if [[ "$TF_NEED_VERBS" == "1" ]]; then
395 write_to_bazelrc 'build --define with_verbs_support=true'
396fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800397
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800398# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800399for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800400 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800401done
402
Andrew Selle09045e42016-09-06 08:19:04 -0800403# Run the gen_git_source to create links where bazel can track dependencies for
404# git hash propagation
405GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
406chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800407"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800408
Benoit Steinera7715982016-11-09 13:14:03 -0800409## Set up SYCL-related environment settings
410while [ "$TF_NEED_OPENCL" == "" ]; do
411 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
412 case $INPUT in
413 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
414 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
415 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
416 * ) echo "Invalid selection: " $INPUT;;
417 esac
418done
419
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800420## Set up Cuda-related environment settings
421
422while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800423 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800424 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800425 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
426 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
427 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800428 * ) echo "Invalid selection: " $INPUT;;
429 esac
430done
431
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800432export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800433write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800434
Rohan Jainaab09972017-01-05 14:39:17 -0800435export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800436write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800437
Benoit Steinera7715982016-11-09 13:14:03 -0800438if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800439while [[ "$TF_CUDA_CLANG" == "" ]]; do
440 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
441 case $INPUT in
442 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
443 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
444 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
445 * ) echo "Invalid selection: " $INPUT;;
446 esac
447done
448
449export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800450write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800451
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800452# Set up which clang we should use as the cuda / host compiler.
453while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
454 fromuser=""
455 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
456 default_clang_host_compiler_path=$(which clang || true)
457 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
458 fromuser="1"
459 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
460 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
461 fi
462 fi
463 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
464 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800465 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800466 break
467 fi
468 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
469 if [ -z "$fromuser" ]; then
470 exit 1
471 fi
472 CLANG_CUDA_COMPILER_PATH=""
473 # Retry
474done
475
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800476# Find out where the CUDA toolkit is installed
477while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800478 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800479 if [ -z "$TF_CUDA_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700480 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 -0800481 fi
482
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800483 fromuser=""
484 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
485 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800486 if is_windows; then
487 if [ -z "$CUDA_PATH" ]; then
488 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
489 else
490 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
491 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800492 elif is_linux; then
493 # If the default doesn't exist, try an alternative default.
494 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
495 default_cuda_path=/opt/cuda
496 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800497 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800498 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 -0800499 fromuser="1"
500 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800501 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800502 fi
503 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800504
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800505 if [[ -z "$TF_CUDA_VERSION" ]]; then
506 TF_CUDA_EXT=""
507 else
508 TF_CUDA_EXT=".$TF_CUDA_VERSION"
509 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800510
Andrew Harp1cb96892016-12-08 20:05:49 -0800511 if is_windows; then
512 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800513 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800514 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800515 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800516 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
517 fi
518
519 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800520 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800521 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800522 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800523 break
524 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800525 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
526
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800527 if [ -z "$fromuser" ]; then
528 exit 1
529 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800530 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800531 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800532 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800533done
534
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700535# Set default CUDA version if not set
536if [ -z "$TF_CUDA_VERSION" ]; then
537 TF_CUDA_VERSION="8.0"
538 export TF_CUDA_VERSION
539fi
540write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
541
Dan Ringwalt692fad22017-05-05 09:09:05 -0800542# Set up which gcc nvcc should use as the host compiler
543# No need to set this on Windows
544while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
545 fromuser=""
546 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
547 default_gcc_host_compiler_path=$(which gcc || true)
548 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
549 if [ -L "$cuda_bin_symlink" ]; then
550 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
551 fi
552 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
553 fromuser="1"
554 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
555 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
556 fi
557 fi
558 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
559 export GCC_HOST_COMPILER_PATH
560 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
561 break
562 fi
563 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
564 if [ -z "$fromuser" ]; then
565 exit 1
566 fi
567 GCC_HOST_COMPILER_PATH=""
568 # Retry
569done
570
Martin Wicke916776a2016-01-14 07:30:00 -0800571# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800572while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800573 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800574 if [ -z "$TF_CUDNN_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700575 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 -0800576 fi
577
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800578 fromuser=""
579 if [ -z "$CUDNN_INSTALL_PATH" ]; then
580 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800581 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 -0800582 fromuser="1"
583 if [ -z "$CUDNN_INSTALL_PATH" ]; then
584 CUDNN_INSTALL_PATH=$default_cudnn_path
585 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700586 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800587 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800588 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 -0800589 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800590
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800591 if [[ -z "$TF_CUDNN_VERSION" ]]; then
592 TF_CUDNN_EXT=""
593 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800594 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800595 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800596
Andrew Harp1cb96892016-12-08 20:05:49 -0800597 if is_windows; then
598 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
599 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800600 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800601 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
602 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800603 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800604 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
605 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800606 fi
607
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700608 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 -0800609 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800610 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800611 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800612 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800613 break
614 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800615
Jonathan Hseuc058a012017-01-17 15:06:43 -0800616 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800617 if ! type ldconfig > /dev/null 2>&1; then
618 LDCONFIG_BIN=/sbin/ldconfig
619 else
620 LDCONFIG_BIN=ldconfig
621 fi
622 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800623 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800624 export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700625 export CUDNN_INSTALL_PATH
626 CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800627 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800628 break
629 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800630 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800631 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
632 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
633 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800634 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800635 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
636 fi
637
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800638 if [ -z "$fromuser" ]; then
639 exit 1
640 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800641 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800642 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800643 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800644done
645
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700646# Set default CUDNN version if not set
647if [ -z "$TF_CUDNN_VERSION" ]; then
648 TF_CUDNN_VERSION="6"
649 export TF_CUDNN_VERSION
650fi
651write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
652
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800653# Configure the compute capabilities that TensorFlow builds for.
654# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
655while true; do
656 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800657 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800658 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800659cat << EOF
660Please specify a list of comma-separated Cuda compute capabilities you want to build with.
661You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
662Please note that each additional compute capability significantly increases your build time and binary size.
663EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800664 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
665 fromuser=1
666 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800667 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
668 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
669 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800670 # Check whether all capabilities from the input is valid
671 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
672 ALL_VALID=1
673 for CAPABILITY in $COMPUTE_CAPABILITIES; do
674 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
675 echo "Invalid compute capability: " $CAPABILITY
676 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800677 break
678 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800679 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800680 if [ "$ALL_VALID" == "0" ]; then
681 if [ -z "$fromuser" ]; then
682 exit 1
683 fi
684 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800685 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800686 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800687 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800688 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800689 TF_CUDA_COMPUTE_CAPABILITIES=""
690done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800691
Andrew Harp1cb96892016-12-08 20:05:49 -0800692if is_windows; then
693 # The following three variables are needed for MSVC toolchain configuration in Bazel
694 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
695 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
696 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800697 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
698 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
699 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Gunhan Gulsoy3cf88d32017-06-06 22:34:30 -0700700 write_to_bazelrc "build --config=win-cuda"
701 write_to_bazelrc "test --config=win-cuda"
702else
703 # If CUDA is enabled, always use GPU during build and test.
704 write_to_bazelrc "build --config=cuda"
705 write_to_bazelrc "test --config=cuda"
Andrew Harp1cb96892016-12-08 20:05:49 -0800706fi
707
Benoit Steinera7715982016-11-09 13:14:03 -0800708# end of if "$TF_NEED_CUDA" == "1"
709fi
710
711# OpenCL configuration
712
713if [ "$TF_NEED_OPENCL" == "1" ]; then
714
715# Determine which C++ compiler should be used as the host compiler
716while true; do
717 fromuser=""
718 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700719 default_cxx_host_compiler=$(which g++ || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800720 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
721 fromuser="1"
722 if [ -z "$HOST_CXX_COMPILER" ]; then
723 HOST_CXX_COMPILER=$default_cxx_host_compiler
724 fi
725 fi
726 if [ -e "$HOST_CXX_COMPILER" ]; then
727 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800728 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800729 break
730 fi
731 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
732 if [ -z "$fromuser" ]; then
733 exit 1
734 fi
735 HOST_CXX_COMPILER=""
736 # Retry
737done
738
739# Determine which C compiler should be used as the host compiler
740while true; do
741 fromuser=""
742 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700743 default_c_host_compiler=$(which gcc || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800744 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
745 fromuser="1"
746 if [ -z "$HOST_C_COMPILER" ]; then
747 HOST_C_COMPILER=$default_c_host_compiler
748 fi
749 fi
750 if [ -e "$HOST_C_COMPILER" ]; then
751 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800752 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800753 break
754 fi
755 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
756 if [ -z "$fromuser" ]; then
757 exit 1
758 fi
759 HOST_C_COMPILER=""
760 # Retry
761done
762
763while true; do
764 # Configure the OPENCL version to use.
765 TF_OPENCL_VERSION="1.2"
766
767 # Point to ComputeCpp root
768 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
769 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800770 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 -0800771 fromuser="1"
772 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
773 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
774 fi
775 fi
776
Jonathan Hseuc058a012017-01-17 15:06:43 -0800777 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800778 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
779 fi
780
781 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
782 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800783 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800784 break
785 fi
786 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
787
788 if [ -z "$fromuser" ]; then
789 exit 1
790 fi
791 # Retry
792 TF_OPENCL_VERSION=""
793 COMPUTECPP_TOOLKIT_PATH=""
794done
795
Benoit Steinera7715982016-11-09 13:14:03 -0800796# end of if "$TF_NEED_OPENCL" == "1"
797fi
798
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700799
800while [ "$TF_NEED_MPI" == "" ]; do
801 read -p "Do you wish to build TensorFlow with "\
802"MPI support? [y/N] " INPUT
803 case $INPUT in
804 [Yy]* ) echo "MPI support will be enabled for "\
805"TensorFlow"; TF_NEED_MPI=1;;
806 [Nn]* ) echo "MPI support will not be enabled for "\
807"TensorFlow"; TF_NEED_MPI=0;;
808 "" ) echo "MPI support will not be enabled for "\
809"TensorFlow"; TF_NEED_MPI=0;;
810 * ) echo "Invalid selection: " $INPUT;;
811 esac
812done
813
814# Find out where the MPI toolkit is installed
815while true; do
816 if [ "$TF_NEED_MPI" == "0" ]; then
817 break;
818 fi
819
820 fromuser=""
821 if [ -z "$MPI_HOME" ]; then
822 #Get the base folder by removing the bin path
823 default_mpi_path=$(dirname $(dirname $(which mpirun)) || dirname $(dirname $(which mpiexec)) || true)
824 read -p "Please specify the MPI toolkit folder. [Default is $default_mpi_path]: " MPI_HOME
825 fromuser="1"
826 if [ -z "$MPI_HOME" ]; then
827 MPI_HOME=$default_mpi_path
828 fi
829 fi
830
831 #Check that the include and library folders are where we expect them to be
832 if [ -e "$MPI_HOME/include" ] && [ -e "$MPI_HOME/lib" ]; then
833 break
834 fi
835
836 echo "Invalid path to the MPI Toolkit. ${MPI_HOME}/include or ${MPI_HOME}/lib cannot be found."
837 if [ -z "$fromuser" ]; then
838 exit 1
839 fi
840
841 # Retry
842 MPI_HOME=""
843done
844
845
846if [ "$TF_NEED_MPI" == "1" ]; then
847 write_to_bazelrc 'build --define with_mpi_support=true'
848
849 #Link the MPI header files
850 ln -sf "${MPI_HOME}/include/mpi.h" third_party/mpi/mpi.h
851
852
853 #Determine if we use OpenMPI or MVAPICH, these require different header files
854 #to be included here to make bazel dependency checker happy
855
856 if [ -e "${MPI_HOME}/include/mpi_portable_platform.h" ]; then
857 #OpenMPI
858 ln -sf "${MPI_HOME}/include/mpi_portable_platform.h" third_party/mpi/
859 sed -i -e "s/MPI_LIB_IS_OPENMPI=False/MPI_LIB_IS_OPENMPI=True/" third_party/mpi/mpi.bzl
860 else
861 #MVAPICH / MPICH
862 ln -sf "${MPI_HOME}/include/mpio.h" third_party/mpi/
863 ln -sf "${MPI_HOME}/include/mpicxx.h" third_party/mpi/
864 sed -i -e "s/MPI_LIB_IS_OPENMPI=True/MPI_LIB_IS_OPENMPI=False/" third_party/mpi/mpi.bzl
865 fi
866
867
868 if [ -e "${MPI_HOME}/lib/libmpi.so" ]; then
869 ln -sf "${MPI_HOME}/lib/libmpi.so" third_party/mpi/
870 else
871 echo "Cannot find the MPI library file in ${MPI_HOME}/lib "
872 exit 1
873 fi
874fi
875
876
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800877echo "Configuration finished"