blob: b7bc87dcb72685d543d48f6b398d37e7e5b748b3 [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
Shanqing Cai90d64212017-07-10 19:22:04 -070028function is_ppc64le() {
Jonathan Hseu9cc871e2017-07-19 15:04:52 -070029 [[ "$(uname -m)" == "ppc64le" ]]
Shanqing Cai90d64212017-07-10 19:22:04 -070030}
31
Dan Ringwalt692fad22017-05-05 09:09:05 -080032function sed_in_place() {
33 sed -e $1 $2 > "$2.bak"
34 mv "$2.bak" $2
Dandelion Mané0386a012017-03-10 14:43:23 -080035}
36
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080037function write_to_bazelrc() {
38 echo "$1" >> .tf_configure.bazelrc
39}
40
41function write_action_env_to_bazelrc() {
42 write_to_bazelrc "build --action_env $1=\"$2\""
43}
44
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080045function python_path {
46 "$PYTHON_BIN_PATH" - <<END
47from __future__ import print_function
48import site
49import os
50
51try:
52 input = raw_input
53except NameError:
54 pass
55
56python_paths = []
57if os.getenv('PYTHONPATH') is not None:
58 python_paths = os.getenv('PYTHONPATH').split(':')
59try:
60 library_paths = site.getsitepackages()
61except AttributeError:
62 from distutils.sysconfig import get_python_lib
63 library_paths = [get_python_lib()]
64all_paths = set(python_paths + library_paths)
65
66paths = []
67for path in all_paths:
68 if os.path.isdir(path):
69 paths.append(path)
70
71print(",".join(paths))
72END
73}
74
75function setup_python {
76 ## Set up python-related environment settings:
77 while true; do
78 fromuser=""
79 if [ -z "$PYTHON_BIN_PATH" ]; then
80 default_python_bin_path=$(which python || which python3 || true)
81 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
82 fromuser="1"
83 if [ -z "$PYTHON_BIN_PATH" ]; then
84 PYTHON_BIN_PATH=$default_python_bin_path
85 fi
86 fi
87 if [ -e "$PYTHON_BIN_PATH" ]; then
88 break
89 fi
90 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
91 if [ -z "$fromuser" ]; then
92 exit 1
93 fi
94 PYTHON_BIN_PATH=""
95 # Retry
96 done
97
98 if [ -z "$PYTHON_LIB_PATH" ]; then
99 # Split python_path into an array of paths, this allows path containing spaces
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700100 IFS=',' read -r -a python_lib_path <<< "$(python_path)"
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800101
102 if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then
103 PYTHON_LIB_PATH=${python_lib_path[0]}
104 echo "Using python library path: $PYTHON_LIB_PATH"
105
106 else
107 echo "Found possible Python library paths:"
108 for x in "${python_lib_path[@]}"; do
109 echo " $x"
110 done
111 set -- "${python_lib_path[@]}"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700112 echo "Please input the desired Python library path to use. Default is [$1]"
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800113 read b || true
114 if [ "$b" == "" ]; then
115 PYTHON_LIB_PATH=${python_lib_path[0]}
116 echo "Using python library path: $PYTHON_LIB_PATH"
117 else
118 PYTHON_LIB_PATH="$b"
119 fi
120 fi
121 fi
122
123 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
124 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
125 exit 1
126 fi
127
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700128 local python_major_version
129 python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);' | head -c1)
130 if [ -z "$python_major_version" ]; then
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800131 echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?"
132 exit 1
133 fi
134
135 # Convert python path to Windows style before writing into bazel.rc
136 if is_windows; then
137 PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700138 PYTHON_LIB_PATH="$(cygpath -m "$PYTHON_LIB_PATH")"
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800139 fi
140
141 # Set-up env variables used by python_configure.bzl
142 write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
143 write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH"
Benoit Steineree112cf2017-05-10 21:12:21 -0700144 write_to_bazelrc "build --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
145 write_to_bazelrc "build --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800146 write_to_bazelrc "build --force_python=py$python_major_version"
147 write_to_bazelrc "build --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700148 write_to_bazelrc "build --python${python_major_version}_path=\"$PYTHON_BIN_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800149 write_to_bazelrc "test --force_python=py$python_major_version"
150 write_to_bazelrc "test --host_force_python=py$python_major_version"
Benoit Steineree112cf2017-05-10 21:12:21 -0700151 write_to_bazelrc "test --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
152 write_to_bazelrc "test --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
153 write_to_bazelrc "run --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\""
154 write_to_bazelrc "run --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\""
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800155
156 # Write tools/python_bin_path.sh
157 echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh
158}
159
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700160function version {
161 echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }';
162}
163
164
165bazel version > bazel.version
A. Unique TensorFlower9f4ec7e2017-07-20 13:34:06 -0700166curr_bazel_version=$(grep -m 1 'Build label:' bazel.version | cut -d ' ' -f3)
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700167rm -f bazel.version
168
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700169
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700170echo "You have bazel $curr_bazel_version installed."
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700171if [ -z "$curr_bazel_version" ]; then
172 echo "WARNING: current bazel installation is not a release version."
173 echo "Make sure you are running at least bazel $MIN_BAZEL_VERSION."
174elif [ "$(version "$MIN_BAZEL_VERSION")" -gt "$(version "$curr_bazel_version")" ]; then
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700175 echo "Please upgrade your bazel installation to version $MIN_BAZEL_VERSION or higher to build TensorFlow!"
176 echo "Exiting..."
177 exit 1
178fi
179
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800180# This file contains customized config settings.
181rm -f .tf_configure.bazelrc
182touch .tf_configure.bazelrc
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700183if [[ ! -e .bazelrc ]]; then
184 if [[ -e "${HOME}/.bazelrc" ]]; then
185 echo "import ${HOME}/.bazelrc" >.bazelrc
186 else
187 touch .bazelrc
188 fi
189fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800190sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800191echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800192
Andrew Harp51dbc462017-01-27 14:42:30 -0800193# Delete any leftover BUILD files from the Makefile build, which would interfere
194# with Bazel parsing.
195MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
196if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
197 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
198fi
199
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800200setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800201
Benoit Steiner639b4e72017-02-08 09:25:09 -0800202## Set up MKL related environment settings
Benoit Steineree112cf2017-05-10 21:12:21 -0700203while [ "$TF_NEED_MKL" == "" ]; do
204 fromuser=""
205 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
206 fromuser="1"
207 case $INPUT in
208 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
209 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
210 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
211 * ) echo "Invalid selection: " $INPUT;;
212 esac
213done
214
215OSNAME=`uname -s`
216
217if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
218 while [ "$TF_DOWNLOAD_MKL" == "" ]; do
Benoit Steiner639b4e72017-02-08 09:25:09 -0800219 fromuser=""
Benoit Steineree112cf2017-05-10 21:12:21 -0700220 read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800221 fromuser="1"
222 case $INPUT in
Benoit Steineree112cf2017-05-10 21:12:21 -0700223 [Yy]* ) TF_DOWNLOAD_MKL=1;;
224 [Nn]* ) TF_DOWNLOAD_MKL=0;;
225 "" ) TF_DOWNLOAD_MKL=1;;
226 * ) echo "Invalid selection: " $INPUT; exit 1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800227 esac
228 done
229
Benoit Steineree112cf2017-05-10 21:12:21 -0700230 if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800231 DST=`dirname $0`
Benoit Steineree112cf2017-05-10 21:12:21 -0700232 ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
233 GITHUB_RELEASE_TAG=v0.7
Benoit Steiner639b4e72017-02-08 09:25:09 -0800234 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
Benoit Steineree112cf2017-05-10 21:12:21 -0700235 if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
236 curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800237 fi
238 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
239 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
240 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
241 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
242
Benoit Steineree112cf2017-05-10 21:12:21 -0700243 else
244 default_mkl_path=/opt/intel/mklml
245 fromuser=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700246 if [ -z "$MKL_INSTALL_PATH" ]; then
247 read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
248 fromuser="1"
249 fi
Benoit Steineree112cf2017-05-10 21:12:21 -0700250 if [ -z "$MKL_INSTALL_PATH" ]; then
251 MKL_INSTALL_PATH=$default_mkl_path
252 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700253 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Benoit Steineree112cf2017-05-10 21:12:21 -0700254 # Going through one more level of expansion to handle that.
255 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
256 fi
257
258 if [ "$OSNAME" == "Linux" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800259 # Full MKL configuration
260 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
261 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
262
263 # MKL-ML configuration
264 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
265 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
Benoit Steineree112cf2017-05-10 21:12:21 -0700266 elif [ "$OSNAME" == "Darwin" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800267 echo "Darwin is unsupported yet";
268 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700269 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800270
Benoit Steineree112cf2017-05-10 21:12:21 -0700271 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800272 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
273 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
274 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
275 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
Benoit Steineree112cf2017-05-10 21:12:21 -0700276 loc=$(locate -e libdl.so.2 | sed -n 1p)
277 ln -sf $loc third_party/mkl/libdl.so.2
278 elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then
279 ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/
280 ln -sf $MKL_INSTALL_PATH/${MKL_RT_OMP_LIB_PATH} third_party/mkl/
281 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
282 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
283 loc=$(locate -e libdl.so.2 | sed -n 1p)
284 ln -sf $loc third_party/mkl/libdl.so.2
285 else
286 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 -0800287 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700288 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800289
290cat > third_party/mkl/mkl.config <<EOF
291# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
292# files can be either in this directory, or under include/ and lib64/
293MKL_INSTALL_PATH=$MKL_INSTALL_PATH
294EOF
295
Benoit Steineree112cf2017-05-10 21:12:21 -0700296fi # TF_NEED_MKL
297## End MKL setup
Benoit Steiner639b4e72017-02-08 09:25:09 -0800298
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800299## Set up architecture-dependent optimization flags.
300if [ -z "$CC_OPT_FLAGS" ]; then
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700301 if is_ppc64le; then
Shanqing Cai90d64212017-07-10 19:22:04 -0700302 # gcc on ppc64le does not support -march, use mcpu instead
303 default_cc_opt_flags="-mcpu=native"
304 else
305 default_cc_opt_flags="-march=native"
306 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800307 read -p "Please specify optimization flags to use during compilation when bazel option "\
308"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800309 if [ -z "$CC_OPT_FLAGS" ]; then
310 CC_OPT_FLAGS=$default_cc_opt_flags
311 fi
312fi
313
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800314if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800315 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800316 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800317 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800318 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800319 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800320fi
321
Jonathan Hseuc058a012017-01-17 15:06:43 -0800322if is_linux; then
323 while [ "$TF_NEED_JEMALLOC" == "" ]; do
324 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
325 INPUT
326 case $INPUT in
327 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
328 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
329 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
330 * ) echo "Invalid selection: " $INPUT;;
331 esac
332 done
333else
334 TF_NEED_JEMALLOC=0
335fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800336
Martin Wickebc456e32017-03-23 12:31:16 -0800337if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800338 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800339fi
340
Martin Wickebc456e32017-03-23 12:31:16 -0800341while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800342 read -p "Do you wish to build TensorFlow with "\
343"Google Cloud Platform support? [y/N] " INPUT
344 case $INPUT in
345 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
346"TensorFlow"; TF_NEED_GCP=1;;
347 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
348"TensorFlow"; TF_NEED_GCP=0;;
349 "" ) echo "No Google Cloud Platform support will be enabled for "\
350"TensorFlow"; TF_NEED_GCP=0;;
351 * ) echo "Invalid selection: " $INPUT;;
352 esac
353done
354
Martin Wickebc456e32017-03-23 12:31:16 -0800355if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800356 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800357fi
358
Martin Wickebc456e32017-03-23 12:31:16 -0800359while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800360 read -p "Do you wish to build TensorFlow with "\
361"Hadoop File System support? [y/N] " INPUT
362 case $INPUT in
363 [Yy]* ) echo "Hadoop File System support will be enabled for "\
364"TensorFlow"; TF_NEED_HDFS=1;;
365 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
366"TensorFlow"; TF_NEED_HDFS=0;;
367 "" ) echo "No Hadoop File System support will be enabled for "\
368"TensorFlow"; TF_NEED_HDFS=0;;
369 * ) echo "Invalid selection: " $INPUT;;
370 esac
371done
372
Martin Wickebc456e32017-03-23 12:31:16 -0800373if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800374 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800375fi
376
Peter Hawkins1e67c902017-01-09 12:04:37 -0800377## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800378while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800379 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
380 case $INPUT in
381 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
382 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
383 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
384 * ) echo "Invalid selection: " $INPUT;;
385 esac
386done
387
Martin Wickebc456e32017-03-23 12:31:16 -0800388if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800389 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800390fi
391
Shanqing Cai32694232017-04-22 06:08:17 -0800392# Verbs configuration
393while [ "$TF_NEED_VERBS" == "" ]; do
394 read -p "Do you wish to build TensorFlow with "\
395"VERBS support? [y/N] " INPUT
396 case $INPUT in
397 [Yy]* ) echo "VERBS support will be enabled for "\
398"TensorFlow"; TF_NEED_VERBS=1;;
399 [Nn]* ) echo "No VERBS support will be enabled for "\
400"TensorFlow"; TF_NEED_VERBS=0;;
401 "" ) echo "No VERBS support will be enabled for "\
402"TensorFlow"; TF_NEED_VERBS=0;;
403 * ) echo "Invalid selection: " $INPUT;;
404 esac
405done
406
407if [[ "$TF_NEED_VERBS" == "1" ]]; then
408 write_to_bazelrc 'build --define with_verbs_support=true'
409fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800410
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800411# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800412for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800413 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800414done
415
Andrew Selle09045e42016-09-06 08:19:04 -0800416# Run the gen_git_source to create links where bazel can track dependencies for
417# git hash propagation
418GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
419chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800420"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800421
Benoit Steinera7715982016-11-09 13:14:03 -0800422## Set up SYCL-related environment settings
423while [ "$TF_NEED_OPENCL" == "" ]; do
424 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
425 case $INPUT in
426 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
427 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
428 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
429 * ) echo "Invalid selection: " $INPUT;;
430 esac
431done
432
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800433## Set up Cuda-related environment settings
434
435while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800436 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800437 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800438 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
439 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
440 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800441 * ) echo "Invalid selection: " $INPUT;;
442 esac
443done
444
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800445export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800446write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800447
Rohan Jainaab09972017-01-05 14:39:17 -0800448export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800449write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800450
Benoit Steinera7715982016-11-09 13:14:03 -0800451if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800452while [[ "$TF_CUDA_CLANG" == "" ]]; do
453 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
454 case $INPUT in
455 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
456 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
457 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
458 * ) echo "Invalid selection: " $INPUT;;
459 esac
460done
461
462export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800463write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800464
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800465# Set up which clang we should use as the cuda / host compiler.
466while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
467 fromuser=""
468 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
469 default_clang_host_compiler_path=$(which clang || true)
470 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
471 fromuser="1"
472 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
473 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
474 fi
475 fi
476 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
477 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800478 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800479 break
480 fi
481 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
482 if [ -z "$fromuser" ]; then
483 exit 1
484 fi
485 CLANG_CUDA_COMPILER_PATH=""
486 # Retry
487done
488
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800489# Find out where the CUDA toolkit is installed
490while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800491 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800492 if [ -z "$TF_CUDA_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700493 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 -0800494 fi
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700495 # Set default CUDA version if not set
496 TF_CUDA_VERSION=${TF_CUDA_VERSION:-8.0}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800497
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800498 fromuser=""
499 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
500 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800501 if is_windows; then
502 if [ -z "$CUDA_PATH" ]; then
503 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
504 else
505 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
506 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800507 elif is_linux; then
508 # If the default doesn't exist, try an alternative default.
509 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
510 default_cuda_path=/opt/cuda
511 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800512 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800513 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 -0800514 fromuser="1"
515 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800516 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800517 fi
518 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800519
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800520 if [[ -z "$TF_CUDA_VERSION" ]]; then
521 TF_CUDA_EXT=""
522 else
523 TF_CUDA_EXT=".$TF_CUDA_VERSION"
524 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800525
Andrew Harp1cb96892016-12-08 20:05:49 -0800526 if is_windows; then
527 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800528 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800529 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800530 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800531 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
532 fi
533
534 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800535 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800536 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800537 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800538 break
539 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800540 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
541
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800542 if [ -z "$fromuser" ]; then
543 exit 1
544 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800545 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800546 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800547 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800548done
549
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700550export TF_CUDA_VERSION
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700551write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700552
Dan Ringwalt692fad22017-05-05 09:09:05 -0800553# Set up which gcc nvcc should use as the host compiler
554# No need to set this on Windows
555while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
556 fromuser=""
557 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
558 default_gcc_host_compiler_path=$(which gcc || true)
559 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
560 if [ -L "$cuda_bin_symlink" ]; then
561 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
562 fi
563 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
564 fromuser="1"
565 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
566 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
567 fi
568 fi
569 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
570 export GCC_HOST_COMPILER_PATH
571 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
572 break
573 fi
574 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
575 if [ -z "$fromuser" ]; then
576 exit 1
577 fi
578 GCC_HOST_COMPILER_PATH=""
579 # Retry
580done
581
Martin Wicke916776a2016-01-14 07:30:00 -0800582# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800583while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800584 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800585 if [ -z "$TF_CUDNN_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700586 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 -0800587 fi
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700588 # Set default CUDNN version if not set
589 TF_CUDNN_VERSION=${TF_CUDNN_VERSION:-6}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800590
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800591 fromuser=""
592 if [ -z "$CUDNN_INSTALL_PATH" ]; then
593 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800594 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 -0800595 fromuser="1"
596 if [ -z "$CUDNN_INSTALL_PATH" ]; then
597 CUDNN_INSTALL_PATH=$default_cudnn_path
598 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700599 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800600 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800601 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 -0700602 if is_windows; then
603 CUDNN_INSTALL_PATH="$(cygpath -m "$CUDNN_INSTALL_PATH")"
604 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800605 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800606
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800607 if [[ -z "$TF_CUDNN_VERSION" ]]; then
608 TF_CUDNN_EXT=""
609 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800610 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800611 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800612
Andrew Harp1cb96892016-12-08 20:05:49 -0800613 if is_windows; then
614 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
615 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800616 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800617 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
618 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800619 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800620 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
621 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800622 fi
623
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700624 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 -0800625 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800626 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800627 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800628 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800629 break
630 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800631
Jonathan Hseuc058a012017-01-17 15:06:43 -0800632 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800633 if ! type ldconfig > /dev/null 2>&1; then
634 LDCONFIG_BIN=/sbin/ldconfig
635 else
636 LDCONFIG_BIN=ldconfig
637 fi
638 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800639 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800640 export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700641 export CUDNN_INSTALL_PATH
642 CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800643 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800644 break
645 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800646 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800647 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
648 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
649 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800650 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800651 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
652 fi
653
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800654 if [ -z "$fromuser" ]; then
655 exit 1
656 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800657 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800658 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800659 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800660done
661
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700662export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700663write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
664
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800665# Configure the compute capabilities that TensorFlow builds for.
666# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700667function get_native_cuda_compute_capabilities {
668 device_query_bin="$CUDA_TOOLKIT_PATH/extras/demo_suite/deviceQuery" # Also works on Windows without .exe
669 "$device_query_bin" | grep 'Capability' | grep -o '[0-9]*\.[0-9]*' | sed ':a;{N;s/\n/,/};ba'
670 exit 0 # ensure that this function always exit success even if device detection fails, to prevent the whole configure from aborting
671}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800672while true; do
673 fromuser=""
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700674 native_cuda_compute_capabilities=$(get_native_cuda_compute_capabilities)
675 default_cuda_compute_capabilities=${native_cuda_compute_capabilities:-"3.5,5.2"}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800676 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800677cat << EOF
678Please specify a list of comma-separated Cuda compute capabilities you want to build with.
679You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
680Please note that each additional compute capability significantly increases your build time and binary size.
681EOF
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700682 read -p "[Default is: \"$default_cuda_compute_capabilities\"]: " TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800683 fromuser=1
684 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800685 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
686 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
687 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800688 # Check whether all capabilities from the input is valid
689 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
690 ALL_VALID=1
691 for CAPABILITY in $COMPUTE_CAPABILITIES; do
692 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
693 echo "Invalid compute capability: " $CAPABILITY
694 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800695 break
696 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800697 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800698 if [ "$ALL_VALID" == "0" ]; then
699 if [ -z "$fromuser" ]; then
700 exit 1
701 fi
702 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800703 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800704 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800705 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800706 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800707 TF_CUDA_COMPUTE_CAPABILITIES=""
708done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800709
Andrew Harp1cb96892016-12-08 20:05:49 -0800710if is_windows; then
711 # The following three variables are needed for MSVC toolchain configuration in Bazel
712 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
713 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
714 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800715 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
716 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
717 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Gunhan Gulsoy3cf88d32017-06-06 22:34:30 -0700718 write_to_bazelrc "build --config=win-cuda"
719 write_to_bazelrc "test --config=win-cuda"
720else
721 # If CUDA is enabled, always use GPU during build and test.
A. Unique TensorFlower64857412017-06-28 11:47:37 -0700722 if [ "$TF_CUDA_CLANG" == "1" ]; then
723 write_to_bazelrc "build --config=cuda_clang"
724 write_to_bazelrc "test --config=cuda_clang"
725 else
726 write_to_bazelrc "build --config=cuda"
727 write_to_bazelrc "test --config=cuda"
728 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800729fi
730
Benoit Steinera7715982016-11-09 13:14:03 -0800731# end of if "$TF_NEED_CUDA" == "1"
732fi
733
734# OpenCL configuration
735
736if [ "$TF_NEED_OPENCL" == "1" ]; then
737
738# Determine which C++ compiler should be used as the host compiler
739while true; do
740 fromuser=""
741 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700742 default_cxx_host_compiler=$(which g++ || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800743 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
744 fromuser="1"
745 if [ -z "$HOST_CXX_COMPILER" ]; then
746 HOST_CXX_COMPILER=$default_cxx_host_compiler
747 fi
748 fi
749 if [ -e "$HOST_CXX_COMPILER" ]; then
750 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800751 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800752 break
753 fi
754 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
755 if [ -z "$fromuser" ]; then
756 exit 1
757 fi
758 HOST_CXX_COMPILER=""
759 # Retry
760done
761
762# Determine which C compiler should be used as the host compiler
763while true; do
764 fromuser=""
765 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700766 default_c_host_compiler=$(which gcc || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800767 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
768 fromuser="1"
769 if [ -z "$HOST_C_COMPILER" ]; then
770 HOST_C_COMPILER=$default_c_host_compiler
771 fi
772 fi
773 if [ -e "$HOST_C_COMPILER" ]; then
774 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800775 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800776 break
777 fi
778 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
779 if [ -z "$fromuser" ]; then
780 exit 1
781 fi
782 HOST_C_COMPILER=""
783 # Retry
784done
785
786while true; do
787 # Configure the OPENCL version to use.
788 TF_OPENCL_VERSION="1.2"
789
790 # Point to ComputeCpp root
791 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
792 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800793 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 -0800794 fromuser="1"
795 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
796 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
797 fi
798 fi
799
Jonathan Hseuc058a012017-01-17 15:06:43 -0800800 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800801 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
802 fi
803
804 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
805 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800806 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800807 break
808 fi
809 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
810
811 if [ -z "$fromuser" ]; then
812 exit 1
813 fi
814 # Retry
815 TF_OPENCL_VERSION=""
816 COMPUTECPP_TOOLKIT_PATH=""
817done
818
Benoit Steinera7715982016-11-09 13:14:03 -0800819# end of if "$TF_NEED_OPENCL" == "1"
820fi
821
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700822
823while [ "$TF_NEED_MPI" == "" ]; do
824 read -p "Do you wish to build TensorFlow with "\
825"MPI support? [y/N] " INPUT
826 case $INPUT in
827 [Yy]* ) echo "MPI support will be enabled for "\
828"TensorFlow"; TF_NEED_MPI=1;;
829 [Nn]* ) echo "MPI support will not be enabled for "\
830"TensorFlow"; TF_NEED_MPI=0;;
831 "" ) echo "MPI support will not be enabled for "\
832"TensorFlow"; TF_NEED_MPI=0;;
833 * ) echo "Invalid selection: " $INPUT;;
834 esac
835done
836
837# Find out where the MPI toolkit is installed
838while true; do
839 if [ "$TF_NEED_MPI" == "0" ]; then
840 break;
841 fi
842
843 fromuser=""
844 if [ -z "$MPI_HOME" ]; then
845 #Get the base folder by removing the bin path
846 default_mpi_path=$(dirname $(dirname $(which mpirun)) || dirname $(dirname $(which mpiexec)) || true)
847 read -p "Please specify the MPI toolkit folder. [Default is $default_mpi_path]: " MPI_HOME
848 fromuser="1"
849 if [ -z "$MPI_HOME" ]; then
850 MPI_HOME=$default_mpi_path
851 fi
852 fi
853
854 #Check that the include and library folders are where we expect them to be
855 if [ -e "$MPI_HOME/include" ] && [ -e "$MPI_HOME/lib" ]; then
856 break
857 fi
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700858
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700859 echo "Invalid path to the MPI Toolkit. ${MPI_HOME}/include or ${MPI_HOME}/lib cannot be found."
860 if [ -z "$fromuser" ]; then
861 exit 1
862 fi
863
864 # Retry
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700865 MPI_HOME=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700866done
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700867
868
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700869if [ "$TF_NEED_MPI" == "1" ]; then
870 write_to_bazelrc 'build --define with_mpi_support=true'
871
872 #Link the MPI header files
873 ln -sf "${MPI_HOME}/include/mpi.h" third_party/mpi/mpi.h
874
875
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700876 #Determine if we use OpenMPI or MVAPICH, these require different header files
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700877 #to be included here to make bazel dependency checker happy
878
879 if [ -e "${MPI_HOME}/include/mpi_portable_platform.h" ]; then
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700880 #OpenMPI
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700881 ln -sf "${MPI_HOME}/include/mpi_portable_platform.h" third_party/mpi/
882 sed -i -e "s/MPI_LIB_IS_OPENMPI=False/MPI_LIB_IS_OPENMPI=True/" third_party/mpi/mpi.bzl
883 else
884 #MVAPICH / MPICH
885 ln -sf "${MPI_HOME}/include/mpio.h" third_party/mpi/
886 ln -sf "${MPI_HOME}/include/mpicxx.h" third_party/mpi/
887 sed -i -e "s/MPI_LIB_IS_OPENMPI=True/MPI_LIB_IS_OPENMPI=False/" third_party/mpi/mpi.bzl
888 fi
889
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700890
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700891 if [ -e "${MPI_HOME}/lib/libmpi.so" ]; then
892 ln -sf "${MPI_HOME}/lib/libmpi.so" third_party/mpi/
893 else
894 echo "Cannot find the MPI library file in ${MPI_HOME}/lib "
895 exit 1
896 fi
897fi
898
899
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800900echo "Configuration finished"