blob: 081db20d7535d36889922a2fec43298df48c7770 [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
A. Unique TensorFlower46d2c282017-01-02 22:19:48 -08007pushd `dirname $0` > /dev/null
Andrew Selle09045e42016-09-06 08:19:04 -08008SOURCE_BASE_DIR=`pwd -P`
9popd > /dev/null
10
Martin Wickebc456e32017-03-23 12:31:16 -080011# This file contains customized config settings.
12touch .bazelrc
13
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080014PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
Jonathan Hseuc058a012017-01-17 15:06:43 -080015
16function is_linux() {
17 if [[ "${PLATFORM}" == "linux" ]]; then
18 true
19 else
20 false
21 fi
22}
23
24function is_macos() {
25 if [[ "${PLATFORM}" == "darwin" ]]; then
26 true
27 else
28 false
29 fi
30}
31
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080032function is_windows() {
33 # On windows, the shell script is actually running in msys
Shanqing Cai56fc8832017-01-23 18:25:25 -080034 if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080035 true
36 else
37 false
38 fi
39}
40
Jonathan Hseu1283b842016-09-29 15:05:32 -080041function bazel_clean_and_fetch() {
Asim Shankar429d14d2017-03-13 13:27:31 -080042 if [ -z "$TF_BAZEL_TARGETS" ]; then
Martin Wickebc456e32017-03-23 12:31:16 -080043 bazel fetch "//tensorflow/... -//tensorflow/contrib/nccl/... -//tensorflow/examples/android/..."
44 else
45 bazel fetch $TF_BAZEL_TARGETS
Asim Shankar429d14d2017-03-13 13:27:31 -080046 fi
Jonathan Hseu1283b842016-09-29 15:05:32 -080047}
48
Dandelion Mané0386a012017-03-10 14:43:23 -080049function sed_hyphen_i() {
50 if is_macos; then
51 sed -i '' "$@"
52 else
53 sed -i "$@"
54 fi
55}
56
Andrew Harp51dbc462017-01-27 14:42:30 -080057# Delete any leftover BUILD files from the Makefile build, which would interfere
58# with Bazel parsing.
59MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
60if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
61 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
62fi
63
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080064## Set up python-related environment settings
65while true; do
66 fromuser=""
67 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080068 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080069 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
70 fromuser="1"
71 if [ -z "$PYTHON_BIN_PATH" ]; then
72 PYTHON_BIN_PATH=$default_python_bin_path
73 fi
74 fi
75 if [ -e "$PYTHON_BIN_PATH" ]; then
76 break
77 fi
78 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
79 if [ -z "$fromuser" ]; then
80 exit 1
81 fi
82 PYTHON_BIN_PATH=""
83 # Retry
84done
85
Benoit Steiner639b4e72017-02-08 09:25:09 -080086## Set up MKL related environment settings
87if false; then # Disable building with MKL for now
88 while [ "$TF_NEED_MKL" == "" ]; do
89 fromuser=""
90 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
91 fromuser="1"
92 case $INPUT in
93 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
94 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
95 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
96 * ) echo "Invalid selection: " $INPUT;;
97 esac
98 done
99
100 OSNAME=`uname -s`
101
102 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
103 DST=`dirname $0`
Martin Wickebc456e32017-03-23 12:31:16 -0800104 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
105 GITHUB_RELEASE_TAG=v0.5
Benoit Steiner639b4e72017-02-08 09:25:09 -0800106 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
107 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
108 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
109 fi
110 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
111 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
112 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
113 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
114
115 if [ "$OSNAME" == "Linux" ]; then
116 # Full MKL configuration
117 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
118 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
119
120 # MKL-ML configuration
121 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
122 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
123 elif [ "$OSNAME" == "Darwin" ]; then
124 echo "Darwin is unsupported yet";
125 exit 1
126 fi
127
128 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
129 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
130 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
131 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
132 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
133 else
134 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
135 exit 1
136 fi
137
138 if [ -z "$fromuser" ]; then
139 exit 1
140 fi
141
142cat > third_party/mkl/mkl.config <<EOF
143# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
144# files can be either in this directory, or under include/ and lib64/
145MKL_INSTALL_PATH=$MKL_INSTALL_PATH
146EOF
147
148 fi # TF_NEED_MKL
149 ################## MKL
150fi # Disable building with MKL for now
151
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800152## Set up architecture-dependent optimization flags.
153if [ -z "$CC_OPT_FLAGS" ]; then
154 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800155 read -p "Please specify optimization flags to use during compilation when bazel option "\
156"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800157 if [ -z "$CC_OPT_FLAGS" ]; then
158 CC_OPT_FLAGS=$default_cc_opt_flags
159 fi
160fi
161
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800162if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800163 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800164 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800165 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800166 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800167fi
168
Jonathan Hseuc058a012017-01-17 15:06:43 -0800169if is_linux; then
170 while [ "$TF_NEED_JEMALLOC" == "" ]; do
171 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
172 INPUT
173 case $INPUT in
174 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
175 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
176 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
177 * ) echo "Invalid selection: " $INPUT;;
178 esac
179 done
180else
181 TF_NEED_JEMALLOC=0
182fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800183
Martin Wickebc456e32017-03-23 12:31:16 -0800184sed_hyphen_i -e "/with_jemalloc/d" .bazelrc
185if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
186 echo 'build --define with_jemalloc=true' >>.bazelrc
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800187fi
188
Martin Wickebc456e32017-03-23 12:31:16 -0800189while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800190 read -p "Do you wish to build TensorFlow with "\
191"Google Cloud Platform support? [y/N] " INPUT
192 case $INPUT in
193 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
194"TensorFlow"; TF_NEED_GCP=1;;
195 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
196"TensorFlow"; TF_NEED_GCP=0;;
197 "" ) echo "No Google Cloud Platform support will be enabled for "\
198"TensorFlow"; TF_NEED_GCP=0;;
199 * ) echo "Invalid selection: " $INPUT;;
200 esac
201done
202
Martin Wickebc456e32017-03-23 12:31:16 -0800203sed_hyphen_i -e "/with_gcp_support/d" .bazelrc
204if [[ "$TF_NEED_GCP" == "1" ]]; then
205 echo 'build --define with_gcp_support=true' >>.bazelrc
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800206fi
207
Martin Wickebc456e32017-03-23 12:31:16 -0800208while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800209 read -p "Do you wish to build TensorFlow with "\
210"Hadoop File System support? [y/N] " INPUT
211 case $INPUT in
212 [Yy]* ) echo "Hadoop File System support will be enabled for "\
213"TensorFlow"; TF_NEED_HDFS=1;;
214 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
215"TensorFlow"; TF_NEED_HDFS=0;;
216 "" ) echo "No Hadoop File System support will be enabled for "\
217"TensorFlow"; TF_NEED_HDFS=0;;
218 * ) echo "Invalid selection: " $INPUT;;
219 esac
220done
221
Martin Wickebc456e32017-03-23 12:31:16 -0800222sed_hyphen_i -e "/with_hdfs_support/d" .bazelrc
223if [[ "$TF_NEED_HDFS" == "1" ]]; then
224 echo 'build --define with_hdfs_support=true' >>.bazelrc
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800225fi
226
Peter Hawkins1e67c902017-01-09 12:04:37 -0800227## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800228while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800229 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
230 case $INPUT in
231 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
232 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
233 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
234 * ) echo "Invalid selection: " $INPUT;;
235 esac
236done
237
Martin Wickebc456e32017-03-23 12:31:16 -0800238sed_hyphen_i -e "/with_xla_support/d" .bazelrc
239if [[ "$TF_ENABLE_XLA" == "1" ]]; then
240 echo 'build --define with_xla_support=true' >>.bazelrc
Peter Hawkins1e67c902017-01-09 12:04:37 -0800241fi
242
243
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800244# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800245./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800246
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800247# Append CC optimization flags to bazel.rc
248echo >> tools/bazel.rc
249for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800250 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800251done
252
Andrew Selle09045e42016-09-06 08:19:04 -0800253# Run the gen_git_source to create links where bazel can track dependencies for
254# git hash propagation
255GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
256chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800257"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800258
Benoit Steinera7715982016-11-09 13:14:03 -0800259## Set up SYCL-related environment settings
260while [ "$TF_NEED_OPENCL" == "" ]; do
261 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
262 case $INPUT in
263 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
264 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
265 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
266 * ) echo "Invalid selection: " $INPUT;;
267 esac
268done
269
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800270## Set up Cuda-related environment settings
271
272while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800273 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800274 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800275 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
276 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
277 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800278 * ) echo "Invalid selection: " $INPUT;;
279 esac
280done
281
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800282export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800283export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800284if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800285 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800286 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800287 exit
288fi
289
Benoit Steinera7715982016-11-09 13:14:03 -0800290if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800291# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800292# No need to set this on Windows
293while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800294 fromuser=""
295 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800296 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800297 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 -0800298 fromuser="1"
299 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800300 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800301 fi
302 fi
303 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800304 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800305 break
306 fi
307 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
308 if [ -z "$fromuser" ]; then
309 exit 1
310 fi
311 GCC_HOST_COMPILER_PATH=""
312 # Retry
313done
314
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800315# Find out where the CUDA toolkit is installed
316while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800317 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800318 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800319 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 -0800320 fi
321
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800322 fromuser=""
323 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
324 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800325 if is_windows; then
326 if [ -z "$CUDA_PATH" ]; then
327 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
328 else
329 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
330 fi
331 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800332 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 -0800333 fromuser="1"
334 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800335 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800336 fi
337 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800338
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800339 if [[ -z "$TF_CUDA_VERSION" ]]; then
340 TF_CUDA_EXT=""
341 else
342 TF_CUDA_EXT=".$TF_CUDA_VERSION"
343 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800344
Andrew Harp1cb96892016-12-08 20:05:49 -0800345 if is_windows; then
346 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800347 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800348 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800349 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800350 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
351 fi
352
353 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800354 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800355 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800356 break
357 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800358 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
359
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800360 if [ -z "$fromuser" ]; then
361 exit 1
362 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800363 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800364 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800365 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800366done
367
Martin Wicke916776a2016-01-14 07:30:00 -0800368# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800369while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800370 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800371 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800372 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 -0800373 fi
374
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800375 fromuser=""
376 if [ -z "$CUDNN_INSTALL_PATH" ]; then
377 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800378 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 -0800379 fromuser="1"
380 if [ -z "$CUDNN_INSTALL_PATH" ]; then
381 CUDNN_INSTALL_PATH=$default_cudnn_path
382 fi
383 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
384 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800385 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 -0800386 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800387
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800388 if [[ -z "$TF_CUDNN_VERSION" ]]; then
389 TF_CUDNN_EXT=""
390 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800391 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800392 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800393
Andrew Harp1cb96892016-12-08 20:05:49 -0800394 if is_windows; then
395 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
396 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800397 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800398 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
399 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800400 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800401 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
402 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800403 fi
404
405 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 -0800406 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800407 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800408 break
409 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800410
Jonathan Hseuc058a012017-01-17 15:06:43 -0800411 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800412 if ! type ldconfig > /dev/null 2>&1; then
413 LDCONFIG_BIN=/sbin/ldconfig
414 else
415 LDCONFIG_BIN=ldconfig
416 fi
417 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800418 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800419 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800420 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800421 break
422 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800423 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800424 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
425 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
426 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800427 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800428 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
429 fi
430
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800431 if [ -z "$fromuser" ]; then
432 exit 1
433 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800434 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800435 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800436 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800437done
438
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800439# Configure the compute capabilities that TensorFlow builds for.
440# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
441while true; do
442 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800443 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800444 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800445cat << EOF
446Please specify a list of comma-separated Cuda compute capabilities you want to build with.
447You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
448Please note that each additional compute capability significantly increases your build time and binary size.
449EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800450 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
451 fromuser=1
452 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800453 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
454 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
455 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800456 # Check whether all capabilities from the input is valid
457 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
458 ALL_VALID=1
459 for CAPABILITY in $COMPUTE_CAPABILITIES; do
460 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
461 echo "Invalid compute capability: " $CAPABILITY
462 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800463 break
464 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800465 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800466 if [ "$ALL_VALID" == "0" ]; then
467 if [ -z "$fromuser" ]; then
468 exit 1
469 fi
470 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800471 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800472 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800473 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800474 TF_CUDA_COMPUTE_CAPABILITIES=""
475done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800476
Andrew Harp1cb96892016-12-08 20:05:49 -0800477if is_windows; then
478 # The following three variables are needed for MSVC toolchain configuration in Bazel
479 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
480 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
481 export NO_WHOLE_ARCHIVE_OPTION=1
482
483 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
484 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
485fi
486
Benoit Steinera7715982016-11-09 13:14:03 -0800487# end of if "$TF_NEED_CUDA" == "1"
488fi
489
490# OpenCL configuration
491
492if [ "$TF_NEED_OPENCL" == "1" ]; then
493
494# Determine which C++ compiler should be used as the host compiler
495while true; do
496 fromuser=""
497 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800498 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800499 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
500 fromuser="1"
501 if [ -z "$HOST_CXX_COMPILER" ]; then
502 HOST_CXX_COMPILER=$default_cxx_host_compiler
503 fi
504 fi
505 if [ -e "$HOST_CXX_COMPILER" ]; then
506 export HOST_CXX_COMPILER
507 break
508 fi
509 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
510 if [ -z "$fromuser" ]; then
511 exit 1
512 fi
513 HOST_CXX_COMPILER=""
514 # Retry
515done
516
517# Determine which C compiler should be used as the host compiler
518while true; do
519 fromuser=""
520 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800521 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800522 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
523 fromuser="1"
524 if [ -z "$HOST_C_COMPILER" ]; then
525 HOST_C_COMPILER=$default_c_host_compiler
526 fi
527 fi
528 if [ -e "$HOST_C_COMPILER" ]; then
529 export HOST_C_COMPILER
530 break
531 fi
532 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
533 if [ -z "$fromuser" ]; then
534 exit 1
535 fi
536 HOST_C_COMPILER=""
537 # Retry
538done
539
540while true; do
541 # Configure the OPENCL version to use.
542 TF_OPENCL_VERSION="1.2"
543
544 # Point to ComputeCpp root
545 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
546 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800547 read -p "Please specify the location where ComputeCpp for SYCL $TF_OPENCL_VERSION is installed. [Default is $default_computecpp_toolkit_path]: " COMPUTECPP_TOOLKIT_PATH
Benoit Steinera7715982016-11-09 13:14:03 -0800548 fromuser="1"
549 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
550 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
551 fi
552 fi
553
Jonathan Hseuc058a012017-01-17 15:06:43 -0800554 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800555 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
556 fi
557
558 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
559 export COMPUTECPP_TOOLKIT_PATH
560 break
561 fi
562 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
563
564 if [ -z "$fromuser" ]; then
565 exit 1
566 fi
567 # Retry
568 TF_OPENCL_VERSION=""
569 COMPUTECPP_TOOLKIT_PATH=""
570done
571
Benoit Steinera7715982016-11-09 13:14:03 -0800572# end of if "$TF_NEED_OPENCL" == "1"
573fi
574
Jonathan Hseu1283b842016-09-29 15:05:32 -0800575bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800576
577echo "Configuration finished"