blob: 6cd5c2f3dbf7051e1a078740f1e1874136463fa9 [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
Shanqing Cai56fc8832017-01-23 18:25:25 -080031 if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080032 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
Andrew Harp51dbc462017-01-27 14:42:30 -080047# Delete any leftover BUILD files from the Makefile build, which would interfere
48# with Bazel parsing.
49MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
50if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
51 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
52fi
53
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080054## Set up python-related environment settings
55while true; do
56 fromuser=""
57 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080058 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080059 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
60 fromuser="1"
61 if [ -z "$PYTHON_BIN_PATH" ]; then
62 PYTHON_BIN_PATH=$default_python_bin_path
63 fi
64 fi
65 if [ -e "$PYTHON_BIN_PATH" ]; then
66 break
67 fi
68 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
69 if [ -z "$fromuser" ]; then
70 exit 1
71 fi
72 PYTHON_BIN_PATH=""
73 # Retry
74done
75
Martin Wickec4e3d4a2017-01-13 12:20:42 -080076## Set up architecture-dependent optimization flags.
77if [ -z "$CC_OPT_FLAGS" ]; then
78 default_cc_opt_flags="-march=native"
79 read -p "Please specify optimization flags to use during compilation [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
80 if [ -z "$CC_OPT_FLAGS" ]; then
81 CC_OPT_FLAGS=$default_cc_opt_flags
82 fi
83fi
84
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080085if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080086 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080087 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080088 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -080089 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080090fi
91
Jonathan Hseuc058a012017-01-17 15:06:43 -080092if is_linux; then
93 while [ "$TF_NEED_JEMALLOC" == "" ]; do
94 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
95 INPUT
96 case $INPUT in
97 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
98 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
99 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
100 * ) echo "Invalid selection: " $INPUT;;
101 esac
102 done
103else
104 TF_NEED_JEMALLOC=0
105fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800106
107if [ "$TF_NEED_JEMALLOC" == "1" ]; then
108 sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
109else
110 sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
111fi
112
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800113while [ "$TF_NEED_GCP" == "" ]; do
114 read -p "Do you wish to build TensorFlow with "\
115"Google Cloud Platform support? [y/N] " INPUT
116 case $INPUT in
117 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
118"TensorFlow"; TF_NEED_GCP=1;;
119 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
120"TensorFlow"; TF_NEED_GCP=0;;
121 "" ) echo "No Google Cloud Platform support will be enabled for "\
122"TensorFlow"; TF_NEED_GCP=0;;
123 * ) echo "Invalid selection: " $INPUT;;
124 esac
125done
126
127if [ "$TF_NEED_GCP" == "1" ]; then
128 ## Verify that libcurl header files are available.
129 # Only check Linux, since on MacOS the header files are installed with XCode.
Jonathan Hseuc058a012017-01-17 15:06:43 -0800130 if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800131 echo "ERROR: It appears that the development version of libcurl is not "\
132"available. Please install the libcurl3-dev package."
133 exit 1
134 fi
135
136 # Update Bazel build configuration.
137 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
138else
139 # Update Bazel build configuration.
140 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
141fi
142
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800143while [ "$TF_NEED_HDFS" == "" ]; do
144 read -p "Do you wish to build TensorFlow with "\
145"Hadoop File System support? [y/N] " INPUT
146 case $INPUT in
147 [Yy]* ) echo "Hadoop File System support will be enabled for "\
148"TensorFlow"; TF_NEED_HDFS=1;;
149 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
150"TensorFlow"; TF_NEED_HDFS=0;;
151 "" ) echo "No Hadoop File System support will be enabled for "\
152"TensorFlow"; TF_NEED_HDFS=0;;
153 * ) echo "Invalid selection: " $INPUT;;
154 esac
155done
156
157if [ "$TF_NEED_HDFS" == "1" ]; then
158 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800159 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 -0800160else
161 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800162 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 -0800163fi
164
Peter Hawkins1e67c902017-01-09 12:04:37 -0800165## Enable XLA.
166while [ "$TF_ENABLE_XLA" == "" ]; do
167 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
168 case $INPUT in
169 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
170 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
171 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
172 * ) echo "Invalid selection: " $INPUT;;
173 esac
174done
175
176if [ "$TF_ENABLE_XLA" == "1" ]; then
177 # Update Bazel build configuration.
Eugene Brevdo8fc39812017-01-27 10:30:02 -0800178 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
Peter Hawkins1e67c902017-01-09 12:04:37 -0800179else
180 # Update Bazel build configuration.
Eugene Brevdo8fc39812017-01-27 10:30:02 -0800181 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
Peter Hawkins1e67c902017-01-09 12:04:37 -0800182fi
183
184
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800185# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800186./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800187
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800188# Append CC optimization flags to bazel.rc
189echo >> tools/bazel.rc
190for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800191 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800192done
193
Andrew Selle09045e42016-09-06 08:19:04 -0800194# Run the gen_git_source to create links where bazel can track dependencies for
195# git hash propagation
196GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
197chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800198"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800199
Benoit Steinera7715982016-11-09 13:14:03 -0800200## Set up SYCL-related environment settings
201while [ "$TF_NEED_OPENCL" == "" ]; do
202 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
203 case $INPUT in
204 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
205 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
206 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
207 * ) echo "Invalid selection: " $INPUT;;
208 esac
209done
210
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800211## Set up Cuda-related environment settings
212
213while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800214 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800215 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800216 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
217 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
218 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800219 * ) echo "Invalid selection: " $INPUT;;
220 esac
221done
222
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800223export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800224export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800225if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800226 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800227 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800228 exit
229fi
230
Benoit Steinera7715982016-11-09 13:14:03 -0800231if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800232# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800233# No need to set this on Windows
234while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800235 fromuser=""
236 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800237 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800238 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 -0800239 fromuser="1"
240 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800241 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800242 fi
243 fi
244 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800245 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800246 break
247 fi
248 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
249 if [ -z "$fromuser" ]; then
250 exit 1
251 fi
252 GCC_HOST_COMPILER_PATH=""
253 # Retry
254done
255
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800256# Find out where the CUDA toolkit is installed
257while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800258 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800259 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800260 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 -0800261 fi
262
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800263 fromuser=""
264 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
265 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800266 if is_windows; then
267 if [ -z "$CUDA_PATH" ]; then
268 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
269 else
270 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
271 fi
272 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800273 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 -0800274 fromuser="1"
275 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800276 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800277 fi
278 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800279
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800280 if [[ -z "$TF_CUDA_VERSION" ]]; then
281 TF_CUDA_EXT=""
282 else
283 TF_CUDA_EXT=".$TF_CUDA_VERSION"
284 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800285
Andrew Harp1cb96892016-12-08 20:05:49 -0800286 if is_windows; then
287 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800288 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800289 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800290 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800291 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
292 fi
293
294 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800295 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800296 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800297 break
298 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800299 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
300
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800301 if [ -z "$fromuser" ]; then
302 exit 1
303 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800304 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800305 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800306 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800307done
308
Martin Wicke916776a2016-01-14 07:30:00 -0800309# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800310while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800311 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800312 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800313 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 -0800314 fi
315
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800316 fromuser=""
317 if [ -z "$CUDNN_INSTALL_PATH" ]; then
318 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800319 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 -0800320 fromuser="1"
321 if [ -z "$CUDNN_INSTALL_PATH" ]; then
322 CUDNN_INSTALL_PATH=$default_cudnn_path
323 fi
324 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
325 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800326 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 -0800327 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800328
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800329 if [[ -z "$TF_CUDNN_VERSION" ]]; then
330 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800331 cudnn_lib_path=""
332 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800333 if is_windows; then
334 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
335 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800336 elif is_linux; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800337 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
338 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800339 elif is_macos; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800340 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
341 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
342 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800343 # Resolve to the SONAME of the symlink. Use readlink without -f
344 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800345 # libcudnn.so.4.
346 # If the path is not a symlink, readlink will exit with an error code, so
347 # in that case, we return the path itself.
348 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800349 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800350 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800351 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800352 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800353
354 # Extract the version of the SONAME, if it was indeed symlinked to
355 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800356 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800357 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
358 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
359 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800360 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800361 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800362 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
363 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800364 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800365 else
Jonathan Hseuc058a012017-01-17 15:06:43 -0800366 if is_macos; then
Shanqing Caiefd40e52017-01-08 20:31:30 -0800367 TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
368 else
369 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
370 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800371 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800372
Andrew Harp1cb96892016-12-08 20:05:49 -0800373 if is_windows; then
374 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
375 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800376 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800377 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
378 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800379 elif is_macos; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800380 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
381 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800382 fi
383
384 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 -0800385 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800386 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800387 break
388 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800389
Jonathan Hseuc058a012017-01-17 15:06:43 -0800390 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800391 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
392 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800393 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800394 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800395 break
396 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800397 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800398 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
399 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
400 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800401 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800402 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
403 fi
404
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800405 if [ -z "$fromuser" ]; then
406 exit 1
407 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800408 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800409 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800410 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800411done
412
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800413# Configure the compute capabilities that TensorFlow builds for.
414# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
415while true; do
416 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800417 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800418 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800419cat << EOF
420Please specify a list of comma-separated Cuda compute capabilities you want to build with.
421You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
422Please note that each additional compute capability significantly increases your build time and binary size.
423EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800424 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
425 fromuser=1
426 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800427 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
428 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
429 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800430 # Check whether all capabilities from the input is valid
431 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
432 ALL_VALID=1
433 for CAPABILITY in $COMPUTE_CAPABILITIES; do
434 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
435 echo "Invalid compute capability: " $CAPABILITY
436 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800437 break
438 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800439 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800440 if [ "$ALL_VALID" == "0" ]; then
441 if [ -z "$fromuser" ]; then
442 exit 1
443 fi
444 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800445 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800446 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800447 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800448 TF_CUDA_COMPUTE_CAPABILITIES=""
449done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800450
Andrew Harp1cb96892016-12-08 20:05:49 -0800451if is_windows; then
452 # The following three variables are needed for MSVC toolchain configuration in Bazel
453 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
454 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
455 export NO_WHOLE_ARCHIVE_OPTION=1
456
457 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
458 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
459fi
460
Benoit Steinera7715982016-11-09 13:14:03 -0800461# end of if "$TF_NEED_CUDA" == "1"
462fi
463
464# OpenCL configuration
465
466if [ "$TF_NEED_OPENCL" == "1" ]; then
467
468# Determine which C++ compiler should be used as the host compiler
469while true; do
470 fromuser=""
471 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800472 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800473 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
474 fromuser="1"
475 if [ -z "$HOST_CXX_COMPILER" ]; then
476 HOST_CXX_COMPILER=$default_cxx_host_compiler
477 fi
478 fi
479 if [ -e "$HOST_CXX_COMPILER" ]; then
480 export HOST_CXX_COMPILER
481 break
482 fi
483 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
484 if [ -z "$fromuser" ]; then
485 exit 1
486 fi
487 HOST_CXX_COMPILER=""
488 # Retry
489done
490
491# Determine which C compiler should be used as the host compiler
492while true; do
493 fromuser=""
494 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800495 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800496 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
497 fromuser="1"
498 if [ -z "$HOST_C_COMPILER" ]; then
499 HOST_C_COMPILER=$default_c_host_compiler
500 fi
501 fi
502 if [ -e "$HOST_C_COMPILER" ]; then
503 export HOST_C_COMPILER
504 break
505 fi
506 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
507 if [ -z "$fromuser" ]; then
508 exit 1
509 fi
510 HOST_C_COMPILER=""
511 # Retry
512done
513
514while true; do
515 # Configure the OPENCL version to use.
516 TF_OPENCL_VERSION="1.2"
517
518 # Point to ComputeCpp root
519 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
520 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800521 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 -0800522 fromuser="1"
523 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
524 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
525 fi
526 fi
527
Jonathan Hseuc058a012017-01-17 15:06:43 -0800528 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800529 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
530 fi
531
532 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
533 export COMPUTECPP_TOOLKIT_PATH
534 break
535 fi
536 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
537
538 if [ -z "$fromuser" ]; then
539 exit 1
540 fi
541 # Retry
542 TF_OPENCL_VERSION=""
543 COMPUTECPP_TOOLKIT_PATH=""
544done
545
Benoit Steinera7715982016-11-09 13:14:03 -0800546# end of if "$TF_NEED_OPENCL" == "1"
547fi
548
Jonathan Hseu1283b842016-09-29 15:05:32 -0800549bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800550
551echo "Configuration finished"