blob: 753841d166a0313fb7998d0c17bebcf0524d3ac8 [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
Martin Wickec4e3d4a2017-01-13 12:20:42 -080057## Set up architecture-dependent optimization flags.
58if [ -z "$CC_OPT_FLAGS" ]; then
59 default_cc_opt_flags="-march=native"
60 read -p "Please specify optimization flags to use during compilation [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
61 if [ -z "$CC_OPT_FLAGS" ]; then
62 CC_OPT_FLAGS=$default_cc_opt_flags
63 fi
64fi
65
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080066if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080067 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080068 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080069 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -080070 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080071fi
72
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080073while [ "$TF_NEED_JEMALLOC" == "" ]; do
74 read -p "Do you wish to use jemalloc as the malloc implementation? "\
75"(Linux only) [Y/n] " INPUT
76 case $INPUT in
77 [Yy]* ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
78 [Nn]* ) echo "jemalloc disabled on Linux"; TF_NEED_JEMALLOC=0;;
79 "" ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
80 * ) echo "Invalid selection: " $INPUT;;
81 esac
82done
83
84if [ "$TF_NEED_JEMALLOC" == "1" ]; then
85 sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
86else
87 sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
88fi
89
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080090while [ "$TF_NEED_GCP" == "" ]; do
91 read -p "Do you wish to build TensorFlow with "\
92"Google Cloud Platform support? [y/N] " INPUT
93 case $INPUT in
94 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
95"TensorFlow"; TF_NEED_GCP=1;;
96 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
97"TensorFlow"; TF_NEED_GCP=0;;
98 "" ) echo "No Google Cloud Platform support will be enabled for "\
99"TensorFlow"; TF_NEED_GCP=0;;
100 * ) echo "Invalid selection: " $INPUT;;
101 esac
102done
103
104if [ "$TF_NEED_GCP" == "1" ]; then
105 ## Verify that libcurl header files are available.
106 # Only check Linux, since on MacOS the header files are installed with XCode.
107 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
108 echo "ERROR: It appears that the development version of libcurl is not "\
109"available. Please install the libcurl3-dev package."
110 exit 1
111 fi
112
113 # Update Bazel build configuration.
114 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
115else
116 # Update Bazel build configuration.
117 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
118fi
119
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800120while [ "$TF_NEED_HDFS" == "" ]; do
121 read -p "Do you wish to build TensorFlow with "\
122"Hadoop File System support? [y/N] " INPUT
123 case $INPUT in
124 [Yy]* ) echo "Hadoop File System support will be enabled for "\
125"TensorFlow"; TF_NEED_HDFS=1;;
126 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
127"TensorFlow"; TF_NEED_HDFS=0;;
128 "" ) echo "No Hadoop File System support will be enabled for "\
129"TensorFlow"; TF_NEED_HDFS=0;;
130 * ) echo "Invalid selection: " $INPUT;;
131 esac
132done
133
134if [ "$TF_NEED_HDFS" == "1" ]; then
135 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800136 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 -0800137else
138 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800139 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 -0800140fi
141
Peter Hawkins1e67c902017-01-09 12:04:37 -0800142## Enable XLA.
143while [ "$TF_ENABLE_XLA" == "" ]; do
144 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
145 case $INPUT in
146 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
147 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
148 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
149 * ) echo "Invalid selection: " $INPUT;;
150 esac
151done
152
153if [ "$TF_ENABLE_XLA" == "1" ]; then
154 # Update Bazel build configuration.
155 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
156else
157 # Update Bazel build configuration.
158 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
159fi
160
161
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800162# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800163./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800164
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800165# Append CC optimization flags to bazel.rc
166echo >> tools/bazel.rc
167for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800168 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800169done
170
Andrew Selle09045e42016-09-06 08:19:04 -0800171# Run the gen_git_source to create links where bazel can track dependencies for
172# git hash propagation
173GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
174chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800175"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800176
Benoit Steinera7715982016-11-09 13:14:03 -0800177## Set up SYCL-related environment settings
178while [ "$TF_NEED_OPENCL" == "" ]; do
179 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
180 case $INPUT in
181 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
182 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
183 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
184 * ) echo "Invalid selection: " $INPUT;;
185 esac
186done
187
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800188## Set up Cuda-related environment settings
189
190while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800191 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800192 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800193 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
194 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
195 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800196 * ) echo "Invalid selection: " $INPUT;;
197 esac
198done
199
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800200export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800201export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800202if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800203 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800204 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800205 exit
206fi
207
Benoit Steinera7715982016-11-09 13:14:03 -0800208if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800209# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800210# No need to set this on Windows
211while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800212 fromuser=""
213 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800214 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800215 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 -0800216 fromuser="1"
217 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800218 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800219 fi
220 fi
221 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800222 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800223 break
224 fi
225 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
226 if [ -z "$fromuser" ]; then
227 exit 1
228 fi
229 GCC_HOST_COMPILER_PATH=""
230 # Retry
231done
232
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800233# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800234OSNAME=`uname -s`
235
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800236while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800237 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800238 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800239 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 -0800240 fi
241
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800242 fromuser=""
243 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
244 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800245 if is_windows; then
246 if [ -z "$CUDA_PATH" ]; then
247 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
248 else
249 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
250 fi
251 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800252 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 -0800253 fromuser="1"
254 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800255 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800256 fi
257 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800258
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800259 if [[ -z "$TF_CUDA_VERSION" ]]; then
260 TF_CUDA_EXT=""
261 else
262 TF_CUDA_EXT=".$TF_CUDA_VERSION"
263 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800264
Andrew Harp1cb96892016-12-08 20:05:49 -0800265 if is_windows; then
266 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
267 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800268 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
269 elif [ "$OSNAME" == "Darwin" ]; then
270 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
271 fi
272
273 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800274 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800275 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800276 break
277 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800278 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
279
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800280 if [ -z "$fromuser" ]; then
281 exit 1
282 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800283 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800284 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800285 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800286done
287
Martin Wicke916776a2016-01-14 07:30:00 -0800288# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800289while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800290 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800291 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800292 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 -0800293 fi
294
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800295 fromuser=""
296 if [ -z "$CUDNN_INSTALL_PATH" ]; then
297 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800298 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 -0800299 fromuser="1"
300 if [ -z "$CUDNN_INSTALL_PATH" ]; then
301 CUDNN_INSTALL_PATH=$default_cudnn_path
302 fi
303 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
304 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800305 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 -0800306 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800307
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800308 if [[ -z "$TF_CUDNN_VERSION" ]]; then
309 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800310 cudnn_lib_path=""
311 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800312 if is_windows; then
313 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
314 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
315 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800316 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
317 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
318 elif [ "$OSNAME" == "Darwin" ]; then
319 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
320 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
321 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800322 # Resolve to the SONAME of the symlink. Use readlink without -f
323 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800324 # libcudnn.so.4.
325 # If the path is not a symlink, readlink will exit with an error code, so
326 # in that case, we return the path itself.
327 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800328 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800329 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800330 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800331 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800332
333 # Extract the version of the SONAME, if it was indeed symlinked to
334 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800335 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800336 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
337 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
338 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800339 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800340 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800341 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
342 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800343 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800344 else
Shanqing Caiefd40e52017-01-08 20:31:30 -0800345 if [ "$OSNAME" == "Darwin" ]; then
346 TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
347 else
348 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
349 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800350 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800351
Andrew Harp1cb96892016-12-08 20:05:49 -0800352 if is_windows; then
353 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
354 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
355 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800356 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
357 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
358 elif [ "$OSNAME" == "Darwin" ]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800359 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
360 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800361 fi
362
363 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 -0800364 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800365 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800366 break
367 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800368
369 if [ "$OSNAME" == "Linux" ]; then
370 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
371 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800372 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800373 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800374 break
375 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800376 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800377 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
378 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
379 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
380 if [ "$OSNAME" == "Linux" ]; then
381 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
382 fi
383
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800384 if [ -z "$fromuser" ]; then
385 exit 1
386 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800387 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800388 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800389 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800390done
391
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800392# Configure the compute capabilities that TensorFlow builds for.
393# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
394while true; do
395 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800396 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800397 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800398cat << EOF
399Please specify a list of comma-separated Cuda compute capabilities you want to build with.
400You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
401Please note that each additional compute capability significantly increases your build time and binary size.
402EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800403 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
404 fromuser=1
405 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800406 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
407 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
408 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800409 # Check whether all capabilities from the input is valid
410 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
411 ALL_VALID=1
412 for CAPABILITY in $COMPUTE_CAPABILITIES; do
413 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
414 echo "Invalid compute capability: " $CAPABILITY
415 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800416 break
417 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800418 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800419 if [ "$ALL_VALID" == "0" ]; then
420 if [ -z "$fromuser" ]; then
421 exit 1
422 fi
423 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800424 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800425 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800426 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800427 TF_CUDA_COMPUTE_CAPABILITIES=""
428done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800429
Andrew Harp1cb96892016-12-08 20:05:49 -0800430if is_windows; then
431 # The following three variables are needed for MSVC toolchain configuration in Bazel
432 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
433 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
434 export NO_WHOLE_ARCHIVE_OPTION=1
435
436 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
437 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
438fi
439
Benoit Steinera7715982016-11-09 13:14:03 -0800440# end of if "$TF_NEED_CUDA" == "1"
441fi
442
443# OpenCL configuration
444
445if [ "$TF_NEED_OPENCL" == "1" ]; then
446
447# Determine which C++ compiler should be used as the host compiler
448while true; do
449 fromuser=""
450 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800451 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800452 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
453 fromuser="1"
454 if [ -z "$HOST_CXX_COMPILER" ]; then
455 HOST_CXX_COMPILER=$default_cxx_host_compiler
456 fi
457 fi
458 if [ -e "$HOST_CXX_COMPILER" ]; then
459 export HOST_CXX_COMPILER
460 break
461 fi
462 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
463 if [ -z "$fromuser" ]; then
464 exit 1
465 fi
466 HOST_CXX_COMPILER=""
467 # Retry
468done
469
470# Determine which C compiler should be used as the host compiler
471while true; do
472 fromuser=""
473 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800474 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800475 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
476 fromuser="1"
477 if [ -z "$HOST_C_COMPILER" ]; then
478 HOST_C_COMPILER=$default_c_host_compiler
479 fi
480 fi
481 if [ -e "$HOST_C_COMPILER" ]; then
482 export HOST_C_COMPILER
483 break
484 fi
485 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
486 if [ -z "$fromuser" ]; then
487 exit 1
488 fi
489 HOST_C_COMPILER=""
490 # Retry
491done
492
493while true; do
494 # Configure the OPENCL version to use.
495 TF_OPENCL_VERSION="1.2"
496
497 # Point to ComputeCpp root
498 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
499 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800500 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 -0800501 fromuser="1"
502 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
503 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
504 fi
505 fi
506
507 if [ "$OSNAME" == "Linux" ]; then
508 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
509 fi
510
511 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
512 export COMPUTECPP_TOOLKIT_PATH
513 break
514 fi
515 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
516
517 if [ -z "$fromuser" ]; then
518 exit 1
519 fi
520 # Retry
521 TF_OPENCL_VERSION=""
522 COMPUTECPP_TOOLKIT_PATH=""
523done
524
Benoit Steinera7715982016-11-09 13:14:03 -0800525# end of if "$TF_NEED_OPENCL" == "1"
526fi
527
Jonathan Hseu1283b842016-09-29 15:05:32 -0800528bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800529
530echo "Configuration finished"