blob: 47bdd5d018e8d965846d7b4477f49e8128b9c74b [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
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080011PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
Jonathan Hseuc058a012017-01-17 15:06:43 -080012
13function is_linux() {
14 if [[ "${PLATFORM}" == "linux" ]]; then
15 true
16 else
17 false
18 fi
19}
20
21function is_macos() {
22 if [[ "${PLATFORM}" == "darwin" ]]; then
23 true
24 else
25 false
26 fi
27}
28
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080029function is_windows() {
30 # On windows, the shell script is actually running in msys
Shanqing Cai56fc8832017-01-23 18:25:25 -080031 if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080032 true
33 else
34 false
35 fi
36}
37
Dandelion Mané0386a012017-03-10 14:43:23 -080038function sed_hyphen_i() {
39 if is_macos; then
40 sed -i '' "$@"
41 else
42 sed -i "$@"
43 fi
44}
45
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080046function write_to_bazelrc() {
47 echo "$1" >> .tf_configure.bazelrc
48}
49
50function write_action_env_to_bazelrc() {
51 write_to_bazelrc "build --action_env $1=\"$2\""
52}
53
54# This file contains customized config settings.
55rm -f .tf_configure.bazelrc
56touch .tf_configure.bazelrc
57touch .bazelrc
58sed_hyphen_i "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -080059echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080060
Andrew Harp51dbc462017-01-27 14:42:30 -080061# Delete any leftover BUILD files from the Makefile build, which would interfere
62# with Bazel parsing.
63MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
64if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
65 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
66fi
67
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080068## Set up python-related environment settings
69while true; do
70 fromuser=""
71 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080072 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080073 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
74 fromuser="1"
75 if [ -z "$PYTHON_BIN_PATH" ]; then
76 PYTHON_BIN_PATH=$default_python_bin_path
77 fi
78 fi
79 if [ -e "$PYTHON_BIN_PATH" ]; then
80 break
81 fi
82 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
83 if [ -z "$fromuser" ]; then
84 exit 1
85 fi
86 PYTHON_BIN_PATH=""
87 # Retry
88done
A. Unique TensorFlower8e0d6f12017-04-21 06:35:18 -080089export PYTHON_BIN_PATH
90write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
91# TODO(ngiraldo): allow the user to optionally set PYTHON_INCLUDE_PATH and NUMPY_INCLUDE_PATH
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080092
Benoit Steiner639b4e72017-02-08 09:25:09 -080093## Set up MKL related environment settings
94if false; then # Disable building with MKL for now
95 while [ "$TF_NEED_MKL" == "" ]; do
96 fromuser=""
97 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
98 fromuser="1"
99 case $INPUT in
100 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
101 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
102 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
103 * ) echo "Invalid selection: " $INPUT;;
104 esac
105 done
106
107 OSNAME=`uname -s`
108
109 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
110 DST=`dirname $0`
Martin Wickebc456e32017-03-23 12:31:16 -0800111 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
112 GITHUB_RELEASE_TAG=v0.5
Benoit Steiner639b4e72017-02-08 09:25:09 -0800113 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
114 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
115 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
116 fi
117 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
118 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
119 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
120 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
121
122 if [ "$OSNAME" == "Linux" ]; then
123 # Full MKL configuration
124 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
125 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
126
127 # MKL-ML configuration
128 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
129 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
130 elif [ "$OSNAME" == "Darwin" ]; then
131 echo "Darwin is unsupported yet";
132 exit 1
133 fi
134
135 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
136 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
137 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
138 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
139 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
140 else
141 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
142 exit 1
143 fi
144
145 if [ -z "$fromuser" ]; then
146 exit 1
147 fi
148
149cat > third_party/mkl/mkl.config <<EOF
150# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
151# files can be either in this directory, or under include/ and lib64/
152MKL_INSTALL_PATH=$MKL_INSTALL_PATH
153EOF
154
155 fi # TF_NEED_MKL
156 ################## MKL
157fi # Disable building with MKL for now
158
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800159## Set up architecture-dependent optimization flags.
160if [ -z "$CC_OPT_FLAGS" ]; then
161 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800162 read -p "Please specify optimization flags to use during compilation when bazel option "\
163"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800164 if [ -z "$CC_OPT_FLAGS" ]; then
165 CC_OPT_FLAGS=$default_cc_opt_flags
166 fi
167fi
168
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800169if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800170 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800171 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800172 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800173 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800174 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800175fi
176
Jonathan Hseuc058a012017-01-17 15:06:43 -0800177if is_linux; then
178 while [ "$TF_NEED_JEMALLOC" == "" ]; do
179 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
180 INPUT
181 case $INPUT in
182 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
183 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
184 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
185 * ) echo "Invalid selection: " $INPUT;;
186 esac
187 done
188else
189 TF_NEED_JEMALLOC=0
190fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800191
Martin Wickebc456e32017-03-23 12:31:16 -0800192if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800193 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800194fi
195
Martin Wickebc456e32017-03-23 12:31:16 -0800196while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800197 read -p "Do you wish to build TensorFlow with "\
198"Google Cloud Platform support? [y/N] " INPUT
199 case $INPUT in
200 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
201"TensorFlow"; TF_NEED_GCP=1;;
202 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
203"TensorFlow"; TF_NEED_GCP=0;;
204 "" ) echo "No Google Cloud Platform support will be enabled for "\
205"TensorFlow"; TF_NEED_GCP=0;;
206 * ) echo "Invalid selection: " $INPUT;;
207 esac
208done
209
Martin Wickebc456e32017-03-23 12:31:16 -0800210if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800211 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800212fi
213
Martin Wickebc456e32017-03-23 12:31:16 -0800214while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800215 read -p "Do you wish to build TensorFlow with "\
216"Hadoop File System support? [y/N] " INPUT
217 case $INPUT in
218 [Yy]* ) echo "Hadoop File System support will be enabled for "\
219"TensorFlow"; TF_NEED_HDFS=1;;
220 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
221"TensorFlow"; TF_NEED_HDFS=0;;
222 "" ) echo "No Hadoop File System support will be enabled for "\
223"TensorFlow"; TF_NEED_HDFS=0;;
224 * ) echo "Invalid selection: " $INPUT;;
225 esac
226done
227
Martin Wickebc456e32017-03-23 12:31:16 -0800228if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800229 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800230fi
231
Peter Hawkins1e67c902017-01-09 12:04:37 -0800232## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800233while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800234 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
235 case $INPUT in
236 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
237 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
238 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
239 * ) echo "Invalid selection: " $INPUT;;
240 esac
241done
242
Martin Wickebc456e32017-03-23 12:31:16 -0800243if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800244 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800245fi
246
247
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800248# Invoke python_config and set up symlinks to python includes
A. Unique TensorFlower8e0d6f12017-04-21 06:35:18 -0800249./util/python/python_config.sh "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800250
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800251# Append CC optimization flags to bazel.rc
252echo >> tools/bazel.rc
253for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800254 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800255done
256
Andrew Selle09045e42016-09-06 08:19:04 -0800257# Run the gen_git_source to create links where bazel can track dependencies for
258# git hash propagation
259GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
260chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800261"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800262
Benoit Steinera7715982016-11-09 13:14:03 -0800263## Set up SYCL-related environment settings
264while [ "$TF_NEED_OPENCL" == "" ]; do
265 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
266 case $INPUT in
267 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
268 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
269 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
270 * ) echo "Invalid selection: " $INPUT;;
271 esac
272done
273
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800274## Set up Cuda-related environment settings
275
276while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800277 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800278 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800279 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
280 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
281 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800282 * ) echo "Invalid selection: " $INPUT;;
283 esac
284done
285
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800286export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800287write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800288
Rohan Jainaab09972017-01-05 14:39:17 -0800289export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800290write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800291
Benoit Steinera7715982016-11-09 13:14:03 -0800292if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800293while [[ "$TF_CUDA_CLANG" == "" ]]; do
294 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
295 case $INPUT in
296 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
297 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
298 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
299 * ) echo "Invalid selection: " $INPUT;;
300 esac
301done
302
303export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800304write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800305
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800306# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800307# No need to set this on Windows
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800308while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800309 fromuser=""
310 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800311 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800312 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 -0800313 fromuser="1"
314 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800315 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800316 fi
317 fi
318 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800319 export GCC_HOST_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800320 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800321 break
322 fi
323 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
324 if [ -z "$fromuser" ]; then
325 exit 1
326 fi
327 GCC_HOST_COMPILER_PATH=""
328 # Retry
329done
330
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800331# Set up which clang we should use as the cuda / host compiler.
332while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
333 fromuser=""
334 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
335 default_clang_host_compiler_path=$(which clang || true)
336 read -p "Please specify which clang should be used as device and host compiler. [Default is $default_clang_host_compiler_path]: " CLANG_CUDA_COMPILER_PATH
337 fromuser="1"
338 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
339 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
340 fi
341 fi
342 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
343 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800344 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800345 break
346 fi
347 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
348 if [ -z "$fromuser" ]; then
349 exit 1
350 fi
351 CLANG_CUDA_COMPILER_PATH=""
352 # Retry
353done
354
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800355# Find out where the CUDA toolkit is installed
356while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800357 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800358 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800359 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 -0800360 fi
361
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800362 fromuser=""
363 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
364 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800365 if is_windows; then
366 if [ -z "$CUDA_PATH" ]; then
367 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
368 else
369 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
370 fi
371 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800372 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 -0800373 fromuser="1"
374 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800375 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800376 fi
377 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800378
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800379 if [[ -z "$TF_CUDA_VERSION" ]]; then
380 TF_CUDA_EXT=""
381 else
382 TF_CUDA_EXT=".$TF_CUDA_VERSION"
383 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800384
Andrew Harp1cb96892016-12-08 20:05:49 -0800385 if is_windows; then
386 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800387 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800388 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800389 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800390 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
391 fi
392
393 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800394 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800395 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800396 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800397 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800398 break
399 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800400 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
401
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800402 if [ -z "$fromuser" ]; then
403 exit 1
404 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800405 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800406 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800407 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800408done
409
Martin Wicke916776a2016-01-14 07:30:00 -0800410# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800411while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800412 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800413 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800414 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 -0800415 fi
416
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800417 fromuser=""
418 if [ -z "$CUDNN_INSTALL_PATH" ]; then
419 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800420 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 -0800421 fromuser="1"
422 if [ -z "$CUDNN_INSTALL_PATH" ]; then
423 CUDNN_INSTALL_PATH=$default_cudnn_path
424 fi
425 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
426 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800427 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 -0800428 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800429
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800430 if [[ -z "$TF_CUDNN_VERSION" ]]; then
431 TF_CUDNN_EXT=""
432 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800433 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800434 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800435
Andrew Harp1cb96892016-12-08 20:05:49 -0800436 if is_windows; then
437 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
438 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800439 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800440 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
441 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800442 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800443 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
444 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800445 fi
446
447 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 -0800448 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800449 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800450 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800451 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800452 break
453 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800454
Jonathan Hseuc058a012017-01-17 15:06:43 -0800455 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800456 if ! type ldconfig > /dev/null 2>&1; then
457 LDCONFIG_BIN=/sbin/ldconfig
458 else
459 LDCONFIG_BIN=ldconfig
460 fi
461 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800462 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800463 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800464 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800465 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800466 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800467 break
468 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800469 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800470 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
471 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
472 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800473 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800474 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
475 fi
476
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800477 if [ -z "$fromuser" ]; then
478 exit 1
479 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800480 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800481 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800482 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800483done
484
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800485# Configure the compute capabilities that TensorFlow builds for.
486# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
487while true; do
488 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800489 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800490 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800491cat << EOF
492Please specify a list of comma-separated Cuda compute capabilities you want to build with.
493You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
494Please note that each additional compute capability significantly increases your build time and binary size.
495EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800496 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
497 fromuser=1
498 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800499 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
500 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
501 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800502 # Check whether all capabilities from the input is valid
503 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
504 ALL_VALID=1
505 for CAPABILITY in $COMPUTE_CAPABILITIES; do
506 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
507 echo "Invalid compute capability: " $CAPABILITY
508 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800509 break
510 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800511 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800512 if [ "$ALL_VALID" == "0" ]; then
513 if [ -z "$fromuser" ]; then
514 exit 1
515 fi
516 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800517 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800518 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800519 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800520 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800521 TF_CUDA_COMPUTE_CAPABILITIES=""
522done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800523
Andrew Harp1cb96892016-12-08 20:05:49 -0800524if is_windows; then
525 # The following three variables are needed for MSVC toolchain configuration in Bazel
526 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
527 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
528 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800529 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
530 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
531 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800532fi
533
Benoit Steinera7715982016-11-09 13:14:03 -0800534# end of if "$TF_NEED_CUDA" == "1"
535fi
536
537# OpenCL configuration
538
539if [ "$TF_NEED_OPENCL" == "1" ]; then
540
541# Determine which C++ compiler should be used as the host compiler
542while true; do
543 fromuser=""
544 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800545 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800546 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
547 fromuser="1"
548 if [ -z "$HOST_CXX_COMPILER" ]; then
549 HOST_CXX_COMPILER=$default_cxx_host_compiler
550 fi
551 fi
552 if [ -e "$HOST_CXX_COMPILER" ]; then
553 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800554 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800555 break
556 fi
557 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
558 if [ -z "$fromuser" ]; then
559 exit 1
560 fi
561 HOST_CXX_COMPILER=""
562 # Retry
563done
564
565# Determine which C compiler should be used as the host compiler
566while true; do
567 fromuser=""
568 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800569 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800570 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
571 fromuser="1"
572 if [ -z "$HOST_C_COMPILER" ]; then
573 HOST_C_COMPILER=$default_c_host_compiler
574 fi
575 fi
576 if [ -e "$HOST_C_COMPILER" ]; then
577 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800578 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800579 break
580 fi
581 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
582 if [ -z "$fromuser" ]; then
583 exit 1
584 fi
585 HOST_C_COMPILER=""
586 # Retry
587done
588
589while true; do
590 # Configure the OPENCL version to use.
591 TF_OPENCL_VERSION="1.2"
592
593 # Point to ComputeCpp root
594 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
595 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800596 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 -0800597 fromuser="1"
598 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
599 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
600 fi
601 fi
602
Jonathan Hseuc058a012017-01-17 15:06:43 -0800603 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800604 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
605 fi
606
607 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
608 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800609 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800610 break
611 fi
612 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
613
614 if [ -z "$fromuser" ]; then
615 exit 1
616 fi
617 # Retry
618 TF_OPENCL_VERSION=""
619 COMPUTECPP_TOOLKIT_PATH=""
620done
621
Benoit Steinera7715982016-11-09 13:14:03 -0800622# end of if "$TF_NEED_OPENCL" == "1"
623fi
624
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800625# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
626bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800627echo "Configuration finished"