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