blob: 87ef6e99be3f452581248577125327961c0bd46c [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
26 fi
Patrick Nguyendb249412017-01-17 10:57:25 -080027 bazel fetch "//tensorflow/... -//tensorflow/examples/android/..."
Jonathan Hseu1283b842016-09-29 15:05:32 -080028}
29
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080030## Set up python-related environment settings
31while true; do
32 fromuser=""
33 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080034 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080035 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
36 fromuser="1"
37 if [ -z "$PYTHON_BIN_PATH" ]; then
38 PYTHON_BIN_PATH=$default_python_bin_path
39 fi
40 fi
41 if [ -e "$PYTHON_BIN_PATH" ]; then
42 break
43 fi
44 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
45 if [ -z "$fromuser" ]; then
46 exit 1
47 fi
48 PYTHON_BIN_PATH=""
49 # Retry
50done
51
Martin Wickec4e3d4a2017-01-13 12:20:42 -080052## Set up architecture-dependent optimization flags.
53if [ -z "$CC_OPT_FLAGS" ]; then
54 default_cc_opt_flags="-march=native"
55 read -p "Please specify optimization flags to use during compilation [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
56 if [ -z "$CC_OPT_FLAGS" ]; then
57 CC_OPT_FLAGS=$default_cc_opt_flags
58 fi
59fi
60
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080061if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080062 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080063 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080064 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -080065 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080066fi
67
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080068while [ "$TF_NEED_JEMALLOC" == "" ]; do
69 read -p "Do you wish to use jemalloc as the malloc implementation? "\
70"(Linux only) [Y/n] " INPUT
71 case $INPUT in
72 [Yy]* ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
73 [Nn]* ) echo "jemalloc disabled on Linux"; TF_NEED_JEMALLOC=0;;
74 "" ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
75 * ) echo "Invalid selection: " $INPUT;;
76 esac
77done
78
79if [ "$TF_NEED_JEMALLOC" == "1" ]; then
80 sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
81else
82 sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
83fi
84
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080085while [ "$TF_NEED_GCP" == "" ]; do
86 read -p "Do you wish to build TensorFlow with "\
87"Google Cloud Platform support? [y/N] " INPUT
88 case $INPUT in
89 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
90"TensorFlow"; TF_NEED_GCP=1;;
91 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
92"TensorFlow"; TF_NEED_GCP=0;;
93 "" ) echo "No Google Cloud Platform support will be enabled for "\
94"TensorFlow"; TF_NEED_GCP=0;;
95 * ) echo "Invalid selection: " $INPUT;;
96 esac
97done
98
99if [ "$TF_NEED_GCP" == "1" ]; then
100 ## Verify that libcurl header files are available.
101 # Only check Linux, since on MacOS the header files are installed with XCode.
102 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
103 echo "ERROR: It appears that the development version of libcurl is not "\
104"available. Please install the libcurl3-dev package."
105 exit 1
106 fi
107
108 # Update Bazel build configuration.
109 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
110else
111 # Update Bazel build configuration.
112 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
113fi
114
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800115while [ "$TF_NEED_HDFS" == "" ]; do
116 read -p "Do you wish to build TensorFlow with "\
117"Hadoop File System support? [y/N] " INPUT
118 case $INPUT in
119 [Yy]* ) echo "Hadoop File System support will be enabled for "\
120"TensorFlow"; TF_NEED_HDFS=1;;
121 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
122"TensorFlow"; TF_NEED_HDFS=0;;
123 "" ) echo "No Hadoop File System support will be enabled for "\
124"TensorFlow"; TF_NEED_HDFS=0;;
125 * ) echo "Invalid selection: " $INPUT;;
126 esac
127done
128
129if [ "$TF_NEED_HDFS" == "1" ]; then
130 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800131 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 -0800132else
133 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800134 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 -0800135fi
136
Peter Hawkins1e67c902017-01-09 12:04:37 -0800137## Enable XLA.
138while [ "$TF_ENABLE_XLA" == "" ]; do
139 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
140 case $INPUT in
141 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
142 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
143 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
144 * ) echo "Invalid selection: " $INPUT;;
145 esac
146done
147
148if [ "$TF_ENABLE_XLA" == "1" ]; then
149 # Update Bazel build configuration.
150 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
151else
152 # Update Bazel build configuration.
153 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
154fi
155
156
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800157# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800158./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800159
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800160# Append CC optimization flags to bazel.rc
161echo >> tools/bazel.rc
162for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800163 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800164done
165
Andrew Selle09045e42016-09-06 08:19:04 -0800166# Run the gen_git_source to create links where bazel can track dependencies for
167# git hash propagation
168GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
169chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800170"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800171
Benoit Steinera7715982016-11-09 13:14:03 -0800172## Set up SYCL-related environment settings
173while [ "$TF_NEED_OPENCL" == "" ]; do
174 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
175 case $INPUT in
176 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
177 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
178 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
179 * ) echo "Invalid selection: " $INPUT;;
180 esac
181done
182
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800183## Set up Cuda-related environment settings
184
185while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800186 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800187 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800188 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
189 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
190 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800191 * ) echo "Invalid selection: " $INPUT;;
192 esac
193done
194
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800195export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800196export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800197if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800198 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800199 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800200 exit
201fi
202
Benoit Steinera7715982016-11-09 13:14:03 -0800203if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800204# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800205# No need to set this on Windows
206while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800207 fromuser=""
208 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800209 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800210 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 -0800211 fromuser="1"
212 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800213 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800214 fi
215 fi
216 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800217 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800218 break
219 fi
220 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
221 if [ -z "$fromuser" ]; then
222 exit 1
223 fi
224 GCC_HOST_COMPILER_PATH=""
225 # Retry
226done
227
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800228# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800229OSNAME=`uname -s`
230
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800231while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800232 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800233 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800234 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 -0800235 fi
236
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800237 fromuser=""
238 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
239 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800240 if is_windows; then
241 if [ -z "$CUDA_PATH" ]; then
242 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
243 else
244 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
245 fi
246 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800247 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 -0800248 fromuser="1"
249 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800250 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800251 fi
252 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800253
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800254 if [[ -z "$TF_CUDA_VERSION" ]]; then
255 TF_CUDA_EXT=""
256 else
257 TF_CUDA_EXT=".$TF_CUDA_VERSION"
258 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800259
Andrew Harp1cb96892016-12-08 20:05:49 -0800260 if is_windows; then
261 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
262 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800263 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
264 elif [ "$OSNAME" == "Darwin" ]; then
265 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
266 fi
267
268 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800269 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800270 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800271 break
272 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800273 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
274
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800275 if [ -z "$fromuser" ]; then
276 exit 1
277 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800278 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800279 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800280 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800281done
282
Martin Wicke916776a2016-01-14 07:30:00 -0800283# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800284while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800285 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800286 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800287 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 -0800288 fi
289
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800290 fromuser=""
291 if [ -z "$CUDNN_INSTALL_PATH" ]; then
292 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800293 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 -0800294 fromuser="1"
295 if [ -z "$CUDNN_INSTALL_PATH" ]; then
296 CUDNN_INSTALL_PATH=$default_cudnn_path
297 fi
298 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
299 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800300 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 -0800301 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800302
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800303 if [[ -z "$TF_CUDNN_VERSION" ]]; then
304 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800305 cudnn_lib_path=""
306 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800307 if is_windows; then
308 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
309 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
310 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800311 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
312 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
313 elif [ "$OSNAME" == "Darwin" ]; then
314 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
315 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
316 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800317 # Resolve to the SONAME of the symlink. Use readlink without -f
318 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800319 # libcudnn.so.4.
320 # If the path is not a symlink, readlink will exit with an error code, so
321 # in that case, we return the path itself.
322 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800323 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800324 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800325 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800326 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800327
328 # Extract the version of the SONAME, if it was indeed symlinked to
329 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800330 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800331 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
332 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
333 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800334 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800335 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800336 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
337 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800338 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800339 else
Shanqing Caiefd40e52017-01-08 20:31:30 -0800340 if [ "$OSNAME" == "Darwin" ]; then
341 TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
342 else
343 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
344 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800345 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800346
Andrew Harp1cb96892016-12-08 20:05:49 -0800347 if is_windows; then
348 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
349 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
350 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800351 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
352 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
353 elif [ "$OSNAME" == "Darwin" ]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800354 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
355 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800356 fi
357
358 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 -0800359 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800360 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800361 break
362 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800363
364 if [ "$OSNAME" == "Linux" ]; then
365 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
366 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800367 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800368 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800369 break
370 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800371 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800372 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
373 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
374 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
375 if [ "$OSNAME" == "Linux" ]; then
376 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
377 fi
378
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800379 if [ -z "$fromuser" ]; then
380 exit 1
381 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800382 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800383 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800384 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800385done
386
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800387# Configure the compute capabilities that TensorFlow builds for.
388# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
389while true; do
390 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800391 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800392 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800393cat << EOF
394Please specify a list of comma-separated Cuda compute capabilities you want to build with.
395You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
396Please note that each additional compute capability significantly increases your build time and binary size.
397EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800398 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
399 fromuser=1
400 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800401 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
402 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
403 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800404 # Check whether all capabilities from the input is valid
405 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
406 ALL_VALID=1
407 for CAPABILITY in $COMPUTE_CAPABILITIES; do
408 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
409 echo "Invalid compute capability: " $CAPABILITY
410 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800411 break
412 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800413 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800414 if [ "$ALL_VALID" == "0" ]; then
415 if [ -z "$fromuser" ]; then
416 exit 1
417 fi
418 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800419 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800420 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800421 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800422 TF_CUDA_COMPUTE_CAPABILITIES=""
423done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800424
Andrew Harp1cb96892016-12-08 20:05:49 -0800425if is_windows; then
426 # The following three variables are needed for MSVC toolchain configuration in Bazel
427 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
428 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
429 export NO_WHOLE_ARCHIVE_OPTION=1
430
431 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
432 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
433fi
434
Benoit Steinera7715982016-11-09 13:14:03 -0800435# end of if "$TF_NEED_CUDA" == "1"
436fi
437
438# OpenCL configuration
439
440if [ "$TF_NEED_OPENCL" == "1" ]; then
441
442# Determine which C++ compiler should be used as the host compiler
443while true; do
444 fromuser=""
445 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800446 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800447 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
448 fromuser="1"
449 if [ -z "$HOST_CXX_COMPILER" ]; then
450 HOST_CXX_COMPILER=$default_cxx_host_compiler
451 fi
452 fi
453 if [ -e "$HOST_CXX_COMPILER" ]; then
454 export HOST_CXX_COMPILER
455 break
456 fi
457 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
458 if [ -z "$fromuser" ]; then
459 exit 1
460 fi
461 HOST_CXX_COMPILER=""
462 # Retry
463done
464
465# Determine which C compiler should be used as the host compiler
466while true; do
467 fromuser=""
468 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800469 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800470 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
471 fromuser="1"
472 if [ -z "$HOST_C_COMPILER" ]; then
473 HOST_C_COMPILER=$default_c_host_compiler
474 fi
475 fi
476 if [ -e "$HOST_C_COMPILER" ]; then
477 export HOST_C_COMPILER
478 break
479 fi
480 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
481 if [ -z "$fromuser" ]; then
482 exit 1
483 fi
484 HOST_C_COMPILER=""
485 # Retry
486done
487
488while true; do
489 # Configure the OPENCL version to use.
490 TF_OPENCL_VERSION="1.2"
491
492 # Point to ComputeCpp root
493 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
494 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800495 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 -0800496 fromuser="1"
497 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
498 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
499 fi
500 fi
501
502 if [ "$OSNAME" == "Linux" ]; then
503 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
504 fi
505
506 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
507 export COMPUTECPP_TOOLKIT_PATH
508 break
509 fi
510 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
511
512 if [ -z "$fromuser" ]; then
513 exit 1
514 fi
515 # Retry
516 TF_OPENCL_VERSION=""
517 COMPUTECPP_TOOLKIT_PATH=""
518done
519
Benoit Steinera7715982016-11-09 13:14:03 -0800520# end of if "$TF_NEED_OPENCL" == "1"
521fi
522
Jonathan Hseu1283b842016-09-29 15:05:32 -0800523bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800524
525echo "Configuration finished"