blob: 05daa23d706f66946b2d67ac882c734b5ac8424b [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
Jonathan Hseu1283b842016-09-29 15:05:32 -080038function bazel_clean_and_fetch() {
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -080039 # bazel clean --expunge currently doesn't work on Windows
40 # TODO(pcloudy): Re-enable it after bazel clean --expunge is fixed.
41 if ! is_windows; then
42 bazel clean --expunge
43 fi
Asim Shankar429d14d2017-03-13 13:27:31 -080044 if [ -z "$TF_BAZEL_TARGETS" ]; then
45 TF_BAZEL_TARGETS="//tensorflow/... -//tensorflow/contrib/nccl/... -//tensorflow/examples/android/..."
46 fi
47 bazel fetch "$TF_BAZEL_TARGETS"
Jonathan Hseu1283b842016-09-29 15:05:32 -080048}
49
Dandelion Mané0386a012017-03-10 14:43:23 -080050function sed_hyphen_i() {
51 if is_macos; then
52 sed -i '' "$@"
53 else
54 sed -i "$@"
55 fi
56}
57
Andrew Harp51dbc462017-01-27 14:42:30 -080058# Delete any leftover BUILD files from the Makefile build, which would interfere
59# with Bazel parsing.
60MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads
61if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then
62 find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete
63fi
64
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080065## Set up python-related environment settings
66while true; do
67 fromuser=""
68 if [ -z "$PYTHON_BIN_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -080069 default_python_bin_path=$(which python || which python3 || true)
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080070 read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH
71 fromuser="1"
72 if [ -z "$PYTHON_BIN_PATH" ]; then
73 PYTHON_BIN_PATH=$default_python_bin_path
74 fi
75 fi
76 if [ -e "$PYTHON_BIN_PATH" ]; then
77 break
78 fi
79 echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2
80 if [ -z "$fromuser" ]; then
81 exit 1
82 fi
83 PYTHON_BIN_PATH=""
84 # Retry
85done
86
Benoit Steiner639b4e72017-02-08 09:25:09 -080087## Set up MKL related environment settings
88if false; then # Disable building with MKL for now
89 while [ "$TF_NEED_MKL" == "" ]; do
90 fromuser=""
91 read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
92 fromuser="1"
93 case $INPUT in
94 [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
95 [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
96 "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
97 * ) echo "Invalid selection: " $INPUT;;
98 esac
99 done
100
101 OSNAME=`uname -s`
102
103 if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
104 DST=`dirname $0`
105 ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170110.tgz
106 GITHUB_RELEASE_TAG=v0.3
107 MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
108 if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
109 wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
110 fi
111 tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
112 extracted_dir_name="${ARCHIVE_BASENAME%.*}"
113 MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
114 MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
115
116 if [ "$OSNAME" == "Linux" ]; then
117 # Full MKL configuration
118 MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
119 MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?
120
121 # MKL-ML configuration
122 MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
123 MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
124 elif [ "$OSNAME" == "Darwin" ]; then
125 echo "Darwin is unsupported yet";
126 exit 1
127 fi
128
129 if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
130 ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
131 ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
132 ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
133 ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
134 else
135 echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
136 exit 1
137 fi
138
139 if [ -z "$fromuser" ]; then
140 exit 1
141 fi
142
143cat > third_party/mkl/mkl.config <<EOF
144# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
145# files can be either in this directory, or under include/ and lib64/
146MKL_INSTALL_PATH=$MKL_INSTALL_PATH
147EOF
148
149 fi # TF_NEED_MKL
150 ################## MKL
151fi # Disable building with MKL for now
152
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800153## Set up architecture-dependent optimization flags.
154if [ -z "$CC_OPT_FLAGS" ]; then
155 default_cc_opt_flags="-march=native"
Benoit Steiner639b4e72017-02-08 09:25:09 -0800156 read -p "Please specify optimization flags to use during compilation when bazel option "\
157"\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800158 if [ -z "$CC_OPT_FLAGS" ]; then
159 CC_OPT_FLAGS=$default_cc_opt_flags
160 fi
161fi
162
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800163if is_windows; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800164 TF_NEED_GCP=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800165 TF_NEED_HDFS=0
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800166 TF_NEED_JEMALLOC=0
Benoit Steinera7715982016-11-09 13:14:03 -0800167 TF_NEED_OPENCL=0
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800168fi
169
Jonathan Hseuc058a012017-01-17 15:06:43 -0800170if is_linux; then
171 while [ "$TF_NEED_JEMALLOC" == "" ]; do
172 read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
173 INPUT
174 case $INPUT in
175 [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
176 [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
177 "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
178 * ) echo "Invalid selection: " $INPUT;;
179 esac
180 done
181else
182 TF_NEED_JEMALLOC=0
183fi
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800184
185if [ "$TF_NEED_JEMALLOC" == "1" ]; then
Dandelion Mané0386a012017-03-10 14:43:23 -0800186 sed_hyphen_i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800187else
Dandelion Mané0386a012017-03-10 14:43:23 -0800188 sed_hyphen_i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu83c6e0c2017-01-11 16:39:35 -0800189fi
190
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800191while [ "$TF_NEED_GCP" == "" ]; do
192 read -p "Do you wish to build TensorFlow with "\
193"Google Cloud Platform support? [y/N] " INPUT
194 case $INPUT in
195 [Yy]* ) echo "Google Cloud Platform support will be enabled for "\
196"TensorFlow"; TF_NEED_GCP=1;;
197 [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\
198"TensorFlow"; TF_NEED_GCP=0;;
199 "" ) echo "No Google Cloud Platform support will be enabled for "\
200"TensorFlow"; TF_NEED_GCP=0;;
201 * ) echo "Invalid selection: " $INPUT;;
202 esac
203done
204
205if [ "$TF_NEED_GCP" == "1" ]; then
206 ## Verify that libcurl header files are available.
207 # Only check Linux, since on MacOS the header files are installed with XCode.
Jonathan Hseuc058a012017-01-17 15:06:43 -0800208 if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800209 echo "ERROR: It appears that the development version of libcurl is not "\
210"available. Please install the libcurl3-dev package."
211 exit 1
212 fi
213
214 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800215 sed_hyphen_i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800216else
217 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800218 sed_hyphen_i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
A. Unique TensorFlower95a954a2016-12-28 13:40:08 -0800219fi
220
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800221while [ "$TF_NEED_HDFS" == "" ]; do
222 read -p "Do you wish to build TensorFlow with "\
223"Hadoop File System support? [y/N] " INPUT
224 case $INPUT in
225 [Yy]* ) echo "Hadoop File System support will be enabled for "\
226"TensorFlow"; TF_NEED_HDFS=1;;
227 [Nn]* ) echo "No Hadoop File System support will be enabled for "\
228"TensorFlow"; TF_NEED_HDFS=0;;
229 "" ) echo "No Hadoop File System support will be enabled for "\
230"TensorFlow"; TF_NEED_HDFS=0;;
231 * ) echo "Invalid selection: " $INPUT;;
232 esac
233done
234
235if [ "$TF_NEED_HDFS" == "1" ]; then
236 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800237 sed_hyphen_i -e "s/WITH_HDFS_SUPPORT = False/WITH_HDFS_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800238else
239 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800240 sed_hyphen_i -e "s/WITH_HDFS_SUPPORT = True/WITH_HDFS_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
Jonathan Hseu9f5b0982016-09-19 11:14:58 -0800241fi
242
Peter Hawkins1e67c902017-01-09 12:04:37 -0800243## Enable XLA.
244while [ "$TF_ENABLE_XLA" == "" ]; do
245 read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
246 case $INPUT in
247 [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
248 [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
249 "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;;
250 * ) echo "Invalid selection: " $INPUT;;
251 esac
252done
253
254if [ "$TF_ENABLE_XLA" == "1" ]; then
255 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800256 sed_hyphen_i -e "s/^WITH_XLA_SUPPORT = [FT].*/WITH_XLA_SUPPORT = True/" tensorflow/core/platform/default/build_config_root.bzl
Peter Hawkins1e67c902017-01-09 12:04:37 -0800257else
258 # Update Bazel build configuration.
Dandelion Mané0386a012017-03-10 14:43:23 -0800259 sed_hyphen_i -e "s/^WITH_XLA_SUPPORT = [FT].*/WITH_XLA_SUPPORT = False/" tensorflow/core/platform/default/build_config_root.bzl
Peter Hawkins1e67c902017-01-09 12:04:37 -0800260fi
261
262
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800263# Invoke python_config and set up symlinks to python includes
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800264./util/python/python_config.sh --setup "$PYTHON_BIN_PATH"
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800265
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800266# Append CC optimization flags to bazel.rc
267echo >> tools/bazel.rc
268for opt in $CC_OPT_FLAGS; do
Gunhan Gulsoyacdbd682017-01-16 01:21:51 -0800269 echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc
Martin Wickec4e3d4a2017-01-13 12:20:42 -0800270done
271
Andrew Selle09045e42016-09-06 08:19:04 -0800272# Run the gen_git_source to create links where bazel can track dependencies for
273# git hash propagation
274GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py
275chmod a+x ${GEN_GIT_SOURCE}
Patrick Nguyenc5ab3dd2016-10-20 12:09:18 -0800276"${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}"
Andrew Selle09045e42016-09-06 08:19:04 -0800277
Benoit Steinera7715982016-11-09 13:14:03 -0800278## Set up SYCL-related environment settings
279while [ "$TF_NEED_OPENCL" == "" ]; do
280 read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT
281 case $INPUT in
282 [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;;
283 [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
284 "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;;
285 * ) echo "Invalid selection: " $INPUT;;
286 esac
287done
288
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800289## Set up Cuda-related environment settings
290
291while [ "$TF_NEED_CUDA" == "" ]; do
Andrew Harp1cb96892016-12-08 20:05:49 -0800292 read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800293 case $INPUT in
Andrew Harp1cb96892016-12-08 20:05:49 -0800294 [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;;
295 [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
296 "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;;
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800297 * ) echo "Invalid selection: " $INPUT;;
298 esac
299done
300
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800301export TF_NEED_CUDA
Rohan Jainaab09972017-01-05 14:39:17 -0800302export TF_NEED_OPENCL
Benoit Steinera7715982016-11-09 13:14:03 -0800303if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800304 echo "Configuration finished"
Jonathan Hseu1283b842016-09-29 15:05:32 -0800305 bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800306 exit
307fi
308
Benoit Steinera7715982016-11-09 13:14:03 -0800309if [ "$TF_NEED_CUDA" == "1" ]; then
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800310# Set up which gcc nvcc should use as the host compiler
Andrew Harp1cb96892016-12-08 20:05:49 -0800311# No need to set this on Windows
312while ! is_windows && true; do
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800313 fromuser=""
314 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFloweredaf3b32016-10-10 10:26:22 -0800315 default_gcc_host_compiler_path=$(which gcc || true)
Shanqing Caia81c4f92016-07-22 10:37:35 -0800316 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 -0800317 fromuser="1"
318 if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800319 GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path"
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800320 fi
321 fi
322 if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800323 export GCC_HOST_COMPILER_PATH
Vijay Vasudevan80a5a3e2016-03-29 18:23:11 -0800324 break
325 fi
326 echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
327 if [ -z "$fromuser" ]; then
328 exit 1
329 fi
330 GCC_HOST_COMPILER_PATH=""
331 # Retry
332done
333
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800334# Find out where the CUDA toolkit is installed
335while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800336 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800337 if [ -z "$TF_CUDA_VERSION" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800338 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 -0800339 fi
340
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800341 fromuser=""
342 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
343 default_cuda_path=/usr/local/cuda
Andrew Harp1cb96892016-12-08 20:05:49 -0800344 if is_windows; then
345 if [ -z "$CUDA_PATH" ]; then
346 default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0"
347 else
348 default_cuda_path="$(cygpath -m "$CUDA_PATH")"
349 fi
350 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800351 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 -0800352 fromuser="1"
353 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
Andrew Harp1cb96892016-12-08 20:05:49 -0800354 CUDA_TOOLKIT_PATH="$default_cuda_path"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800355 fi
356 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800357
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800358 if [[ -z "$TF_CUDA_VERSION" ]]; then
359 TF_CUDA_EXT=""
360 else
361 TF_CUDA_EXT=".$TF_CUDA_VERSION"
362 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800363
Andrew Harp1cb96892016-12-08 20:05:49 -0800364 if is_windows; then
365 CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800366 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800367 CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800368 elif is_macos; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800369 CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
370 fi
371
372 if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800373 export CUDA_TOOLKIT_PATH
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800374 export TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800375 break
376 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800377 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
378
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800379 if [ -z "$fromuser" ]; then
380 exit 1
381 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800382 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800383 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800384 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800385done
386
Martin Wicke916776a2016-01-14 07:30:00 -0800387# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800388while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800389 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800390 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800391 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 -0800392 fi
393
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800394 fromuser=""
395 if [ -z "$CUDNN_INSTALL_PATH" ]; then
396 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800397 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 -0800398 fromuser="1"
399 if [ -z "$CUDNN_INSTALL_PATH" ]; then
400 CUDNN_INSTALL_PATH=$default_cudnn_path
401 fi
402 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
403 # Going through one more level of expansion to handle that.
Andrew Harp1cb96892016-12-08 20:05:49 -0800404 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 -0800405 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800406
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800407 if [[ -z "$TF_CUDNN_VERSION" ]]; then
408 TF_CUDNN_EXT=""
409 else
Benoit Steiner639b4e72017-02-08 09:25:09 -0800410 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800411 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800412
Andrew Harp1cb96892016-12-08 20:05:49 -0800413 if is_windows; then
414 CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
415 CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800416 elif is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800417 CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
418 CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800419 elif is_macos; then
Benoit Steiner639b4e72017-02-08 09:25:09 -0800420 CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib"
421 CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800422 fi
423
424 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 -0800425 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800426 export CUDNN_INSTALL_PATH
Eugene Brevdo56f1d642016-03-10 17:18:30 -0800427 break
428 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800429
Jonathan Hseuc058a012017-01-17 15:06:43 -0800430 if is_linux; then
Vijay Vasudevan93a975e2017-02-17 17:05:49 -0800431 if ! type ldconfig > /dev/null 2>&1; then
432 LDCONFIG_BIN=/sbin/ldconfig
433 else
434 LDCONFIG_BIN=ldconfig
435 fi
436 CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800437 if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800438 export TF_CUDNN_VERSION
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800439 export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800440 break
441 fi
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800442 fi
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800443 echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
444 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
445 echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
Jonathan Hseuc058a012017-01-17 15:06:43 -0800446 if is_linux; then
A. Unique TensorFlower8bf6ef12016-05-05 08:36:05 -0800447 echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
448 fi
449
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800450 if [ -z "$fromuser" ]; then
451 exit 1
452 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800453 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800454 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800455 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800456done
457
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800458# Configure the compute capabilities that TensorFlow builds for.
459# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
460while true; do
461 fromuser=""
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800462 default_cuda_compute_capabilities="3.5,5.2"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800463 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800464cat << EOF
465Please specify a list of comma-separated Cuda compute capabilities you want to build with.
466You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
467Please note that each additional compute capability significantly increases your build time and binary size.
468EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800469 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
470 fromuser=1
471 fi
A. Unique TensorFlower2c598e82016-08-25 10:22:44 -0800472 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
473 TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
474 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800475 # Check whether all capabilities from the input is valid
476 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
477 ALL_VALID=1
478 for CAPABILITY in $COMPUTE_CAPABILITIES; do
479 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
480 echo "Invalid compute capability: " $CAPABILITY
481 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800482 break
483 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800484 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800485 if [ "$ALL_VALID" == "0" ]; then
486 if [ -z "$fromuser" ]; then
487 exit 1
488 fi
489 else
A. Unique TensorFlowerb0bdff42016-08-26 12:50:48 -0800490 export TF_CUDA_COMPUTE_CAPABILITIES
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800491 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800492 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800493 TF_CUDA_COMPUTE_CAPABILITIES=""
494done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800495
Andrew Harp1cb96892016-12-08 20:05:49 -0800496if is_windows; then
497 # The following three variables are needed for MSVC toolchain configuration in Bazel
498 export CUDA_PATH="$CUDA_TOOLKIT_PATH"
499 export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES"
500 export NO_WHOLE_ARCHIVE_OPTION=1
501
502 # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy
503 export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler"
504fi
505
Benoit Steinera7715982016-11-09 13:14:03 -0800506# end of if "$TF_NEED_CUDA" == "1"
507fi
508
509# OpenCL configuration
510
511if [ "$TF_NEED_OPENCL" == "1" ]; then
512
513# Determine which C++ compiler should be used as the host compiler
514while true; do
515 fromuser=""
516 if [ -z "$HOST_CXX_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800517 default_cxx_host_compiler=$(which clang++-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800518 read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER
519 fromuser="1"
520 if [ -z "$HOST_CXX_COMPILER" ]; then
521 HOST_CXX_COMPILER=$default_cxx_host_compiler
522 fi
523 fi
524 if [ -e "$HOST_CXX_COMPILER" ]; then
525 export HOST_CXX_COMPILER
526 break
527 fi
528 echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2
529 if [ -z "$fromuser" ]; then
530 exit 1
531 fi
532 HOST_CXX_COMPILER=""
533 # Retry
534done
535
536# Determine which C compiler should be used as the host compiler
537while true; do
538 fromuser=""
539 if [ -z "$HOST_C_COMPILER" ]; then
Jonathan Hseubed83832016-12-22 15:38:30 -0800540 default_c_host_compiler=$(which clang-3.6 || true)
Benoit Steinera7715982016-11-09 13:14:03 -0800541 read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER
542 fromuser="1"
543 if [ -z "$HOST_C_COMPILER" ]; then
544 HOST_C_COMPILER=$default_c_host_compiler
545 fi
546 fi
547 if [ -e "$HOST_C_COMPILER" ]; then
548 export HOST_C_COMPILER
549 break
550 fi
551 echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2
552 if [ -z "$fromuser" ]; then
553 exit 1
554 fi
555 HOST_C_COMPILER=""
556 # Retry
557done
558
559while true; do
560 # Configure the OPENCL version to use.
561 TF_OPENCL_VERSION="1.2"
562
563 # Point to ComputeCpp root
564 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
565 default_computecpp_toolkit_path=/usr/local/computecpp
Martin Wicke2e4869a2016-12-14 15:46:53 -0800566 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 -0800567 fromuser="1"
568 if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then
569 COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path
570 fi
571 fi
572
Jonathan Hseuc058a012017-01-17 15:06:43 -0800573 if is_linux; then
Benoit Steinera7715982016-11-09 13:14:03 -0800574 SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
575 fi
576
577 if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then
578 export COMPUTECPP_TOOLKIT_PATH
579 break
580 fi
581 echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found"
582
583 if [ -z "$fromuser" ]; then
584 exit 1
585 fi
586 # Retry
587 TF_OPENCL_VERSION=""
588 COMPUTECPP_TOOLKIT_PATH=""
589done
590
Benoit Steinera7715982016-11-09 13:14:03 -0800591# end of if "$TF_NEED_OPENCL" == "1"
592fi
593
Jonathan Hseu1283b842016-09-29 15:05:32 -0800594bazel_clean_and_fetch
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800595
596echo "Configuration finished"