blob: 6360641be2ca99c8c8cbe58c95fc2fd59f917744 [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
59echo "import .tf_configure.bazelrc" >> .bazelrc
60
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
89
Benoit Steiner639b4e72017-02-08 09:25:09 -080090## Set up MKL related environment settings
91if false; then # Disable building with MKL for now
92 while [ "$TF_NEED_MKL" == "" ]; do
93 fromuser=""
94 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
95 fromuser="1"
96 case $INPUT in
97 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
98 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
99 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
100 * ) echo "Invalid selection: " $INPUT;;
101 esac
102 done
103
104 OSNAME=`uname -s`
105
106 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
107 DST=`dirname $0`
Martin Wickebc456e32017-03-23 12:31:16 -0800108 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
109 GITHUB_RELEASE_TAG=v0.5
Benoit Steiner639b4e72017-02-08 09:25:09 -0800110 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
111 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
112 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
113 fi
114 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
115 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
116 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
117 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
118
119 if [ "$OSNAME" == "Linux" ]; then
120 # Full MKL configuration
121 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
122 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
123
124 # MKL-ML configuration
125 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
126 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
127 elif [ "$OSNAME" == "Darwin" ]; then
128 echo "Darwin is unsupported yet";
129 exit 1
130 fi
131
132 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
133 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
134 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
135 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
136 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
137 else
138 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
139 exit 1
140 fi
141
142 if [ -z "$fromuser" ]; then
143 exit 1
144 fi
145
146cat > third_party/mkl/mkl.config <<EOF
147# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
148# files can be either in this directory, or under include/ and lib64/
149MKL_INSTALL_PATH=$MKL_INSTALL_PATH
150EOF
151
152 fi # TF_NEED_MKL
153 ################## MKL
154fi # Disable building with MKL for now
155
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800156## Set up architecture-dependent optimization flags.
157if [ -z "$CC_OPT_FLAGS" ]; then
158 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800159 read -p "Please specify optimization flags to use during compilation when bazel option "\
160"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800161 if [ -z "$CC_OPT_FLAGS" ]; then
162 CC_OPT_FLAGS=$default_cc_opt_flags
163 fi
164fi
165
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800166if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800167 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800168 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800169 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800170 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800171 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800172fi
173
Jonathan Hseuc058a012017-01-17 15:06:43 -0800174if is_linux; then
175 while [ "$TF_NEED_JEMALLOC" == "" ]; do
176 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
177 INPUT
178 case $INPUT in
179 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
180 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
181 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
182 * ) echo "Invalid selection: " $INPUT;;
183 esac
184 done
185else
186 TF_NEED_JEMALLOC=0
187fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800188
Martin Wickebc456e32017-03-23 12:31:16 -0800189if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800190 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800191fi
192
Martin Wickebc456e32017-03-23 12:31:16 -0800193while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800194 read -p "Do you wish to build TensorFlow with "\
195"Google Cloud Platform support? [y/N] " INPUT
196 case $INPUT in
197 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
198"TensorFlow"; TF_NEED_GCP=1;;
199 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
200"TensorFlow"; TF_NEED_GCP=0;;
201 "" ) echo "No Google Cloud Platform support will be enabled for "\
202"TensorFlow"; TF_NEED_GCP=0;;
203 * ) echo "Invalid selection: " $INPUT;;
204 esac
205done
206
Martin Wickebc456e32017-03-23 12:31:16 -0800207if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800208 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800209fi
210
Martin Wickebc456e32017-03-23 12:31:16 -0800211while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800212 read -p "Do you wish to build TensorFlow with "\
213"Hadoop File System support? [y/N] " INPUT
214 case $INPUT in
215 [Yy]* ) echo "Hadoop File System support will be enabled for "\
216"TensorFlow"; TF_NEED_HDFS=1;;
217 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
218"TensorFlow"; TF_NEED_HDFS=0;;
219 "" ) echo "No Hadoop File System support will be enabled for "\
220"TensorFlow"; TF_NEED_HDFS=0;;
221 * ) echo "Invalid selection: " $INPUT;;
222 esac
223done
224
Martin Wickebc456e32017-03-23 12:31:16 -0800225if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800226 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800227fi
228
Peter Hawkins1e67c902017-01-09 12:04:37 -0800229## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800230while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800231 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
232 case $INPUT in
233 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
234 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
235 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
236 * ) echo "Invalid selection: " $INPUT;;
237 esac
238done
239
Martin Wickebc456e32017-03-23 12:31:16 -0800240if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800241 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800242fi
243
244
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800245# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800246./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800247
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800248# Append CC optimization flags to bazel.rc
249echo >> tools/bazel.rc
250for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800251 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800252done
253
Andrew Selle09045e42016-09-06 08:19:04 -0800254# Run the gen_git_source to create links where bazel can track dependencies for
255# git hash propagation
256GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
257chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800258"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800259
Benoit Steinera7715982016-11-09 13:14:03 -0800260## Set up SYCL-related environment settings
261while [ "$TF_NEED_OPENCL" == "" ]; do
262 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
263 case $INPUT in
264 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
265 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
266 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
267 * ) echo "Invalid selection: " $INPUT;;
268 esac
269done
270
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800271## Set up Cuda-related environment settings
272
273while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800274 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800275 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800276 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
277 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
278 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800279 * ) echo "Invalid selection: " $INPUT;;
280 esac
281done
282
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800283export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800284write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800285
Rohan Jainaab09972017-01-05 14:39:17 -0800286export TF_NEED_OPENCL
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800287
Benoit Steinera7715982016-11-09 13:14:03 -0800288if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800289while [[ "$TF_CUDA_CLANG" == "" ]]; do
290 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
291 case $INPUT in
292 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
293 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
294 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
295 * ) echo "Invalid selection: " $INPUT;;
296 esac
297done
298
299export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800300write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800301
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800302# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800303# No need to set this on Windows
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800304while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800305 fromuser=""
306 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800307 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800308 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 -0800309 fromuser="1"
310 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800311 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800312 fi
313 fi
314 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800315 export GCC_HOST_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800316 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800317 break
318 fi
319 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
320 if [ -z "$fromuser" ]; then
321 exit 1
322 fi
323 GCC_HOST_COMPILER_PATH=""
324 # Retry
325done
326
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800327# Set up which clang we should use as the cuda / host compiler.
328while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
329 fromuser=""
330 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
331 default_clang_host_compiler_path=$(which clang || true)
332 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
333 fromuser="1"
334 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
335 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
336 fi
337 fi
338 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
339 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800340 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800341 break
342 fi
343 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
344 if [ -z "$fromuser" ]; then
345 exit 1
346 fi
347 CLANG_CUDA_COMPILER_PATH=""
348 # Retry
349done
350
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800351# Find out where the CUDA toolkit is installed
352while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800353 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800354 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800355 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 -0800356 fi
357
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800358 fromuser=""
359 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
360 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800361 if is_windows; then
362 if [ -z "$CUDA_PATH" ]; then
363 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
364 else
365 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
366 fi
367 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800368 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 -0800369 fromuser="1"
370 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800371 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800372 fi
373 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800374
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800375 if [[ -z "$TF_CUDA_VERSION" ]]; then
376 TF_CUDA_EXT=""
377 else
378 TF_CUDA_EXT=".$TF_CUDA_VERSION"
379 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800380
Andrew Harp1cb96892016-12-08 20:05:49 -0800381 if is_windows; then
382 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800383 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800384 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800385 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800386 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
387 fi
388
389 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800390 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800391 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800392 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800393 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800394 break
395 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800396 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
397
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800398 if [ -z "$fromuser" ]; then
399 exit 1
400 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800401 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800402 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800403 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800404done
405
Martin Wicke916776a2016-01-14 07:30:00 -0800406# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800407while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800408 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800409 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800410 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 -0800411 fi
412
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800413 fromuser=""
414 if [ -z "$CUDNN_INSTALL_PATH" ]; then
415 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800416 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 -0800417 fromuser="1"
418 if [ -z "$CUDNN_INSTALL_PATH" ]; then
419 CUDNN_INSTALL_PATH=$default_cudnn_path
420 fi
421 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
422 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800423 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 -0800424 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800425
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800426 if [[ -z "$TF_CUDNN_VERSION" ]]; then
427 TF_CUDNN_EXT=""
428 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800429 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800430 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800431
Andrew Harp1cb96892016-12-08 20:05:49 -0800432 if is_windows; then
433 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
434 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800435 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800436 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
437 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800438 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800439 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
440 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800441 fi
442
443 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 -0800444 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800445 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800446 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800447 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800448 break
449 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800450
Jonathan Hseuc058a012017-01-17 15:06:43 -0800451 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800452 if ! type ldconfig > /dev/null 2>&1; then
453 LDCONFIG_BIN=/sbin/ldconfig
454 else
455 LDCONFIG_BIN=ldconfig
456 fi
457 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800458 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800459 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800460 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800461 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800462 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800463 break
464 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800465 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800466 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
467 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
468 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800469 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800470 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
471 fi
472
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800473 if [ -z "$fromuser" ]; then
474 exit 1
475 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800476 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800477 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800478 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800479done
480
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800481# Configure the compute capabilities that TensorFlow builds for.
482# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
483while true; do
484 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800485 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800486 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800487cat << EOF
488Please specify a list of comma-separated Cuda compute capabilities you want to build with.
489You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
490Please note that each additional compute capability significantly increases your build time and binary size.
491EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800492 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
493 fromuser=1
494 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800495 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
496 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
497 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800498 # Check whether all capabilities from the input is valid
499 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
500 ALL_VALID=1
501 for CAPABILITY in $COMPUTE_CAPABILITIES; do
502 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
503 echo "Invalid compute capability: " $CAPABILITY
504 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800505 break
506 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800507 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800508 if [ "$ALL_VALID" == "0" ]; then
509 if [ -z "$fromuser" ]; then
510 exit 1
511 fi
512 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800513 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800514 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800515 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800516 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800517 TF_CUDA_COMPUTE_CAPABILITIES=""
518done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800519
Andrew Harp1cb96892016-12-08 20:05:49 -0800520if is_windows; then
521 # The following three variables are needed for MSVC toolchain configuration in Bazel
522 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
523 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
524 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800525 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
526 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
527 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800528fi
529
Benoit Steinera7715982016-11-09 13:14:03 -0800530# end of if "$TF_NEED_CUDA" == "1"
531fi
532
533# OpenCL configuration
534
535if [ "$TF_NEED_OPENCL" == "1" ]; then
536
537# Determine which C++ compiler should be used as the host compiler
538while true; do
539 fromuser=""
540 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800541 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800542 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
543 fromuser="1"
544 if [ -z "$HOST_CXX_COMPILER" ]; then
545 HOST_CXX_COMPILER=$default_cxx_host_compiler
546 fi
547 fi
548 if [ -e "$HOST_CXX_COMPILER" ]; then
549 export HOST_CXX_COMPILER
550 break
551 fi
552 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
553 if [ -z "$fromuser" ]; then
554 exit 1
555 fi
556 HOST_CXX_COMPILER=""
557 # Retry
558done
559
560# Determine which C compiler should be used as the host compiler
561while true; do
562 fromuser=""
563 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800564 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800565 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
566 fromuser="1"
567 if [ -z "$HOST_C_COMPILER" ]; then
568 HOST_C_COMPILER=$default_c_host_compiler
569 fi
570 fi
571 if [ -e "$HOST_C_COMPILER" ]; then
572 export HOST_C_COMPILER
573 break
574 fi
575 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
576 if [ -z "$fromuser" ]; then
577 exit 1
578 fi
579 HOST_C_COMPILER=""
580 # Retry
581done
582
583while true; do
584 # Configure the OPENCL version to use.
585 TF_OPENCL_VERSION="1.2"
586
587 # Point to ComputeCpp root
588 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
589 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800590 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 -0800591 fromuser="1"
592 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
593 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
594 fi
595 fi
596
Jonathan Hseuc058a012017-01-17 15:06:43 -0800597 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800598 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
599 fi
600
601 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
602 export COMPUTECPP_TOOLKIT_PATH
603 break
604 fi
605 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
606
607 if [ -z "$fromuser" ]; then
608 exit 1
609 fi
610 # Retry
611 TF_OPENCL_VERSION=""
612 COMPUTECPP_TOOLKIT_PATH=""
613done
614
Benoit Steinera7715982016-11-09 13:14:03 -0800615# end of if "$TF_NEED_OPENCL" == "1"
616fi
617
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800618# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
619bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800620echo "Configuration finished"