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