blob: 48a4594da6345a3f8d8b88c5b5503456805cf21e [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
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 TensorFlower82684762017-04-05 11:30:37 -0800287write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800288
Benoit Steinera7715982016-11-09 13:14:03 -0800289if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800290while [[ "$TF_CUDA_CLANG" == "" ]]; do
291 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
292 case $INPUT in
293 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
294 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
295 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
296 * ) echo "Invalid selection: " $INPUT;;
297 esac
298done
299
300export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800301write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800302
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800303# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800304# No need to set this on Windows
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800305while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800306 fromuser=""
307 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800308 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800309 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 -0800310 fromuser="1"
311 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800312 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800313 fi
314 fi
315 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800316 export GCC_HOST_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800317 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800318 break
319 fi
320 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
321 if [ -z "$fromuser" ]; then
322 exit 1
323 fi
324 GCC_HOST_COMPILER_PATH=""
325 # Retry
326done
327
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800328# Set up which clang we should use as the cuda / host compiler.
329while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
330 fromuser=""
331 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
332 default_clang_host_compiler_path=$(which clang || true)
333 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
334 fromuser="1"
335 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
336 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
337 fi
338 fi
339 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
340 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800341 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800342 break
343 fi
344 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
345 if [ -z "$fromuser" ]; then
346 exit 1
347 fi
348 CLANG_CUDA_COMPILER_PATH=""
349 # Retry
350done
351
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800352# Find out where the CUDA toolkit is installed
353while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800354 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800355 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800356 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 -0800357 fi
358
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800359 fromuser=""
360 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
361 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800362 if is_windows; then
363 if [ -z "$CUDA_PATH" ]; then
364 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
365 else
366 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
367 fi
368 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800369 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 -0800370 fromuser="1"
371 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800372 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800373 fi
374 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800375
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800376 if [[ -z "$TF_CUDA_VERSION" ]]; then
377 TF_CUDA_EXT=""
378 else
379 TF_CUDA_EXT=".$TF_CUDA_VERSION"
380 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800381
Andrew Harp1cb96892016-12-08 20:05:49 -0800382 if is_windows; then
383 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800384 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800385 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800386 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800387 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
388 fi
389
390 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800391 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800392 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800393 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800394 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800395 break
396 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800397 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
398
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800399 if [ -z "$fromuser" ]; then
400 exit 1
401 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800402 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800403 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800404 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800405done
406
Martin Wicke916776a2016-01-14 07:30:00 -0800407# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800408while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800409 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800410 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800411 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 -0800412 fi
413
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800414 fromuser=""
415 if [ -z "$CUDNN_INSTALL_PATH" ]; then
416 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800417 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 -0800418 fromuser="1"
419 if [ -z "$CUDNN_INSTALL_PATH" ]; then
420 CUDNN_INSTALL_PATH=$default_cudnn_path
421 fi
422 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
423 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800424 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 -0800425 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800426
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800427 if [[ -z "$TF_CUDNN_VERSION" ]]; then
428 TF_CUDNN_EXT=""
429 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800430 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800431 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800432
Andrew Harp1cb96892016-12-08 20:05:49 -0800433 if is_windows; then
434 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
435 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800436 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800437 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
438 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800439 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800440 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
441 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800442 fi
443
444 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 -0800445 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800446 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800447 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800448 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800449 break
450 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800451
Jonathan Hseuc058a012017-01-17 15:06:43 -0800452 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800453 if ! type ldconfig > /dev/null 2>&1; then
454 LDCONFIG_BIN=/sbin/ldconfig
455 else
456 LDCONFIG_BIN=ldconfig
457 fi
458 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800459 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800460 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800461 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800462 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800463 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800464 break
465 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800466 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800467 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
468 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
469 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800470 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800471 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
472 fi
473
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800474 if [ -z "$fromuser" ]; then
475 exit 1
476 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800477 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800478 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800479 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800480done
481
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800482# Configure the compute capabilities that TensorFlow builds for.
483# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
484while true; do
485 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800486 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800487 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800488cat << EOF
489Please specify a list of comma-separated Cuda compute capabilities you want to build with.
490You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
491Please note that each additional compute capability significantly increases your build time and binary size.
492EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800493 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
494 fromuser=1
495 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800496 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
497 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
498 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800499 # Check whether all capabilities from the input is valid
500 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
501 ALL_VALID=1
502 for CAPABILITY in $COMPUTE_CAPABILITIES; do
503 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
504 echo "Invalid compute capability: " $CAPABILITY
505 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800506 break
507 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800508 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800509 if [ "$ALL_VALID" == "0" ]; then
510 if [ -z "$fromuser" ]; then
511 exit 1
512 fi
513 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800514 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800515 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800516 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800517 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800518 TF_CUDA_COMPUTE_CAPABILITIES=""
519done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800520
Andrew Harp1cb96892016-12-08 20:05:49 -0800521if is_windows; then
522 # The following three variables are needed for MSVC toolchain configuration in Bazel
523 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
524 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
525 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800526 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
527 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
528 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800529fi
530
Benoit Steinera7715982016-11-09 13:14:03 -0800531# end of if "$TF_NEED_CUDA" == "1"
532fi
533
534# OpenCL configuration
535
536if [ "$TF_NEED_OPENCL" == "1" ]; then
537
538# Determine which C++ compiler should be used as the host compiler
539while true; do
540 fromuser=""
541 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800542 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800543 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
544 fromuser="1"
545 if [ -z "$HOST_CXX_COMPILER" ]; then
546 HOST_CXX_COMPILER=$default_cxx_host_compiler
547 fi
548 fi
549 if [ -e "$HOST_CXX_COMPILER" ]; then
550 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800551 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800552 break
553 fi
554 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
555 if [ -z "$fromuser" ]; then
556 exit 1
557 fi
558 HOST_CXX_COMPILER=""
559 # Retry
560done
561
562# Determine which C compiler should be used as the host compiler
563while true; do
564 fromuser=""
565 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800566 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800567 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
568 fromuser="1"
569 if [ -z "$HOST_C_COMPILER" ]; then
570 HOST_C_COMPILER=$default_c_host_compiler
571 fi
572 fi
573 if [ -e "$HOST_C_COMPILER" ]; then
574 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800575 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800576 break
577 fi
578 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
579 if [ -z "$fromuser" ]; then
580 exit 1
581 fi
582 HOST_C_COMPILER=""
583 # Retry
584done
585
586while true; do
587 # Configure the OPENCL version to use.
588 TF_OPENCL_VERSION="1.2"
589
590 # Point to ComputeCpp root
591 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
592 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800593 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 -0800594 fromuser="1"
595 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
596 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
597 fi
598 fi
599
Jonathan Hseuc058a012017-01-17 15:06:43 -0800600 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800601 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
602 fi
603
604 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
605 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800606 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800607 break
608 fi
609 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
610
611 if [ -z "$fromuser" ]; then
612 exit 1
613 fi
614 # Retry
615 TF_OPENCL_VERSION=""
616 COMPUTECPP_TOOLKIT_PATH=""
617done
618
Benoit Steinera7715982016-11-09 13:14:03 -0800619# end of if "$TF_NEED_OPENCL" == "1"
620fi
621
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800622# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
623bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800624echo "Configuration finished"