blob: 288674753b68987de1221873ad97733e7c061108 [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 TensorFlower0264e102017-07-20 15:52:20 -0700166set +e
A. Unique TensorFlower9f4ec7e2017-07-20 13:34:06 -0700167curr_bazel_version=$(grep -m 1 'Build label:' bazel.version | cut -d ' ' -f3)
A. Unique TensorFlower0264e102017-07-20 15:52:20 -0700168set -e
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700169rm -f bazel.version
170
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700171
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700172echo "You have bazel $curr_bazel_version installed."
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700173if [ -z "$curr_bazel_version" ]; then
174 echo "WARNING: current bazel installation is not a release version."
175 echo "Make sure you are running at least bazel $MIN_BAZEL_VERSION."
176elif [ "$(version "$MIN_BAZEL_VERSION")" -gt "$(version "$curr_bazel_version")" ]; then
A. Unique TensorFlowerabe08772017-06-07 11:34:47 -0700177 echo "Please upgrade your bazel installation to version $MIN_BAZEL_VERSION or higher to build TensorFlow!"
178 echo "Exiting..."
179 exit 1
180fi
181
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800182# This file contains customized config settings.
183rm -f .tf_configure.bazelrc
184touch .tf_configure.bazelrc
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700185if [[ ! -e .bazelrc ]]; then
186 if [[ -e "${HOME}/.bazelrc" ]]; then
187 echo "import ${HOME}/.bazelrc" >.bazelrc
188 else
189 touch .bazelrc
190 fi
191fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800192sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800193echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800194
Andrew Harp51dbc462017-01-27 14:42:30 -0800195# Delete any leftover BUILD files from the Makefile build, which would interfere
196# with Bazel parsing.
197MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
198if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
199 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
200fi
201
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800202setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800203
Benoit Steiner639b4e72017-02-08 09:25:09 -0800204## Set up MKL related environment settings
Benoit Steineree112cf2017-05-10 21:12:21 -0700205while [ "$TF_NEED_MKL" == "" ]; do
206 fromuser=""
207 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
208 fromuser="1"
209 case $INPUT in
210 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
211 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
212 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
213 * ) echo "Invalid selection: " $INPUT;;
214 esac
215done
216
217OSNAME=`uname -s`
218
219if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
220 while [ "$TF_DOWNLOAD_MKL" == "" ]; do
Benoit Steiner639b4e72017-02-08 09:25:09 -0800221 fromuser=""
Benoit Steineree112cf2017-05-10 21:12:21 -0700222 read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800223 fromuser="1"
224 case $INPUT in
Benoit Steineree112cf2017-05-10 21:12:21 -0700225 [Yy]* ) TF_DOWNLOAD_MKL=1;;
226 [Nn]* ) TF_DOWNLOAD_MKL=0;;
227 "" ) TF_DOWNLOAD_MKL=1;;
228 * ) echo "Invalid selection: " $INPUT; exit 1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800229 esac
230 done
231
Benoit Steineree112cf2017-05-10 21:12:21 -0700232 if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800233 DST=`dirname $0`
Benoit Steineree112cf2017-05-10 21:12:21 -0700234 ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
235 GITHUB_RELEASE_TAG=v0.7
Benoit Steiner639b4e72017-02-08 09:25:09 -0800236 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
Benoit Steineree112cf2017-05-10 21:12:21 -0700237 if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
238 curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800239 fi
240 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
241 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
242 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
243 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
244
Benoit Steineree112cf2017-05-10 21:12:21 -0700245 else
246 default_mkl_path=/opt/intel/mklml
247 fromuser=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700248 if [ -z "$MKL_INSTALL_PATH" ]; then
249 read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
250 fromuser="1"
251 fi
Benoit Steineree112cf2017-05-10 21:12:21 -0700252 if [ -z "$MKL_INSTALL_PATH" ]; then
253 MKL_INSTALL_PATH=$default_mkl_path
254 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700255 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Benoit Steineree112cf2017-05-10 21:12:21 -0700256 # Going through one more level of expansion to handle that.
257 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
258 fi
259
260 if [ "$OSNAME" == "Linux" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800261 # Full MKL configuration
262 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
263 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
264
265 # MKL-ML configuration
266 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
267 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
Benoit Steineree112cf2017-05-10 21:12:21 -0700268 elif [ "$OSNAME" == "Darwin" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800269 echo "Darwin is unsupported yet";
270 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700271 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800272
Benoit Steineree112cf2017-05-10 21:12:21 -0700273 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800274 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
275 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
276 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
277 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
Benoit Steineree112cf2017-05-10 21:12:21 -0700278 loc=$(locate -e libdl.so.2 | sed -n 1p)
279 ln -sf $loc third_party/mkl/libdl.so.2
280 elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then
281 ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/
282 ln -sf $MKL_INSTALL_PATH/${MKL_RT_OMP_LIB_PATH} third_party/mkl/
283 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
284 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
285 loc=$(locate -e libdl.so.2 | sed -n 1p)
286 ln -sf $loc third_party/mkl/libdl.so.2
287 else
288 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 -0800289 exit 1
Benoit Steineree112cf2017-05-10 21:12:21 -0700290 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800291
292cat > third_party/mkl/mkl.config <<EOF
293# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
294# files can be either in this directory, or under include/ and lib64/
295MKL_INSTALL_PATH=$MKL_INSTALL_PATH
296EOF
297
Benoit Steineree112cf2017-05-10 21:12:21 -0700298fi # TF_NEED_MKL
299## End MKL setup
Benoit Steiner639b4e72017-02-08 09:25:09 -0800300
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800301## Set up architecture-dependent optimization flags.
302if [ -z "$CC_OPT_FLAGS" ]; then
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700303 if is_ppc64le; then
Shanqing Cai90d64212017-07-10 19:22:04 -0700304 # gcc on ppc64le does not support -march, use mcpu instead
305 default_cc_opt_flags="-mcpu=native"
306 else
307 default_cc_opt_flags="-march=native"
308 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800309 read -p "Please specify optimization flags to use during compilation when bazel option "\
310"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800311 if [ -z "$CC_OPT_FLAGS" ]; then
312 CC_OPT_FLAGS=$default_cc_opt_flags
313 fi
314fi
315
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800316if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800317 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800318 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800319 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800320 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800321 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800322fi
323
Jonathan Hseuc058a012017-01-17 15:06:43 -0800324if is_linux; then
325 while [ "$TF_NEED_JEMALLOC" == "" ]; do
326 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
327 INPUT
328 case $INPUT in
329 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
330 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
331 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
332 * ) echo "Invalid selection: " $INPUT;;
333 esac
334 done
335else
336 TF_NEED_JEMALLOC=0
337fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800338
Martin Wickebc456e32017-03-23 12:31:16 -0800339if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800340 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800341fi
342
Martin Wickebc456e32017-03-23 12:31:16 -0800343while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800344 read -p "Do you wish to build TensorFlow with "\
345"Google Cloud Platform support? [y/N] " INPUT
346 case $INPUT in
347 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
348"TensorFlow"; TF_NEED_GCP=1;;
349 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
350"TensorFlow"; TF_NEED_GCP=0;;
351 "" ) echo "No Google Cloud Platform support will be enabled for "\
352"TensorFlow"; TF_NEED_GCP=0;;
353 * ) echo "Invalid selection: " $INPUT;;
354 esac
355done
356
Martin Wickebc456e32017-03-23 12:31:16 -0800357if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800358 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800359fi
360
Martin Wickebc456e32017-03-23 12:31:16 -0800361while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800362 read -p "Do you wish to build TensorFlow with "\
363"Hadoop File System support? [y/N] " INPUT
364 case $INPUT in
365 [Yy]* ) echo "Hadoop File System support will be enabled for "\
366"TensorFlow"; TF_NEED_HDFS=1;;
367 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
368"TensorFlow"; TF_NEED_HDFS=0;;
369 "" ) echo "No Hadoop File System support will be enabled for "\
370"TensorFlow"; TF_NEED_HDFS=0;;
371 * ) echo "Invalid selection: " $INPUT;;
372 esac
373done
374
Martin Wickebc456e32017-03-23 12:31:16 -0800375if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800376 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800377fi
378
Peter Hawkins1e67c902017-01-09 12:04:37 -0800379## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800380while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800381 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
382 case $INPUT in
383 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
384 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
385 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
386 * ) echo "Invalid selection: " $INPUT;;
387 esac
388done
389
Martin Wickebc456e32017-03-23 12:31:16 -0800390if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800391 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800392fi
393
Shanqing Cai32694232017-04-22 06:08:17 -0800394# Verbs configuration
395while [ "$TF_NEED_VERBS" == "" ]; do
396 read -p "Do you wish to build TensorFlow with "\
397"VERBS support? [y/N] " INPUT
398 case $INPUT in
399 [Yy]* ) echo "VERBS support will be enabled for "\
400"TensorFlow"; TF_NEED_VERBS=1;;
401 [Nn]* ) echo "No VERBS support will be enabled for "\
402"TensorFlow"; TF_NEED_VERBS=0;;
403 "" ) echo "No VERBS support will be enabled for "\
404"TensorFlow"; TF_NEED_VERBS=0;;
405 * ) echo "Invalid selection: " $INPUT;;
406 esac
407done
408
409if [[ "$TF_NEED_VERBS" == "1" ]]; then
410 write_to_bazelrc 'build --define with_verbs_support=true'
411fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800412
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800413# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800414for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800415 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800416done
417
Andrew Selle09045e42016-09-06 08:19:04 -0800418# Run the gen_git_source to create links where bazel can track dependencies for
419# git hash propagation
420GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
421chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800422"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800423
Benoit Steinera7715982016-11-09 13:14:03 -0800424## Set up SYCL-related environment settings
425while [ "$TF_NEED_OPENCL" == "" ]; do
426 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
427 case $INPUT in
428 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
429 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
430 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
431 * ) echo "Invalid selection: " $INPUT;;
432 esac
433done
434
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800435## Set up Cuda-related environment settings
436
437while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800438 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800439 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800440 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
441 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
442 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800443 * ) echo "Invalid selection: " $INPUT;;
444 esac
445done
446
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800447export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800448write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800449
Rohan Jainaab09972017-01-05 14:39:17 -0800450export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800451write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800452
Benoit Steinera7715982016-11-09 13:14:03 -0800453if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800454while [[ "$TF_CUDA_CLANG" == "" ]]; do
455 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
456 case $INPUT in
457 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
458 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
459 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
460 * ) echo "Invalid selection: " $INPUT;;
461 esac
462done
463
464export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800465write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800466
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800467# Set up which clang we should use as the cuda / host compiler.
468while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
469 fromuser=""
470 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
471 default_clang_host_compiler_path=$(which clang || true)
472 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
473 fromuser="1"
474 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
475 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
476 fi
477 fi
478 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
479 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800480 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800481 break
482 fi
483 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
484 if [ -z "$fromuser" ]; then
485 exit 1
486 fi
487 CLANG_CUDA_COMPILER_PATH=""
488 # Retry
489done
490
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800491# Find out where the CUDA toolkit is installed
492while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800493 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800494 if [ -z "$TF_CUDA_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700495 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 -0800496 fi
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700497 # Set default CUDA version if not set
498 TF_CUDA_VERSION=${TF_CUDA_VERSION:-8.0}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800499
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800500 fromuser=""
501 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
502 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800503 if is_windows; then
504 if [ -z "$CUDA_PATH" ]; then
505 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
506 else
507 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
508 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800509 elif is_linux; then
510 # If the default doesn't exist, try an alternative default.
511 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
512 default_cuda_path=/opt/cuda
513 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800514 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800515 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 -0800516 fromuser="1"
517 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800518 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800519 fi
520 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800521
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800522 if [[ -z "$TF_CUDA_VERSION" ]]; then
523 TF_CUDA_EXT=""
524 else
525 TF_CUDA_EXT=".$TF_CUDA_VERSION"
526 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800527
Andrew Harp1cb96892016-12-08 20:05:49 -0800528 if is_windows; then
529 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800530 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800531 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800532 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800533 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
534 fi
535
536 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800537 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800538 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800539 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800540 break
541 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800542 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
543
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800544 if [ -z "$fromuser" ]; then
545 exit 1
546 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800547 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800548 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800549 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800550done
551
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700552export TF_CUDA_VERSION
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700553write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700554
Dan Ringwalt692fad22017-05-05 09:09:05 -0800555# Set up which gcc nvcc should use as the host compiler
556# No need to set this on Windows
557while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
558 fromuser=""
559 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
560 default_gcc_host_compiler_path=$(which gcc || true)
561 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
562 if [ -L "$cuda_bin_symlink" ]; then
563 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
564 fi
565 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
566 fromuser="1"
567 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
568 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
569 fi
570 fi
571 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
572 export GCC_HOST_COMPILER_PATH
573 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
574 break
575 fi
576 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
577 if [ -z "$fromuser" ]; then
578 exit 1
579 fi
580 GCC_HOST_COMPILER_PATH=""
581 # Retry
582done
583
Martin Wicke916776a2016-01-14 07:30:00 -0800584# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800585while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800586 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800587 if [ -z "$TF_CUDNN_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700588 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 -0800589 fi
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700590 # Set default CUDNN version if not set
591 TF_CUDNN_VERSION=${TF_CUDNN_VERSION:-6}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800592
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800593 fromuser=""
594 if [ -z "$CUDNN_INSTALL_PATH" ]; then
595 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800596 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 -0800597 fromuser="1"
598 if [ -z "$CUDNN_INSTALL_PATH" ]; then
599 CUDNN_INSTALL_PATH=$default_cudnn_path
600 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700601 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800602 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800603 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 -0700604 if is_windows; then
605 CUDNN_INSTALL_PATH="$(cygpath -m "$CUDNN_INSTALL_PATH")"
606 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800607 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800608
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800609 if [[ -z "$TF_CUDNN_VERSION" ]]; then
610 TF_CUDNN_EXT=""
611 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800612 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800613 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800614
Andrew Harp1cb96892016-12-08 20:05:49 -0800615 if is_windows; then
616 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
617 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800618 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800619 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
620 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800621 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800622 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
623 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800624 fi
625
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700626 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 -0800627 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800628 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800629 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800630 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800631 break
632 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800633
Jonathan Hseuc058a012017-01-17 15:06:43 -0800634 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800635 if ! type ldconfig > /dev/null 2>&1; then
636 LDCONFIG_BIN=/sbin/ldconfig
637 else
638 LDCONFIG_BIN=ldconfig
639 fi
640 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800641 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800642 export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700643 export CUDNN_INSTALL_PATH
644 CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800645 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800646 break
647 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800648 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800649 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
650 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
651 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800652 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800653 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
654 fi
655
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800656 if [ -z "$fromuser" ]; then
657 exit 1
658 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800659 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800660 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800661 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800662done
663
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700664export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700665write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
666
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800667# Configure the compute capabilities that TensorFlow builds for.
668# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700669function get_native_cuda_compute_capabilities {
670 device_query_bin="$CUDA_TOOLKIT_PATH/extras/demo_suite/deviceQuery" # Also works on Windows without .exe
671 "$device_query_bin" | grep 'Capability' | grep -o '[0-9]*\.[0-9]*' | sed ':a;{N;s/\n/,/};ba'
672 exit 0 # ensure that this function always exit success even if device detection fails, to prevent the whole configure from aborting
673}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800674while true; do
675 fromuser=""
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700676 native_cuda_compute_capabilities=$(get_native_cuda_compute_capabilities)
677 default_cuda_compute_capabilities=${native_cuda_compute_capabilities:-"3.5,5.2"}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800678 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800679cat << EOF
680Please specify a list of comma-separated Cuda compute capabilities you want to build with.
681You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
682Please note that each additional compute capability significantly increases your build time and binary size.
683EOF
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700684 read -p "[Default is: \"$default_cuda_compute_capabilities\"]: " TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800685 fromuser=1
686 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800687 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
688 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
689 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800690 # Check whether all capabilities from the input is valid
691 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
692 ALL_VALID=1
693 for CAPABILITY in $COMPUTE_CAPABILITIES; do
694 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
695 echo "Invalid compute capability: " $CAPABILITY
696 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800697 break
698 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800699 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800700 if [ "$ALL_VALID" == "0" ]; then
701 if [ -z "$fromuser" ]; then
702 exit 1
703 fi
704 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800705 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800706 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800707 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800708 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800709 TF_CUDA_COMPUTE_CAPABILITIES=""
710done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800711
Andrew Harp1cb96892016-12-08 20:05:49 -0800712if is_windows; then
713 # The following three variables are needed for MSVC toolchain configuration in Bazel
714 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
715 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
716 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800717 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
718 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
719 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Gunhan Gulsoy3cf88d32017-06-06 22:34:30 -0700720 write_to_bazelrc "build --config=win-cuda"
721 write_to_bazelrc "test --config=win-cuda"
722else
723 # If CUDA is enabled, always use GPU during build and test.
A. Unique TensorFlower64857412017-06-28 11:47:37 -0700724 if [ "$TF_CUDA_CLANG" == "1" ]; then
725 write_to_bazelrc "build --config=cuda_clang"
726 write_to_bazelrc "test --config=cuda_clang"
727 else
728 write_to_bazelrc "build --config=cuda"
729 write_to_bazelrc "test --config=cuda"
730 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800731fi
732
Benoit Steinera7715982016-11-09 13:14:03 -0800733# end of if "$TF_NEED_CUDA" == "1"
734fi
735
736# OpenCL configuration
737
738if [ "$TF_NEED_OPENCL" == "1" ]; then
739
740# Determine which C++ compiler should be used as the host compiler
741while true; do
742 fromuser=""
743 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700744 default_cxx_host_compiler=$(which g++ || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800745 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
746 fromuser="1"
747 if [ -z "$HOST_CXX_COMPILER" ]; then
748 HOST_CXX_COMPILER=$default_cxx_host_compiler
749 fi
750 fi
751 if [ -e "$HOST_CXX_COMPILER" ]; then
752 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800753 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800754 break
755 fi
756 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
757 if [ -z "$fromuser" ]; then
758 exit 1
759 fi
760 HOST_CXX_COMPILER=""
761 # Retry
762done
763
764# Determine which C compiler should be used as the host compiler
765while true; do
766 fromuser=""
767 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700768 default_c_host_compiler=$(which gcc || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800769 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
770 fromuser="1"
771 if [ -z "$HOST_C_COMPILER" ]; then
772 HOST_C_COMPILER=$default_c_host_compiler
773 fi
774 fi
775 if [ -e "$HOST_C_COMPILER" ]; then
776 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800777 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800778 break
779 fi
780 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
781 if [ -z "$fromuser" ]; then
782 exit 1
783 fi
784 HOST_C_COMPILER=""
785 # Retry
786done
787
788while true; do
789 # Configure the OPENCL version to use.
790 TF_OPENCL_VERSION="1.2"
791
792 # Point to ComputeCpp root
793 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
794 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800795 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 -0800796 fromuser="1"
797 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
798 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
799 fi
800 fi
801
Jonathan Hseuc058a012017-01-17 15:06:43 -0800802 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800803 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
804 fi
805
806 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
807 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800808 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800809 break
810 fi
811 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
812
813 if [ -z "$fromuser" ]; then
814 exit 1
815 fi
816 # Retry
817 TF_OPENCL_VERSION=""
818 COMPUTECPP_TOOLKIT_PATH=""
819done
820
Benoit Steinera7715982016-11-09 13:14:03 -0800821# end of if "$TF_NEED_OPENCL" == "1"
822fi
823
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700824
825while [ "$TF_NEED_MPI" == "" ]; do
826 read -p "Do you wish to build TensorFlow with "\
827"MPI support? [y/N] " INPUT
828 case $INPUT in
829 [Yy]* ) echo "MPI support will be enabled for "\
830"TensorFlow"; TF_NEED_MPI=1;;
831 [Nn]* ) echo "MPI support will not be enabled for "\
832"TensorFlow"; TF_NEED_MPI=0;;
833 "" ) echo "MPI support will not be enabled for "\
834"TensorFlow"; TF_NEED_MPI=0;;
835 * ) echo "Invalid selection: " $INPUT;;
836 esac
837done
838
839# Find out where the MPI toolkit is installed
840while true; do
841 if [ "$TF_NEED_MPI" == "0" ]; then
842 break;
843 fi
844
845 fromuser=""
846 if [ -z "$MPI_HOME" ]; then
847 #Get the base folder by removing the bin path
848 default_mpi_path=$(dirname $(dirname $(which mpirun)) || dirname $(dirname $(which mpiexec)) || true)
849 read -p "Please specify the MPI toolkit folder. [Default is $default_mpi_path]: " MPI_HOME
850 fromuser="1"
851 if [ -z "$MPI_HOME" ]; then
852 MPI_HOME=$default_mpi_path
853 fi
854 fi
855
856 #Check that the include and library folders are where we expect them to be
857 if [ -e "$MPI_HOME/include" ] && [ -e "$MPI_HOME/lib" ]; then
858 break
859 fi
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700860
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700861 echo "Invalid path to the MPI Toolkit. ${MPI_HOME}/include or ${MPI_HOME}/lib cannot be found."
862 if [ -z "$fromuser" ]; then
863 exit 1
864 fi
865
866 # Retry
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700867 MPI_HOME=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700868done
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700869
870
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700871if [ "$TF_NEED_MPI" == "1" ]; then
872 write_to_bazelrc 'build --define with_mpi_support=true'
873
874 #Link the MPI header files
875 ln -sf "${MPI_HOME}/include/mpi.h" third_party/mpi/mpi.h
876
877
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700878 #Determine if we use OpenMPI or MVAPICH, these require different header files
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700879 #to be included here to make bazel dependency checker happy
880
881 if [ -e "${MPI_HOME}/include/mpi_portable_platform.h" ]; then
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700882 #OpenMPI
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700883 ln -sf "${MPI_HOME}/include/mpi_portable_platform.h" third_party/mpi/
884 sed -i -e "s/MPI_LIB_IS_OPENMPI=False/MPI_LIB_IS_OPENMPI=True/" third_party/mpi/mpi.bzl
885 else
886 #MVAPICH / MPICH
887 ln -sf "${MPI_HOME}/include/mpio.h" third_party/mpi/
888 ln -sf "${MPI_HOME}/include/mpicxx.h" third_party/mpi/
889 sed -i -e "s/MPI_LIB_IS_OPENMPI=True/MPI_LIB_IS_OPENMPI=False/" third_party/mpi/mpi.bzl
890 fi
891
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700892
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700893 if [ -e "${MPI_HOME}/lib/libmpi.so" ]; then
894 ln -sf "${MPI_HOME}/lib/libmpi.so" third_party/mpi/
895 else
896 echo "Cannot find the MPI library file in ${MPI_HOME}/lib "
897 exit 1
898 fi
899fi
900
901
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800902echo "Configuration finished"