blob: 0064d5574a38c275fbb8bf19394efd6b2d0b2f63 [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
Andrew Selle09045e42016-09-06 08:19:04 -08006# Find out the absolute path to where ./configure resides
A. Unique TensorFlower46d2c282017-01-02 22:19:48 -08007pushd `dirname $0` > /dev/null
Andrew Selle09045e42016-09-06 08:19:04 -08008SOURCE_BASE_DIR=`pwd -P`
9popd > /dev/null
10
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080011PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
Jonathan Hseuc058a012017-01-17 15:06:43 -080012
13function is_linux() {
14 if [[ "${PLATFORM}" == "linux" ]]; then
15 true
16 else
17 false
18 fi
19}
20
21function is_macos() {
22 if [[ "${PLATFORM}" == "darwin" ]]; then
23 true
24 else
25 false
26 fi
27}
28
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080029function is_windows() {
30 # On windows, the shell script is actually running in msys
Shanqing Cai56fc8832017-01-23 18:25:25 -080031 if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080032 true
33 else
34 false
35 fi
36}
37
Jonathan Hseu1283b842016-09-29 15:05:32 -080038function bazel_clean_and_fetch() {
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080039 # bazel clean --expunge currently doesn't work on Windows
40 # TODO(pcloudy): Re-enable it after bazel clean --expunge is fixed.
41 if ! is_windows; then
42 bazel clean --expunge
43 fi
Benoit Steiner639b4e72017-02-08 09:25:09 -080044 bazel fetch "//tensorflow/... -//tensorflow/contrib/nccl/... \
45 -//tensorflow/examples/android/..."
Jonathan Hseu1283b842016-09-29 15:05:32 -080046}
47
Dandelion Mané0386a012017-03-10 14:43:23 -080048function sed_hyphen_i() {
49 if is_macos; then
50 sed -i '' "$@"
51 else
52 sed -i "$@"
53 fi
54}
55
Andrew Harp51dbc462017-01-27 14:42:30 -080056# Delete any leftover BUILD files from the Makefile build, which would interfere
57# with Bazel parsing.
58MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
59if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
60 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
61fi
62
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080063## Set up python-related environment settings
64while true; do
65 fromuser=""
66 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080067 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080068 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
69 fromuser="1"
70 if [ -z "$PYTHON_BIN_PATH" ]; then
71 PYTHON_BIN_PATH=$default_python_bin_path
72 fi
73 fi
74 if [ -e "$PYTHON_BIN_PATH" ]; then
75 break
76 fi
77 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
78 if [ -z "$fromuser" ]; then
79 exit 1
80 fi
81 PYTHON_BIN_PATH=""
82 # Retry
83done
84
Benoit Steiner639b4e72017-02-08 09:25:09 -080085## Set up MKL related environment settings
86if false; then # Disable building with MKL for now
87 while [ "$TF_NEED_MKL" == "" ]; do
88 fromuser=""
89 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
90 fromuser="1"
91 case $INPUT in
92 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
93 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
94 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
95 * ) echo "Invalid selection: " $INPUT;;
96 esac
97 done
98
99 OSNAME=`uname -s`
100
101 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
102 DST=`dirname $0`
103 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170110.tgz
104 GITHUB_RELEASE_TAG=v0.3
105 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
106 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
107 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
108 fi
109 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
110 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
111 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
112 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
113
114 if [ "$OSNAME" == "Linux" ]; then
115 # Full MKL configuration
116 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
117 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
118
119 # MKL-ML configuration
120 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
121 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
122 elif [ "$OSNAME" == "Darwin" ]; then
123 echo "Darwin is unsupported yet";
124 exit 1
125 fi
126
127 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
128 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
129 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
130 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
131 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
132 else
133 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
134 exit 1
135 fi
136
137 if [ -z "$fromuser" ]; then
138 exit 1
139 fi
140
141cat > third_party/mkl/mkl.config <<EOF
142# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
143# files can be either in this directory, or under include/ and lib64/
144MKL_INSTALL_PATH=$MKL_INSTALL_PATH
145EOF
146
147 fi # TF_NEED_MKL
148 ################## MKL
149fi # Disable building with MKL for now
150
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800151## Set up architecture-dependent optimization flags.
152if [ -z "$CC_OPT_FLAGS" ]; then
153 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800154 read -p "Please specify optimization flags to use during compilation when bazel option "\
155"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800156 if [ -z "$CC_OPT_FLAGS" ]; then
157 CC_OPT_FLAGS=$default_cc_opt_flags
158 fi
159fi
160
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800161if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800162 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800163 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800164 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800165 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800166fi
167
Jonathan Hseuc058a012017-01-17 15:06:43 -0800168if is_linux; then
169 while [ "$TF_NEED_JEMALLOC" == "" ]; do
170 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
171 INPUT
172 case $INPUT in
173 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
174 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
175 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
176 * ) echo "Invalid selection: " $INPUT;;
177 esac
178 done
179else
180 TF_NEED_JEMALLOC=0
181fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800182
183if [ "$TF_NEED_JEMALLOC" == "1" ]; then
Dandelion Mané0386a012017-03-10 14:43:23 -0800184 sed_hyphen_i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800185else
Dandelion Mané0386a012017-03-10 14:43:23 -0800186 sed_hyphen_i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800187fi
188
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800189while [ "$TF_NEED_GCP" == "" ]; do
190 read -p "Do you wish to build TensorFlow with "\
191"Google Cloud Platform support? [y/N] " INPUT
192 case $INPUT in
193 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
194"TensorFlow"; TF_NEED_GCP=1;;
195 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
196"TensorFlow"; TF_NEED_GCP=0;;
197 "" ) echo "No Google Cloud Platform support will be enabled for "\
198"TensorFlow"; TF_NEED_GCP=0;;
199 * ) echo "Invalid selection: " $INPUT;;
200 esac
201done
202
203if [ "$TF_NEED_GCP" == "1" ]; then
204 ## Verify that libcurl header files are available.
205 # Only check Linux, since on MacOS the header files are installed with XCode.
Jonathan Hseuc058a012017-01-17 15:06:43 -0800206 if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800207 echo "ERROR: It appears that the development version of libcurl is not "\
208"available. Please install the libcurl3-dev package."
209 exit 1
210 fi
211
212 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800213 sed_hyphen_i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800214else
215 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800216 sed_hyphen_i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800217fi
218
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800219while [ "$TF_NEED_HDFS" == "" ]; do
220 read -p "Do you wish to build TensorFlow with "\
221"Hadoop File System support? [y/N] " INPUT
222 case $INPUT in
223 [Yy]* ) echo "Hadoop File System support will be enabled for "\
224"TensorFlow"; TF_NEED_HDFS=1;;
225 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
226"TensorFlow"; TF_NEED_HDFS=0;;
227 "" ) echo "No Hadoop File System support will be enabled for "\
228"TensorFlow"; TF_NEED_HDFS=0;;
229 * ) echo "Invalid selection: " $INPUT;;
230 esac
231done
232
233if [ "$TF_NEED_HDFS" == "1" ]; then
234 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800235 sed_hyphen_i -e "s/WITH_HDFS_SUPPORT = False/WITH_HDFS_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800236else
237 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800238 sed_hyphen_i -e "s/WITH_HDFS_SUPPORT = True/WITH_HDFS_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800239fi
240
Peter Hawkins1e67c902017-01-09 12:04:37 -0800241## Enable XLA.
242while [ "$TF_ENABLE_XLA" == "" ]; do
243 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
244 case $INPUT in
245 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
246 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
247 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
248 * ) echo "Invalid selection: " $INPUT;;
249 esac
250done
251
252if [ "$TF_ENABLE_XLA" == "1" ]; then
253 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800254 sed_hyphen_i -e "s/^WITH_XLA_SUPPORT = [FT].*/WITH_XLA_SUPPORT = True/" tensorflow/core/platform/default/build_config_root.bzl
Peter Hawkins1e67c902017-01-09 12:04:37 -0800255else
256 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800257 sed_hyphen_i -e "s/^WITH_XLA_SUPPORT = [FT].*/WITH_XLA_SUPPORT = False/" tensorflow/core/platform/default/build_config_root.bzl
Peter Hawkins1e67c902017-01-09 12:04:37 -0800258fi
259
260
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800261# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800262./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800263
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800264# Append CC optimization flags to bazel.rc
265echo >> tools/bazel.rc
266for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800267 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800268done
269
Andrew Selle09045e42016-09-06 08:19:04 -0800270# Run the gen_git_source to create links where bazel can track dependencies for
271# git hash propagation
272GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
273chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800274"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800275
Benoit Steinera7715982016-11-09 13:14:03 -0800276## Set up SYCL-related environment settings
277while [ "$TF_NEED_OPENCL" == "" ]; do
278 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
279 case $INPUT in
280 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
281 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
282 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
283 * ) echo "Invalid selection: " $INPUT;;
284 esac
285done
286
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800287## Set up Cuda-related environment settings
288
289while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800290 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800291 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800292 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
293 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
294 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800295 * ) echo "Invalid selection: " $INPUT;;
296 esac
297done
298
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800299export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800300export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800301if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800302 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800303 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800304 exit
305fi
306
Benoit Steinera7715982016-11-09 13:14:03 -0800307if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800308# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800309# No need to set this on Windows
310while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800311 fromuser=""
312 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800313 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800314 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
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800315 fromuser="1"
316 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800317 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800318 fi
319 fi
320 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800321 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800322 break
323 fi
324 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
325 if [ -z "$fromuser" ]; then
326 exit 1
327 fi
328 GCC_HOST_COMPILER_PATH=""
329 # Retry
330done
331
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800332# Find out where the CUDA toolkit is installed
333while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800334 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800335 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800336 read -p "Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: " TF_CUDA_VERSION
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800337 fi
338
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800339 fromuser=""
340 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
341 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800342 if is_windows; then
343 if [ -z "$CUDA_PATH" ]; then
344 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
345 else
346 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
347 fi
348 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800349 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 -0800350 fromuser="1"
351 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800352 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800353 fi
354 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800355
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800356 if [[ -z "$TF_CUDA_VERSION" ]]; then
357 TF_CUDA_EXT=""
358 else
359 TF_CUDA_EXT=".$TF_CUDA_VERSION"
360 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800361
Andrew Harp1cb96892016-12-08 20:05:49 -0800362 if is_windows; then
363 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800364 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800365 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800366 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800367 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
368 fi
369
370 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800371 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800372 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800373 break
374 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800375 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
376
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800377 if [ -z "$fromuser" ]; then
378 exit 1
379 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800380 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800381 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800382 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800383done
384
Martin Wicke916776a2016-01-14 07:30:00 -0800385# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800386while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800387 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800388 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800389 read -p "Please specify the Cudnn version you want to use. [Leave empty to use system default]: " TF_CUDNN_VERSION
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800390 fi
391
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800392 fromuser=""
393 if [ -z "$CUDNN_INSTALL_PATH" ]; then
394 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800395 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 -0800396 fromuser="1"
397 if [ -z "$CUDNN_INSTALL_PATH" ]; then
398 CUDNN_INSTALL_PATH=$default_cudnn_path
399 fi
400 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
401 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800402 CUDNN_INSTALL_PATH=`"${PYTHON_BIN_PATH}" -c "import os; print(os.path.realpath(os.path.expanduser('${CUDNN_INSTALL_PATH}')))"`
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800403 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800404
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800405 if [[ -z "$TF_CUDNN_VERSION" ]]; then
406 TF_CUDNN_EXT=""
407 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800408 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800409 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800410
Andrew Harp1cb96892016-12-08 20:05:49 -0800411 if is_windows; then
412 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
413 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800414 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800415 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
416 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800417 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800418 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
419 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800420 fi
421
422 if [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_ALT_PATH}" -o -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_PATH}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800423 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800424 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800425 break
426 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800427
Jonathan Hseuc058a012017-01-17 15:06:43 -0800428 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800429 if ! type ldconfig > /dev/null 2>&1; then
430 LDCONFIG_BIN=/sbin/ldconfig
431 else
432 LDCONFIG_BIN=ldconfig
433 fi
434 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800435 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800436 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800437 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800438 break
439 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800440 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800441 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
442 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
443 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800444 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800445 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
446 fi
447
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800448 if [ -z "$fromuser" ]; then
449 exit 1
450 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800451 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800452 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800453 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800454done
455
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800456# Configure the compute capabilities that TensorFlow builds for.
457# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
458while true; do
459 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800460 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800461 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800462cat << EOF
463Please specify a list of comma-separated Cuda compute capabilities you want to build with.
464You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
465Please note that each additional compute capability significantly increases your build time and binary size.
466EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800467 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
468 fromuser=1
469 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800470 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
471 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
472 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800473 # Check whether all capabilities from the input is valid
474 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
475 ALL_VALID=1
476 for CAPABILITY in $COMPUTE_CAPABILITIES; do
477 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
478 echo "Invalid compute capability: " $CAPABILITY
479 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800480 break
481 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800482 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800483 if [ "$ALL_VALID" == "0" ]; then
484 if [ -z "$fromuser" ]; then
485 exit 1
486 fi
487 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800488 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800489 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800490 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800491 TF_CUDA_COMPUTE_CAPABILITIES=""
492done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800493
Andrew Harp1cb96892016-12-08 20:05:49 -0800494if is_windows; then
495 # The following three variables are needed for MSVC toolchain configuration in Bazel
496 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
497 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
498 export NO_WHOLE_ARCHIVE_OPTION=1
499
500 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
501 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
502fi
503
Benoit Steinera7715982016-11-09 13:14:03 -0800504# end of if "$TF_NEED_CUDA" == "1"
505fi
506
507# OpenCL configuration
508
509if [ "$TF_NEED_OPENCL" == "1" ]; then
510
511# Determine which C++ compiler should be used as the host compiler
512while true; do
513 fromuser=""
514 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800515 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800516 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
517 fromuser="1"
518 if [ -z "$HOST_CXX_COMPILER" ]; then
519 HOST_CXX_COMPILER=$default_cxx_host_compiler
520 fi
521 fi
522 if [ -e "$HOST_CXX_COMPILER" ]; then
523 export HOST_CXX_COMPILER
524 break
525 fi
526 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
527 if [ -z "$fromuser" ]; then
528 exit 1
529 fi
530 HOST_CXX_COMPILER=""
531 # Retry
532done
533
534# Determine which C compiler should be used as the host compiler
535while true; do
536 fromuser=""
537 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800538 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800539 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
540 fromuser="1"
541 if [ -z "$HOST_C_COMPILER" ]; then
542 HOST_C_COMPILER=$default_c_host_compiler
543 fi
544 fi
545 if [ -e "$HOST_C_COMPILER" ]; then
546 export HOST_C_COMPILER
547 break
548 fi
549 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
550 if [ -z "$fromuser" ]; then
551 exit 1
552 fi
553 HOST_C_COMPILER=""
554 # Retry
555done
556
557while true; do
558 # Configure the OPENCL version to use.
559 TF_OPENCL_VERSION="1.2"
560
561 # Point to ComputeCpp root
562 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
563 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800564 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 -0800565 fromuser="1"
566 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
567 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
568 fi
569 fi
570
Jonathan Hseuc058a012017-01-17 15:06:43 -0800571 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800572 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
573 fi
574
575 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
576 export COMPUTECPP_TOOLKIT_PATH
577 break
578 fi
579 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
580
581 if [ -z "$fromuser" ]; then
582 exit 1
583 fi
584 # Retry
585 TF_OPENCL_VERSION=""
586 COMPUTECPP_TOOLKIT_PATH=""
587done
588
Benoit Steinera7715982016-11-09 13:14:03 -0800589# end of if "$TF_NEED_OPENCL" == "1"
590fi
591
Jonathan Hseu1283b842016-09-29 15:05:32 -0800592bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800593
594echo "Configuration finished"