blob: ce75bb490a7a4f87e0edff554036aeeb053724da [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
Andrew Selle09045e42016-09-06 08:19:04 -08005# Find out the absolute path to where ./configure resides
6pushd `dirname $0` #> /dev/null
7SOURCE_BASE_DIR=`pwd -P`
8popd > /dev/null
9
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080010## Set up python-related environment settings
11while true; do
12 fromuser=""
13 if [ -z "$PYTHON_BIN_PATH" ]; then
14 default_python_bin_path=$(which python)
15 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
16 fromuser="1"
17 if [ -z "$PYTHON_BIN_PATH" ]; then
18 PYTHON_BIN_PATH=$default_python_bin_path
19 fi
20 fi
21 if [ -e "$PYTHON_BIN_PATH" ]; then
22 break
23 fi
24 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
25 if [ -z "$fromuser" ]; then
26 exit 1
27 fi
28 PYTHON_BIN_PATH=""
29 # Retry
30done
31
A. Unique TensorFlowered65e692016-05-11 21:03:48 -080032while [ "$TF_NEED_GCP" == "" ]; do
33 read -p "Do you wish to build TensorFlow with "\
34"Google Cloud Platform support? [y/N] " INPUT
35 case $INPUT in
36 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
37"TensorFlow"; TF_NEED_GCP=1;;
38 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
39"TensorFlow"; TF_NEED_GCP=0;;
40 "" ) echo "No Google Cloud Platform support will be enabled for "\
41"TensorFlow"; TF_NEED_GCP=0;;
42 * ) echo "Invalid selection: " $INPUT;;
43 esac
44done
45
46if [ "$TF_NEED_GCP" == "1" ]; then
47
48 ## Verify that libcurl header files are available.
49 # Only check Linux, since on MacOS the header files are installed with XCode.
50 if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
51 echo "ERROR: It appears that the development version of libcurl is not "\
52"available. Please install the libcurl3-dev package."
53 exit 1
54 fi
55
56 # Update Bazel build configuration.
57 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl
58else
59 # Update Bazel build configuration.
60 perl -pi -e "s,WITH_GCP_SUPPORT = (False|True),WITH_GCP_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl
61fi
62
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -080063## Find swig path
64if [ -z "$SWIG_PATH" ]; then
65 SWIG_PATH=`type -p swig 2> /dev/null`
66fi
67if [[ ! -e "$SWIG_PATH" ]]; then
68 echo "Can't find swig. Ensure swig is in \$PATH or set \$SWIG_PATH."
69 exit 1
70fi
71echo "$SWIG_PATH" > tensorflow/tools/swig/swig_path
72
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080073# Invoke python_config and set up symlinks to python includes
74(./util/python/python_config.sh --setup "$PYTHON_BIN_PATH";) || exit -1
75
Andrew Selle09045e42016-09-06 08:19:04 -080076# Run the gen_git_source to create links where bazel can track dependencies for
77# git hash propagation
78GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
79chmod a+x ${GEN_GIT_SOURCE}
80${PYTHON_BIN_PATH} ${GEN_GIT_SOURCE} --configure ${SOURCE_BASE_DIR}
81
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080082## Set up Cuda-related environment settings
83
84while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080085 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080086 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080087 [Yy]* ) echo "GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
88 [Nn]* ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
89 "" ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080090 * ) echo "Invalid selection: " $INPUT;;
91 esac
92done
93
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -080094export TF_NEED_CUDA
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080095if [ "$TF_NEED_CUDA" == "0" ]; then
96 echo "Configuration finished"
97 exit
98fi
99
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800100# Set up which gcc nvcc should use as the host compiler
101while true; do
102 fromuser=""
103 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
104 default_gcc_host_compiler_path=$(which gcc)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800105 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 -0800106 fromuser="1"
107 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
108 GCC_HOST_COMPILER_PATH=$default_gcc_host_compiler_path
109 fi
110 fi
111 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800112 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800113 break
114 fi
115 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
116 if [ -z "$fromuser" ]; then
117 exit 1
118 fi
119 GCC_HOST_COMPILER_PATH=""
120 # Retry
121done
122
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800123# Find out where the CUDA toolkit is installed
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800124OSNAME=`uname -s`
125
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800126while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800127 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800128 if [ -z "$TF_CUDA_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800129 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 -0800130 fi
131
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800132 fromuser=""
133 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
134 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800135 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 -0800136 fromuser="1"
137 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
138 CUDA_TOOLKIT_PATH=$default_cuda_path
139 fi
140 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800141
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800142 if [[ -z "$TF_CUDA_VERSION" ]]; then
143 TF_CUDA_EXT=""
144 else
145 TF_CUDA_EXT=".$TF_CUDA_VERSION"
146 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800147
148 if [ "$OSNAME" == "Linux" ]; then
149 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
150 elif [ "$OSNAME" == "Darwin" ]; then
151 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
152 fi
153
154 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800155 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800156 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800157 break
158 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800159 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
160
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800161 if [ -z "$fromuser" ]; then
162 exit 1
163 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800164 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800165 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800166 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800167done
168
Martin Wicke916776a2016-01-14 07:30:00 -0800169# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800170while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800171 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800172 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800173 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 -0800174 fi
175
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800176 fromuser=""
177 if [ -z "$CUDNN_INSTALL_PATH" ]; then
178 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800179 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 -0800180 fromuser="1"
181 if [ -z "$CUDNN_INSTALL_PATH" ]; then
182 CUDNN_INSTALL_PATH=$default_cudnn_path
183 fi
184 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
185 # Going through one more level of expansion to handle that.
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800186 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 -0800187 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800188
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800189 if [[ -z "$TF_CUDNN_VERSION" ]]; then
190 TF_CUDNN_EXT=""
A. Unique TensorFlower533d8912016-06-30 12:10:50 -0800191 # Resolve to the SONAME of the symlink. Use readlink without -f
192 # to resolve exactly once to the SONAME. E.g, libcudnn.so ->
193 # libcudnn.so.4
194 REALVAL=`readlink ${CUDNN_INSTALL_PATH}/lib64/libcudnn.so`
195
196 # Extract the version of the SONAME, if it was indeed symlinked to
197 # the SONAME version of the file.
198 if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]];
199 then
200 TF_CUDNN_EXT="."${BASH_REMATCH[1]}
201 TF_CUDNN_VERSION=${BASH_REMATCH[1]}
202 echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}"
203 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800204 else
205 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
206 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800207
208 if [ "$OSNAME" == "Linux" ]; then
209 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
210 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
211 elif [ "$OSNAME" == "Darwin" ]; then
212 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
213 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
214 fi
215
216 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 -0800217 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800218 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800219 break
220 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800221
222 if [ "$OSNAME" == "Linux" ]; then
223 CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
224 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800225 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800226 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800227 break
228 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800229 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800230 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
231 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
232 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
233 if [ "$OSNAME" == "Linux" ]; then
234 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
235 fi
236
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800237 if [ -z "$fromuser" ]; then
238 exit 1
239 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800240 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800241 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800242 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800243done
244
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800245# Configure the compute capabilities that TensorFlow builds for.
246# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
247while true; do
248 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800249 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800250 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800251cat << EOF
252Please specify a list of comma-separated Cuda compute capabilities you want to build with.
253You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
254Please note that each additional compute capability significantly increases your build time and binary size.
255EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800256 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
257 fromuser=1
258 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800259 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
260 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
261 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800262 # Check whether all capabilities from the input is valid
263 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
264 ALL_VALID=1
265 for CAPABILITY in $COMPUTE_CAPABILITIES; do
266 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
267 echo "Invalid compute capability: " $CAPABILITY
268 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800269 break
270 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800271 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800272 if [ "$ALL_VALID" == "0" ]; then
273 if [ -z "$fromuser" ]; then
274 exit 1
275 fi
276 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800277 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800278 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800279 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800280 TF_CUDA_COMPUTE_CAPABILITIES=""
281done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800282
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800283bazel clean --expunge
284bazel fetch //...
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800285
286echo "Configuration finished"