blob: feac140664268364944b49ae23123a8b2bbadb45 [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
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -08008## Set up python-related environment settings
9while true; do
10 fromuser=""
11 if [ -z "$PYTHON_BIN_PATH" ]; then
12 default_python_bin_path=$(which python)
13 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
14 fromuser="1"
15 if [ -z "$PYTHON_BIN_PATH" ]; then
16 PYTHON_BIN_PATH=$default_python_bin_path
17 fi
18 fi
19 if [ -e "$PYTHON_BIN_PATH" ]; then
20 break
21 fi
22 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
23 if [ -z "$fromuser" ]; then
24 exit 1
25 fi
26 PYTHON_BIN_PATH=""
27 # Retry
28done
29
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080030while [ "$TF_NEED_GCP" == "" ]; do
31 read -p "Do you wish to build TensorFlow with "\
32"Google Cloud Platform support? [y/N] " INPUT
33 case $INPUT in
34 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
35"TensorFlow"; TF_NEED_GCP=1;;
36 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
37"TensorFlow"; TF_NEED_GCP=0;;
38 "" ) echo "No Google Cloud Platform support will be enabled for "\
39"TensorFlow"; TF_NEED_GCP=0;;
40 * ) echo "Invalid selection: " $INPUT;;
41 esac
42done
43
44if [ "$TF_NEED_GCP" == "1" ]; then
45
46 ## Verify that libcurl header files are available.
47 # Only check Linux, since on MacOS the header files are installed with XCode.
48 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
49 echo "ERROR: It appears that the development version of libcurl is not "\
50"available. Please install the libcurl3-dev package."
51 exit 1
52 fi
53
54 # Update Bazel build configuration.
55 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
56else
57 # Update Bazel build configuration.
58 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
59fi
60
Jonathan Hseu9f5b0982016-09-19 11:14:58 -080061while [ "$TF_NEED_HDFS" == "" ]; do
62 read -p "Do you wish to build TensorFlow with "\
63"Hadoop File System support? [y/N] " INPUT
64 case $INPUT in
65 [Yy]* ) echo "Hadoop File System support will be enabled for "\
66"TensorFlow"; TF_NEED_HDFS=1;;
67 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
68"TensorFlow"; TF_NEED_HDFS=0;;
69 "" ) echo "No Hadoop File System support will be enabled for "\
70"TensorFlow"; TF_NEED_HDFS=0;;
71 * ) echo "Invalid selection: " $INPUT;;
72 esac
73done
74
75if [ "$TF_NEED_HDFS" == "1" ]; then
76 # Update Bazel build configuration.
77 perl -pi -e "s,WITH_HDFS_SUPPORT = (False|True),WITH_HDFS_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
78else
79 # Update Bazel build configuration.
80 perl -pi -e "s,WITH_HDFS_SUPPORT = (False|True),WITH_HDFS_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
81fi
82
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -080083## Find swig path
84if [ -z "$SWIG_PATH" ]; then
85 SWIG_PATH=`type -p swig 2> /dev/null`
86fi
87if [[ ! -e "$SWIG_PATH" ]]; then
88 echo "Can't find swig. Ensure swig is in \$PATH or set \$SWIG_PATH."
89 exit 1
90fi
91echo "$SWIG_PATH" > tensorflow/tools/swig/swig_path
92
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080093# Invoke python_config and set up symlinks to python includes
94(./util/python/python_config.sh --setup "$PYTHON_BIN_PATH";) || exit -1
95
Andrew Selle09045e42016-09-06 08:19:04 -080096# Run the gen_git_source to create links where bazel can track dependencies for
97# git hash propagation
98GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
99chmod a+x ${GEN_GIT_SOURCE}
100${PYTHON_BIN_PATH} ${GEN_GIT_SOURCE} --configure ${SOURCE_BASE_DIR}
101
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800102## Set up Cuda-related environment settings
103
104while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800105 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800106 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800107 [Yy]* ) echo "GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
108 [Nn]* ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
109 "" ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800110 * ) echo "Invalid selection: " $INPUT;;
111 esac
112done
113
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800114export TF_NEED_CUDA
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800115if [ "$TF_NEED_CUDA" == "0" ]; then
116 echo "Configuration finished"
117 exit
118fi
119
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800120# Set up which gcc nvcc should use as the host compiler
121while true; do
122 fromuser=""
123 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
124 default_gcc_host_compiler_path=$(which gcc)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800125 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 -0800126 fromuser="1"
127 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
128 GCC_HOST_COMPILER_PATH=$default_gcc_host_compiler_path
129 fi
130 fi
131 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800132 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800133 break
134 fi
135 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
136 if [ -z "$fromuser" ]; then
137 exit 1
138 fi
139 GCC_HOST_COMPILER_PATH=""
140 # Retry
141done
142
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800143# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800144OSNAME=`uname -s`
145
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800146while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800147 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800148 if [ -z "$TF_CUDA_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800149 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 -0800150 fi
151
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800152 fromuser=""
153 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
154 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800155 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 -0800156 fromuser="1"
157 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
158 CUDA_TOOLKIT_PATH=$default_cuda_path
159 fi
160 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800161
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800162 if [[ -z "$TF_CUDA_VERSION" ]]; then
163 TF_CUDA_EXT=""
164 else
165 TF_CUDA_EXT=".$TF_CUDA_VERSION"
166 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800167
168 if [ "$OSNAME" == "Linux" ]; then
169 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
170 elif [ "$OSNAME" == "Darwin" ]; then
171 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
172 fi
173
174 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800175 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800176 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800177 break
178 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800179 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
180
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800181 if [ -z "$fromuser" ]; then
182 exit 1
183 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800184 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800185 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800186 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800187done
188
Martin Wicke916776a2016-01-14 07:30:00 -0800189# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800190while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800191 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800192 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800193 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 -0800194 fi
195
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800196 fromuser=""
197 if [ -z "$CUDNN_INSTALL_PATH" ]; then
198 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800199 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 -0800200 fromuser="1"
201 if [ -z "$CUDNN_INSTALL_PATH" ]; then
202 CUDNN_INSTALL_PATH=$default_cudnn_path
203 fi
204 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
205 # Going through one more level of expansion to handle that.
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800206 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 -0800207 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800208
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800209 if [[ -z "$TF_CUDNN_VERSION" ]]; then
210 TF_CUDNN_EXT=""
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800211 # Resolve to the SONAME of the symlink. Use readlink without -f
212 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
213 # libcudnn.so.4
214 REALVAL=`readlink ${CUDNN_INSTALL_PATH}/lib64/libcudnn.so`
215
216 # Extract the version of the SONAME, if it was indeed symlinked to
217 # the SONAME version of the file.
218 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]];
219 then
220 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
221 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
222 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
223 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800224 else
225 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
226 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800227
228 if [ "$OSNAME" == "Linux" ]; then
229 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
230 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
231 elif [ "$OSNAME" == "Darwin" ]; then
232 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
233 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
234 fi
235
236 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 -0800237 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800238 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800239 break
240 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800241
242 if [ "$OSNAME" == "Linux" ]; then
243 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
244 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800245 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800246 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800247 break
248 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800249 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800250 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
251 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
252 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
253 if [ "$OSNAME" == "Linux" ]; then
254 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
255 fi
256
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800257 if [ -z "$fromuser" ]; then
258 exit 1
259 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800260 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800261 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800262 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800263done
264
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800265# Configure the compute capabilities that TensorFlow builds for.
266# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
267while true; do
268 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800269 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800270 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800271cat << EOF
272Please specify a list of comma-separated Cuda compute capabilities you want to build with.
273You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
274Please note that each additional compute capability significantly increases your build time and binary size.
275EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800276 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
277 fromuser=1
278 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800279 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
280 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
281 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800282 # Check whether all capabilities from the input is valid
283 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
284 ALL_VALID=1
285 for CAPABILITY in $COMPUTE_CAPABILITIES; do
286 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
287 echo "Invalid compute capability: " $CAPABILITY
288 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800289 break
290 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800291 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800292 if [ "$ALL_VALID" == "0" ]; then
293 if [ -z "$fromuser" ]; then
294 exit 1
295 fi
296 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800297 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800298 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800299 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800300 TF_CUDA_COMPUTE_CAPABILITIES=""
301done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800302
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800303bazel clean --expunge
304bazel fetch //...
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800305
306echo "Configuration finished"