blob: c755ee1b7525426fb3888b593f6b9f7cacd060b5 [file] [log] [blame]
Geoffrey Irving4c85a082016-03-16 12:20:34 -08001#!/usr/bin/env bash
Manjunath Kudlurf41959c2015-11-06 16:27:58 -08002
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -08003set -e
4set -o pipefail
5
Andrew Selle09045e42016-09-06 08:19:04 -08006# Find out the absolute path to where ./configure resides
A. Unique TensorFlower46d2c282017-01-02 22:19:48 -08007pushd `dirname $0` > /dev/null
Andrew Selle09045e42016-09-06 08:19:04 -08008SOURCE_BASE_DIR=`pwd -P`
9popd > /dev/null
10
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080011PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
Jonathan Hseuc058a012017-01-17 15:06:43 -080012
13function is_linux() {
14 if [[ "${PLATFORM}" == "linux" ]]; then
15 true
16 else
17 false
18 fi
19}
20
21function is_macos() {
22 if [[ "${PLATFORM}" == "darwin" ]]; then
23 true
24 else
25 false
26 fi
27}
28
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080029function is_windows() {
30 # On windows, the shell script is actually running in msys
31 if [[ "${PLATFORM}" =~ msys_nt* ]]; then
32 true
33 else
34 false
35 fi
36}
37
Jonathan Hseu1283b842016-09-29 15:05:32 -080038function bazel_clean_and_fetch() {
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080039 # bazel clean --expunge currently doesn't work on Windows
40 # TODO(pcloudy): Re-enable it after bazel clean --expunge is fixed.
41 if ! is_windows; then
42 bazel clean --expunge
43 fi
Patrick Nguyendb249412017-01-17 10:57:25 -080044 bazel fetch "//tensorflow/... -//tensorflow/examples/android/..."
Jonathan Hseu1283b842016-09-29 15:05:32 -080045}
46
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080047## Set up python-related environment settings
48while true; do
49 fromuser=""
50 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080051 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080052 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
53 fromuser="1"
54 if [ -z "$PYTHON_BIN_PATH" ]; then
55 PYTHON_BIN_PATH=$default_python_bin_path
56 fi
57 fi
58 if [ -e "$PYTHON_BIN_PATH" ]; then
59 break
60 fi
61 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
62 if [ -z "$fromuser" ]; then
63 exit 1
64 fi
65 PYTHON_BIN_PATH=""
66 # Retry
67done
68
Martin Wickec4e3d4a2017-01-13 12:20:42 -080069## Set up architecture-dependent optimization flags.
70if [ -z "$CC_OPT_FLAGS" ]; then
71 default_cc_opt_flags="-march=native"
72 read -p "Please specify optimization flags to use during compilation [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
73 if [ -z "$CC_OPT_FLAGS" ]; then
74 CC_OPT_FLAGS=$default_cc_opt_flags
75 fi
76fi
77
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080078if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080079 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080080 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080081 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -080082 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080083fi
84
Jonathan Hseuc058a012017-01-17 15:06:43 -080085if is_linux; then
86 while [ "$TF_NEED_JEMALLOC" == "" ]; do
87 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
88 INPUT
89 case $INPUT in
90 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
91 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
92 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
93 * ) echo "Invalid selection: " $INPUT;;
94 esac
95 done
96else
97 TF_NEED_JEMALLOC=0
98fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080099
100if [ "$TF_NEED_JEMALLOC" == "1" ]; then
101 sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
102else
103 sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
104fi
105
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800106while [ "$TF_NEED_GCP" == "" ]; do
107 read -p "Do you wish to build TensorFlow with "\
108"Google Cloud Platform support? [y/N] " INPUT
109 case $INPUT in
110 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
111"TensorFlow"; TF_NEED_GCP=1;;
112 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
113"TensorFlow"; TF_NEED_GCP=0;;
114 "" ) echo "No Google Cloud Platform support will be enabled for "\
115"TensorFlow"; TF_NEED_GCP=0;;
116 * ) echo "Invalid selection: " $INPUT;;
117 esac
118done
119
120if [ "$TF_NEED_GCP" == "1" ]; then
121 ## Verify that libcurl header files are available.
122 # Only check Linux, since on MacOS the header files are installed with XCode.
Jonathan Hseuc058a012017-01-17 15:06:43 -0800123 if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800124 echo "ERROR: It appears that the development version of libcurl is not "\
125"available. Please install the libcurl3-dev package."
126 exit 1
127 fi
128
129 # Update Bazel build configuration.
130 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
131else
132 # Update Bazel build configuration.
133 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
134fi
135
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800136while [ "$TF_NEED_HDFS" == "" ]; do
137 read -p "Do you wish to build TensorFlow with "\
138"Hadoop File System support? [y/N] " INPUT
139 case $INPUT in
140 [Yy]* ) echo "Hadoop File System support will be enabled for "\
141"TensorFlow"; TF_NEED_HDFS=1;;
142 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
143"TensorFlow"; TF_NEED_HDFS=0;;
144 "" ) echo "No Hadoop File System support will be enabled for "\
145"TensorFlow"; TF_NEED_HDFS=0;;
146 * ) echo "Invalid selection: " $INPUT;;
147 esac
148done
149
150if [ "$TF_NEED_HDFS" == "1" ]; then
151 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800152 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 -0800153else
154 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800155 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 -0800156fi
157
Peter Hawkins1e67c902017-01-09 12:04:37 -0800158## Enable XLA.
159while [ "$TF_ENABLE_XLA" == "" ]; do
160 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
161 case $INPUT in
162 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
163 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
164 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
165 * ) echo "Invalid selection: " $INPUT;;
166 esac
167done
168
169if [ "$TF_ENABLE_XLA" == "1" ]; then
170 # Update Bazel build configuration.
171 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
172else
173 # Update Bazel build configuration.
174 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
175fi
176
177
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800178# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800179./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800180
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800181# Append CC optimization flags to bazel.rc
182echo >> tools/bazel.rc
183for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800184 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800185done
186
Andrew Selle09045e42016-09-06 08:19:04 -0800187# Run the gen_git_source to create links where bazel can track dependencies for
188# git hash propagation
189GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
190chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800191"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800192
Benoit Steinera7715982016-11-09 13:14:03 -0800193## Set up SYCL-related environment settings
194while [ "$TF_NEED_OPENCL" == "" ]; do
195 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
196 case $INPUT in
197 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
198 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
199 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
200 * ) echo "Invalid selection: " $INPUT;;
201 esac
202done
203
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800204## Set up Cuda-related environment settings
205
206while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800207 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800208 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800209 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
210 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
211 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800212 * ) echo "Invalid selection: " $INPUT;;
213 esac
214done
215
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800216export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800217export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800218if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800219 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800220 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800221 exit
222fi
223
Benoit Steinera7715982016-11-09 13:14:03 -0800224if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800225# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800226# No need to set this on Windows
227while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800228 fromuser=""
229 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800230 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800231 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 -0800232 fromuser="1"
233 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800234 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800235 fi
236 fi
237 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800238 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800239 break
240 fi
241 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
242 if [ -z "$fromuser" ]; then
243 exit 1
244 fi
245 GCC_HOST_COMPILER_PATH=""
246 # Retry
247done
248
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800249# Find out where the CUDA toolkit is installed
250while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800251 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800252 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800253 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 -0800254 fi
255
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800256 fromuser=""
257 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
258 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800259 if is_windows; then
260 if [ -z "$CUDA_PATH" ]; then
261 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
262 else
263 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
264 fi
265 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800266 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 -0800267 fromuser="1"
268 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800269 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800270 fi
271 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800272
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800273 if [[ -z "$TF_CUDA_VERSION" ]]; then
274 TF_CUDA_EXT=""
275 else
276 TF_CUDA_EXT=".$TF_CUDA_VERSION"
277 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800278
Andrew Harp1cb96892016-12-08 20:05:49 -0800279 if is_windows; then
280 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800281 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800282 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800283 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800284 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
285 fi
286
287 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800288 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800289 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800290 break
291 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800292 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
293
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800294 if [ -z "$fromuser" ]; then
295 exit 1
296 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800297 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800298 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800299 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800300done
301
Martin Wicke916776a2016-01-14 07:30:00 -0800302# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800303while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800304 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800305 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800306 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 -0800307 fi
308
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800309 fromuser=""
310 if [ -z "$CUDNN_INSTALL_PATH" ]; then
311 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800312 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 -0800313 fromuser="1"
314 if [ -z "$CUDNN_INSTALL_PATH" ]; then
315 CUDNN_INSTALL_PATH=$default_cudnn_path
316 fi
317 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
318 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800319 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 -0800320 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800321
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800322 if [[ -z "$TF_CUDNN_VERSION" ]]; then
323 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800324 cudnn_lib_path=""
325 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800326 if is_windows; then
327 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
328 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800329 elif is_linux; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800330 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
331 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800332 elif is_macos; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800333 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
334 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
335 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800336 # Resolve to the SONAME of the symlink. Use readlink without -f
337 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800338 # libcudnn.so.4.
339 # If the path is not a symlink, readlink will exit with an error code, so
340 # in that case, we return the path itself.
341 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800342 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800343 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800344 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800345 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800346
347 # Extract the version of the SONAME, if it was indeed symlinked to
348 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800349 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800350 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
351 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
352 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800353 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800354 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800355 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
356 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800357 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800358 else
Jonathan Hseuc058a012017-01-17 15:06:43 -0800359 if is_macos; then
Shanqing Caiefd40e52017-01-08 20:31:30 -0800360 TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
361 else
362 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
363 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800364 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800365
Andrew Harp1cb96892016-12-08 20:05:49 -0800366 if is_windows; then
367 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
368 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800369 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800370 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
371 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800372 elif is_macos; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800373 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
374 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800375 fi
376
377 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 -0800378 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800379 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800380 break
381 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800382
Jonathan Hseuc058a012017-01-17 15:06:43 -0800383 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800384 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
385 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800386 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800387 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800388 break
389 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800390 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800391 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
392 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
393 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800394 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800395 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
396 fi
397
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800398 if [ -z "$fromuser" ]; then
399 exit 1
400 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800401 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800402 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800403 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800404done
405
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800406# Configure the compute capabilities that TensorFlow builds for.
407# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
408while true; do
409 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800410 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800411 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800412cat << EOF
413Please specify a list of comma-separated Cuda compute capabilities you want to build with.
414You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
415Please note that each additional compute capability significantly increases your build time and binary size.
416EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800417 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
418 fromuser=1
419 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800420 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
421 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
422 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800423 # Check whether all capabilities from the input is valid
424 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
425 ALL_VALID=1
426 for CAPABILITY in $COMPUTE_CAPABILITIES; do
427 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
428 echo "Invalid compute capability: " $CAPABILITY
429 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800430 break
431 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800432 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800433 if [ "$ALL_VALID" == "0" ]; then
434 if [ -z "$fromuser" ]; then
435 exit 1
436 fi
437 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800438 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800439 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800440 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800441 TF_CUDA_COMPUTE_CAPABILITIES=""
442done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800443
Andrew Harp1cb96892016-12-08 20:05:49 -0800444if is_windows; then
445 # The following three variables are needed for MSVC toolchain configuration in Bazel
446 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
447 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
448 export NO_WHOLE_ARCHIVE_OPTION=1
449
450 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
451 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
452fi
453
Benoit Steinera7715982016-11-09 13:14:03 -0800454# end of if "$TF_NEED_CUDA" == "1"
455fi
456
457# OpenCL configuration
458
459if [ "$TF_NEED_OPENCL" == "1" ]; then
460
461# Determine which C++ compiler should be used as the host compiler
462while true; do
463 fromuser=""
464 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800465 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800466 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
467 fromuser="1"
468 if [ -z "$HOST_CXX_COMPILER" ]; then
469 HOST_CXX_COMPILER=$default_cxx_host_compiler
470 fi
471 fi
472 if [ -e "$HOST_CXX_COMPILER" ]; then
473 export HOST_CXX_COMPILER
474 break
475 fi
476 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
477 if [ -z "$fromuser" ]; then
478 exit 1
479 fi
480 HOST_CXX_COMPILER=""
481 # Retry
482done
483
484# Determine which C compiler should be used as the host compiler
485while true; do
486 fromuser=""
487 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800488 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800489 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
490 fromuser="1"
491 if [ -z "$HOST_C_COMPILER" ]; then
492 HOST_C_COMPILER=$default_c_host_compiler
493 fi
494 fi
495 if [ -e "$HOST_C_COMPILER" ]; then
496 export HOST_C_COMPILER
497 break
498 fi
499 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
500 if [ -z "$fromuser" ]; then
501 exit 1
502 fi
503 HOST_C_COMPILER=""
504 # Retry
505done
506
507while true; do
508 # Configure the OPENCL version to use.
509 TF_OPENCL_VERSION="1.2"
510
511 # Point to ComputeCpp root
512 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
513 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800514 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 -0800515 fromuser="1"
516 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
517 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
518 fi
519 fi
520
Jonathan Hseuc058a012017-01-17 15:06:43 -0800521 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800522 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
523 fi
524
525 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
526 export COMPUTECPP_TOOLKIT_PATH
527 break
528 fi
529 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
530
531 if [ -z "$fromuser" ]; then
532 exit 1
533 fi
534 # Retry
535 TF_OPENCL_VERSION=""
536 COMPUTECPP_TOOLKIT_PATH=""
537done
538
Benoit Steinera7715982016-11-09 13:14:03 -0800539# end of if "$TF_NEED_OPENCL" == "1"
540fi
541
Jonathan Hseu1283b842016-09-29 15:05:32 -0800542bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800543
544echo "Configuration finished"