blob: 1e4d786974d07eeb803f5ac76ef9c272f058742d [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
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080057if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080058 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080059 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080060 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -080061 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080062fi
63
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -080064while [ "$TF_NEED_JEMALLOC" == "" ]; do
65 read -p "Do you wish to use jemalloc as the malloc implementation? "\
66"(Linux only) [Y/n] " INPUT
67 case $INPUT in
68 [Yy]* ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
69 [Nn]* ) echo "jemalloc disabled on Linux"; TF_NEED_JEMALLOC=0;;
70 "" ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
71 * ) echo "Invalid selection: " $INPUT;;
72 esac
73done
74
75if [ "$TF_NEED_JEMALLOC" == "1" ]; then
76 sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
77else
78 sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
79fi
80
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080081while [ "$TF_NEED_GCP" == "" ]; do
82 read -p "Do you wish to build TensorFlow with "\
83"Google Cloud Platform support? [y/N] " INPUT
84 case $INPUT in
85 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
86"TensorFlow"; TF_NEED_GCP=1;;
87 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
88"TensorFlow"; TF_NEED_GCP=0;;
89 "" ) echo "No Google Cloud Platform support will be enabled for "\
90"TensorFlow"; TF_NEED_GCP=0;;
91 * ) echo "Invalid selection: " $INPUT;;
92 esac
93done
94
95if [ "$TF_NEED_GCP" == "1" ]; then
96 ## Verify that libcurl header files are available.
97 # Only check Linux, since on MacOS the header files are installed with XCode.
98 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
99 echo "ERROR: It appears that the development version of libcurl is not "\
100"available. Please install the libcurl3-dev package."
101 exit 1
102 fi
103
104 # Update Bazel build configuration.
105 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
106else
107 # Update Bazel build configuration.
108 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
109fi
110
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800111while [ "$TF_NEED_HDFS" == "" ]; do
112 read -p "Do you wish to build TensorFlow with "\
113"Hadoop File System support? [y/N] " INPUT
114 case $INPUT in
115 [Yy]* ) echo "Hadoop File System support will be enabled for "\
116"TensorFlow"; TF_NEED_HDFS=1;;
117 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
118"TensorFlow"; TF_NEED_HDFS=0;;
119 "" ) echo "No Hadoop File System support will be enabled for "\
120"TensorFlow"; TF_NEED_HDFS=0;;
121 * ) echo "Invalid selection: " $INPUT;;
122 esac
123done
124
125if [ "$TF_NEED_HDFS" == "1" ]; then
126 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800127 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 -0800128else
129 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800130 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 -0800131fi
132
Peter Hawkins1e67c902017-01-09 12:04:37 -0800133## Enable XLA.
134while [ "$TF_ENABLE_XLA" == "" ]; do
135 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
136 case $INPUT in
137 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
138 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
139 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
140 * ) echo "Invalid selection: " $INPUT;;
141 esac
142done
143
144if [ "$TF_ENABLE_XLA" == "1" ]; then
145 # Update Bazel build configuration.
146 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
147else
148 # Update Bazel build configuration.
149 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
150fi
151
152
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800153# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800154./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800155
Andrew Selle09045e42016-09-06 08:19:04 -0800156# Run the gen_git_source to create links where bazel can track dependencies for
157# git hash propagation
158GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
159chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800160"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800161
Benoit Steinera7715982016-11-09 13:14:03 -0800162## Set up SYCL-related environment settings
163while [ "$TF_NEED_OPENCL" == "" ]; do
164 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
165 case $INPUT in
166 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
167 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
168 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
169 * ) echo "Invalid selection: " $INPUT;;
170 esac
171done
172
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800173## Set up Cuda-related environment settings
174
175while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800176 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800177 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800178 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
179 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
180 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800181 * ) echo "Invalid selection: " $INPUT;;
182 esac
183done
184
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800185export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800186export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800187if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800188 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800189 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800190 exit
191fi
192
Benoit Steinera7715982016-11-09 13:14:03 -0800193if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800194# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800195# No need to set this on Windows
196while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800197 fromuser=""
198 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800199 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800200 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 -0800201 fromuser="1"
202 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800203 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800204 fi
205 fi
206 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800207 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800208 break
209 fi
210 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
211 if [ -z "$fromuser" ]; then
212 exit 1
213 fi
214 GCC_HOST_COMPILER_PATH=""
215 # Retry
216done
217
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800218# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800219OSNAME=`uname -s`
220
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800221while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800222 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800223 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800224 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 -0800225 fi
226
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800227 fromuser=""
228 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
229 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800230 if is_windows; then
231 if [ -z "$CUDA_PATH" ]; then
232 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
233 else
234 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
235 fi
236 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800237 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 -0800238 fromuser="1"
239 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800240 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800241 fi
242 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800243
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800244 if [[ -z "$TF_CUDA_VERSION" ]]; then
245 TF_CUDA_EXT=""
246 else
247 TF_CUDA_EXT=".$TF_CUDA_VERSION"
248 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800249
Andrew Harp1cb96892016-12-08 20:05:49 -0800250 if is_windows; then
251 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
252 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800253 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
254 elif [ "$OSNAME" == "Darwin" ]; then
255 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
256 fi
257
258 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800259 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800260 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800261 break
262 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800263 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
264
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800265 if [ -z "$fromuser" ]; then
266 exit 1
267 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800268 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800269 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800270 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800271done
272
Martin Wicke916776a2016-01-14 07:30:00 -0800273# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800274while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800275 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800276 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800277 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 -0800278 fi
279
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800280 fromuser=""
281 if [ -z "$CUDNN_INSTALL_PATH" ]; then
282 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800283 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 -0800284 fromuser="1"
285 if [ -z "$CUDNN_INSTALL_PATH" ]; then
286 CUDNN_INSTALL_PATH=$default_cudnn_path
287 fi
288 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
289 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800290 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 -0800291 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800292
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800293 if [[ -z "$TF_CUDNN_VERSION" ]]; then
294 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800295 cudnn_lib_path=""
296 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800297 if is_windows; then
298 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
299 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
300 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800301 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
302 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
303 elif [ "$OSNAME" == "Darwin" ]; then
304 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
305 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
306 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800307 # Resolve to the SONAME of the symlink. Use readlink without -f
308 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800309 # libcudnn.so.4.
310 # If the path is not a symlink, readlink will exit with an error code, so
311 # in that case, we return the path itself.
312 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800313 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800314 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800315 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800316 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800317
318 # Extract the version of the SONAME, if it was indeed symlinked to
319 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800320 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800321 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
322 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
323 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800324 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800325 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800326 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
327 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800328 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800329 else
Shanqing Caiefd40e52017-01-08 20:31:30 -0800330 if [ "$OSNAME" == "Darwin" ]; then
331 TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
332 else
333 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
334 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800335 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800336
Andrew Harp1cb96892016-12-08 20:05:49 -0800337 if is_windows; then
338 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
339 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
340 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800341 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
342 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
343 elif [ "$OSNAME" == "Darwin" ]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800344 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
345 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800346 fi
347
348 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 -0800349 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800350 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800351 break
352 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800353
354 if [ "$OSNAME" == "Linux" ]; then
355 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
356 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800357 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800358 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800359 break
360 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800361 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800362 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
363 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
364 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
365 if [ "$OSNAME" == "Linux" ]; then
366 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
367 fi
368
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800369 if [ -z "$fromuser" ]; then
370 exit 1
371 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800372 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800373 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800374 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800375done
376
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800377# Configure the compute capabilities that TensorFlow builds for.
378# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
379while true; do
380 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800381 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800382 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800383cat << EOF
384Please specify a list of comma-separated Cuda compute capabilities you want to build with.
385You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
386Please note that each additional compute capability significantly increases your build time and binary size.
387EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800388 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
389 fromuser=1
390 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800391 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
392 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
393 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800394 # Check whether all capabilities from the input is valid
395 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
396 ALL_VALID=1
397 for CAPABILITY in $COMPUTE_CAPABILITIES; do
398 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
399 echo "Invalid compute capability: " $CAPABILITY
400 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800401 break
402 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800403 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800404 if [ "$ALL_VALID" == "0" ]; then
405 if [ -z "$fromuser" ]; then
406 exit 1
407 fi
408 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800409 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800410 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800411 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800412 TF_CUDA_COMPUTE_CAPABILITIES=""
413done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800414
Andrew Harp1cb96892016-12-08 20:05:49 -0800415if is_windows; then
416 # The following three variables are needed for MSVC toolchain configuration in Bazel
417 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
418 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
419 export NO_WHOLE_ARCHIVE_OPTION=1
420
421 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
422 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
423fi
424
Benoit Steinera7715982016-11-09 13:14:03 -0800425# end of if "$TF_NEED_CUDA" == "1"
426fi
427
428# OpenCL configuration
429
430if [ "$TF_NEED_OPENCL" == "1" ]; then
431
432# Determine which C++ compiler should be used as the host compiler
433while true; do
434 fromuser=""
435 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800436 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800437 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
438 fromuser="1"
439 if [ -z "$HOST_CXX_COMPILER" ]; then
440 HOST_CXX_COMPILER=$default_cxx_host_compiler
441 fi
442 fi
443 if [ -e "$HOST_CXX_COMPILER" ]; then
444 export HOST_CXX_COMPILER
445 break
446 fi
447 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
448 if [ -z "$fromuser" ]; then
449 exit 1
450 fi
451 HOST_CXX_COMPILER=""
452 # Retry
453done
454
455# Determine which C compiler should be used as the host compiler
456while true; do
457 fromuser=""
458 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800459 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800460 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
461 fromuser="1"
462 if [ -z "$HOST_C_COMPILER" ]; then
463 HOST_C_COMPILER=$default_c_host_compiler
464 fi
465 fi
466 if [ -e "$HOST_C_COMPILER" ]; then
467 export HOST_C_COMPILER
468 break
469 fi
470 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
471 if [ -z "$fromuser" ]; then
472 exit 1
473 fi
474 HOST_C_COMPILER=""
475 # Retry
476done
477
478while true; do
479 # Configure the OPENCL version to use.
480 TF_OPENCL_VERSION="1.2"
481
482 # Point to ComputeCpp root
483 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
484 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800485 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 -0800486 fromuser="1"
487 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
488 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
489 fi
490 fi
491
492 if [ "$OSNAME" == "Linux" ]; then
493 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
494 fi
495
496 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
497 export COMPUTECPP_TOOLKIT_PATH
498 break
499 fi
500 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
501
502 if [ -z "$fromuser" ]; then
503 exit 1
504 fi
505 # Retry
506 TF_OPENCL_VERSION=""
507 COMPUTECPP_TOOLKIT_PATH=""
508done
509
Benoit Steinera7715982016-11-09 13:14:03 -0800510# end of if "$TF_NEED_OPENCL" == "1"
511fi
512
Jonathan Hseu1283b842016-09-29 15:05:32 -0800513bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800514
515echo "Configuration finished"