blob: 64add33bd5d6262af3165e23093b7456cdf63961 [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
Benoit Steinera7715982016-11-09 13:14:03 -080060 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080061fi
62
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -080063while [ "$TF_NEED_GCP" == "" ]; do
64 read -p "Do you wish to build TensorFlow with "\
65"Google Cloud Platform support? [y/N] " INPUT
66 case $INPUT in
67 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
68"TensorFlow"; TF_NEED_GCP=1;;
69 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
70"TensorFlow"; TF_NEED_GCP=0;;
71 "" ) echo "No Google Cloud Platform support will be enabled for "\
72"TensorFlow"; TF_NEED_GCP=0;;
73 * ) echo "Invalid selection: " $INPUT;;
74 esac
75done
76
77if [ "$TF_NEED_GCP" == "1" ]; then
78 ## Verify that libcurl header files are available.
79 # Only check Linux, since on MacOS the header files are installed with XCode.
80 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
81 echo "ERROR: It appears that the development version of libcurl is not "\
82"available. Please install the libcurl3-dev package."
83 exit 1
84 fi
85
86 # Update Bazel build configuration.
87 sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
88else
89 # Update Bazel build configuration.
90 sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
91fi
92
Jonathan Hseu9f5b0982016-09-19 11:14:58 -080093while [ "$TF_NEED_HDFS" == "" ]; do
94 read -p "Do you wish to build TensorFlow with "\
95"Hadoop File System support? [y/N] " INPUT
96 case $INPUT in
97 [Yy]* ) echo "Hadoop File System support will be enabled for "\
98"TensorFlow"; TF_NEED_HDFS=1;;
99 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
100"TensorFlow"; TF_NEED_HDFS=0;;
101 "" ) echo "No Hadoop File System support will be enabled for "\
102"TensorFlow"; TF_NEED_HDFS=0;;
103 * ) echo "Invalid selection: " $INPUT;;
104 esac
105done
106
107if [ "$TF_NEED_HDFS" == "1" ]; then
108 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800109 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 -0800110else
111 # Update Bazel build configuration.
Andrew Harp1cb96892016-12-08 20:05:49 -0800112 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 -0800113fi
114
Peter Hawkins1e67c902017-01-09 12:04:37 -0800115## Enable XLA.
116while [ "$TF_ENABLE_XLA" == "" ]; do
117 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
118 case $INPUT in
119 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
120 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
121 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
122 * ) echo "Invalid selection: " $INPUT;;
123 esac
124done
125
126if [ "$TF_ENABLE_XLA" == "1" ]; then
127 # Update Bazel build configuration.
128 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
129else
130 # Update Bazel build configuration.
131 perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
132fi
133
134
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800135# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800136./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800137
Andrew Selle09045e42016-09-06 08:19:04 -0800138# Run the gen_git_source to create links where bazel can track dependencies for
139# git hash propagation
140GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
141chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800142"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800143
Benoit Steinera7715982016-11-09 13:14:03 -0800144## Set up SYCL-related environment settings
145while [ "$TF_NEED_OPENCL" == "" ]; do
146 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
147 case $INPUT in
148 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
149 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
150 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
151 * ) echo "Invalid selection: " $INPUT;;
152 esac
153done
154
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800155## Set up Cuda-related environment settings
156
157while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800158 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800159 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800160 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
161 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
162 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800163 * ) echo "Invalid selection: " $INPUT;;
164 esac
165done
166
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800167export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800168export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800169if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800170 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800171 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800172 exit
173fi
174
Benoit Steinera7715982016-11-09 13:14:03 -0800175if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800176# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800177# No need to set this on Windows
178while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800179 fromuser=""
180 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800181 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800182 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 -0800183 fromuser="1"
184 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800185 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800186 fi
187 fi
188 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800189 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800190 break
191 fi
192 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
193 if [ -z "$fromuser" ]; then
194 exit 1
195 fi
196 GCC_HOST_COMPILER_PATH=""
197 # Retry
198done
199
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800200# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800201OSNAME=`uname -s`
202
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800203while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800204 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800205 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800206 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 -0800207 fi
208
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800209 fromuser=""
210 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
211 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800212 if is_windows; then
213 if [ -z "$CUDA_PATH" ]; then
214 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
215 else
216 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
217 fi
218 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800219 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 -0800220 fromuser="1"
221 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800222 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800223 fi
224 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800225
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800226 if [[ -z "$TF_CUDA_VERSION" ]]; then
227 TF_CUDA_EXT=""
228 else
229 TF_CUDA_EXT=".$TF_CUDA_VERSION"
230 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800231
Andrew Harp1cb96892016-12-08 20:05:49 -0800232 if is_windows; then
233 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
234 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800235 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
236 elif [ "$OSNAME" == "Darwin" ]; then
237 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
238 fi
239
240 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800241 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800242 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800243 break
244 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800245 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
246
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800247 if [ -z "$fromuser" ]; then
248 exit 1
249 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800250 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800251 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800252 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800253done
254
Martin Wicke916776a2016-01-14 07:30:00 -0800255# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800256while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800257 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800258 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800259 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 -0800260 fi
261
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800262 fromuser=""
263 if [ -z "$CUDNN_INSTALL_PATH" ]; then
264 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800265 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 -0800266 fromuser="1"
267 if [ -z "$CUDNN_INSTALL_PATH" ]; then
268 CUDNN_INSTALL_PATH=$default_cudnn_path
269 fi
270 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
271 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800272 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 -0800273 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800274
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800275 if [[ -z "$TF_CUDNN_VERSION" ]]; then
276 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800277 cudnn_lib_path=""
278 cudnn_alt_lib_path=""
Andrew Harp1cb96892016-12-08 20:05:49 -0800279 if is_windows; then
280 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
281 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
282 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800283 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
284 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
285 elif [ "$OSNAME" == "Darwin" ]; then
286 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
287 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
288 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800289 # Resolve to the SONAME of the symlink. Use readlink without -f
290 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800291 # libcudnn.so.4.
292 # If the path is not a symlink, readlink will exit with an error code, so
293 # in that case, we return the path itself.
294 if [ -f "$cudnn_lib_path" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800295 REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800296 else
Andrew Harp1cb96892016-12-08 20:05:49 -0800297 REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"`
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800298 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800299
300 # Extract the version of the SONAME, if it was indeed symlinked to
301 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800302 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800303 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
304 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
305 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800306 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800307 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800308 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
309 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800310 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800311 else
Shanqing Caiefd40e52017-01-08 20:31:30 -0800312 if [ "$OSNAME" == "Darwin" ]; then
313 TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
314 else
315 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
316 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800317 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800318
Andrew Harp1cb96892016-12-08 20:05:49 -0800319 if is_windows; then
320 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
321 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
322 elif [ "$OSNAME" == "Linux" ]; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800323 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
324 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
325 elif [ "$OSNAME" == "Darwin" ]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800326 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
327 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800328 fi
329
330 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 -0800331 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800332 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800333 break
334 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800335
336 if [ "$OSNAME" == "Linux" ]; then
337 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
338 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800339 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800340 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800341 break
342 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800343 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800344 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
345 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
346 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
347 if [ "$OSNAME" == "Linux" ]; then
348 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
349 fi
350
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800351 if [ -z "$fromuser" ]; then
352 exit 1
353 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800354 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800355 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800356 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800357done
358
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800359# Configure the compute capabilities that TensorFlow builds for.
360# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
361while true; do
362 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800363 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800364 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800365cat << EOF
366Please specify a list of comma-separated Cuda compute capabilities you want to build with.
367You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
368Please note that each additional compute capability significantly increases your build time and binary size.
369EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800370 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
371 fromuser=1
372 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800373 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
374 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
375 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800376 # Check whether all capabilities from the input is valid
377 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
378 ALL_VALID=1
379 for CAPABILITY in $COMPUTE_CAPABILITIES; do
380 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
381 echo "Invalid compute capability: " $CAPABILITY
382 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800383 break
384 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800385 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800386 if [ "$ALL_VALID" == "0" ]; then
387 if [ -z "$fromuser" ]; then
388 exit 1
389 fi
390 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800391 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800392 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800393 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800394 TF_CUDA_COMPUTE_CAPABILITIES=""
395done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800396
Andrew Harp1cb96892016-12-08 20:05:49 -0800397if is_windows; then
398 # The following three variables are needed for MSVC toolchain configuration in Bazel
399 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
400 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
401 export NO_WHOLE_ARCHIVE_OPTION=1
402
403 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
404 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
405fi
406
Benoit Steinera7715982016-11-09 13:14:03 -0800407# end of if "$TF_NEED_CUDA" == "1"
408fi
409
410# OpenCL configuration
411
412if [ "$TF_NEED_OPENCL" == "1" ]; then
413
414# Determine which C++ compiler should be used as the host compiler
415while true; do
416 fromuser=""
417 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800418 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800419 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
420 fromuser="1"
421 if [ -z "$HOST_CXX_COMPILER" ]; then
422 HOST_CXX_COMPILER=$default_cxx_host_compiler
423 fi
424 fi
425 if [ -e "$HOST_CXX_COMPILER" ]; then
426 export HOST_CXX_COMPILER
427 break
428 fi
429 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
430 if [ -z "$fromuser" ]; then
431 exit 1
432 fi
433 HOST_CXX_COMPILER=""
434 # Retry
435done
436
437# Determine which C compiler should be used as the host compiler
438while true; do
439 fromuser=""
440 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800441 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800442 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
443 fromuser="1"
444 if [ -z "$HOST_C_COMPILER" ]; then
445 HOST_C_COMPILER=$default_c_host_compiler
446 fi
447 fi
448 if [ -e "$HOST_C_COMPILER" ]; then
449 export HOST_C_COMPILER
450 break
451 fi
452 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
453 if [ -z "$fromuser" ]; then
454 exit 1
455 fi
456 HOST_C_COMPILER=""
457 # Retry
458done
459
460while true; do
461 # Configure the OPENCL version to use.
462 TF_OPENCL_VERSION="1.2"
463
464 # Point to ComputeCpp root
465 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
466 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800467 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 -0800468 fromuser="1"
469 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
470 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
471 fi
472 fi
473
474 if [ "$OSNAME" == "Linux" ]; then
475 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
476 fi
477
478 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
479 export COMPUTECPP_TOOLKIT_PATH
480 break
481 fi
482 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
483
484 if [ -z "$fromuser" ]; then
485 exit 1
486 fi
487 # Retry
488 TF_OPENCL_VERSION=""
489 COMPUTECPP_TOOLKIT_PATH=""
490done
491
Benoit Steinera7715982016-11-09 13:14:03 -0800492# end of if "$TF_NEED_OPENCL" == "1"
493fi
494
Jonathan Hseu1283b842016-09-29 15:05:32 -0800495bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800496
497echo "Configuration finished"