blob: ee1967f93740eefbb234267b5bf882c3061e8d83 [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')"
12function is_windows() {
13 # On windows, the shell script is actually running in msys
14 if [[ "${PLATFORM}" =~ msys_nt* ]]; then
15 true
16 else
17 false
18 fi
19}
20
Jonathan Hseu1283b842016-09-29 15:05:32 -080021function bazel_clean_and_fetch() {
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080022 # bazel clean --expunge currently doesn't work on Windows
23 # TODO(pcloudy): Re-enable it after bazel clean --expunge is fixed.
24 if ! is_windows; then
25 bazel clean --expunge
Jonathan Hseubed83832016-12-22 15:38:30 -080026 # TODO(https://github.com/bazelbuild/bazel/issues/2220) Remove the nested `bazel query`.
27 bazel fetch $(bazel query "//tensorflow/... -//tensorflow/examples/android/...")
28 else
29 # TODO(pcloudy): Also filter out //tensorflow/examples/android/... on Windows after
30 # https://github.com/bazelbuild/bazel/issues/2248 is fixed.
31 bazel fetch //tensorflow/...
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080032 fi
Jonathan Hseu1283b842016-09-29 15:05:32 -080033}
34
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080035## Set up python-related environment settings
36while true; do
37 fromuser=""
38 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080039 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080040 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
41 fromuser="1"
42 if [ -z "$PYTHON_BIN_PATH" ]; then
43 PYTHON_BIN_PATH=$default_python_bin_path
44 fi
45 fi
46 if [ -e "$PYTHON_BIN_PATH" ]; then
47 break
48 fi
49 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
50 if [ -z "$fromuser" ]; then
51 exit 1
52 fi
53 PYTHON_BIN_PATH=""
54 # Retry
55done
56
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080057if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080058 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080059 TF_NEED_HDFS=0
Benoit Steinera7715982016-11-09 13:14:03 -080060 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080061fi
62
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080063while [ "$TF_NEED_GCP" == "" ]; do
64 read -p "Do you wish to build TensorFlow with "\
65"Google Cloud Platform support? [y/N] " INPUT
66 case $INPUT in
67 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
68"TensorFlow"; TF_NEED_GCP=1;;
69 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
70"TensorFlow"; TF_NEED_GCP=0;;
71 "" ) echo "No Google Cloud Platform support will be enabled for "\
72"TensorFlow"; TF_NEED_GCP=0;;
73 * ) echo "Invalid selection: " $INPUT;;
74 esac
75done
76
77if [ "$TF_NEED_GCP" == "1" ]; then
78 ## Verify that libcurl header files are available.
79 # Only check Linux, since on MacOS the header files are installed with XCode.
80 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
81 echo "ERROR: It appears that the development version of libcurl is not "\
82"available. Please install the libcurl3-dev package."
83 exit 1
84 fi
85
86 # Update Bazel build configuration.
87 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
88else
89 # Update Bazel build configuration.
90 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
91fi
92
Jonathan Hseu9f5b0982016-09-19 11:14:58 -080093while [ "$TF_NEED_HDFS" == "" ]; do
94 read -p "Do you wish to build TensorFlow with "\
95"Hadoop File System support? [y/N] " INPUT
96 case $INPUT in
97 [Yy]* ) echo "Hadoop File System support will be enabled for "\
98"TensorFlow"; TF_NEED_HDFS=1;;
99 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
100"TensorFlow"; TF_NEED_HDFS=0;;
101 "" ) echo "No Hadoop File System support will be enabled for "\
102"TensorFlow"; TF_NEED_HDFS=0;;
103 * ) echo "Invalid selection: " $INPUT;;
104 esac
105done
106
107if [ "$TF_NEED_HDFS" == "1" ]; then
108 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800109 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 -0800110else
111 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800112 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 -0800113fi
114
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800115# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800116./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800117
Andrew Selle09045e42016-09-06 08:19:04 -0800118# Run the gen_git_source to create links where bazel can track dependencies for
119# git hash propagation
120GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
121chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800122"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800123
Benoit Steinera7715982016-11-09 13:14:03 -0800124## Set up SYCL-related environment settings
125while [ "$TF_NEED_OPENCL" == "" ]; do
126 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
127 case $INPUT in
128 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
129 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
130 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
131 * ) echo "Invalid selection: " $INPUT;;
132 esac
133done
134
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800135## Set up Cuda-related environment settings
136
137while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800138 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800139 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800140 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
141 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
142 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800143 * ) echo "Invalid selection: " $INPUT;;
144 esac
145done
146
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800147export TF_NEED_CUDA
Benoit Steinera7715982016-11-09 13:14:03 -0800148export TF_NEED_SYCL
149if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800150 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800151 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800152 exit
153fi
154
Benoit Steinera7715982016-11-09 13:14:03 -0800155if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800156# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800157# No need to set this on Windows
158while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800159 fromuser=""
160 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800161 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800162 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 -0800163 fromuser="1"
164 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800165 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800166 fi
167 fi
168 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800169 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800170 break
171 fi
172 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
173 if [ -z "$fromuser" ]; then
174 exit 1
175 fi
176 GCC_HOST_COMPILER_PATH=""
177 # Retry
178done
179
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800180# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800181OSNAME=`uname -s`
182
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800183while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800184 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800185 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800186 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 -0800187 fi
188
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800189 fromuser=""
190 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
191 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800192 if is_windows; then
193 if [ -z "$CUDA_PATH" ]; then
194 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
195 else
196 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
197 fi
198 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800199 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 -0800200 fromuser="1"
201 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800202 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800203 fi
204 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800205
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800206 if [[ -z "$TF_CUDA_VERSION" ]]; then
207 TF_CUDA_EXT=""
208 else
209 TF_CUDA_EXT=".$TF_CUDA_VERSION"
210 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800211
Andrew Harp1cb96892016-12-08 20:05:49 -0800212 if is_windows; then
213 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
214 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800215 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
216 elif [ "$OSNAME" == "Darwin" ]; then
217 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
218 fi
219
220 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800221 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800222 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800223 break
224 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800225 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
226
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800227 if [ -z "$fromuser" ]; then
228 exit 1
229 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800230 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800231 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800232 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800233done
234
Martin Wicke916776a2016-01-14 07:30:00 -0800235# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800236while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800237 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800238 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800239 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 -0800240 fi
241
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800242 fromuser=""
243 if [ -z "$CUDNN_INSTALL_PATH" ]; then
244 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800245 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 -0800246 fromuser="1"
247 if [ -z "$CUDNN_INSTALL_PATH" ]; then
248 CUDNN_INSTALL_PATH=$default_cudnn_path
249 fi
250 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
251 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800252 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 -0800253 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800254
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800255 if [[ -z "$TF_CUDNN_VERSION" ]]; then
256 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800257 cudnn_lib_path=""
258 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800259 if is_windows; then
260 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
261 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
262 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800263 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
264 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
265 elif [ "$OSNAME" == "Darwin" ]; then
266 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
267 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
268 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800269 # Resolve to the SONAME of the symlink. Use readlink without -f
270 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800271 # libcudnn.so.4.
272 # If the path is not a symlink, readlink will exit with an error code, so
273 # in that case, we return the path itself.
274 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800275 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800276 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800277 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800278 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800279
280 # Extract the version of the SONAME, if it was indeed symlinked to
281 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800282 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800283 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
284 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
285 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800286 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800287 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800288 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
289 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800290 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800291 else
292 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
293 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800294
Andrew Harp1cb96892016-12-08 20:05:49 -0800295 if is_windows; then
296 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
297 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
298 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800299 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
300 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
301 elif [ "$OSNAME" == "Darwin" ]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800302 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
303 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800304 fi
305
306 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 -0800307 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800308 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800309 break
310 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800311
312 if [ "$OSNAME" == "Linux" ]; then
313 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
314 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800315 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800316 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800317 break
318 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800319 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800320 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
321 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
322 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
323 if [ "$OSNAME" == "Linux" ]; then
324 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
325 fi
326
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800327 if [ -z "$fromuser" ]; then
328 exit 1
329 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800330 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800331 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800332 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800333done
334
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800335# Configure the compute capabilities that TensorFlow builds for.
336# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
337while true; do
338 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800339 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800340 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800341cat << EOF
342Please specify a list of comma-separated Cuda compute capabilities you want to build with.
343You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
344Please note that each additional compute capability significantly increases your build time and binary size.
345EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800346 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
347 fromuser=1
348 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800349 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
350 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
351 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800352 # Check whether all capabilities from the input is valid
353 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
354 ALL_VALID=1
355 for CAPABILITY in $COMPUTE_CAPABILITIES; do
356 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
357 echo "Invalid compute capability: " $CAPABILITY
358 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800359 break
360 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800361 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800362 if [ "$ALL_VALID" == "0" ]; then
363 if [ -z "$fromuser" ]; then
364 exit 1
365 fi
366 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800367 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800368 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800369 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800370 TF_CUDA_COMPUTE_CAPABILITIES=""
371done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800372
Andrew Harp1cb96892016-12-08 20:05:49 -0800373if is_windows; then
374 # The following three variables are needed for MSVC toolchain configuration in Bazel
375 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
376 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
377 export NO_WHOLE_ARCHIVE_OPTION=1
378
379 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
380 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
381fi
382
Benoit Steinera7715982016-11-09 13:14:03 -0800383# end of if "$TF_NEED_CUDA" == "1"
384fi
385
386# OpenCL configuration
387
388if [ "$TF_NEED_OPENCL" == "1" ]; then
389
390# Determine which C++ compiler should be used as the host compiler
391while true; do
392 fromuser=""
393 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800394 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800395 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
396 fromuser="1"
397 if [ -z "$HOST_CXX_COMPILER" ]; then
398 HOST_CXX_COMPILER=$default_cxx_host_compiler
399 fi
400 fi
401 if [ -e "$HOST_CXX_COMPILER" ]; then
402 export HOST_CXX_COMPILER
403 break
404 fi
405 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
406 if [ -z "$fromuser" ]; then
407 exit 1
408 fi
409 HOST_CXX_COMPILER=""
410 # Retry
411done
412
413# Determine which C compiler should be used as the host compiler
414while true; do
415 fromuser=""
416 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800417 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800418 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
419 fromuser="1"
420 if [ -z "$HOST_C_COMPILER" ]; then
421 HOST_C_COMPILER=$default_c_host_compiler
422 fi
423 fi
424 if [ -e "$HOST_C_COMPILER" ]; then
425 export HOST_C_COMPILER
426 break
427 fi
428 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
429 if [ -z "$fromuser" ]; then
430 exit 1
431 fi
432 HOST_C_COMPILER=""
433 # Retry
434done
435
436while true; do
437 # Configure the OPENCL version to use.
438 TF_OPENCL_VERSION="1.2"
439
440 # Point to ComputeCpp root
441 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
442 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800443 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 -0800444 fromuser="1"
445 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
446 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
447 fi
448 fi
449
450 if [ "$OSNAME" == "Linux" ]; then
451 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
452 fi
453
454 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
455 export COMPUTECPP_TOOLKIT_PATH
456 break
457 fi
458 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
459
460 if [ -z "$fromuser" ]; then
461 exit 1
462 fi
463 # Retry
464 TF_OPENCL_VERSION=""
465 COMPUTECPP_TOOLKIT_PATH=""
466done
467
468export TF_NEED_OPENCL
469# end of if "$TF_NEED_OPENCL" == "1"
470fi
471
Jonathan Hseu1283b842016-09-29 15:05:32 -0800472bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800473
474echo "Configuration finished"