blob: d6d3e19afa6abf22b3b92bd97f4f26bbed4d855f [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
7pushd `dirname $0` #> /dev/null
8SOURCE_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
26 fi
Martin Wicke2e4869a2016-12-14 15:46:53 -080027 # TODO(https://github.com/bazelbuild/bazel/issues/2220) Remove the nested `bazel query`.
28 bazel fetch $(bazel query "//tensorflow/... -//tensorflow/examples/android/...")
Jonathan Hseu1283b842016-09-29 15:05:32 -080029}
30
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080031## Set up python-related environment settings
32while true; do
33 fromuser=""
34 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080035 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080036 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
37 fromuser="1"
38 if [ -z "$PYTHON_BIN_PATH" ]; then
39 PYTHON_BIN_PATH=$default_python_bin_path
40 fi
41 fi
42 if [ -e "$PYTHON_BIN_PATH" ]; then
43 break
44 fi
45 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
46 if [ -z "$fromuser" ]; then
47 exit 1
48 fi
49 PYTHON_BIN_PATH=""
50 # Retry
51done
52
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080053if is_windows; then
54 TF_NEED_GCP=0
55 TF_NEED_HDFS=0
Benoit Steinera7715982016-11-09 13:14:03 -080056 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080057fi
58
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080059while [ "$TF_NEED_GCP" == "" ]; do
60 read -p "Do you wish to build TensorFlow with "\
61"Google Cloud Platform support? [y/N] " INPUT
62 case $INPUT in
63 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
64"TensorFlow"; TF_NEED_GCP=1;;
65 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
66"TensorFlow"; TF_NEED_GCP=0;;
67 "" ) echo "No Google Cloud Platform support will be enabled for "\
68"TensorFlow"; TF_NEED_GCP=0;;
69 * ) echo "Invalid selection: " $INPUT;;
70 esac
71done
72
73if [ "$TF_NEED_GCP" == "1" ]; then
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080074 ## Verify that libcurl header files are available.
75 # Only check Linux, since on MacOS the header files are installed with XCode.
76 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
77 echo "ERROR: It appears that the development version of libcurl is not "\
78"available. Please install the libcurl3-dev package."
79 exit 1
80 fi
81
82 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -080083 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080084else
85 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -080086 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080087fi
88
Jonathan Hseu9f5b0982016-09-19 11:14:58 -080089while [ "$TF_NEED_HDFS" == "" ]; do
90 read -p "Do you wish to build TensorFlow with "\
91"Hadoop File System support? [y/N] " INPUT
92 case $INPUT in
93 [Yy]* ) echo "Hadoop File System support will be enabled for "\
94"TensorFlow"; TF_NEED_HDFS=1;;
95 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
96"TensorFlow"; TF_NEED_HDFS=0;;
97 "" ) echo "No Hadoop File System support will be enabled for "\
98"TensorFlow"; TF_NEED_HDFS=0;;
99 * ) echo "Invalid selection: " $INPUT;;
100 esac
101done
102
103if [ "$TF_NEED_HDFS" == "1" ]; then
104 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800105 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 -0800106else
107 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800108 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 -0800109fi
110
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800111# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800112./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800113
Andrew Selle09045e42016-09-06 08:19:04 -0800114# Run the gen_git_source to create links where bazel can track dependencies for
115# git hash propagation
116GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
117chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800118"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800119
Benoit Steinera7715982016-11-09 13:14:03 -0800120## Set up SYCL-related environment settings
121while [ "$TF_NEED_OPENCL" == "" ]; do
122 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
123 case $INPUT in
124 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
125 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
126 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
127 * ) echo "Invalid selection: " $INPUT;;
128 esac
129done
130
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800131## Set up Cuda-related environment settings
132
133while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800134 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800135 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800136 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
137 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
138 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800139 * ) echo "Invalid selection: " $INPUT;;
140 esac
141done
142
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800143export TF_NEED_CUDA
Benoit Steinera7715982016-11-09 13:14:03 -0800144export TF_NEED_SYCL
145if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800146 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800147 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800148 exit
149fi
150
Benoit Steinera7715982016-11-09 13:14:03 -0800151if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800152# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800153# No need to set this on Windows
154while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800155 fromuser=""
156 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800157 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800158 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 -0800159 fromuser="1"
160 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800161 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800162 fi
163 fi
164 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800165 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800166 break
167 fi
168 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
169 if [ -z "$fromuser" ]; then
170 exit 1
171 fi
172 GCC_HOST_COMPILER_PATH=""
173 # Retry
174done
175
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800176# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800177OSNAME=`uname -s`
178
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800179while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800180 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800181 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800182 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 -0800183 fi
184
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800185 fromuser=""
186 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
187 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800188 if is_windows; then
189 if [ -z "$CUDA_PATH" ]; then
190 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
191 else
192 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
193 fi
194 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800195 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 -0800196 fromuser="1"
197 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800198 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800199 fi
200 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800201
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800202 if [[ -z "$TF_CUDA_VERSION" ]]; then
203 TF_CUDA_EXT=""
204 else
205 TF_CUDA_EXT=".$TF_CUDA_VERSION"
206 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800207
Andrew Harp1cb96892016-12-08 20:05:49 -0800208 if is_windows; then
209 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
210 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800211 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
212 elif [ "$OSNAME" == "Darwin" ]; then
213 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
214 fi
215
216 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800217 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800218 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800219 break
220 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800221 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
222
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800223 if [ -z "$fromuser" ]; then
224 exit 1
225 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800226 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800227 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800228 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800229done
230
Martin Wicke916776a2016-01-14 07:30:00 -0800231# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800232while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800233 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800234 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800235 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 -0800236 fi
237
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800238 fromuser=""
239 if [ -z "$CUDNN_INSTALL_PATH" ]; then
240 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800241 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 -0800242 fromuser="1"
243 if [ -z "$CUDNN_INSTALL_PATH" ]; then
244 CUDNN_INSTALL_PATH=$default_cudnn_path
245 fi
246 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
247 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800248 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 -0800249 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800250
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800251 if [[ -z "$TF_CUDNN_VERSION" ]]; then
252 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800253 cudnn_lib_path=""
254 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800255 if is_windows; then
256 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
257 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
258 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800259 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
260 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
261 elif [ "$OSNAME" == "Darwin" ]; then
262 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
263 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
264 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800265 # Resolve to the SONAME of the symlink. Use readlink without -f
266 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800267 # libcudnn.so.4.
268 # If the path is not a symlink, readlink will exit with an error code, so
269 # in that case, we return the path itself.
270 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800271 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800272 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800273 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800274 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800275
276 # Extract the version of the SONAME, if it was indeed symlinked to
277 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800278 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800279 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
280 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
281 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800282 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Martin Wicke2e4869a2016-12-14 15:46:53 -0800283 TF_CUDNN_EXT="."${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800284 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
285 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800286 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800287 else
288 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
289 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800290
Andrew Harp1cb96892016-12-08 20:05:49 -0800291 if is_windows; then
292 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
293 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
294 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800295 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
296 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
297 elif [ "$OSNAME" == "Darwin" ]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800298 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
299 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800300 fi
301
302 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 -0800303 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800304 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800305 break
306 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800307
308 if [ "$OSNAME" == "Linux" ]; then
309 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
310 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800311 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800312 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800313 break
314 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800315 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800316 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
317 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
318 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
319 if [ "$OSNAME" == "Linux" ]; then
320 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
321 fi
322
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800323 if [ -z "$fromuser" ]; then
324 exit 1
325 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800326 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800327 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800328 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800329done
330
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800331# Configure the compute capabilities that TensorFlow builds for.
332# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
333while true; do
334 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800335 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800336 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800337cat << EOF
338Please specify a list of comma-separated Cuda compute capabilities you want to build with.
339You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
340Please note that each additional compute capability significantly increases your build time and binary size.
341EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800342 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
343 fromuser=1
344 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800345 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
346 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
347 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800348 # Check whether all capabilities from the input is valid
349 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
350 ALL_VALID=1
351 for CAPABILITY in $COMPUTE_CAPABILITIES; do
352 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
353 echo "Invalid compute capability: " $CAPABILITY
354 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800355 break
356 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800357 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800358 if [ "$ALL_VALID" == "0" ]; then
359 if [ -z "$fromuser" ]; then
360 exit 1
361 fi
362 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800363 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800364 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800365 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800366 TF_CUDA_COMPUTE_CAPABILITIES=""
367done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800368
Andrew Harp1cb96892016-12-08 20:05:49 -0800369if is_windows; then
370 # The following three variables are needed for MSVC toolchain configuration in Bazel
371 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
372 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
373 export NO_WHOLE_ARCHIVE_OPTION=1
374
375 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
376 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
377fi
378
Benoit Steinera7715982016-11-09 13:14:03 -0800379# end of if "$TF_NEED_CUDA" == "1"
380fi
381
382# OpenCL configuration
383
384if [ "$TF_NEED_OPENCL" == "1" ]; then
385
386# Determine which C++ compiler should be used as the host compiler
387while true; do
388 fromuser=""
389 if [ -z "$HOST_CXX_COMPILER" ]; then
390 default_cxx_host_compiler=$(which g++|| true)
391 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
392 fromuser="1"
393 if [ -z "$HOST_CXX_COMPILER" ]; then
394 HOST_CXX_COMPILER=$default_cxx_host_compiler
395 fi
396 fi
397 if [ -e "$HOST_CXX_COMPILER" ]; then
398 export HOST_CXX_COMPILER
399 break
400 fi
401 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
402 if [ -z "$fromuser" ]; then
403 exit 1
404 fi
405 HOST_CXX_COMPILER=""
406 # Retry
407done
408
409# Determine which C compiler should be used as the host compiler
410while true; do
411 fromuser=""
412 if [ -z "$HOST_C_COMPILER" ]; then
413 default_c_host_compiler=$(which gcc|| true)
414 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
415 fromuser="1"
416 if [ -z "$HOST_C_COMPILER" ]; then
417 HOST_C_COMPILER=$default_c_host_compiler
418 fi
419 fi
420 if [ -e "$HOST_C_COMPILER" ]; then
421 export HOST_C_COMPILER
422 break
423 fi
424 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
425 if [ -z "$fromuser" ]; then
426 exit 1
427 fi
428 HOST_C_COMPILER=""
429 # Retry
430done
431
432while true; do
433 # Configure the OPENCL version to use.
434 TF_OPENCL_VERSION="1.2"
435
436 # Point to ComputeCpp root
437 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
438 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800439 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 -0800440 fromuser="1"
441 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
442 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
443 fi
444 fi
445
446 if [ "$OSNAME" == "Linux" ]; then
447 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
448 fi
449
450 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
451 export COMPUTECPP_TOOLKIT_PATH
452 break
453 fi
454 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
455
456 if [ -z "$fromuser" ]; then
457 exit 1
458 fi
459 # Retry
460 TF_OPENCL_VERSION=""
461 COMPUTECPP_TOOLKIT_PATH=""
462done
463
464export TF_NEED_OPENCL
465# end of if "$TF_NEED_OPENCL" == "1"
466fi
467
Jonathan Hseu1283b842016-09-29 15:05:32 -0800468bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800469
470echo "Configuration finished"