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