blob: 75d3e160f58a2d1e841b1e04c23ff1e4545baf80 [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
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080054function python_path {
55 "$PYTHON_BIN_PATH" - <<END
56from __future__ import print_function
57import site
58import os
59
60try:
61 input = raw_input
62except NameError:
63 pass
64
65python_paths = []
66if os.getenv('PYTHONPATH') is not None:
67 python_paths = os.getenv('PYTHONPATH').split(':')
68try:
69 library_paths = site.getsitepackages()
70except AttributeError:
71 from distutils.sysconfig import get_python_lib
72 library_paths = [get_python_lib()]
73all_paths = set(python_paths + library_paths)
74
75paths = []
76for path in all_paths:
77 if os.path.isdir(path):
78 paths.append(path)
79
80print(",".join(paths))
81END
82}
83
84function setup_python {
85 ## Set up python-related environment settings:
86 while true; do
87 fromuser=""
88 if [ -z "$PYTHON_BIN_PATH" ]; then
89 default_python_bin_path=$(which python || which python3 || true)
90 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
91 fromuser="1"
92 if [ -z "$PYTHON_BIN_PATH" ]; then
93 PYTHON_BIN_PATH=$default_python_bin_path
94 fi
95 fi
96 if [ -e "$PYTHON_BIN_PATH" ]; then
97 break
98 fi
99 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
100 if [ -z "$fromuser" ]; then
101 exit 1
102 fi
103 PYTHON_BIN_PATH=""
104 # Retry
105 done
106
107 if [ -z "$PYTHON_LIB_PATH" ]; then
108 # Split python_path into an array of paths, this allows path containing spaces
109 IFS=','
110 python_lib_path=($(python_path))
111 unset IFS
112
113 if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then
114 PYTHON_LIB_PATH=${python_lib_path[0]}
115 echo "Using python library path: $PYTHON_LIB_PATH"
116
117 else
118 echo "Found possible Python library paths:"
119 for x in "${python_lib_path[@]}"; do
120 echo " $x"
121 done
122 set -- "${python_lib_path[@]}"
123 echo "Please input the desired Python library path to use. Default is ["$1"]"
124 read b || true
125 if [ "$b" == "" ]; then
126 PYTHON_LIB_PATH=${python_lib_path[0]}
127 echo "Using python library path: $PYTHON_LIB_PATH"
128 else
129 PYTHON_LIB_PATH="$b"
130 fi
131 fi
132 fi
133
134 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
135 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
136 exit 1
137 fi
138
139 local python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);')
140 if [ "$python_major_version" == "" ]; then
141 echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?"
142 exit 1
143 fi
144
145 # Convert python path to Windows style before writing into bazel.rc
146 if is_windows; then
147 PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
148 fi
149
150 # Set-up env variables used by python_configure.bzl
151 write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
152 write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH"
153 write_to_bazelrc "build --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH"
154 write_to_bazelrc "build --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH"
155 write_to_bazelrc "build --force_python=py$python_major_version"
156 write_to_bazelrc "build --host_force_python=py$python_major_version"
157 write_to_bazelrc "build --python${python_major_version}_path=$PYTHON_BIN_PATH"
158 write_to_bazelrc "test --force_python=py$python_major_version"
159 write_to_bazelrc "test --host_force_python=py$python_major_version"
160 write_to_bazelrc "test --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH"
161 write_to_bazelrc "test --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH"
162 write_to_bazelrc "run --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH"
163 write_to_bazelrc "run --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH"
164
165 # Write tools/python_bin_path.sh
166 echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh
167}
168
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800169# This file contains customized config settings.
170rm -f .tf_configure.bazelrc
171touch .tf_configure.bazelrc
172touch .bazelrc
173sed_hyphen_i "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800174echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800175
Andrew Harp51dbc462017-01-27 14:42:30 -0800176# Delete any leftover BUILD files from the Makefile build, which would interfere
177# with Bazel parsing.
178MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
179if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
180 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
181fi
182
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800183setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800184
Benoit Steiner639b4e72017-02-08 09:25:09 -0800185## Set up MKL related environment settings
186if false; then # Disable building with MKL for now
187 while [ "$TF_NEED_MKL" == "" ]; do
188 fromuser=""
Shanqing Cai32694232017-04-22 06:08:17 -0800189 read -p "Do you wish to build TensorFlow with MKL support (experimental)? [y/N] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800190 fromuser="1"
191 case $INPUT in
Shanqing Cai32694232017-04-22 06:08:17 -0800192 [Yy]* ) echo "MKL support (experimental) (will be enabled for TensorFlow"; TF_NEED_MKL=1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800193 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
194 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
195 * ) echo "Invalid selection: " $INPUT;;
196 esac
197 done
198
199 OSNAME=`uname -s`
200
201 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
202 DST=`dirname $0`
Martin Wickebc456e32017-03-23 12:31:16 -0800203 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
204 GITHUB_RELEASE_TAG=v0.5
Benoit Steiner639b4e72017-02-08 09:25:09 -0800205 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
206 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
207 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
208 fi
209 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
210 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
211 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
212 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
213
214 if [ "$OSNAME" == "Linux" ]; then
215 # Full MKL configuration
216 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
217 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
218
219 # MKL-ML configuration
220 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
221 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
222 elif [ "$OSNAME" == "Darwin" ]; then
223 echo "Darwin is unsupported yet";
224 exit 1
225 fi
226
227 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
228 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
229 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
230 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
231 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
232 else
233 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
234 exit 1
235 fi
236
237 if [ -z "$fromuser" ]; then
238 exit 1
239 fi
240
241cat > third_party/mkl/mkl.config <<EOF
242# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
243# files can be either in this directory, or under include/ and lib64/
244MKL_INSTALL_PATH=$MKL_INSTALL_PATH
245EOF
246
247 fi # TF_NEED_MKL
248 ################## MKL
249fi # Disable building with MKL for now
250
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800251## Set up architecture-dependent optimization flags.
252if [ -z "$CC_OPT_FLAGS" ]; then
253 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800254 read -p "Please specify optimization flags to use during compilation when bazel option "\
255"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800256 if [ -z "$CC_OPT_FLAGS" ]; then
257 CC_OPT_FLAGS=$default_cc_opt_flags
258 fi
259fi
260
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800261if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800262 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800263 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800264 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800265 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800266 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800267fi
268
Jonathan Hseuc058a012017-01-17 15:06:43 -0800269if is_linux; then
270 while [ "$TF_NEED_JEMALLOC" == "" ]; do
271 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
272 INPUT
273 case $INPUT in
274 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
275 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
276 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
277 * ) echo "Invalid selection: " $INPUT;;
278 esac
279 done
280else
281 TF_NEED_JEMALLOC=0
282fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800283
Martin Wickebc456e32017-03-23 12:31:16 -0800284if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800285 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800286fi
287
Martin Wickebc456e32017-03-23 12:31:16 -0800288while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800289 read -p "Do you wish to build TensorFlow with "\
290"Google Cloud Platform support? [y/N] " INPUT
291 case $INPUT in
292 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
293"TensorFlow"; TF_NEED_GCP=1;;
294 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
295"TensorFlow"; TF_NEED_GCP=0;;
296 "" ) echo "No Google Cloud Platform support will be enabled for "\
297"TensorFlow"; TF_NEED_GCP=0;;
298 * ) echo "Invalid selection: " $INPUT;;
299 esac
300done
301
Martin Wickebc456e32017-03-23 12:31:16 -0800302if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800303 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800304fi
305
Martin Wickebc456e32017-03-23 12:31:16 -0800306while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800307 read -p "Do you wish to build TensorFlow with "\
308"Hadoop File System support? [y/N] " INPUT
309 case $INPUT in
310 [Yy]* ) echo "Hadoop File System support will be enabled for "\
311"TensorFlow"; TF_NEED_HDFS=1;;
312 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
313"TensorFlow"; TF_NEED_HDFS=0;;
314 "" ) echo "No Hadoop File System support will be enabled for "\
315"TensorFlow"; TF_NEED_HDFS=0;;
316 * ) echo "Invalid selection: " $INPUT;;
317 esac
318done
319
Martin Wickebc456e32017-03-23 12:31:16 -0800320if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800321 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800322fi
323
Peter Hawkins1e67c902017-01-09 12:04:37 -0800324## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800325while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800326 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
327 case $INPUT in
328 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
329 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
330 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
331 * ) echo "Invalid selection: " $INPUT;;
332 esac
333done
334
Martin Wickebc456e32017-03-23 12:31:16 -0800335if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800336 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800337fi
338
Shanqing Cai32694232017-04-22 06:08:17 -0800339# Verbs configuration
340while [ "$TF_NEED_VERBS" == "" ]; do
341 read -p "Do you wish to build TensorFlow with "\
342"VERBS support? [y/N] " INPUT
343 case $INPUT in
344 [Yy]* ) echo "VERBS support will be enabled for "\
345"TensorFlow"; TF_NEED_VERBS=1;;
346 [Nn]* ) echo "No VERBS support will be enabled for "\
347"TensorFlow"; TF_NEED_VERBS=0;;
348 "" ) echo "No VERBS support will be enabled for "\
349"TensorFlow"; TF_NEED_VERBS=0;;
350 * ) echo "Invalid selection: " $INPUT;;
351 esac
352done
353
354if [[ "$TF_NEED_VERBS" == "1" ]]; then
355 write_to_bazelrc 'build --define with_verbs_support=true'
356fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800357
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800358# Append CC optimization flags to bazel.rc
359echo >> tools/bazel.rc
360for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800361 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800362done
363
Andrew Selle09045e42016-09-06 08:19:04 -0800364# Run the gen_git_source to create links where bazel can track dependencies for
365# git hash propagation
366GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
367chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800368"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800369
Benoit Steinera7715982016-11-09 13:14:03 -0800370## Set up SYCL-related environment settings
371while [ "$TF_NEED_OPENCL" == "" ]; do
372 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
373 case $INPUT in
374 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
375 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
376 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
377 * ) echo "Invalid selection: " $INPUT;;
378 esac
379done
380
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800381## Set up Cuda-related environment settings
382
383while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800384 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800385 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800386 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
387 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
388 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800389 * ) echo "Invalid selection: " $INPUT;;
390 esac
391done
392
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800393export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800394write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800395
Rohan Jainaab09972017-01-05 14:39:17 -0800396export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800397write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800398
Benoit Steinera7715982016-11-09 13:14:03 -0800399if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800400while [[ "$TF_CUDA_CLANG" == "" ]]; do
401 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
402 case $INPUT in
403 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
404 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
405 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
406 * ) echo "Invalid selection: " $INPUT;;
407 esac
408done
409
410export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800411write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800412
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800413# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800414# No need to set this on Windows
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800415while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800416 fromuser=""
417 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800418 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800419 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 -0800420 fromuser="1"
421 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800422 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800423 fi
424 fi
425 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800426 export GCC_HOST_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800427 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800428 break
429 fi
430 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
431 if [ -z "$fromuser" ]; then
432 exit 1
433 fi
434 GCC_HOST_COMPILER_PATH=""
435 # Retry
436done
437
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800438# Set up which clang we should use as the cuda / host compiler.
439while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
440 fromuser=""
441 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
442 default_clang_host_compiler_path=$(which clang || true)
443 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
444 fromuser="1"
445 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
446 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
447 fi
448 fi
449 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
450 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800451 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800452 break
453 fi
454 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
455 if [ -z "$fromuser" ]; then
456 exit 1
457 fi
458 CLANG_CUDA_COMPILER_PATH=""
459 # Retry
460done
461
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800462# Find out where the CUDA toolkit is installed
463while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800464 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800465 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800466 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 -0800467 fi
468
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800469 fromuser=""
470 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
471 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800472 if is_windows; then
473 if [ -z "$CUDA_PATH" ]; then
474 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
475 else
476 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
477 fi
478 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800479 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 -0800480 fromuser="1"
481 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800482 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800483 fi
484 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800485
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800486 if [[ -z "$TF_CUDA_VERSION" ]]; then
487 TF_CUDA_EXT=""
488 else
489 TF_CUDA_EXT=".$TF_CUDA_VERSION"
490 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800491
Andrew Harp1cb96892016-12-08 20:05:49 -0800492 if is_windows; then
493 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800494 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800495 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800496 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800497 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
498 fi
499
500 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800501 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800502 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800503 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800504 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800505 break
506 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800507 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
508
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800509 if [ -z "$fromuser" ]; then
510 exit 1
511 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800512 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800513 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800514 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800515done
516
Martin Wicke916776a2016-01-14 07:30:00 -0800517# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800518while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800519 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800520 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800521 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 -0800522 fi
523
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800524 fromuser=""
525 if [ -z "$CUDNN_INSTALL_PATH" ]; then
526 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800527 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 -0800528 fromuser="1"
529 if [ -z "$CUDNN_INSTALL_PATH" ]; then
530 CUDNN_INSTALL_PATH=$default_cudnn_path
531 fi
532 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
533 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800534 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 -0800535 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800536
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800537 if [[ -z "$TF_CUDNN_VERSION" ]]; then
538 TF_CUDNN_EXT=""
539 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800540 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800541 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800542
Andrew Harp1cb96892016-12-08 20:05:49 -0800543 if is_windows; then
544 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
545 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800546 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800547 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
548 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800549 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800550 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
551 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800552 fi
553
554 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 -0800555 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800556 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800557 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800558 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800559 break
560 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800561
Jonathan Hseuc058a012017-01-17 15:06:43 -0800562 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800563 if ! type ldconfig > /dev/null 2>&1; then
564 LDCONFIG_BIN=/sbin/ldconfig
565 else
566 LDCONFIG_BIN=ldconfig
567 fi
568 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800569 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800570 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800571 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800572 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800573 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800574 break
575 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800576 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800577 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
578 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
579 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800580 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800581 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
582 fi
583
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800584 if [ -z "$fromuser" ]; then
585 exit 1
586 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800587 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800588 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800589 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800590done
591
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800592# Configure the compute capabilities that TensorFlow builds for.
593# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
594while true; do
595 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800596 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800597 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800598cat << EOF
599Please specify a list of comma-separated Cuda compute capabilities you want to build with.
600You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
601Please note that each additional compute capability significantly increases your build time and binary size.
602EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800603 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
604 fromuser=1
605 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800606 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
607 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
608 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800609 # Check whether all capabilities from the input is valid
610 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
611 ALL_VALID=1
612 for CAPABILITY in $COMPUTE_CAPABILITIES; do
613 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
614 echo "Invalid compute capability: " $CAPABILITY
615 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800616 break
617 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800618 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800619 if [ "$ALL_VALID" == "0" ]; then
620 if [ -z "$fromuser" ]; then
621 exit 1
622 fi
623 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800624 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800625 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800626 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800627 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800628 TF_CUDA_COMPUTE_CAPABILITIES=""
629done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800630
Andrew Harp1cb96892016-12-08 20:05:49 -0800631if is_windows; then
632 # The following three variables are needed for MSVC toolchain configuration in Bazel
633 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
634 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
635 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800636 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
637 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
638 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800639fi
640
Benoit Steinera7715982016-11-09 13:14:03 -0800641# end of if "$TF_NEED_CUDA" == "1"
642fi
643
644# OpenCL configuration
645
646if [ "$TF_NEED_OPENCL" == "1" ]; then
647
648# Determine which C++ compiler should be used as the host compiler
649while true; do
650 fromuser=""
651 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800652 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800653 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
654 fromuser="1"
655 if [ -z "$HOST_CXX_COMPILER" ]; then
656 HOST_CXX_COMPILER=$default_cxx_host_compiler
657 fi
658 fi
659 if [ -e "$HOST_CXX_COMPILER" ]; then
660 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800661 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800662 break
663 fi
664 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
665 if [ -z "$fromuser" ]; then
666 exit 1
667 fi
668 HOST_CXX_COMPILER=""
669 # Retry
670done
671
672# Determine which C compiler should be used as the host compiler
673while true; do
674 fromuser=""
675 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800676 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800677 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
678 fromuser="1"
679 if [ -z "$HOST_C_COMPILER" ]; then
680 HOST_C_COMPILER=$default_c_host_compiler
681 fi
682 fi
683 if [ -e "$HOST_C_COMPILER" ]; then
684 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800685 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800686 break
687 fi
688 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
689 if [ -z "$fromuser" ]; then
690 exit 1
691 fi
692 HOST_C_COMPILER=""
693 # Retry
694done
695
696while true; do
697 # Configure the OPENCL version to use.
698 TF_OPENCL_VERSION="1.2"
699
700 # Point to ComputeCpp root
701 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
702 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800703 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 -0800704 fromuser="1"
705 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
706 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
707 fi
708 fi
709
Jonathan Hseuc058a012017-01-17 15:06:43 -0800710 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800711 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
712 fi
713
714 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
715 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800716 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800717 break
718 fi
719 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
720
721 if [ -z "$fromuser" ]; then
722 exit 1
723 fi
724 # Retry
725 TF_OPENCL_VERSION=""
726 COMPUTECPP_TOOLKIT_PATH=""
727done
728
Benoit Steinera7715982016-11-09 13:14:03 -0800729# end of if "$TF_NEED_OPENCL" == "1"
730fi
731
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800732# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
733bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800734echo "Configuration finished"