blob: eccc204945e54cc59e05269e0bf6b5bfa3320a44 [file] [log] [blame]
Geoffrey Irving4c85a082016-03-16 12:20:34 -08001#!/usr/bin/env bash
Manjunath Kudlurf41959c2015-11-06 16:27:58 -08002
Andrew Selle09045e42016-09-06 08:19:04 -08003# Find out the absolute path to where ./configure resides
4pushd `dirname $0` #> /dev/null
5SOURCE_BASE_DIR=`pwd -P`
6popd > /dev/null
7
Jonathan Hseu1283b842016-09-29 15:05:32 -08008function bazel_clean_and_fetch() {
9 bazel clean --expunge
10 bazel fetch //tensorflow/...
11}
12
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080013## Set up python-related environment settings
14while true; do
15 fromuser=""
16 if [ -z "$PYTHON_BIN_PATH" ]; then
17 default_python_bin_path=$(which python)
18 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
19 fromuser="1"
20 if [ -z "$PYTHON_BIN_PATH" ]; then
21 PYTHON_BIN_PATH=$default_python_bin_path
22 fi
23 fi
24 if [ -e "$PYTHON_BIN_PATH" ]; then
25 break
26 fi
27 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
28 if [ -z "$fromuser" ]; then
29 exit 1
30 fi
31 PYTHON_BIN_PATH=""
32 # Retry
33done
34
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080035while [ "$TF_NEED_GCP" == "" ]; do
36 read -p "Do you wish to build TensorFlow with "\
37"Google Cloud Platform support? [y/N] " INPUT
38 case $INPUT in
39 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
40"TensorFlow"; TF_NEED_GCP=1;;
41 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
42"TensorFlow"; TF_NEED_GCP=0;;
43 "" ) echo "No Google Cloud Platform support will be enabled for "\
44"TensorFlow"; TF_NEED_GCP=0;;
45 * ) echo "Invalid selection: " $INPUT;;
46 esac
47done
48
49if [ "$TF_NEED_GCP" == "1" ]; then
50
51 ## Verify that libcurl header files are available.
52 # Only check Linux, since on MacOS the header files are installed with XCode.
53 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
54 echo "ERROR: It appears that the development version of libcurl is not "\
55"available. Please install the libcurl3-dev package."
56 exit 1
57 fi
58
59 # Update Bazel build configuration.
60 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
61else
62 # Update Bazel build configuration.
63 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
64fi
65
Jonathan Hseu9f5b0982016-09-19 11:14:58 -080066while [ "$TF_NEED_HDFS" == "" ]; do
67 read -p "Do you wish to build TensorFlow with "\
68"Hadoop File System support? [y/N] " INPUT
69 case $INPUT in
70 [Yy]* ) echo "Hadoop File System support will be enabled for "\
71"TensorFlow"; TF_NEED_HDFS=1;;
72 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
73"TensorFlow"; TF_NEED_HDFS=0;;
74 "" ) echo "No Hadoop File System support will be enabled for "\
75"TensorFlow"; TF_NEED_HDFS=0;;
76 * ) echo "Invalid selection: " $INPUT;;
77 esac
78done
79
80if [ "$TF_NEED_HDFS" == "1" ]; then
81 # Update Bazel build configuration.
82 perl -pi -e "s,WITH_HDFS_SUPPORT = (False|True),WITH_HDFS_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
83else
84 # Update Bazel build configuration.
85 perl -pi -e "s,WITH_HDFS_SUPPORT = (False|True),WITH_HDFS_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
86fi
87
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -080088## Find swig path
89if [ -z "$SWIG_PATH" ]; then
90 SWIG_PATH=`type -p swig 2> /dev/null`
91fi
92if [[ ! -e "$SWIG_PATH" ]]; then
93 echo "Can't find swig. Ensure swig is in \$PATH or set \$SWIG_PATH."
94 exit 1
95fi
96echo "$SWIG_PATH" > tensorflow/tools/swig/swig_path
97
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080098# Invoke python_config and set up symlinks to python includes
99(./util/python/python_config.sh --setup "$PYTHON_BIN_PATH";) || exit -1
100
Andrew Selle09045e42016-09-06 08:19:04 -0800101# Run the gen_git_source to create links where bazel can track dependencies for
102# git hash propagation
103GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
104chmod a+x ${GEN_GIT_SOURCE}
105${PYTHON_BIN_PATH} ${GEN_GIT_SOURCE} --configure ${SOURCE_BASE_DIR}
106
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800107## Set up Cuda-related environment settings
108
109while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800110 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800111 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800112 [Yy]* ) echo "GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
113 [Nn]* ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
114 "" ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800115 * ) echo "Invalid selection: " $INPUT;;
116 esac
117done
118
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800119export TF_NEED_CUDA
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800120if [ "$TF_NEED_CUDA" == "0" ]; then
121 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800122 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800123 exit
124fi
125
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800126# Set up which gcc nvcc should use as the host compiler
127while true; do
128 fromuser=""
129 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
130 default_gcc_host_compiler_path=$(which gcc)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800131 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 -0800132 fromuser="1"
133 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
134 GCC_HOST_COMPILER_PATH=$default_gcc_host_compiler_path
135 fi
136 fi
137 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800138 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800139 break
140 fi
141 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
142 if [ -z "$fromuser" ]; then
143 exit 1
144 fi
145 GCC_HOST_COMPILER_PATH=""
146 # Retry
147done
148
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800149# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800150OSNAME=`uname -s`
151
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800152while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800153 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800154 if [ -z "$TF_CUDA_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800155 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 -0800156 fi
157
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800158 fromuser=""
159 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
160 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800161 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 -0800162 fromuser="1"
163 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
164 CUDA_TOOLKIT_PATH=$default_cuda_path
165 fi
166 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800167
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800168 if [[ -z "$TF_CUDA_VERSION" ]]; then
169 TF_CUDA_EXT=""
170 else
171 TF_CUDA_EXT=".$TF_CUDA_VERSION"
172 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800173
174 if [ "$OSNAME" == "Linux" ]; then
175 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
176 elif [ "$OSNAME" == "Darwin" ]; then
177 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
178 fi
179
180 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800181 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800182 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800183 break
184 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800185 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
186
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800187 if [ -z "$fromuser" ]; then
188 exit 1
189 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800190 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800191 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800192 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800193done
194
Martin Wicke916776a2016-01-14 07:30:00 -0800195# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800196while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800197 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800198 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800199 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 -0800200 fi
201
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800202 fromuser=""
203 if [ -z "$CUDNN_INSTALL_PATH" ]; then
204 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800205 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 -0800206 fromuser="1"
207 if [ -z "$CUDNN_INSTALL_PATH" ]; then
208 CUDNN_INSTALL_PATH=$default_cudnn_path
209 fi
210 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
211 # Going through one more level of expansion to handle that.
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800212 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 -0800213 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800214
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800215 if [[ -z "$TF_CUDNN_VERSION" ]]; then
216 TF_CUDNN_EXT=""
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800217 # Resolve to the SONAME of the symlink. Use readlink without -f
218 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
219 # libcudnn.so.4
220 REALVAL=`readlink ${CUDNN_INSTALL_PATH}/lib64/libcudnn.so`
221
222 # Extract the version of the SONAME, if it was indeed symlinked to
223 # the SONAME version of the file.
224 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]];
225 then
226 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
227 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
228 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
229 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800230 else
231 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
232 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800233
234 if [ "$OSNAME" == "Linux" ]; then
235 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
236 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
237 elif [ "$OSNAME" == "Darwin" ]; then
238 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
239 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
240 fi
241
242 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 -0800243 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800244 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800245 break
246 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800247
248 if [ "$OSNAME" == "Linux" ]; then
249 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
250 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800251 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800252 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800253 break
254 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800255 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800256 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
257 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
258 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
259 if [ "$OSNAME" == "Linux" ]; then
260 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
261 fi
262
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800263 if [ -z "$fromuser" ]; then
264 exit 1
265 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800266 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800267 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800268 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800269done
270
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800271# Configure the compute capabilities that TensorFlow builds for.
272# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
273while true; do
274 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800275 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800276 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800277cat << EOF
278Please specify a list of comma-separated Cuda compute capabilities you want to build with.
279You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
280Please note that each additional compute capability significantly increases your build time and binary size.
281EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800282 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
283 fromuser=1
284 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800285 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
286 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
287 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800288 # Check whether all capabilities from the input is valid
289 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
290 ALL_VALID=1
291 for CAPABILITY in $COMPUTE_CAPABILITIES; do
292 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
293 echo "Invalid compute capability: " $CAPABILITY
294 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800295 break
296 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800297 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800298 if [ "$ALL_VALID" == "0" ]; then
299 if [ -z "$fromuser" ]; then
300 exit 1
301 fi
302 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800303 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800304 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800305 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800306 TF_CUDA_COMPUTE_CAPABILITIES=""
307done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800308
Jonathan Hseu1283b842016-09-29 15:05:32 -0800309bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800310
311echo "Configuration finished"