blob: 8bc271aaf3a1423784c0f7355bca8df474f02c10 [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
7pushd `dirname $0` #> /dev/null
8SOURCE_BASE_DIR=`pwd -P`
9popd > /dev/null
10
Jonathan Hseu1283b842016-09-29 15:05:32 -080011function bazel_clean_and_fetch() {
12 bazel clean --expunge
13 bazel fetch //tensorflow/...
14}
15
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080016## Set up python-related environment settings
17while true; do
18 fromuser=""
19 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080020 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080021 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
22 fromuser="1"
23 if [ -z "$PYTHON_BIN_PATH" ]; then
24 PYTHON_BIN_PATH=$default_python_bin_path
25 fi
26 fi
27 if [ -e "$PYTHON_BIN_PATH" ]; then
28 break
29 fi
30 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
31 if [ -z "$fromuser" ]; then
32 exit 1
33 fi
34 PYTHON_BIN_PATH=""
35 # Retry
36done
37
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080038while [ "$TF_NEED_GCP" == "" ]; do
39 read -p "Do you wish to build TensorFlow with "\
40"Google Cloud Platform support? [y/N] " INPUT
41 case $INPUT in
42 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
43"TensorFlow"; TF_NEED_GCP=1;;
44 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
45"TensorFlow"; TF_NEED_GCP=0;;
46 "" ) echo "No Google Cloud Platform support will be enabled for "\
47"TensorFlow"; TF_NEED_GCP=0;;
48 * ) echo "Invalid selection: " $INPUT;;
49 esac
50done
51
52if [ "$TF_NEED_GCP" == "1" ]; then
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080053 ## Verify that libcurl header files are available.
54 # Only check Linux, since on MacOS the header files are installed with XCode.
55 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
56 echo "ERROR: It appears that the development version of libcurl is not "\
57"available. Please install the libcurl3-dev package."
58 exit 1
59 fi
60
61 # Update Bazel build configuration.
62 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
63else
64 # Update Bazel build configuration.
65 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
66fi
67
Jonathan Hseu9f5b0982016-09-19 11:14:58 -080068while [ "$TF_NEED_HDFS" == "" ]; do
69 read -p "Do you wish to build TensorFlow with "\
70"Hadoop File System support? [y/N] " INPUT
71 case $INPUT in
72 [Yy]* ) echo "Hadoop File System support will be enabled for "\
73"TensorFlow"; TF_NEED_HDFS=1;;
74 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
75"TensorFlow"; TF_NEED_HDFS=0;;
76 "" ) echo "No Hadoop File System support will be enabled for "\
77"TensorFlow"; TF_NEED_HDFS=0;;
78 * ) echo "Invalid selection: " $INPUT;;
79 esac
80done
81
82if [ "$TF_NEED_HDFS" == "1" ]; then
83 # Update Bazel build configuration.
84 perl -pi -e "s,WITH_HDFS_SUPPORT = (False|True),WITH_HDFS_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
85else
86 # Update Bazel build configuration.
87 perl -pi -e "s,WITH_HDFS_SUPPORT = (False|True),WITH_HDFS_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
88fi
89
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -080090## Find swig path
91if [ -z "$SWIG_PATH" ]; then
92 SWIG_PATH=`type -p swig 2> /dev/null`
93fi
94if [[ ! -e "$SWIG_PATH" ]]; then
95 echo "Can't find swig. Ensure swig is in \$PATH or set \$SWIG_PATH."
96 exit 1
97fi
98echo "$SWIG_PATH" > tensorflow/tools/swig/swig_path
99
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800100# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800101./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800102
Andrew Selle09045e42016-09-06 08:19:04 -0800103# Run the gen_git_source to create links where bazel can track dependencies for
104# git hash propagation
105GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
106chmod a+x ${GEN_GIT_SOURCE}
107${PYTHON_BIN_PATH} ${GEN_GIT_SOURCE} --configure ${SOURCE_BASE_DIR}
108
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800109## Set up Cuda-related environment settings
110
111while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800112 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800113 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800114 [Yy]* ) echo "GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
115 [Nn]* ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
116 "" ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800117 * ) echo "Invalid selection: " $INPUT;;
118 esac
119done
120
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800121export TF_NEED_CUDA
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800122if [ "$TF_NEED_CUDA" == "0" ]; then
123 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800124 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800125 exit
126fi
127
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800128# Set up which gcc nvcc should use as the host compiler
129while true; do
130 fromuser=""
131 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800132 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800133 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 -0800134 fromuser="1"
135 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
136 GCC_HOST_COMPILER_PATH=$default_gcc_host_compiler_path
137 fi
138 fi
139 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800140 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800141 break
142 fi
143 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
144 if [ -z "$fromuser" ]; then
145 exit 1
146 fi
147 GCC_HOST_COMPILER_PATH=""
148 # Retry
149done
150
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800151# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800152OSNAME=`uname -s`
153
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800154while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800155 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800156 if [ -z "$TF_CUDA_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800157 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 -0800158 fi
159
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800160 fromuser=""
161 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
162 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800163 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 -0800164 fromuser="1"
165 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
166 CUDA_TOOLKIT_PATH=$default_cuda_path
167 fi
168 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800169
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800170 if [[ -z "$TF_CUDA_VERSION" ]]; then
171 TF_CUDA_EXT=""
172 else
173 TF_CUDA_EXT=".$TF_CUDA_VERSION"
174 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800175
176 if [ "$OSNAME" == "Linux" ]; then
177 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
178 elif [ "$OSNAME" == "Darwin" ]; then
179 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
180 fi
181
182 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800183 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800184 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800185 break
186 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800187 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
188
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800189 if [ -z "$fromuser" ]; then
190 exit 1
191 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800192 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800193 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800194 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800195done
196
Martin Wicke916776a2016-01-14 07:30:00 -0800197# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800198while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800199 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800200 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800201 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 -0800202 fi
203
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800204 fromuser=""
205 if [ -z "$CUDNN_INSTALL_PATH" ]; then
206 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800207 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 -0800208 fromuser="1"
209 if [ -z "$CUDNN_INSTALL_PATH" ]; then
210 CUDNN_INSTALL_PATH=$default_cudnn_path
211 fi
212 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
213 # Going through one more level of expansion to handle that.
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800214 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 -0800215 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800216
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800217 if [[ -z "$TF_CUDNN_VERSION" ]]; then
218 TF_CUDNN_EXT=""
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800219 cudnn_lib_path=""
220 cudnn_alt_lib_path=""
221 if [ "$OSNAME" == "Linux" ]; then
222 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
223 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
224 elif [ "$OSNAME" == "Darwin" ]; then
225 cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
226 cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
227 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800228 # Resolve to the SONAME of the symlink. Use readlink without -f
229 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800230 # libcudnn.so.4.
231 # If the path is not a symlink, readlink will exit with an error code, so
232 # in that case, we return the path itself.
233 if [ -f "$cudnn_lib_path" ]; then
234 REALVAL=`readlink ${cudnn_lib_path} || echo "${cudnn_lib_path}"`
235 else
236 REALVAL=`readlink ${cudnn_alt_lib_path} || echo "${cudnn_alt_lib_path}"`
237 fi
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800238
239 # Extract the version of the SONAME, if it was indeed symlinked to
240 # the SONAME version of the file.
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800241 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800242 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
243 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
244 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800245 elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then
246 TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib"
247 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
248 echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800249 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800250 else
251 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
252 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800253
254 if [ "$OSNAME" == "Linux" ]; then
255 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
256 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
257 elif [ "$OSNAME" == "Darwin" ]; then
258 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
259 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
260 fi
261
262 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 -0800263 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800264 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800265 break
266 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800267
268 if [ "$OSNAME" == "Linux" ]; then
269 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
270 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800271 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800272 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800273 break
274 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800275 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800276 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
277 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
278 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
279 if [ "$OSNAME" == "Linux" ]; then
280 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
281 fi
282
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800283 if [ -z "$fromuser" ]; then
284 exit 1
285 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800286 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800287 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800288 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800289done
290
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800291# Configure the compute capabilities that TensorFlow builds for.
292# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
293while true; do
294 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800295 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800296 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800297cat << EOF
298Please specify a list of comma-separated Cuda compute capabilities you want to build with.
299You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
300Please note that each additional compute capability significantly increases your build time and binary size.
301EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800302 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
303 fromuser=1
304 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800305 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
306 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
307 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800308 # Check whether all capabilities from the input is valid
309 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
310 ALL_VALID=1
311 for CAPABILITY in $COMPUTE_CAPABILITIES; do
312 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
313 echo "Invalid compute capability: " $CAPABILITY
314 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800315 break
316 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800317 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800318 if [ "$ALL_VALID" == "0" ]; then
319 if [ -z "$fromuser" ]; then
320 exit 1
321 fi
322 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800323 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800324 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800325 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800326 TF_CUDA_COMPUTE_CAPABILITIES=""
327done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800328
Jonathan Hseu1283b842016-09-29 15:05:32 -0800329bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800330
331echo "Configuration finished"