blob: fad3fdbebd944e2bb54b719a7f43a8be840fe0ea [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=""
Shanqing Cai32694232017-04-22 06:08:17 -080097 read -p "Do you wish to build TensorFlow with MKL support (experimental)? [y/N] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -080098 fromuser="1"
99 case $INPUT in
Shanqing Cai32694232017-04-22 06:08:17 -0800100 [Yy]* ) echo "MKL support (experimental) (will be enabled for TensorFlow"; TF_NEED_MKL=1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800101 [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
Shanqing Cai32694232017-04-22 06:08:17 -0800247# Verbs configuration
248while [ "$TF_NEED_VERBS" == "" ]; do
249 read -p "Do you wish to build TensorFlow with "\
250"VERBS support? [y/N] " INPUT
251 case $INPUT in
252 [Yy]* ) echo "VERBS support will be enabled for "\
253"TensorFlow"; TF_NEED_VERBS=1;;
254 [Nn]* ) echo "No VERBS support will be enabled for "\
255"TensorFlow"; TF_NEED_VERBS=0;;
256 "" ) echo "No VERBS support will be enabled for "\
257"TensorFlow"; TF_NEED_VERBS=0;;
258 * ) echo "Invalid selection: " $INPUT;;
259 esac
260done
261
262if [[ "$TF_NEED_VERBS" == "1" ]]; then
263 write_to_bazelrc 'build --define with_verbs_support=true'
264fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800265
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800266# Invoke python_config and set up symlinks to python includes
A. Unique TensorFlower8e0d6f12017-04-21 06:35:18 -0800267./util/python/python_config.sh "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800268
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800269# Append CC optimization flags to bazel.rc
270echo >> tools/bazel.rc
271for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800272 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800273done
274
Andrew Selle09045e42016-09-06 08:19:04 -0800275# Run the gen_git_source to create links where bazel can track dependencies for
276# git hash propagation
277GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
278chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800279"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800280
Benoit Steinera7715982016-11-09 13:14:03 -0800281## Set up SYCL-related environment settings
282while [ "$TF_NEED_OPENCL" == "" ]; do
283 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
284 case $INPUT in
285 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
286 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
287 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
288 * ) echo "Invalid selection: " $INPUT;;
289 esac
290done
291
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800292## Set up Cuda-related environment settings
293
294while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800295 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800296 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800297 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
298 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
299 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800300 * ) echo "Invalid selection: " $INPUT;;
301 esac
302done
303
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800304export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800305write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800306
Rohan Jainaab09972017-01-05 14:39:17 -0800307export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800308write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800309
Benoit Steinera7715982016-11-09 13:14:03 -0800310if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800311while [[ "$TF_CUDA_CLANG" == "" ]]; do
312 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
313 case $INPUT in
314 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
315 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
316 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
317 * ) echo "Invalid selection: " $INPUT;;
318 esac
319done
320
321export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800322write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800323
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800324# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800325# No need to set this on Windows
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800326while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800327 fromuser=""
328 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800329 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800330 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 -0800331 fromuser="1"
332 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800333 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800334 fi
335 fi
336 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800337 export GCC_HOST_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800338 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800339 break
340 fi
341 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
342 if [ -z "$fromuser" ]; then
343 exit 1
344 fi
345 GCC_HOST_COMPILER_PATH=""
346 # Retry
347done
348
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800349# Set up which clang we should use as the cuda / host compiler.
350while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
351 fromuser=""
352 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
353 default_clang_host_compiler_path=$(which clang || true)
354 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
355 fromuser="1"
356 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
357 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
358 fi
359 fi
360 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
361 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800362 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800363 break
364 fi
365 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
366 if [ -z "$fromuser" ]; then
367 exit 1
368 fi
369 CLANG_CUDA_COMPILER_PATH=""
370 # Retry
371done
372
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800373# Find out where the CUDA toolkit is installed
374while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800375 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800376 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800377 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 -0800378 fi
379
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800380 fromuser=""
381 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
382 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800383 if is_windows; then
384 if [ -z "$CUDA_PATH" ]; then
385 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
386 else
387 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
388 fi
389 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800390 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 -0800391 fromuser="1"
392 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800393 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800394 fi
395 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800396
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800397 if [[ -z "$TF_CUDA_VERSION" ]]; then
398 TF_CUDA_EXT=""
399 else
400 TF_CUDA_EXT=".$TF_CUDA_VERSION"
401 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800402
Andrew Harp1cb96892016-12-08 20:05:49 -0800403 if is_windows; then
404 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800405 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800406 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800407 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800408 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
409 fi
410
411 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800412 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800413 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800414 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800415 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800416 break
417 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800418 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
419
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800420 if [ -z "$fromuser" ]; then
421 exit 1
422 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800423 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800424 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800425 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800426done
427
Martin Wicke916776a2016-01-14 07:30:00 -0800428# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800429while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800430 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800431 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800432 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 -0800433 fi
434
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800435 fromuser=""
436 if [ -z "$CUDNN_INSTALL_PATH" ]; then
437 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800438 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 -0800439 fromuser="1"
440 if [ -z "$CUDNN_INSTALL_PATH" ]; then
441 CUDNN_INSTALL_PATH=$default_cudnn_path
442 fi
443 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
444 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800445 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 -0800446 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800447
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800448 if [[ -z "$TF_CUDNN_VERSION" ]]; then
449 TF_CUDNN_EXT=""
450 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800451 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800452 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800453
Andrew Harp1cb96892016-12-08 20:05:49 -0800454 if is_windows; then
455 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
456 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800457 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800458 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
459 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800460 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800461 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
462 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800463 fi
464
465 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 -0800466 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800467 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800468 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800469 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800470 break
471 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800472
Jonathan Hseuc058a012017-01-17 15:06:43 -0800473 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800474 if ! type ldconfig > /dev/null 2>&1; then
475 LDCONFIG_BIN=/sbin/ldconfig
476 else
477 LDCONFIG_BIN=ldconfig
478 fi
479 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800480 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800481 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800482 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800483 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800484 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800485 break
486 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800487 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800488 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
489 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
490 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800491 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800492 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
493 fi
494
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800495 if [ -z "$fromuser" ]; then
496 exit 1
497 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800498 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800499 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800500 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800501done
502
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800503# Configure the compute capabilities that TensorFlow builds for.
504# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
505while true; do
506 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800507 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800508 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800509cat << EOF
510Please specify a list of comma-separated Cuda compute capabilities you want to build with.
511You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
512Please note that each additional compute capability significantly increases your build time and binary size.
513EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800514 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
515 fromuser=1
516 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800517 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
518 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
519 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800520 # Check whether all capabilities from the input is valid
521 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
522 ALL_VALID=1
523 for CAPABILITY in $COMPUTE_CAPABILITIES; do
524 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
525 echo "Invalid compute capability: " $CAPABILITY
526 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800527 break
528 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800529 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800530 if [ "$ALL_VALID" == "0" ]; then
531 if [ -z "$fromuser" ]; then
532 exit 1
533 fi
534 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800535 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800536 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800537 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800538 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800539 TF_CUDA_COMPUTE_CAPABILITIES=""
540done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800541
Andrew Harp1cb96892016-12-08 20:05:49 -0800542if is_windows; then
543 # The following three variables are needed for MSVC toolchain configuration in Bazel
544 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
545 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
546 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800547 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
548 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
549 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800550fi
551
Benoit Steinera7715982016-11-09 13:14:03 -0800552# end of if "$TF_NEED_CUDA" == "1"
553fi
554
555# OpenCL configuration
556
557if [ "$TF_NEED_OPENCL" == "1" ]; then
558
559# Determine which C++ compiler should be used as the host compiler
560while true; do
561 fromuser=""
562 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800563 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800564 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
565 fromuser="1"
566 if [ -z "$HOST_CXX_COMPILER" ]; then
567 HOST_CXX_COMPILER=$default_cxx_host_compiler
568 fi
569 fi
570 if [ -e "$HOST_CXX_COMPILER" ]; then
571 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800572 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800573 break
574 fi
575 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
576 if [ -z "$fromuser" ]; then
577 exit 1
578 fi
579 HOST_CXX_COMPILER=""
580 # Retry
581done
582
583# Determine which C compiler should be used as the host compiler
584while true; do
585 fromuser=""
586 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800587 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800588 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
589 fromuser="1"
590 if [ -z "$HOST_C_COMPILER" ]; then
591 HOST_C_COMPILER=$default_c_host_compiler
592 fi
593 fi
594 if [ -e "$HOST_C_COMPILER" ]; then
595 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800596 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800597 break
598 fi
599 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
600 if [ -z "$fromuser" ]; then
601 exit 1
602 fi
603 HOST_C_COMPILER=""
604 # Retry
605done
606
607while true; do
608 # Configure the OPENCL version to use.
609 TF_OPENCL_VERSION="1.2"
610
611 # Point to ComputeCpp root
612 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
613 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800614 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 -0800615 fromuser="1"
616 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
617 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
618 fi
619 fi
620
Jonathan Hseuc058a012017-01-17 15:06:43 -0800621 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800622 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
623 fi
624
625 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
626 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800627 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800628 break
629 fi
630 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
631
632 if [ -z "$fromuser" ]; then
633 exit 1
634 fi
635 # Retry
636 TF_OPENCL_VERSION=""
637 COMPUTECPP_TOOLKIT_PATH=""
638done
639
Benoit Steinera7715982016-11-09 13:14:03 -0800640# end of if "$TF_NEED_OPENCL" == "1"
641fi
642
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800643# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
644bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800645echo "Configuration finished"