blob: 7f68a8f5d47760b9b22c70ec92094d4f91d6b001 [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
Dan Ringwalt692fad22017-05-05 09:09:05 -080038function sed_in_place() {
39 sed -e $1 $2 > "$2.bak"
40 mv "$2.bak" $2
Dandelion Mané0386a012017-03-10 14:43:23 -080041}
42
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -080043function write_to_bazelrc() {
44 echo "$1" >> .tf_configure.bazelrc
45}
46
47function write_action_env_to_bazelrc() {
48 write_to_bazelrc "build --action_env $1=\"$2\""
49}
50
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -080051function python_path {
52 "$PYTHON_BIN_PATH" - <<END
53from __future__ import print_function
54import site
55import os
56
57try:
58 input = raw_input
59except NameError:
60 pass
61
62python_paths = []
63if os.getenv('PYTHONPATH') is not None:
64 python_paths = os.getenv('PYTHONPATH').split(':')
65try:
66 library_paths = site.getsitepackages()
67except AttributeError:
68 from distutils.sysconfig import get_python_lib
69 library_paths = [get_python_lib()]
70all_paths = set(python_paths + library_paths)
71
72paths = []
73for path in all_paths:
74 if os.path.isdir(path):
75 paths.append(path)
76
77print(",".join(paths))
78END
79}
80
81function setup_python {
82 ## Set up python-related environment settings:
83 while true; do
84 fromuser=""
85 if [ -z "$PYTHON_BIN_PATH" ]; then
86 default_python_bin_path=$(which python || which python3 || true)
87 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
88 fromuser="1"
89 if [ -z "$PYTHON_BIN_PATH" ]; then
90 PYTHON_BIN_PATH=$default_python_bin_path
91 fi
92 fi
93 if [ -e "$PYTHON_BIN_PATH" ]; then
94 break
95 fi
96 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
97 if [ -z "$fromuser" ]; then
98 exit 1
99 fi
100 PYTHON_BIN_PATH=""
101 # Retry
102 done
103
104 if [ -z "$PYTHON_LIB_PATH" ]; then
105 # Split python_path into an array of paths, this allows path containing spaces
106 IFS=','
107 python_lib_path=($(python_path))
108 unset IFS
109
110 if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then
111 PYTHON_LIB_PATH=${python_lib_path[0]}
112 echo "Using python library path: $PYTHON_LIB_PATH"
113
114 else
115 echo "Found possible Python library paths:"
116 for x in "${python_lib_path[@]}"; do
117 echo " $x"
118 done
119 set -- "${python_lib_path[@]}"
120 echo "Please input the desired Python library path to use. Default is ["$1"]"
121 read b || true
122 if [ "$b" == "" ]; then
123 PYTHON_LIB_PATH=${python_lib_path[0]}
124 echo "Using python library path: $PYTHON_LIB_PATH"
125 else
126 PYTHON_LIB_PATH="$b"
127 fi
128 fi
129 fi
130
131 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
132 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
133 exit 1
134 fi
135
136 local python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);')
137 if [ "$python_major_version" == "" ]; then
138 echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?"
139 exit 1
140 fi
141
142 # Convert python path to Windows style before writing into bazel.rc
143 if is_windows; then
144 PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
145 fi
146
147 # Set-up env variables used by python_configure.bzl
148 write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH"
149 write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH"
150 write_to_bazelrc "build --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH"
151 write_to_bazelrc "build --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH"
152 write_to_bazelrc "build --force_python=py$python_major_version"
153 write_to_bazelrc "build --host_force_python=py$python_major_version"
154 write_to_bazelrc "build --python${python_major_version}_path=$PYTHON_BIN_PATH"
155 write_to_bazelrc "test --force_python=py$python_major_version"
156 write_to_bazelrc "test --host_force_python=py$python_major_version"
157 write_to_bazelrc "test --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH"
158 write_to_bazelrc "test --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH"
159 write_to_bazelrc "run --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH"
160 write_to_bazelrc "run --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH"
161
162 # Write tools/python_bin_path.sh
163 echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh
164}
165
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800166# This file contains customized config settings.
167rm -f .tf_configure.bazelrc
168touch .tf_configure.bazelrc
169touch .bazelrc
Dan Ringwalt692fad22017-05-05 09:09:05 -0800170sed_in_place "/tf_configure/d" .bazelrc
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800171echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800172
Andrew Harp51dbc462017-01-27 14:42:30 -0800173# Delete any leftover BUILD files from the Makefile build, which would interfere
174# with Bazel parsing.
175MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
176if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
177 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
178fi
179
A. Unique TensorFlower79789dd2017-04-27 04:47:01 -0800180setup_python
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800181
Benoit Steiner639b4e72017-02-08 09:25:09 -0800182## Set up MKL related environment settings
183if false; then # Disable building with MKL for now
184 while [ "$TF_NEED_MKL" == "" ]; do
185 fromuser=""
Shanqing Cai32694232017-04-22 06:08:17 -0800186 read -p "Do you wish to build TensorFlow with MKL support (experimental)? [y/N] " INPUT
Benoit Steiner639b4e72017-02-08 09:25:09 -0800187 fromuser="1"
188 case $INPUT in
Shanqing Cai32694232017-04-22 06:08:17 -0800189 [Yy]* ) echo "MKL support (experimental) (will be enabled for TensorFlow"; TF_NEED_MKL=1;;
Benoit Steiner639b4e72017-02-08 09:25:09 -0800190 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
191 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
192 * ) echo "Invalid selection: " $INPUT;;
193 esac
194 done
195
196 OSNAME=`uname -s`
197
198 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
199 DST=`dirname $0`
Martin Wickebc456e32017-03-23 12:31:16 -0800200 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
201 GITHUB_RELEASE_TAG=v0.5
Benoit Steiner639b4e72017-02-08 09:25:09 -0800202 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
203 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
204 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
205 fi
206 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
207 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
208 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
209 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
210
211 if [ "$OSNAME" == "Linux" ]; then
212 # Full MKL configuration
213 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
214 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
215
216 # MKL-ML configuration
217 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
218 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
219 elif [ "$OSNAME" == "Darwin" ]; then
220 echo "Darwin is unsupported yet";
221 exit 1
222 fi
223
224 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
225 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
226 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
227 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
228 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
229 else
230 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
231 exit 1
232 fi
233
234 if [ -z "$fromuser" ]; then
235 exit 1
236 fi
237
238cat > third_party/mkl/mkl.config <<EOF
239# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
240# files can be either in this directory, or under include/ and lib64/
241MKL_INSTALL_PATH=$MKL_INSTALL_PATH
242EOF
243
244 fi # TF_NEED_MKL
245 ################## MKL
246fi # Disable building with MKL for now
247
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800248## Set up architecture-dependent optimization flags.
249if [ -z "$CC_OPT_FLAGS" ]; then
250 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800251 read -p "Please specify optimization flags to use during compilation when bazel option "\
252"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800253 if [ -z "$CC_OPT_FLAGS" ]; then
254 CC_OPT_FLAGS=$default_cc_opt_flags
255 fi
256fi
257
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800258if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800259 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800260 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800261 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800262 TF_NEED_OPENCL=0
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800263 TF_CUDA_CLANG=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800264fi
265
Jonathan Hseuc058a012017-01-17 15:06:43 -0800266if is_linux; then
267 while [ "$TF_NEED_JEMALLOC" == "" ]; do
268 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
269 INPUT
270 case $INPUT in
271 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
272 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
273 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
274 * ) echo "Invalid selection: " $INPUT;;
275 esac
276 done
277else
278 TF_NEED_JEMALLOC=0
279fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800280
Martin Wickebc456e32017-03-23 12:31:16 -0800281if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800282 write_to_bazelrc 'build --define with_jemalloc=true'
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800283fi
284
Martin Wickebc456e32017-03-23 12:31:16 -0800285while [[ "$TF_NEED_GCP" == "" ]]; do
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800286 read -p "Do you wish to build TensorFlow with "\
287"Google Cloud Platform support? [y/N] " INPUT
288 case $INPUT in
289 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
290"TensorFlow"; TF_NEED_GCP=1;;
291 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
292"TensorFlow"; TF_NEED_GCP=0;;
293 "" ) echo "No Google Cloud Platform support will be enabled for "\
294"TensorFlow"; TF_NEED_GCP=0;;
295 * ) echo "Invalid selection: " $INPUT;;
296 esac
297done
298
Martin Wickebc456e32017-03-23 12:31:16 -0800299if [[ "$TF_NEED_GCP" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800300 write_to_bazelrc 'build --define with_gcp_support=true'
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800301fi
302
Martin Wickebc456e32017-03-23 12:31:16 -0800303while [[ "$TF_NEED_HDFS" == "" ]]; do
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800304 read -p "Do you wish to build TensorFlow with "\
305"Hadoop File System support? [y/N] " INPUT
306 case $INPUT in
307 [Yy]* ) echo "Hadoop File System support will be enabled for "\
308"TensorFlow"; TF_NEED_HDFS=1;;
309 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
310"TensorFlow"; TF_NEED_HDFS=0;;
311 "" ) echo "No Hadoop File System support will be enabled for "\
312"TensorFlow"; TF_NEED_HDFS=0;;
313 * ) echo "Invalid selection: " $INPUT;;
314 esac
315done
316
Martin Wickebc456e32017-03-23 12:31:16 -0800317if [[ "$TF_NEED_HDFS" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800318 write_to_bazelrc 'build --define with_hdfs_support=true'
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800319fi
320
Peter Hawkins1e67c902017-01-09 12:04:37 -0800321## Enable XLA.
Martin Wickebc456e32017-03-23 12:31:16 -0800322while [[ "$TF_ENABLE_XLA" == "" ]]; do
Peter Hawkins1e67c902017-01-09 12:04:37 -0800323 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
324 case $INPUT in
325 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
326 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
327 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
328 * ) echo "Invalid selection: " $INPUT;;
329 esac
330done
331
Martin Wickebc456e32017-03-23 12:31:16 -0800332if [[ "$TF_ENABLE_XLA" == "1" ]]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800333 write_to_bazelrc 'build --define with_xla_support=true'
Peter Hawkins1e67c902017-01-09 12:04:37 -0800334fi
335
Shanqing Cai32694232017-04-22 06:08:17 -0800336# Verbs configuration
337while [ "$TF_NEED_VERBS" == "" ]; do
338 read -p "Do you wish to build TensorFlow with "\
339"VERBS support? [y/N] " INPUT
340 case $INPUT in
341 [Yy]* ) echo "VERBS support will be enabled for "\
342"TensorFlow"; TF_NEED_VERBS=1;;
343 [Nn]* ) echo "No VERBS support will be enabled for "\
344"TensorFlow"; TF_NEED_VERBS=0;;
345 "" ) echo "No VERBS support will be enabled for "\
346"TensorFlow"; TF_NEED_VERBS=0;;
347 * ) echo "Invalid selection: " $INPUT;;
348 esac
349done
350
351if [[ "$TF_NEED_VERBS" == "1" ]]; then
352 write_to_bazelrc 'build --define with_verbs_support=true'
353fi
Peter Hawkins1e67c902017-01-09 12:04:37 -0800354
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800355# Append CC optimization flags to bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800356for opt in $CC_OPT_FLAGS; do
Patrick Nguyen3bee9232017-05-04 08:48:51 -0800357 write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt"
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800358done
359
Andrew Selle09045e42016-09-06 08:19:04 -0800360# Run the gen_git_source to create links where bazel can track dependencies for
361# git hash propagation
362GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
363chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800364"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800365
Benoit Steinera7715982016-11-09 13:14:03 -0800366## Set up SYCL-related environment settings
367while [ "$TF_NEED_OPENCL" == "" ]; do
368 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
369 case $INPUT in
370 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
371 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
372 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
373 * ) echo "Invalid selection: " $INPUT;;
374 esac
375done
376
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800377## Set up Cuda-related environment settings
378
379while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800380 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800381 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800382 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
383 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
384 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800385 * ) echo "Invalid selection: " $INPUT;;
386 esac
387done
388
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800389export TF_NEED_CUDA
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800390write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800391
Rohan Jainaab09972017-01-05 14:39:17 -0800392export TF_NEED_OPENCL
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800393write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800394
Benoit Steinera7715982016-11-09 13:14:03 -0800395if [ "$TF_NEED_CUDA" == "1" ]; then
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800396while [[ "$TF_CUDA_CLANG" == "" ]]; do
397 read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT
398 case $INPUT in
399 [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;;
400 [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
401 "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;;
402 * ) echo "Invalid selection: " $INPUT;;
403 esac
404done
405
406export TF_CUDA_CLANG
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800407write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800408
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800409# Set up which clang we should use as the cuda / host compiler.
410while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do
411 fromuser=""
412 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
413 default_clang_host_compiler_path=$(which clang || true)
414 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
415 fromuser="1"
416 if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then
417 CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path"
418 fi
419 fi
420 if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then
421 export CLANG_CUDA_COMPILER_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800422 write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH"
A. Unique TensorFlower8d393ea2017-03-30 07:38:55 -0800423 break
424 fi
425 echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2
426 if [ -z "$fromuser" ]; then
427 exit 1
428 fi
429 CLANG_CUDA_COMPILER_PATH=""
430 # Retry
431done
432
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800433# Find out where the CUDA toolkit is installed
434while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800435 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800436 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800437 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 -0800438 fi
439
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800440 fromuser=""
441 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
442 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800443 if is_windows; then
444 if [ -z "$CUDA_PATH" ]; then
445 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
446 else
447 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
448 fi
Dan Ringwalt692fad22017-05-05 09:09:05 -0800449 elif is_linux; then
450 # If the default doesn't exist, try an alternative default.
451 if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then
452 default_cuda_path=/opt/cuda
453 fi
Andrew Harp1cb96892016-12-08 20:05:49 -0800454 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800455 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 -0800456 fromuser="1"
457 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800458 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800459 fi
460 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800461
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800462 if [[ -z "$TF_CUDA_VERSION" ]]; then
463 TF_CUDA_EXT=""
464 else
465 TF_CUDA_EXT=".$TF_CUDA_VERSION"
466 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800467
Andrew Harp1cb96892016-12-08 20:05:49 -0800468 if is_windows; then
469 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800470 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800471 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800472 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800473 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
474 fi
475
476 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800477 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800478 write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH"
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800479 export TF_CUDA_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800480 write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800481 break
482 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800483 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
484
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800485 if [ -z "$fromuser" ]; then
486 exit 1
487 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800488 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800489 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800490 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800491done
492
Dan Ringwalt692fad22017-05-05 09:09:05 -0800493# Set up which gcc nvcc should use as the host compiler
494# No need to set this on Windows
495while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do
496 fromuser=""
497 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
498 default_gcc_host_compiler_path=$(which gcc || true)
499 cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc"
500 if [ -L "$cuda_bin_symlink" ]; then
501 default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink)
502 fi
503 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
504 fromuser="1"
505 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
506 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
507 fi
508 fi
509 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
510 export GCC_HOST_COMPILER_PATH
511 write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH"
512 break
513 fi
514 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
515 if [ -z "$fromuser" ]; then
516 exit 1
517 fi
518 GCC_HOST_COMPILER_PATH=""
519 # Retry
520done
521
Martin Wicke916776a2016-01-14 07:30:00 -0800522# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800523while true; do
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800524 # Configure the cuDNN version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800525 if [ -z "$TF_CUDNN_VERSION" ]; then
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800526 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 -0800527 fi
528
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800529 fromuser=""
530 if [ -z "$CUDNN_INSTALL_PATH" ]; then
531 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800532 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 -0800533 fromuser="1"
534 if [ -z "$CUDNN_INSTALL_PATH" ]; then
535 CUDNN_INSTALL_PATH=$default_cudnn_path
536 fi
537 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
538 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800539 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 -0800540 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800541
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800542 if [[ -z "$TF_CUDNN_VERSION" ]]; then
543 TF_CUDNN_EXT=""
544 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800545 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800546 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800547
Andrew Harp1cb96892016-12-08 20:05:49 -0800548 if is_windows; then
549 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
550 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800551 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800552 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
553 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800554 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800555 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
556 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800557 fi
558
559 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 -0800560 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800561 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800562 export CUDNN_INSTALL_PATH
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800563 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800564 break
565 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800566
Jonathan Hseuc058a012017-01-17 15:06:43 -0800567 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800568 if ! type ldconfig > /dev/null 2>&1; then
569 LDCONFIG_BIN=/sbin/ldconfig
570 else
571 LDCONFIG_BIN=ldconfig
572 fi
573 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800574 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800575 export TF_CUDNN_VERSION
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800576 write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION"
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800577 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800578 write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800579 break
580 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800581 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800582 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
583 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
584 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800585 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800586 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
587 fi
588
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800589 if [ -z "$fromuser" ]; then
590 exit 1
591 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800592 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800593 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800594 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800595done
596
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800597# Configure the compute capabilities that TensorFlow builds for.
598# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
599while true; do
600 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800601 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800602 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800603cat << EOF
604Please specify a list of comma-separated Cuda compute capabilities you want to build with.
605You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
606Please note that each additional compute capability significantly increases your build time and binary size.
607EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800608 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
609 fromuser=1
610 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800611 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
612 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
613 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800614 # Check whether all capabilities from the input is valid
615 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
616 ALL_VALID=1
617 for CAPABILITY in $COMPUTE_CAPABILITIES; do
618 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
619 echo "Invalid compute capability: " $CAPABILITY
620 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800621 break
622 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800623 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800624 if [ "$ALL_VALID" == "0" ]; then
625 if [ -z "$fromuser" ]; then
626 exit 1
627 fi
628 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800629 export TF_CUDA_COMPUTE_CAPABILITIES
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800630 write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800631 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800632 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800633 TF_CUDA_COMPUTE_CAPABILITIES=""
634done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800635
Andrew Harp1cb96892016-12-08 20:05:49 -0800636if is_windows; then
637 # The following three variables are needed for MSVC toolchain configuration in Bazel
638 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
639 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
640 export NO_WHOLE_ARCHIVE_OPTION=1
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800641 write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH"
642 write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES"
643 write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1"
Andrew Harp1cb96892016-12-08 20:05:49 -0800644fi
645
Benoit Steinera7715982016-11-09 13:14:03 -0800646# end of if "$TF_NEED_CUDA" == "1"
647fi
648
649# OpenCL configuration
650
651if [ "$TF_NEED_OPENCL" == "1" ]; then
652
653# Determine which C++ compiler should be used as the host compiler
654while true; do
655 fromuser=""
656 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800657 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800658 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
659 fromuser="1"
660 if [ -z "$HOST_CXX_COMPILER" ]; then
661 HOST_CXX_COMPILER=$default_cxx_host_compiler
662 fi
663 fi
664 if [ -e "$HOST_CXX_COMPILER" ]; then
665 export HOST_CXX_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800666 write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800667 break
668 fi
669 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
670 if [ -z "$fromuser" ]; then
671 exit 1
672 fi
673 HOST_CXX_COMPILER=""
674 # Retry
675done
676
677# Determine which C compiler should be used as the host compiler
678while true; do
679 fromuser=""
680 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800681 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800682 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
683 fromuser="1"
684 if [ -z "$HOST_C_COMPILER" ]; then
685 HOST_C_COMPILER=$default_c_host_compiler
686 fi
687 fi
688 if [ -e "$HOST_C_COMPILER" ]; then
689 export HOST_C_COMPILER
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800690 write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER"
Benoit Steinera7715982016-11-09 13:14:03 -0800691 break
692 fi
693 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
694 if [ -z "$fromuser" ]; then
695 exit 1
696 fi
697 HOST_C_COMPILER=""
698 # Retry
699done
700
701while true; do
702 # Configure the OPENCL version to use.
703 TF_OPENCL_VERSION="1.2"
704
705 # Point to ComputeCpp root
706 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
707 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800708 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 -0800709 fromuser="1"
710 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
711 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
712 fi
713 fi
714
Jonathan Hseuc058a012017-01-17 15:06:43 -0800715 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800716 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
717 fi
718
719 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
720 export COMPUTECPP_TOOLKIT_PATH
A. Unique TensorFlower82684762017-04-05 11:30:37 -0800721 write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH"
Benoit Steinera7715982016-11-09 13:14:03 -0800722 break
723 fi
724 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
725
726 if [ -z "$fromuser" ]; then
727 exit 1
728 fi
729 # Retry
730 TF_OPENCL_VERSION=""
731 COMPUTECPP_TOOLKIT_PATH=""
732done
733
Benoit Steinera7715982016-11-09 13:14:03 -0800734# end of if "$TF_NEED_OPENCL" == "1"
735fi
736
A. Unique TensorFlowerccbc8992017-04-04 16:10:08 -0800737# TODO(gunan): Remove once bazel correctly handles changes in remote repositories.
738bazel clean
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800739echo "Configuration finished"