blob: bcef37bd26b34bd2e236824a57be21165d83332d [file] [log] [blame]
Geoffrey Irving4c85a082016-03-16 12:20:34 -08001#!/usr/bin/env bash
Manjunath Kudlurf41959c2015-11-06 16:27:58 -08002
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -08003DO_NOT_SUBMIT_WARNING="Unofficial setting. DO NOT SUBMIT!!!"
4
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -08005## Set up python-related environment settings
6while true; do
7 fromuser=""
8 if [ -z "$PYTHON_BIN_PATH" ]; then
9 default_python_bin_path=$(which python)
10 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
11 fromuser="1"
12 if [ -z "$PYTHON_BIN_PATH" ]; then
13 PYTHON_BIN_PATH=$default_python_bin_path
14 fi
15 fi
16 if [ -e "$PYTHON_BIN_PATH" ]; then
17 break
18 fi
19 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
20 if [ -z "$fromuser" ]; then
21 exit 1
22 fi
23 PYTHON_BIN_PATH=""
24 # Retry
25done
26
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080027while [ "$TF_NEED_GCP" == "" ]; do
28 read -p "Do you wish to build TensorFlow with "\
29"Google Cloud Platform support? [y/N] " INPUT
30 case $INPUT in
31 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
32"TensorFlow"; TF_NEED_GCP=1;;
33 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
34"TensorFlow"; TF_NEED_GCP=0;;
35 "" ) echo "No Google Cloud Platform support will be enabled for "\
36"TensorFlow"; TF_NEED_GCP=0;;
37 * ) echo "Invalid selection: " $INPUT;;
38 esac
39done
40
41if [ "$TF_NEED_GCP" == "1" ]; then
42
43 ## Verify that libcurl header files are available.
44 # Only check Linux, since on MacOS the header files are installed with XCode.
45 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
46 echo "ERROR: It appears that the development version of libcurl is not "\
47"available. Please install the libcurl3-dev package."
48 exit 1
49 fi
50
51 # Update Bazel build configuration.
52 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
53else
54 # Update Bazel build configuration.
55 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
56fi
57
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -080058## Find swig path
59if [ -z "$SWIG_PATH" ]; then
60 SWIG_PATH=`type -p swig 2> /dev/null`
61fi
62if [[ ! -e "$SWIG_PATH" ]]; then
63 echo "Can't find swig. Ensure swig is in \$PATH or set \$SWIG_PATH."
64 exit 1
65fi
66echo "$SWIG_PATH" > tensorflow/tools/swig/swig_path
67
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080068# Invoke python_config and set up symlinks to python includes
69(./util/python/python_config.sh --setup "$PYTHON_BIN_PATH";) || exit -1
70
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080071## Set up Cuda-related environment settings
72
73while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080074 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080075 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080076 [Yy]* ) echo "GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
77 [Nn]* ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
78 "" ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080079 * ) echo "Invalid selection: " $INPUT;;
80 esac
81done
82
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -080083export TF_NEED_CUDA
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080084if [ "$TF_NEED_CUDA" == "0" ]; then
85 echo "Configuration finished"
86 exit
87fi
88
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -080089# Set up which gcc nvcc should use as the host compiler
90while true; do
91 fromuser=""
92 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
93 default_gcc_host_compiler_path=$(which gcc)
Shanqing Caia81c4f92016-07-22 10:37:35 -080094 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 -080095 fromuser="1"
96 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
97 GCC_HOST_COMPILER_PATH=$default_gcc_host_compiler_path
98 fi
99 fi
100 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800101 export CC=$GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800102 break
103 fi
104 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
105 if [ -z "$fromuser" ]; then
106 exit 1
107 fi
108 GCC_HOST_COMPILER_PATH=""
109 # Retry
110done
111
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800112# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800113OSNAME=`uname -s`
114
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800115while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800116 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800117 if [ -z "$TF_CUDA_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800118 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 -0800119 fi
120
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800121 fromuser=""
122 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
123 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800124 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 -0800125 fromuser="1"
126 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
127 CUDA_TOOLKIT_PATH=$default_cuda_path
128 fi
129 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800130
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800131 if [[ -z "$TF_CUDA_VERSION" ]]; then
132 TF_CUDA_EXT=""
133 else
134 TF_CUDA_EXT=".$TF_CUDA_VERSION"
135 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800136
137 if [ "$OSNAME" == "Linux" ]; then
138 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
139 elif [ "$OSNAME" == "Darwin" ]; then
140 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
141 fi
142
143 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800144 export CUDA_TOOLKIT_PATH
145 export CUDA_VERSION=$TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800146 break
147 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800148 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
149
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800150 if [ -z "$fromuser" ]; then
151 exit 1
152 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800153 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800154 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800155 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800156done
157
Martin Wicke916776a2016-01-14 07:30:00 -0800158# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800159while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800160 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800161 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800162 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 -0800163 fi
164
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800165 fromuser=""
166 if [ -z "$CUDNN_INSTALL_PATH" ]; then
167 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800168 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 -0800169 fromuser="1"
170 if [ -z "$CUDNN_INSTALL_PATH" ]; then
171 CUDNN_INSTALL_PATH=$default_cudnn_path
172 fi
173 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
174 # Going through one more level of expansion to handle that.
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800175 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 -0800176 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800177
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800178 if [[ -z "$TF_CUDNN_VERSION" ]]; then
179 TF_CUDNN_EXT=""
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800180 # Resolve to the SONAME of the symlink. Use readlink without -f
181 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
182 # libcudnn.so.4
183 REALVAL=`readlink ${CUDNN_INSTALL_PATH}/lib64/libcudnn.so`
184
185 # Extract the version of the SONAME, if it was indeed symlinked to
186 # the SONAME version of the file.
187 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]];
188 then
189 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
190 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
191 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
192 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800193 else
194 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
195 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800196
197 if [ "$OSNAME" == "Linux" ]; then
198 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
199 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
200 elif [ "$OSNAME" == "Darwin" ]; then
201 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
202 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
203 fi
204
205 if [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_ALT_PATH}" -o -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800206 export CUDNN_VERSION=$TF_CUDNN_VERSION
207 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800208 break
209 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800210
211 if [ "$OSNAME" == "Linux" ]; then
212 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
213 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800214 export CUDNN_VERSION=$TF_CUDNN_VERSION
215 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800216 break
217 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800218 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800219 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
220 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
221 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
222 if [ "$OSNAME" == "Linux" ]; then
223 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
224 fi
225
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800226 if [ -z "$fromuser" ]; then
227 exit 1
228 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800229 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800230 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800231 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800232done
233
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800234# Configure the compute capabilities that TensorFlow builds for.
235# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
236while true; do
237 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800238 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800239 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800240cat << EOF
241Please specify a list of comma-separated Cuda compute capabilities you want to build with.
242You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
243Please note that each additional compute capability significantly increases your build time and binary size.
244EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800245 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
246 fromuser=1
247 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800248 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
249 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
250 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800251 # Check whether all capabilities from the input is valid
252 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
253 ALL_VALID=1
254 for CAPABILITY in $COMPUTE_CAPABILITIES; do
255 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
256 echo "Invalid compute capability: " $CAPABILITY
257 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800258 break
259 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800260 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800261 if [ "$ALL_VALID" == "0" ]; then
262 if [ -z "$fromuser" ]; then
263 exit 1
264 fi
265 else
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800266 export CUDA_COMPUTE_CAPABILITIES=$TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800267 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800268 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800269 TF_CUDA_COMPUTE_CAPABILITIES=""
270done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800271
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800272bazel clean --expunge
273bazel fetch //...
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800274
275echo "Configuration finished"