blob: 1eeaffaf74ca7538c21911e8109beff8838ed45e [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
Gunhan Gulsoy54428252017-07-21 14:41:54 -0700205write_to_bazelrc 'build:mkl --define with_mkl_support=true'
206write_to_bazelrc 'build:mkl --define using_mkl=true'
207write_to_bazelrc 'build:mkl -c opt'
208write_to_bazelrc 'build:mkl --copt="-DEIGEN_USE_VML"'
209echo ""
210echo "Add \"--config=mkl\" to your bazel command to build with MKL support."
211echo "Please note that MKL on MacOS or windows is still not supported."
212echo "If you would like to use a local MKL instead of downloading, please "
213echo " set the environment variable \"TF_MKL_ROOT\" every time before build."
214echo ""
Benoit Steineree112cf2017-05-10 21:12:21 -0700215## End MKL setup
Benoit Steiner639b4e72017-02-08 09:25:09 -0800216
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800217## Set up architecture-dependent optimization flags.
218if [ -z "$CC_OPT_FLAGS" ]; then
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700219 if is_ppc64le; then
Shanqing Cai90d64212017-07-10 19:22:04 -0700220 # gcc on ppc64le does not support -march, use mcpu instead
221 default_cc_opt_flags="-mcpu=native"
222 else
223 default_cc_opt_flags="-march=native"
224 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -0800225 read -p "Please specify optimization flags to use during compilation when bazel option "\
226"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800227 if [ -z "$CC_OPT_FLAGS" ]; then
228 CC_OPT_FLAGS=$default_cc_opt_flags
229 fi
230fi
231
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800232if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800233 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800234 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800235 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800236 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800237 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800238fi
239
Jonathan Hseuc058a012017-01-17 15:06:43 -0800240if is_linux; then
241 while [ "$TF_NEED_JEMALLOC" == "" ]; do
242 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
243 INPUT
244 case $INPUT in
245 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
246 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
247 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
248 * ) echo "Invalid selection: " $INPUT;;
249 esac
250 done
251else
252 TF_NEED_JEMALLOC=0
253fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800254
Martin Wickebc456e32017-03-23 12:31:16 -0800255if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800256 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800257fi
258
Martin Wickebc456e32017-03-23 12:31:16 -0800259while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800260 read -p "Do you wish to build TensorFlow with "\
261"Google Cloud Platform support? [y/N] " INPUT
262 case $INPUT in
263 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
264"TensorFlow"; TF_NEED_GCP=1;;
265 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
266"TensorFlow"; TF_NEED_GCP=0;;
267 "" ) echo "No Google Cloud Platform support will be enabled for "\
268"TensorFlow"; TF_NEED_GCP=0;;
269 * ) echo "Invalid selection: " $INPUT;;
270 esac
271done
272
Martin Wickebc456e32017-03-23 12:31:16 -0800273if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800274 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800275fi
276
Martin Wickebc456e32017-03-23 12:31:16 -0800277while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800278 read -p "Do you wish to build TensorFlow with "\
279"Hadoop File System support? [y/N] " INPUT
280 case $INPUT in
281 [Yy]* ) echo "Hadoop File System support will be enabled for "\
282"TensorFlow"; TF_NEED_HDFS=1;;
283 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
284"TensorFlow"; TF_NEED_HDFS=0;;
285 "" ) echo "No Hadoop File System support will be enabled for "\
286"TensorFlow"; TF_NEED_HDFS=0;;
287 * ) echo "Invalid selection: " $INPUT;;
288 esac
289done
290
Martin Wickebc456e32017-03-23 12:31:16 -0800291if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800292 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800293fi
294
Peter Hawkins1e67c902017-01-09 12:04:37 -0800295## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800296while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800297 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
298 case $INPUT in
299 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
300 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
301 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
302 * ) echo "Invalid selection: " $INPUT;;
303 esac
304done
305
Martin Wickebc456e32017-03-23 12:31:16 -0800306if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800307 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800308fi
309
Shanqing Cai32694232017-04-22 06:08:17 -0800310# Verbs configuration
311while [ "$TF_NEED_VERBS" == "" ]; do
312 read -p "Do you wish to build TensorFlow with "\
313"VERBS support? [y/N] " INPUT
314 case $INPUT in
315 [Yy]* ) echo "VERBS support will be enabled for "\
316"TensorFlow"; TF_NEED_VERBS=1;;
317 [Nn]* ) echo "No VERBS support will be enabled for "\
318"TensorFlow"; TF_NEED_VERBS=0;;
319 "" ) echo "No VERBS support will be enabled for "\
320"TensorFlow"; TF_NEED_VERBS=0;;
321 * ) echo "Invalid selection: " $INPUT;;
322 esac
323done
324
325if [[ "$TF_NEED_VERBS" == "1" ]]; then
326 write_to_bazelrc 'build --define with_verbs_support=true'
327fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800328
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800329# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800330for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800331 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800332done
333
Andrew Selle09045e42016-09-06 08:19:04 -0800334# Run the gen_git_source to create links where bazel can track dependencies for
335# git hash propagation
336GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
337chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800338"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800339
Benoit Steinera7715982016-11-09 13:14:03 -0800340## Set up SYCL-related environment settings
341while [ "$TF_NEED_OPENCL" == "" ]; do
342 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
343 case $INPUT in
344 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
345 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
346 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
347 * ) echo "Invalid selection: " $INPUT;;
348 esac
349done
350
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800351## Set up Cuda-related environment settings
352
353while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800354 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800355 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800356 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
357 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
358 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800359 * ) echo "Invalid selection: " $INPUT;;
360 esac
361done
362
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800363export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800364write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800365
Rohan Jainaab09972017-01-05 14:39:17 -0800366export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800367write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800368
Benoit Steinera7715982016-11-09 13:14:03 -0800369if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800370while [[ "$TF_CUDA_CLANG" == "" ]]; do
371 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
372 case $INPUT in
373 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
374 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
375 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
376 * ) echo "Invalid selection: " $INPUT;;
377 esac
378done
379
380export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800381write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800382
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800383# Set up which clang we should use as the cuda / host compiler.
384while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
385 fromuser=""
386 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
387 default_clang_host_compiler_path=$(which clang || true)
388 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
389 fromuser="1"
390 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
391 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
392 fi
393 fi
394 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
395 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800396 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800397 break
398 fi
399 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
400 if [ -z "$fromuser" ]; then
401 exit 1
402 fi
403 CLANG_CUDA_COMPILER_PATH=""
404 # Retry
405done
406
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800407# Find out where the CUDA toolkit is installed
408while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800409 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800410 if [ -z "$TF_CUDA_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700411 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 -0800412 fi
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700413 # Set default CUDA version if not set
414 TF_CUDA_VERSION=${TF_CUDA_VERSION:-8.0}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800415
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800416 fromuser=""
417 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
418 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800419 if is_windows; then
420 if [ -z "$CUDA_PATH" ]; then
421 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
422 else
423 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
424 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800425 elif is_linux; then
426 # If the default doesn't exist, try an alternative default.
427 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
428 default_cuda_path=/opt/cuda
429 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800430 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800431 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 -0800432 fromuser="1"
433 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800434 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800435 fi
436 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800437
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800438 if [[ -z "$TF_CUDA_VERSION" ]]; then
439 TF_CUDA_EXT=""
440 else
441 TF_CUDA_EXT=".$TF_CUDA_VERSION"
442 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800443
Andrew Harp1cb96892016-12-08 20:05:49 -0800444 if is_windows; then
445 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800446 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800447 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800448 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800449 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
450 fi
451
452 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800453 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800454 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800455 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800456 break
457 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800458 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
459
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800460 if [ -z "$fromuser" ]; then
461 exit 1
462 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800463 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800464 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800465 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800466done
467
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700468export TF_CUDA_VERSION
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700469write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700470
Dan Ringwalt692fad22017-05-05 09:09:05 -0800471# Set up which gcc nvcc should use as the host compiler
472# No need to set this on Windows
473while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
474 fromuser=""
475 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
476 default_gcc_host_compiler_path=$(which gcc || true)
477 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
478 if [ -L "$cuda_bin_symlink" ]; then
479 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
480 fi
481 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
482 fromuser="1"
483 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
484 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
485 fi
486 fi
487 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
488 export GCC_HOST_COMPILER_PATH
489 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
490 break
491 fi
492 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
493 if [ -z "$fromuser" ]; then
494 exit 1
495 fi
496 GCC_HOST_COMPILER_PATH=""
497 # Retry
498done
499
Martin Wicke916776a2016-01-14 07:30:00 -0800500# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800501while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800502 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800503 if [ -z "$TF_CUDNN_VERSION" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700504 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 -0800505 fi
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700506 # Set default CUDNN version if not set
507 TF_CUDNN_VERSION=${TF_CUDNN_VERSION:-6}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800508
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800509 fromuser=""
510 if [ -z "$CUDNN_INSTALL_PATH" ]; then
511 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800512 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 -0800513 fromuser="1"
514 if [ -z "$CUDNN_INSTALL_PATH" ]; then
515 CUDNN_INSTALL_PATH=$default_cudnn_path
516 fi
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700517 # Result returned from "read" will be used unexpanded. That make "~" unusable.
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800518 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800519 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 -0700520 if is_windows; then
521 CUDNN_INSTALL_PATH="$(cygpath -m "$CUDNN_INSTALL_PATH")"
522 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800523 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800524
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800525 if [[ -z "$TF_CUDNN_VERSION" ]]; then
526 TF_CUDNN_EXT=""
527 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800528 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800529 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800530
Andrew Harp1cb96892016-12-08 20:05:49 -0800531 if is_windows; then
532 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
533 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800534 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800535 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
536 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800537 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800538 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
539 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800540 fi
541
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700542 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 -0800543 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800544 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800545 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800546 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800547 break
548 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800549
Jonathan Hseuc058a012017-01-17 15:06:43 -0800550 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800551 if ! type ldconfig > /dev/null 2>&1; then
552 LDCONFIG_BIN=/sbin/ldconfig
553 else
554 LDCONFIG_BIN=ldconfig
555 fi
556 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800557 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800558 export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700559 export CUDNN_INSTALL_PATH
560 CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800561 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800562 break
563 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800564 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800565 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
566 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
567 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800568 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800569 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
570 fi
571
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800572 if [ -z "$fromuser" ]; then
573 exit 1
574 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800575 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800576 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800577 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800578done
579
Jonathan Hseu9cc871e2017-07-19 15:04:52 -0700580export TF_CUDNN_VERSION
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700581write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
582
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800583# Configure the compute capabilities that TensorFlow builds for.
584# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700585function get_native_cuda_compute_capabilities {
586 device_query_bin="$CUDA_TOOLKIT_PATH/extras/demo_suite/deviceQuery" # Also works on Windows without .exe
587 "$device_query_bin" | grep 'Capability' | grep -o '[0-9]*\.[0-9]*' | sed ':a;{N;s/\n/,/};ba'
588 exit 0 # ensure that this function always exit success even if device detection fails, to prevent the whole configure from aborting
589}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800590while true; do
591 fromuser=""
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700592 native_cuda_compute_capabilities=$(get_native_cuda_compute_capabilities)
593 default_cuda_compute_capabilities=${native_cuda_compute_capabilities:-"3.5,5.2"}
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800594 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800595cat << EOF
596Please specify a list of comma-separated Cuda compute capabilities you want to build with.
597You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
598Please note that each additional compute capability significantly increases your build time and binary size.
599EOF
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700600 read -p "[Default is: \"$default_cuda_compute_capabilities\"]: " TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800601 fromuser=1
602 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800603 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
604 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
605 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800606 # Check whether all capabilities from the input is valid
607 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
608 ALL_VALID=1
609 for CAPABILITY in $COMPUTE_CAPABILITIES; do
610 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
611 echo "Invalid compute capability: " $CAPABILITY
612 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800613 break
614 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800615 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800616 if [ "$ALL_VALID" == "0" ]; then
617 if [ -z "$fromuser" ]; then
618 exit 1
619 fi
620 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800621 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800622 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800623 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800624 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800625 TF_CUDA_COMPUTE_CAPABILITIES=""
626done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800627
Andrew Harp1cb96892016-12-08 20:05:49 -0800628if is_windows; then
629 # The following three variables are needed for MSVC toolchain configuration in Bazel
630 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
631 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
632 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800633 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
634 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
635 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Gunhan Gulsoy3cf88d32017-06-06 22:34:30 -0700636 write_to_bazelrc "build --config=win-cuda"
637 write_to_bazelrc "test --config=win-cuda"
638else
639 # If CUDA is enabled, always use GPU during build and test.
A. Unique TensorFlower64857412017-06-28 11:47:37 -0700640 if [ "$TF_CUDA_CLANG" == "1" ]; then
641 write_to_bazelrc "build --config=cuda_clang"
642 write_to_bazelrc "test --config=cuda_clang"
643 else
644 write_to_bazelrc "build --config=cuda"
645 write_to_bazelrc "test --config=cuda"
646 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800647fi
648
Benoit Steinera7715982016-11-09 13:14:03 -0800649# end of if "$TF_NEED_CUDA" == "1"
650fi
651
652# OpenCL configuration
653
654if [ "$TF_NEED_OPENCL" == "1" ]; then
655
656# Determine which C++ compiler should be used as the host compiler
657while true; do
658 fromuser=""
659 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700660 default_cxx_host_compiler=$(which g++ || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800661 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
662 fromuser="1"
663 if [ -z "$HOST_CXX_COMPILER" ]; then
664 HOST_CXX_COMPILER=$default_cxx_host_compiler
665 fi
666 fi
667 if [ -e "$HOST_CXX_COMPILER" ]; then
668 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800669 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800670 break
671 fi
672 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
673 if [ -z "$fromuser" ]; then
674 exit 1
675 fi
676 HOST_CXX_COMPILER=""
677 # Retry
678done
679
680# Determine which C compiler should be used as the host compiler
681while true; do
682 fromuser=""
683 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700684 default_c_host_compiler=$(which gcc || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800685 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
686 fromuser="1"
687 if [ -z "$HOST_C_COMPILER" ]; then
688 HOST_C_COMPILER=$default_c_host_compiler
689 fi
690 fi
691 if [ -e "$HOST_C_COMPILER" ]; then
692 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800693 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800694 break
695 fi
696 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
697 if [ -z "$fromuser" ]; then
698 exit 1
699 fi
700 HOST_C_COMPILER=""
701 # Retry
702done
703
704while true; do
705 # Configure the OPENCL version to use.
706 TF_OPENCL_VERSION="1.2"
707
708 # Point to ComputeCpp root
709 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
710 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800711 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 -0800712 fromuser="1"
713 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
714 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
715 fi
716 fi
717
Jonathan Hseuc058a012017-01-17 15:06:43 -0800718 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800719 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
720 fi
721
722 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
723 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800724 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800725 break
726 fi
727 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
728
729 if [ -z "$fromuser" ]; then
730 exit 1
731 fi
732 # Retry
733 TF_OPENCL_VERSION=""
734 COMPUTECPP_TOOLKIT_PATH=""
735done
736
Benoit Steinera7715982016-11-09 13:14:03 -0800737# end of if "$TF_NEED_OPENCL" == "1"
738fi
739
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700740
741while [ "$TF_NEED_MPI" == "" ]; do
742 read -p "Do you wish to build TensorFlow with "\
743"MPI support? [y/N] " INPUT
744 case $INPUT in
745 [Yy]* ) echo "MPI support will be enabled for "\
746"TensorFlow"; TF_NEED_MPI=1;;
747 [Nn]* ) echo "MPI support will not be enabled for "\
748"TensorFlow"; TF_NEED_MPI=0;;
749 "" ) echo "MPI support will not be enabled for "\
750"TensorFlow"; TF_NEED_MPI=0;;
751 * ) echo "Invalid selection: " $INPUT;;
752 esac
753done
754
755# Find out where the MPI toolkit is installed
756while true; do
757 if [ "$TF_NEED_MPI" == "0" ]; then
758 break;
759 fi
760
761 fromuser=""
762 if [ -z "$MPI_HOME" ]; then
763 #Get the base folder by removing the bin path
764 default_mpi_path=$(dirname $(dirname $(which mpirun)) || dirname $(dirname $(which mpiexec)) || true)
765 read -p "Please specify the MPI toolkit folder. [Default is $default_mpi_path]: " MPI_HOME
766 fromuser="1"
767 if [ -z "$MPI_HOME" ]; then
768 MPI_HOME=$default_mpi_path
769 fi
770 fi
771
772 #Check that the include and library folders are where we expect them to be
773 if [ -e "$MPI_HOME/include" ] && [ -e "$MPI_HOME/lib" ]; then
774 break
775 fi
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700776
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700777 echo "Invalid path to the MPI Toolkit. ${MPI_HOME}/include or ${MPI_HOME}/lib cannot be found."
778 if [ -z "$fromuser" ]; then
779 exit 1
780 fi
781
782 # Retry
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700783 MPI_HOME=""
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700784done
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700785
786
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700787if [ "$TF_NEED_MPI" == "1" ]; then
788 write_to_bazelrc 'build --define with_mpi_support=true'
789
790 #Link the MPI header files
791 ln -sf "${MPI_HOME}/include/mpi.h" third_party/mpi/mpi.h
792
793
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700794 #Determine if we use OpenMPI or MVAPICH, these require different header files
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700795 #to be included here to make bazel dependency checker happy
796
797 if [ -e "${MPI_HOME}/include/mpi_portable_platform.h" ]; then
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700798 #OpenMPI
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700799 ln -sf "${MPI_HOME}/include/mpi_portable_platform.h" third_party/mpi/
800 sed -i -e "s/MPI_LIB_IS_OPENMPI=False/MPI_LIB_IS_OPENMPI=True/" third_party/mpi/mpi.bzl
801 else
802 #MVAPICH / MPICH
803 ln -sf "${MPI_HOME}/include/mpio.h" third_party/mpi/
804 ln -sf "${MPI_HOME}/include/mpicxx.h" third_party/mpi/
805 sed -i -e "s/MPI_LIB_IS_OPENMPI=True/MPI_LIB_IS_OPENMPI=False/" third_party/mpi/mpi.bzl
806 fi
807
A. Unique TensorFlower50b999a2017-06-27 16:33:00 -0700808
Jonathan Hseu1b5235f2017-06-09 10:37:18 -0700809 if [ -e "${MPI_HOME}/lib/libmpi.so" ]; then
810 ln -sf "${MPI_HOME}/lib/libmpi.so" third_party/mpi/
811 else
812 echo "Cannot find the MPI library file in ${MPI_HOME}/lib "
813 exit 1
814 fi
815fi
816
817
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800818echo "Configuration finished"