Geoffrey Irving | 4c85a08 | 2016-03-16 12:20:34 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 2 | |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 3 | set -e |
| 4 | set -o pipefail |
| 5 | |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 6 | # Find out the absolute path to where ./configure resides |
A. Unique TensorFlower | 46d2c28 | 2017-01-02 22:19:48 -0800 | [diff] [blame] | 7 | pushd `dirname $0` > /dev/null |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 8 | SOURCE_BASE_DIR=`pwd -P` |
| 9 | popd > /dev/null |
| 10 | |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 11 | PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" |
| 12 | function is_windows() { |
| 13 | # On windows, the shell script is actually running in msys |
| 14 | if [[ "${PLATFORM}" =~ msys_nt* ]]; then |
| 15 | true |
| 16 | else |
| 17 | false |
| 18 | fi |
| 19 | } |
| 20 | |
Jonathan Hseu | 1283b84 | 2016-09-29 15:05:32 -0800 | [diff] [blame] | 21 | function bazel_clean_and_fetch() { |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 22 | # bazel clean --expunge currently doesn't work on Windows |
| 23 | # TODO(pcloudy): Re-enable it after bazel clean --expunge is fixed. |
| 24 | if ! is_windows; then |
| 25 | bazel clean --expunge |
| 26 | fi |
Patrick Nguyen | db24941 | 2017-01-17 10:57:25 -0800 | [diff] [blame^] | 27 | bazel fetch "//tensorflow/... -//tensorflow/examples/android/..." |
Jonathan Hseu | 1283b84 | 2016-09-29 15:05:32 -0800 | [diff] [blame] | 28 | } |
| 29 | |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 30 | ## Set up python-related environment settings |
| 31 | while true; do |
| 32 | fromuser="" |
| 33 | if [ -z "$PYTHON_BIN_PATH" ]; then |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 34 | default_python_bin_path=$(which python || which python3 || true) |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 35 | read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH |
| 36 | fromuser="1" |
| 37 | if [ -z "$PYTHON_BIN_PATH" ]; then |
| 38 | PYTHON_BIN_PATH=$default_python_bin_path |
| 39 | fi |
| 40 | fi |
| 41 | if [ -e "$PYTHON_BIN_PATH" ]; then |
| 42 | break |
| 43 | fi |
| 44 | echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2 |
| 45 | if [ -z "$fromuser" ]; then |
| 46 | exit 1 |
| 47 | fi |
| 48 | PYTHON_BIN_PATH="" |
| 49 | # Retry |
| 50 | done |
| 51 | |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 52 | ## Set up architecture-dependent optimization flags. |
| 53 | if [ -z "$CC_OPT_FLAGS" ]; then |
| 54 | default_cc_opt_flags="-march=native" |
| 55 | read -p "Please specify optimization flags to use during compilation [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS |
| 56 | if [ -z "$CC_OPT_FLAGS" ]; then |
| 57 | CC_OPT_FLAGS=$default_cc_opt_flags |
| 58 | fi |
| 59 | fi |
| 60 | |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 61 | if is_windows; then |
A. Unique TensorFlower | 95a954a | 2016-12-28 13:40:08 -0800 | [diff] [blame] | 62 | TF_NEED_GCP=0 |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 63 | TF_NEED_HDFS=0 |
Jonathan Hseu | 83c6e0c | 2017-01-11 16:39:35 -0800 | [diff] [blame] | 64 | TF_NEED_JEMALLOC=0 |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 65 | TF_NEED_OPENCL=0 |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 66 | fi |
| 67 | |
Jonathan Hseu | 83c6e0c | 2017-01-11 16:39:35 -0800 | [diff] [blame] | 68 | while [ "$TF_NEED_JEMALLOC" == "" ]; do |
| 69 | read -p "Do you wish to use jemalloc as the malloc implementation? "\ |
| 70 | "(Linux only) [Y/n] " INPUT |
| 71 | case $INPUT in |
| 72 | [Yy]* ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;; |
| 73 | [Nn]* ) echo "jemalloc disabled on Linux"; TF_NEED_JEMALLOC=0;; |
| 74 | "" ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;; |
| 75 | * ) echo "Invalid selection: " $INPUT;; |
| 76 | esac |
| 77 | done |
| 78 | |
| 79 | if [ "$TF_NEED_JEMALLOC" == "1" ]; then |
| 80 | sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl |
| 81 | else |
| 82 | sed -i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl |
| 83 | fi |
| 84 | |
A. Unique TensorFlower | 95a954a | 2016-12-28 13:40:08 -0800 | [diff] [blame] | 85 | while [ "$TF_NEED_GCP" == "" ]; do |
| 86 | read -p "Do you wish to build TensorFlow with "\ |
| 87 | "Google Cloud Platform support? [y/N] " INPUT |
| 88 | case $INPUT in |
| 89 | [Yy]* ) echo "Google Cloud Platform support will be enabled for "\ |
| 90 | "TensorFlow"; TF_NEED_GCP=1;; |
| 91 | [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\ |
| 92 | "TensorFlow"; TF_NEED_GCP=0;; |
| 93 | "" ) echo "No Google Cloud Platform support will be enabled for "\ |
| 94 | "TensorFlow"; TF_NEED_GCP=0;; |
| 95 | * ) echo "Invalid selection: " $INPUT;; |
| 96 | esac |
| 97 | done |
| 98 | |
| 99 | if [ "$TF_NEED_GCP" == "1" ]; then |
| 100 | ## Verify that libcurl header files are available. |
| 101 | # Only check Linux, since on MacOS the header files are installed with XCode. |
| 102 | if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then |
| 103 | echo "ERROR: It appears that the development version of libcurl is not "\ |
| 104 | "available. Please install the libcurl3-dev package." |
| 105 | exit 1 |
| 106 | fi |
| 107 | |
| 108 | # Update Bazel build configuration. |
| 109 | sed -i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl |
| 110 | else |
| 111 | # Update Bazel build configuration. |
| 112 | sed -i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl |
| 113 | fi |
| 114 | |
Jonathan Hseu | 9f5b098 | 2016-09-19 11:14:58 -0800 | [diff] [blame] | 115 | while [ "$TF_NEED_HDFS" == "" ]; do |
| 116 | read -p "Do you wish to build TensorFlow with "\ |
| 117 | "Hadoop File System support? [y/N] " INPUT |
| 118 | case $INPUT in |
| 119 | [Yy]* ) echo "Hadoop File System support will be enabled for "\ |
| 120 | "TensorFlow"; TF_NEED_HDFS=1;; |
| 121 | [Nn]* ) echo "No Hadoop File System support will be enabled for "\ |
| 122 | "TensorFlow"; TF_NEED_HDFS=0;; |
| 123 | "" ) echo "No Hadoop File System support will be enabled for "\ |
| 124 | "TensorFlow"; TF_NEED_HDFS=0;; |
| 125 | * ) echo "Invalid selection: " $INPUT;; |
| 126 | esac |
| 127 | done |
| 128 | |
| 129 | if [ "$TF_NEED_HDFS" == "1" ]; then |
| 130 | # Update Bazel build configuration. |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 131 | sed -i -e "s/WITH_HDFS_SUPPORT = False/WITH_HDFS_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl |
Jonathan Hseu | 9f5b098 | 2016-09-19 11:14:58 -0800 | [diff] [blame] | 132 | else |
| 133 | # Update Bazel build configuration. |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 134 | sed -i -e "s/WITH_HDFS_SUPPORT = True/WITH_HDFS_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl |
Jonathan Hseu | 9f5b098 | 2016-09-19 11:14:58 -0800 | [diff] [blame] | 135 | fi |
| 136 | |
Peter Hawkins | 1e67c90 | 2017-01-09 12:04:37 -0800 | [diff] [blame] | 137 | ## Enable XLA. |
| 138 | while [ "$TF_ENABLE_XLA" == "" ]; do |
| 139 | read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT |
| 140 | case $INPUT in |
| 141 | [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;; |
| 142 | [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;; |
| 143 | "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;; |
| 144 | * ) echo "Invalid selection: " $INPUT;; |
| 145 | esac |
| 146 | done |
| 147 | |
| 148 | if [ "$TF_ENABLE_XLA" == "1" ]; then |
| 149 | # Update Bazel build configuration. |
| 150 | perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = True,s" tensorflow/core/platform/default/build_config.bzl |
| 151 | else |
| 152 | # Update Bazel build configuration. |
| 153 | perl -pi -e "s,WITH_XLA_SUPPORT = (False|True),WITH_XLA_SUPPORT = False,s" tensorflow/core/platform/default/build_config.bzl |
| 154 | fi |
| 155 | |
| 156 | |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 157 | # Invoke python_config and set up symlinks to python includes |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 158 | ./util/python/python_config.sh --setup "$PYTHON_BIN_PATH" |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 159 | |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 160 | # Append CC optimization flags to bazel.rc |
| 161 | echo >> tools/bazel.rc |
| 162 | for opt in $CC_OPT_FLAGS; do |
Gunhan Gulsoy | acdbd68 | 2017-01-16 01:21:51 -0800 | [diff] [blame] | 163 | echo "build:opt --cxxopt=$opt --copt=$opt" >> tools/bazel.rc |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 164 | done |
| 165 | |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 166 | # Run the gen_git_source to create links where bazel can track dependencies for |
| 167 | # git hash propagation |
| 168 | GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py |
| 169 | chmod a+x ${GEN_GIT_SOURCE} |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 170 | "${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}" |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 171 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 172 | ## Set up SYCL-related environment settings |
| 173 | while [ "$TF_NEED_OPENCL" == "" ]; do |
| 174 | read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT |
| 175 | case $INPUT in |
| 176 | [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;; |
| 177 | [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;; |
| 178 | "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;; |
| 179 | * ) echo "Invalid selection: " $INPUT;; |
| 180 | esac |
| 181 | done |
| 182 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 183 | ## Set up Cuda-related environment settings |
| 184 | |
| 185 | while [ "$TF_NEED_CUDA" == "" ]; do |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 186 | read -p "Do you wish to build TensorFlow with CUDA support? [y/N] " INPUT |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 187 | case $INPUT in |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 188 | [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;; |
| 189 | [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;; |
| 190 | "" ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;; |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 191 | * ) echo "Invalid selection: " $INPUT;; |
| 192 | esac |
| 193 | done |
| 194 | |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 195 | export TF_NEED_CUDA |
Rohan Jain | aab0997 | 2017-01-05 14:39:17 -0800 | [diff] [blame] | 196 | export TF_NEED_OPENCL |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 197 | if [[ "$TF_NEED_CUDA" == "0" ]] && [[ "$TF_NEED_OPENCL" == "0" ]]; then |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 198 | echo "Configuration finished" |
Jonathan Hseu | 1283b84 | 2016-09-29 15:05:32 -0800 | [diff] [blame] | 199 | bazel_clean_and_fetch |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 200 | exit |
| 201 | fi |
| 202 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 203 | if [ "$TF_NEED_CUDA" == "1" ]; then |
Vijay Vasudevan | 80a5a3e | 2016-03-29 18:23:11 -0800 | [diff] [blame] | 204 | # Set up which gcc nvcc should use as the host compiler |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 205 | # No need to set this on Windows |
| 206 | while ! is_windows && true; do |
Vijay Vasudevan | 80a5a3e | 2016-03-29 18:23:11 -0800 | [diff] [blame] | 207 | fromuser="" |
| 208 | if [ -z "$GCC_HOST_COMPILER_PATH" ]; then |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 209 | default_gcc_host_compiler_path=$(which gcc || true) |
Shanqing Cai | a81c4f9 | 2016-07-22 10:37:35 -0800 | [diff] [blame] | 210 | 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 Vasudevan | 80a5a3e | 2016-03-29 18:23:11 -0800 | [diff] [blame] | 211 | fromuser="1" |
| 212 | if [ -z "$GCC_HOST_COMPILER_PATH" ]; then |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 213 | GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path" |
Vijay Vasudevan | 80a5a3e | 2016-03-29 18:23:11 -0800 | [diff] [blame] | 214 | fi |
| 215 | fi |
| 216 | if [ -e "$GCC_HOST_COMPILER_PATH" ]; then |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 217 | export GCC_HOST_COMPILER_PATH |
Vijay Vasudevan | 80a5a3e | 2016-03-29 18:23:11 -0800 | [diff] [blame] | 218 | break |
| 219 | fi |
| 220 | echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2 |
| 221 | if [ -z "$fromuser" ]; then |
| 222 | exit 1 |
| 223 | fi |
| 224 | GCC_HOST_COMPILER_PATH="" |
| 225 | # Retry |
| 226 | done |
| 227 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 228 | # Find out where the CUDA toolkit is installed |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 229 | OSNAME=`uname -s` |
| 230 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 231 | while true; do |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 232 | # Configure the Cuda SDK version to use. |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 233 | if [ -z "$TF_CUDA_VERSION" ]; then |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 234 | 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 TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 235 | fi |
| 236 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 237 | fromuser="" |
| 238 | if [ -z "$CUDA_TOOLKIT_PATH" ]; then |
| 239 | default_cuda_path=/usr/local/cuda |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 240 | if is_windows; then |
| 241 | if [ -z "$CUDA_PATH" ]; then |
| 242 | default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0" |
| 243 | else |
| 244 | default_cuda_path="$(cygpath -m "$CUDA_PATH")" |
| 245 | fi |
| 246 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 247 | 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 Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 248 | fromuser="1" |
| 249 | if [ -z "$CUDA_TOOLKIT_PATH" ]; then |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 250 | CUDA_TOOLKIT_PATH="$default_cuda_path" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 251 | fi |
| 252 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 253 | |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 254 | if [[ -z "$TF_CUDA_VERSION" ]]; then |
| 255 | TF_CUDA_EXT="" |
| 256 | else |
| 257 | TF_CUDA_EXT=".$TF_CUDA_VERSION" |
| 258 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 259 | |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 260 | if is_windows; then |
| 261 | CUDA_RT_LIB_PATH="lib/x64/cudart.lib" |
| 262 | elif [ "$OSNAME" == "Linux" ]; then |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 263 | CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}" |
| 264 | elif [ "$OSNAME" == "Darwin" ]; then |
| 265 | CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib" |
| 266 | fi |
| 267 | |
| 268 | if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 269 | export CUDA_TOOLKIT_PATH |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 270 | export TF_CUDA_VERSION |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 271 | break |
| 272 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 273 | echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found" |
| 274 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 275 | if [ -z "$fromuser" ]; then |
| 276 | exit 1 |
| 277 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 278 | # Retry |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 279 | TF_CUDA_VERSION="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 280 | CUDA_TOOLKIT_PATH="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 281 | done |
| 282 | |
Martin Wicke | 916776a | 2016-01-14 07:30:00 -0800 | [diff] [blame] | 283 | # Find out where the cuDNN library is installed |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 284 | while true; do |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 285 | # Configure the Cudnn version to use. |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 286 | if [ -z "$TF_CUDNN_VERSION" ]; then |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 287 | read -p "Please specify the Cudnn version you want to use. [Leave empty to use system default]: " TF_CUDNN_VERSION |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 288 | fi |
| 289 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 290 | fromuser="" |
| 291 | if [ -z "$CUDNN_INSTALL_PATH" ]; then |
| 292 | default_cudnn_path=${CUDA_TOOLKIT_PATH} |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 293 | 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 Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 294 | fromuser="1" |
| 295 | if [ -z "$CUDNN_INSTALL_PATH" ]; then |
| 296 | CUDNN_INSTALL_PATH=$default_cudnn_path |
| 297 | fi |
| 298 | # Result returned from "read" will be used unexpanded. That make "~" unuseable. |
| 299 | # Going through one more level of expansion to handle that. |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 300 | CUDNN_INSTALL_PATH=`"${PYTHON_BIN_PATH}" -c "import os; print(os.path.realpath(os.path.expanduser('${CUDNN_INSTALL_PATH}')))"` |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 301 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 302 | |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 303 | if [[ -z "$TF_CUDNN_VERSION" ]]; then |
| 304 | TF_CUDNN_EXT="" |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 305 | cudnn_lib_path="" |
| 306 | cudnn_alt_lib_path="" |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 307 | if is_windows; then |
| 308 | cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib" |
| 309 | cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib" |
| 310 | elif [ "$OSNAME" == "Linux" ]; then |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 311 | cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so" |
| 312 | cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so" |
| 313 | elif [ "$OSNAME" == "Darwin" ]; then |
| 314 | cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib" |
| 315 | cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib" |
| 316 | fi |
A. Unique TensorFlower | 533d891 | 2016-06-30 12:10:50 -0800 | [diff] [blame] | 317 | # Resolve to the SONAME of the symlink. Use readlink without -f |
| 318 | # to resolve exactly once to the SONAME. E.g, libcudnn.so -> |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 319 | # libcudnn.so.4. |
| 320 | # If the path is not a symlink, readlink will exit with an error code, so |
| 321 | # in that case, we return the path itself. |
| 322 | if [ -f "$cudnn_lib_path" ]; then |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 323 | REALVAL=`readlink "${cudnn_lib_path}" || echo "${cudnn_lib_path}"` |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 324 | else |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 325 | REALVAL=`readlink "${cudnn_alt_lib_path}" || echo "${cudnn_alt_lib_path}"` |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 326 | fi |
A. Unique TensorFlower | 533d891 | 2016-06-30 12:10:50 -0800 | [diff] [blame] | 327 | |
| 328 | # Extract the version of the SONAME, if it was indeed symlinked to |
| 329 | # the SONAME version of the file. |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 330 | if [[ "$REALVAL" =~ .so[.]+([0-9]*) ]]; then |
A. Unique TensorFlower | 533d891 | 2016-06-30 12:10:50 -0800 | [diff] [blame] | 331 | TF_CUDNN_EXT="."${BASH_REMATCH[1]} |
| 332 | TF_CUDNN_VERSION=${BASH_REMATCH[1]} |
| 333 | echo "libcudnn.so resolves to libcudnn${TF_CUDNN_EXT}" |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 334 | elif [[ "$REALVAL" =~ ([0-9]*).dylib ]]; then |
Jonathan Hseu | bed8383 | 2016-12-22 15:38:30 -0800 | [diff] [blame] | 335 | TF_CUDNN_EXT=${BASH_REMATCH[1]}".dylib" |
A. Unique TensorFlower | edaf3b3 | 2016-10-10 10:26:22 -0800 | [diff] [blame] | 336 | TF_CUDNN_VERSION=${BASH_REMATCH[1]} |
| 337 | echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}" |
A. Unique TensorFlower | 533d891 | 2016-06-30 12:10:50 -0800 | [diff] [blame] | 338 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 339 | else |
Shanqing Cai | efd40e5 | 2017-01-08 20:31:30 -0800 | [diff] [blame] | 340 | if [ "$OSNAME" == "Darwin" ]; then |
| 341 | TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib" |
| 342 | else |
| 343 | TF_CUDNN_EXT=".$TF_CUDNN_VERSION" |
| 344 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 345 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 346 | |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 347 | if is_windows; then |
| 348 | CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib" |
| 349 | CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib" |
| 350 | elif [ "$OSNAME" == "Linux" ]; then |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 351 | CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}" |
| 352 | CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}" |
| 353 | elif [ "$OSNAME" == "Darwin" ]; then |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 354 | CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}" |
| 355 | CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}" |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 356 | fi |
| 357 | |
| 358 | if [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_ALT_PATH}" -o -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_PATH}" ]; then |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 359 | export TF_CUDNN_VERSION |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 360 | export CUDNN_INSTALL_PATH |
Eugene Brevdo | 56f1d64 | 2016-03-10 17:18:30 -0800 | [diff] [blame] | 361 | break |
| 362 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 363 | |
| 364 | if [ "$OSNAME" == "Linux" ]; then |
| 365 | CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')" |
| 366 | if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 367 | export TF_CUDNN_VERSION |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 368 | export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})" |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 369 | break |
| 370 | fi |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 371 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 372 | echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:" |
| 373 | echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}" |
| 374 | echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}" |
| 375 | if [ "$OSNAME" == "Linux" ]; then |
| 376 | echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" |
| 377 | fi |
| 378 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 379 | if [ -z "$fromuser" ]; then |
| 380 | exit 1 |
| 381 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 382 | # Retry |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 383 | TF_CUDNN_VERSION="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 384 | CUDNN_INSTALL_PATH="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 385 | done |
| 386 | |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 387 | # Configure the compute capabilities that TensorFlow builds for. |
| 388 | # Since Cuda toolkit is not backward-compatible, this is not guaranteed to work. |
| 389 | while true; do |
| 390 | fromuser="" |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 391 | default_cuda_compute_capabilities="3.5,5.2" |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 392 | if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 393 | cat << EOF |
| 394 | Please specify a list of comma-separated Cuda compute capabilities you want to build with. |
| 395 | You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. |
| 396 | Please note that each additional compute capability significantly increases your build time and binary size. |
| 397 | EOF |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 398 | read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES |
| 399 | fromuser=1 |
| 400 | fi |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 401 | if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then |
| 402 | TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities |
| 403 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 404 | # Check whether all capabilities from the input is valid |
| 405 | COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ } |
| 406 | ALL_VALID=1 |
| 407 | for CAPABILITY in $COMPUTE_CAPABILITIES; do |
| 408 | if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then |
| 409 | echo "Invalid compute capability: " $CAPABILITY |
| 410 | ALL_VALID=0 |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 411 | break |
| 412 | fi |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 413 | done |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 414 | if [ "$ALL_VALID" == "0" ]; then |
| 415 | if [ -z "$fromuser" ]; then |
| 416 | exit 1 |
| 417 | fi |
| 418 | else |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 419 | export TF_CUDA_COMPUTE_CAPABILITIES |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 420 | break |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 421 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 422 | TF_CUDA_COMPUTE_CAPABILITIES="" |
| 423 | done |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 424 | |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 425 | if is_windows; then |
| 426 | # The following three variables are needed for MSVC toolchain configuration in Bazel |
| 427 | export CUDA_PATH="$CUDA_TOOLKIT_PATH" |
| 428 | export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES" |
| 429 | export NO_WHOLE_ARCHIVE_OPTION=1 |
| 430 | |
| 431 | # Set GCC_HOST_COMPILER_PATH to keep cuda_configure.bzl happy |
| 432 | export GCC_HOST_COMPILER_PATH="/usr/bin/dummy_compiler" |
| 433 | fi |
| 434 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 435 | # end of if "$TF_NEED_CUDA" == "1" |
| 436 | fi |
| 437 | |
| 438 | # OpenCL configuration |
| 439 | |
| 440 | if [ "$TF_NEED_OPENCL" == "1" ]; then |
| 441 | |
| 442 | # Determine which C++ compiler should be used as the host compiler |
| 443 | while true; do |
| 444 | fromuser="" |
| 445 | if [ -z "$HOST_CXX_COMPILER" ]; then |
Jonathan Hseu | bed8383 | 2016-12-22 15:38:30 -0800 | [diff] [blame] | 446 | default_cxx_host_compiler=$(which clang++-3.6 || true) |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 447 | read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER |
| 448 | fromuser="1" |
| 449 | if [ -z "$HOST_CXX_COMPILER" ]; then |
| 450 | HOST_CXX_COMPILER=$default_cxx_host_compiler |
| 451 | fi |
| 452 | fi |
| 453 | if [ -e "$HOST_CXX_COMPILER" ]; then |
| 454 | export HOST_CXX_COMPILER |
| 455 | break |
| 456 | fi |
| 457 | echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2 |
| 458 | if [ -z "$fromuser" ]; then |
| 459 | exit 1 |
| 460 | fi |
| 461 | HOST_CXX_COMPILER="" |
| 462 | # Retry |
| 463 | done |
| 464 | |
| 465 | # Determine which C compiler should be used as the host compiler |
| 466 | while true; do |
| 467 | fromuser="" |
| 468 | if [ -z "$HOST_C_COMPILER" ]; then |
Jonathan Hseu | bed8383 | 2016-12-22 15:38:30 -0800 | [diff] [blame] | 469 | default_c_host_compiler=$(which clang-3.6 || true) |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 470 | read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER |
| 471 | fromuser="1" |
| 472 | if [ -z "$HOST_C_COMPILER" ]; then |
| 473 | HOST_C_COMPILER=$default_c_host_compiler |
| 474 | fi |
| 475 | fi |
| 476 | if [ -e "$HOST_C_COMPILER" ]; then |
| 477 | export HOST_C_COMPILER |
| 478 | break |
| 479 | fi |
| 480 | echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2 |
| 481 | if [ -z "$fromuser" ]; then |
| 482 | exit 1 |
| 483 | fi |
| 484 | HOST_C_COMPILER="" |
| 485 | # Retry |
| 486 | done |
| 487 | |
| 488 | while true; do |
| 489 | # Configure the OPENCL version to use. |
| 490 | TF_OPENCL_VERSION="1.2" |
| 491 | |
| 492 | # Point to ComputeCpp root |
| 493 | if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then |
| 494 | default_computecpp_toolkit_path=/usr/local/computecpp |
Martin Wicke | 2e4869a | 2016-12-14 15:46:53 -0800 | [diff] [blame] | 495 | 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 Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 496 | fromuser="1" |
| 497 | if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then |
| 498 | COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path |
| 499 | fi |
| 500 | fi |
| 501 | |
| 502 | if [ "$OSNAME" == "Linux" ]; then |
| 503 | SYCL_RT_LIB_PATH="lib/libComputeCpp.so" |
| 504 | fi |
| 505 | |
| 506 | if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then |
| 507 | export COMPUTECPP_TOOLKIT_PATH |
| 508 | break |
| 509 | fi |
| 510 | echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found" |
| 511 | |
| 512 | if [ -z "$fromuser" ]; then |
| 513 | exit 1 |
| 514 | fi |
| 515 | # Retry |
| 516 | TF_OPENCL_VERSION="" |
| 517 | COMPUTECPP_TOOLKIT_PATH="" |
| 518 | done |
| 519 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 520 | # end of if "$TF_NEED_OPENCL" == "1" |
| 521 | fi |
| 522 | |
Jonathan Hseu | 1283b84 | 2016-09-29 15:05:32 -0800 | [diff] [blame] | 523 | bazel_clean_and_fetch |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 524 | |
| 525 | echo "Configuration finished" |