blob: 5a9a7c0d30a04bc04904d598b3ead0a1c0024999 [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
Andrew Harp51dbc462017-01-27 14:42:30 -080048# Delete any leftover BUILD files from the Makefile build, which would interfere
49# with Bazel parsing.
50MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
51if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
52 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
53fi
54
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080055## Set up python-related environment settings
56while true; do
57 fromuser=""
58 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080059 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080060 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
61 fromuser="1"
62 if [ -z "$PYTHON_BIN_PATH" ]; then
63 PYTHON_BIN_PATH=$default_python_bin_path
64 fi
65 fi
66 if [ -e "$PYTHON_BIN_PATH" ]; then
67 break
68 fi
69 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
70 if [ -z "$fromuser" ]; then
71 exit 1
72 fi
73 PYTHON_BIN_PATH=""
74 # Retry
75done
76
Benoit Steiner639b4e72017-02-08 09:25:09 -080077## Set up MKL related environment settings
78if false; then # Disable building with MKL for now
79 while [ "$TF_NEED_MKL" == "" ]; do
80 fromuser=""
81 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
82 fromuser="1"
83 case $INPUT in
84 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
85 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
86 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
87 * ) echo "Invalid selection: " $INPUT;;
88 esac
89 done
90
91 OSNAME=`uname -s`
92
93 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
94 DST=`dirname $0`
95 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170110.tgz
96 GITHUB_RELEASE_TAG=v0.3
97 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
98 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
99 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
100 fi
101 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
102 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
103 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
104 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
105
106 if [ "$OSNAME" == "Linux" ]; then
107 # Full MKL configuration
108 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
109 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
110
111 # MKL-ML configuration
112 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
113 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
114 elif [ "$OSNAME" == "Darwin" ]; then
115 echo "Darwin is unsupported yet";
116 exit 1
117 fi
118
119 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
120 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
121 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
122 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
123 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
124 else
125 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
126 exit 1
127 fi
128
129 if [ -z "$fromuser" ]; then
130 exit 1
131 fi
132
133cat > third_party/mkl/mkl.config <<EOF
134# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
135# files can be either in this directory, or under include/ and lib64/
136MKL_INSTALL_PATH=$MKL_INSTALL_PATH
137EOF
138
139 fi # TF_NEED_MKL
140 ################## MKL
141fi # Disable building with MKL for now
142
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800143## Set up architecture-dependent optimization flags.
144if [ -z "$CC_OPT_FLAGS" ]; then
145 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800146 read -p "Please specify optimization flags to use during compilation when bazel option "\
147"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800148 if [ -z "$CC_OPT_FLAGS" ]; then
149 CC_OPT_FLAGS=$default_cc_opt_flags
150 fi
151fi
152
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800153if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800154 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800155 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800156 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800157 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800158fi
159
Jonathan Hseuc058a012017-01-17 15:06:43 -0800160if is_linux; then
161 while [ "$TF_NEED_JEMALLOC" == "" ]; do
162 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
163 INPUT
164 case $INPUT in
165 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
166 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
167 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
168 * ) echo "Invalid selection: " $INPUT;;
169 esac
170 done
171else
172 TF_NEED_JEMALLOC=0
173fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800174
175if [ "$TF_NEED_JEMALLOC" == "1" ]; then
176 sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
177else
178 sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
179fi
180
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800181while [ "$TF_NEED_GCP" == "" ]; do
182 read -p "Do you wish to build TensorFlow with "\
183"Google Cloud Platform support? [y/N] " INPUT
184 case $INPUT in
185 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
186"TensorFlow"; TF_NEED_GCP=1;;
187 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
188"TensorFlow"; TF_NEED_GCP=0;;
189 "" ) echo "No Google Cloud Platform support will be enabled for "\
190"TensorFlow"; TF_NEED_GCP=0;;
191 * ) echo "Invalid selection: " $INPUT;;
192 esac
193done
194
195if [ "$TF_NEED_GCP" == "1" ]; then
196 ## Verify that libcurl header files are available.
197 # Only check Linux, since on MacOS the header files are installed with XCode.
Jonathan Hseuc058a012017-01-17 15:06:43 -0800198 if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800199 echo "ERROR: It appears that the development version of libcurl is not "\
200"available. Please install the libcurl3-dev package."
201 exit 1
202 fi
203
204 # Update Bazel build configuration.
205 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
206else
207 # Update Bazel build configuration.
208 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
209fi
210
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800211while [ "$TF_NEED_HDFS" == "" ]; do
212 read -p "Do you wish to build TensorFlow with "\
213"Hadoop File System support? [y/N] " INPUT
214 case $INPUT in
215 [Yy]* ) echo "Hadoop File System support will be enabled for "\
216"TensorFlow"; TF_NEED_HDFS=1;;
217 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
218"TensorFlow"; TF_NEED_HDFS=0;;
219 "" ) echo "No Hadoop File System support will be enabled for "\
220"TensorFlow"; TF_NEED_HDFS=0;;
221 * ) echo "Invalid selection: " $INPUT;;
222 esac
223done
224
225if [ "$TF_NEED_HDFS" == "1" ]; then
226 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800227 sed -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 -0800228else
229 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800230 sed -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 -0800231fi
232
Peter Hawkins1e67c902017-01-09 12:04:37 -0800233## Enable XLA.
234while [ "$TF_ENABLE_XLA" == "" ]; do
235 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
236 case $INPUT in
237 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
238 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
239 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
240 * ) echo "Invalid selection: " $INPUT;;
241 esac
242done
243
244if [ "$TF_ENABLE_XLA" == "1" ]; then
245 # Update Bazel build configuration.
Eugene Brevdoce2a1022017-01-27 17:37:30 -0800246 sed -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 -0800247else
248 # Update Bazel build configuration.
Eugene Brevdoce2a1022017-01-27 17:37:30 -0800249 sed -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 -0800250fi
251
252
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800253# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800254./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800255
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800256# Append CC optimization flags to bazel.rc
257echo >> tools/bazel.rc
258for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800259 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800260done
261
Andrew Selle09045e42016-09-06 08:19:04 -0800262# Run the gen_git_source to create links where bazel can track dependencies for
263# git hash propagation
264GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
265chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800266"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800267
Benoit Steinera7715982016-11-09 13:14:03 -0800268## Set up SYCL-related environment settings
269while [ "$TF_NEED_OPENCL" == "" ]; do
270 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
271 case $INPUT in
272 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
273 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
274 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
275 * ) echo "Invalid selection: " $INPUT;;
276 esac
277done
278
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800279## Set up Cuda-related environment settings
280
281while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800282 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800283 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800284 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
285 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
286 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800287 * ) echo "Invalid selection: " $INPUT;;
288 esac
289done
290
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800291export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800292export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800293if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800294 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800295 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800296 exit
297fi
298
Benoit Steinera7715982016-11-09 13:14:03 -0800299if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800300# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800301# No need to set this on Windows
302while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800303 fromuser=""
304 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800305 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800306 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 -0800307 fromuser="1"
308 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800309 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800310 fi
311 fi
312 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800313 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800314 break
315 fi
316 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
317 if [ -z "$fromuser" ]; then
318 exit 1
319 fi
320 GCC_HOST_COMPILER_PATH=""
321 # Retry
322done
323
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800324# Find out where the CUDA toolkit is installed
325while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800326 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800327 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800328 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 -0800329 fi
330
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800331 fromuser=""
332 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
333 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800334 if is_windows; then
335 if [ -z "$CUDA_PATH" ]; then
336 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
337 else
338 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
339 fi
340 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800341 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 -0800342 fromuser="1"
343 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800344 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800345 fi
346 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800347
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800348 if [[ -z "$TF_CUDA_VERSION" ]]; then
349 TF_CUDA_EXT=""
350 else
351 TF_CUDA_EXT=".$TF_CUDA_VERSION"
352 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800353
Andrew Harp1cb96892016-12-08 20:05:49 -0800354 if is_windows; then
355 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800356 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800357 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800358 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800359 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
360 fi
361
362 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800363 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800364 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800365 break
366 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800367 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
368
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800369 if [ -z "$fromuser" ]; then
370 exit 1
371 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800372 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800373 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800374 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800375done
376
Martin Wicke916776a2016-01-14 07:30:00 -0800377# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800378while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800379 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800380 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800381 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 -0800382 fi
383
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800384 fromuser=""
385 if [ -z "$CUDNN_INSTALL_PATH" ]; then
386 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800387 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 -0800388 fromuser="1"
389 if [ -z "$CUDNN_INSTALL_PATH" ]; then
390 CUDNN_INSTALL_PATH=$default_cudnn_path
391 fi
392 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
393 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800394 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 -0800395 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800396
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800397 if [[ -z "$TF_CUDNN_VERSION" ]]; then
398 TF_CUDNN_EXT=""
399 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800400 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800401 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800402
Andrew Harp1cb96892016-12-08 20:05:49 -0800403 if is_windows; then
404 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
405 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800406 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800407 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
408 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800409 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800410 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
411 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800412 fi
413
414 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 -0800415 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800416 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800417 break
418 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800419
Jonathan Hseuc058a012017-01-17 15:06:43 -0800420 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800421 if ! type ldconfig > /dev/null 2>&1; then
422 LDCONFIG_BIN=/sbin/ldconfig
423 else
424 LDCONFIG_BIN=ldconfig
425 fi
426 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800427 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800428 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800429 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800430 break
431 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800432 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800433 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
434 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
435 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800436 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800437 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
438 fi
439
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800440 if [ -z "$fromuser" ]; then
441 exit 1
442 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800443 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800444 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800445 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800446done
447
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800448# Configure the compute capabilities that TensorFlow builds for.
449# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
450while true; do
451 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800452 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800453 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800454cat << EOF
455Please specify a list of comma-separated Cuda compute capabilities you want to build with.
456You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
457Please note that each additional compute capability significantly increases your build time and binary size.
458EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800459 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
460 fromuser=1
461 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800462 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
463 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
464 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800465 # Check whether all capabilities from the input is valid
466 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
467 ALL_VALID=1
468 for CAPABILITY in $COMPUTE_CAPABILITIES; do
469 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
470 echo "Invalid compute capability: " $CAPABILITY
471 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800472 break
473 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800474 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800475 if [ "$ALL_VALID" == "0" ]; then
476 if [ -z "$fromuser" ]; then
477 exit 1
478 fi
479 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800480 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800481 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800482 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800483 TF_CUDA_COMPUTE_CAPABILITIES=""
484done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800485
Andrew Harp1cb96892016-12-08 20:05:49 -0800486if is_windows; then
487 # The following three variables are needed for MSVC toolchain configuration in Bazel
488 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
489 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
490 export NO_WHOLE_ARCHIVE_OPTION=1
491
492 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
493 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
494fi
495
Benoit Steinera7715982016-11-09 13:14:03 -0800496# end of if "$TF_NEED_CUDA" == "1"
497fi
498
499# OpenCL configuration
500
501if [ "$TF_NEED_OPENCL" == "1" ]; then
502
503# Determine which C++ compiler should be used as the host compiler
504while true; do
505 fromuser=""
506 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800507 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800508 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
509 fromuser="1"
510 if [ -z "$HOST_CXX_COMPILER" ]; then
511 HOST_CXX_COMPILER=$default_cxx_host_compiler
512 fi
513 fi
514 if [ -e "$HOST_CXX_COMPILER" ]; then
515 export HOST_CXX_COMPILER
516 break
517 fi
518 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
519 if [ -z "$fromuser" ]; then
520 exit 1
521 fi
522 HOST_CXX_COMPILER=""
523 # Retry
524done
525
526# Determine which C compiler should be used as the host compiler
527while true; do
528 fromuser=""
529 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800530 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800531 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
532 fromuser="1"
533 if [ -z "$HOST_C_COMPILER" ]; then
534 HOST_C_COMPILER=$default_c_host_compiler
535 fi
536 fi
537 if [ -e "$HOST_C_COMPILER" ]; then
538 export HOST_C_COMPILER
539 break
540 fi
541 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
542 if [ -z "$fromuser" ]; then
543 exit 1
544 fi
545 HOST_C_COMPILER=""
546 # Retry
547done
548
549while true; do
550 # Configure the OPENCL version to use.
551 TF_OPENCL_VERSION="1.2"
552
553 # Point to ComputeCpp root
554 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
555 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800556 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 -0800557 fromuser="1"
558 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
559 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
560 fi
561 fi
562
Jonathan Hseuc058a012017-01-17 15:06:43 -0800563 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800564 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
565 fi
566
567 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
568 export COMPUTECPP_TOOLKIT_PATH
569 break
570 fi
571 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
572
573 if [ -z "$fromuser" ]; then
574 exit 1
575 fi
576 # Retry
577 TF_OPENCL_VERSION=""
578 COMPUTECPP_TOOLKIT_PATH=""
579done
580
Benoit Steinera7715982016-11-09 13:14:03 -0800581# end of if "$TF_NEED_OPENCL" == "1"
582fi
583
Jonathan Hseu1283b842016-09-29 15:05:32 -0800584bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800585
586echo "Configuration finished"