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