blob: e59ee2a925b4441c9d3903b7fbe302aa39ca002c [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
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -080041function bazel_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 TensorFlower8d393ea2017-03-30 07:38:55 -0800282sed_hyphen_i -e "/--action_env TF_NEED_CUDA/d" .bazelrc
283sed_hyphen_i -e "/--action_env CUD/d" .bazelrc
284sed_hyphen_i -e "/--action_env GCC_HOST/d" .bazelrc
285sed_hyphen_i -e "/--action_env TF_CUD/d" .bazelrc
286sed_hyphen_i -e "/--action_env CLANG_CUDA/d" .bazelrc
287
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800288export TF_NEED_CUDA
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800289echo "build --action_env TF_NEED_CUDA=$TF_NEED_CUDA" >>.bazelrc
290
Rohan Jainaab09972017-01-05 14:39:17 -0800291export TF_NEED_OPENCL
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800292
Benoit Steinera7715982016-11-09 13:14:03 -0800293if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800294 echo "Configuration finished"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800295 bazel_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800296 exit
297fi
298
Benoit Steinera7715982016-11-09 13:14:03 -0800299if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800300while [[ "$TF_CUDA_CLANG" == "" ]]; do
301 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
302 case $INPUT in
303 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
304 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
305 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
306 * ) echo "Invalid selection: " $INPUT;;
307 esac
308done
309
310export TF_CUDA_CLANG
311echo "build --action_env TF_CUDA_CLANG=$TF_CUDA_CLANG" >>.bazelrc
312
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800313# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800314# No need to set this on Windows
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800315while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800316 fromuser=""
317 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800318 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800319 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 -0800320 fromuser="1"
321 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800322 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800323 fi
324 fi
325 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800326 export GCC_HOST_COMPILER_PATH
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800327 echo "build --action_env GCC_HOST_COMPILER_PATH=\"$GCC_HOST_COMPILER_PATH\"" >>.bazelrc
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800328 break
329 fi
330 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
331 if [ -z "$fromuser" ]; then
332 exit 1
333 fi
334 GCC_HOST_COMPILER_PATH=""
335 # Retry
336done
337
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800338# Set up which clang we should use as the cuda / host compiler.
339while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
340 fromuser=""
341 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
342 default_clang_host_compiler_path=$(which clang || true)
343 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
344 fromuser="1"
345 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
346 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
347 fi
348 fi
349 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
350 export CLANG_CUDA_COMPILER_PATH
351 echo "build --action_env CLANG_CUDA_COMPILER_PATH=\"$CLANG_CUDA_COMPILER_PATH\"" >>.bazelrc
352 break
353 fi
354 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
355 if [ -z "$fromuser" ]; then
356 exit 1
357 fi
358 CLANG_CUDA_COMPILER_PATH=""
359 # Retry
360done
361
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800362# Find out where the CUDA toolkit is installed
363while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800364 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800365 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800366 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 -0800367 fi
368
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800369 fromuser=""
370 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
371 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800372 if is_windows; then
373 if [ -z "$CUDA_PATH" ]; then
374 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
375 else
376 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
377 fi
378 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800379 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 -0800380 fromuser="1"
381 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800382 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800383 fi
384 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800385
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800386 if [[ -z "$TF_CUDA_VERSION" ]]; then
387 TF_CUDA_EXT=""
388 else
389 TF_CUDA_EXT=".$TF_CUDA_VERSION"
390 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800391
Andrew Harp1cb96892016-12-08 20:05:49 -0800392 if is_windows; then
393 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800394 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800395 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800396 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800397 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
398 fi
399
400 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800401 export CUDA_TOOLKIT_PATH
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800402 echo "build --action_env CUDA_TOOLKIT_PATH=\"$CUDA_TOOLKIT_PATH\"" >>.bazelrc
403
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800404 export TF_CUDA_VERSION
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800405 echo "build --action_env TF_CUDA_VERSION=$TF_CUDA_VERSION" >>.bazelrc
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800406 break
407 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800408 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
409
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800410 if [ -z "$fromuser" ]; then
411 exit 1
412 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800413 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800414 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800415 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800416done
417
Martin Wicke916776a2016-01-14 07:30:00 -0800418# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800419while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800420 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800421 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800422 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 -0800423 fi
424
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800425 fromuser=""
426 if [ -z "$CUDNN_INSTALL_PATH" ]; then
427 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800428 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 -0800429 fromuser="1"
430 if [ -z "$CUDNN_INSTALL_PATH" ]; then
431 CUDNN_INSTALL_PATH=$default_cudnn_path
432 fi
433 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
434 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800435 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 -0800436 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800437
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800438 if [[ -z "$TF_CUDNN_VERSION" ]]; then
439 TF_CUDNN_EXT=""
440 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800441 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800442 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800443
Andrew Harp1cb96892016-12-08 20:05:49 -0800444 if is_windows; then
445 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
446 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800447 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800448 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
449 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800450 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800451 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
452 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800453 fi
454
455 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 -0800456 export TF_CUDNN_VERSION
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800457 echo "build --action_env TF_CUDNN_VERSION=$TF_CUDNN_VERSION" >>.bazelrc
458
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800459 export CUDNN_INSTALL_PATH
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800460 echo "build --action_env CUDNN_INSTALL_PATH=\"$CUDNN_INSTALL_PATH\"" >>.bazelrc
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800461 break
462 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800463
Jonathan Hseuc058a012017-01-17 15:06:43 -0800464 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800465 if ! type ldconfig > /dev/null 2>&1; then
466 LDCONFIG_BIN=/sbin/ldconfig
467 else
468 LDCONFIG_BIN=ldconfig
469 fi
470 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800471 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800472 export TF_CUDNN_VERSION
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800473 echo "build --action_env TF_CUDNN_VERSION=$TF_CUDNN_VERSION" >>.bazelrc
474
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800475 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800476 echo "build --action_env CUDNN_INSTALL_PATH=\"$CUDNN_INSTALL_PATH\"" >>.bazelrc
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800477 break
478 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800479 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800480 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
481 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
482 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800483 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800484 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
485 fi
486
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800487 if [ -z "$fromuser" ]; then
488 exit 1
489 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800490 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800491 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800492 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800493done
494
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800495# Configure the compute capabilities that TensorFlow builds for.
496# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
497while true; do
498 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800499 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800500 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800501cat << EOF
502Please specify a list of comma-separated Cuda compute capabilities you want to build with.
503You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
504Please note that each additional compute capability significantly increases your build time and binary size.
505EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800506 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
507 fromuser=1
508 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800509 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
510 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
511 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800512 # Check whether all capabilities from the input is valid
513 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
514 ALL_VALID=1
515 for CAPABILITY in $COMPUTE_CAPABILITIES; do
516 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
517 echo "Invalid compute capability: " $CAPABILITY
518 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800519 break
520 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800521 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800522 if [ "$ALL_VALID" == "0" ]; then
523 if [ -z "$fromuser" ]; then
524 exit 1
525 fi
526 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800527 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800528 echo "build --action_env TF_CUDA_COMPUTE_CAPABILITIES=$TF_CUDA_COMPUTE_CAPABILITIES" >>.bazelrc
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800529 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800530 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800531 TF_CUDA_COMPUTE_CAPABILITIES=""
532done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800533
Andrew Harp1cb96892016-12-08 20:05:49 -0800534if is_windows; then
535 # The following three variables are needed for MSVC toolchain configuration in Bazel
536 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
537 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
538 export NO_WHOLE_ARCHIVE_OPTION=1
539
540 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
541 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
542fi
543
Benoit Steinera7715982016-11-09 13:14:03 -0800544# end of if "$TF_NEED_CUDA" == "1"
545fi
546
547# OpenCL configuration
548
549if [ "$TF_NEED_OPENCL" == "1" ]; then
550
551# Determine which C++ compiler should be used as the host compiler
552while true; do
553 fromuser=""
554 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800555 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800556 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
557 fromuser="1"
558 if [ -z "$HOST_CXX_COMPILER" ]; then
559 HOST_CXX_COMPILER=$default_cxx_host_compiler
560 fi
561 fi
562 if [ -e "$HOST_CXX_COMPILER" ]; then
563 export HOST_CXX_COMPILER
564 break
565 fi
566 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
567 if [ -z "$fromuser" ]; then
568 exit 1
569 fi
570 HOST_CXX_COMPILER=""
571 # Retry
572done
573
574# Determine which C compiler should be used as the host compiler
575while true; do
576 fromuser=""
577 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800578 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800579 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
580 fromuser="1"
581 if [ -z "$HOST_C_COMPILER" ]; then
582 HOST_C_COMPILER=$default_c_host_compiler
583 fi
584 fi
585 if [ -e "$HOST_C_COMPILER" ]; then
586 export HOST_C_COMPILER
587 break
588 fi
589 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
590 if [ -z "$fromuser" ]; then
591 exit 1
592 fi
593 HOST_C_COMPILER=""
594 # Retry
595done
596
597while true; do
598 # Configure the OPENCL version to use.
599 TF_OPENCL_VERSION="1.2"
600
601 # Point to ComputeCpp root
602 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
603 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800604 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 -0800605 fromuser="1"
606 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
607 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
608 fi
609 fi
610
Jonathan Hseuc058a012017-01-17 15:06:43 -0800611 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800612 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
613 fi
614
615 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
616 export COMPUTECPP_TOOLKIT_PATH
617 break
618 fi
619 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
620
621 if [ -z "$fromuser" ]; then
622 exit 1
623 fi
624 # Retry
625 TF_OPENCL_VERSION=""
626 COMPUTECPP_TOOLKIT_PATH=""
627done
628
Benoit Steinera7715982016-11-09 13:14:03 -0800629# end of if "$TF_NEED_OPENCL" == "1"
630fi
631
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800632bazel_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800633
634echo "Configuration finished"