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 | |
A. Unique TensorFlower | abe0877 | 2017-06-07 11:34:47 -0700 | [diff] [blame] | 6 | MIN_BAZEL_VERSION=0.4.5 |
| 7 | |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 8 | # Find out the absolute path to where ./configure resides |
A. Unique TensorFlower | 46d2c28 | 2017-01-02 22:19:48 -0800 | [diff] [blame] | 9 | pushd `dirname $0` > /dev/null |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 10 | SOURCE_BASE_DIR=`pwd -P` |
| 11 | popd > /dev/null |
| 12 | |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 13 | PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 14 | |
| 15 | function is_linux() { |
| 16 | if [[ "${PLATFORM}" == "linux" ]]; then |
| 17 | true |
| 18 | else |
| 19 | false |
| 20 | fi |
| 21 | } |
| 22 | |
| 23 | function is_macos() { |
| 24 | if [[ "${PLATFORM}" == "darwin" ]]; then |
| 25 | true |
| 26 | else |
| 27 | false |
| 28 | fi |
| 29 | } |
| 30 | |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 31 | function is_windows() { |
| 32 | # On windows, the shell script is actually running in msys |
Shanqing Cai | 56fc883 | 2017-01-23 18:25:25 -0800 | [diff] [blame] | 33 | if [[ "${PLATFORM}" =~ msys_nt*|mingw*|cygwin*|uwin* ]]; then |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 34 | true |
| 35 | else |
| 36 | false |
| 37 | fi |
| 38 | } |
| 39 | |
Dan Ringwalt | 692fad2 | 2017-05-05 09:09:05 -0800 | [diff] [blame] | 40 | function sed_in_place() { |
| 41 | sed -e $1 $2 > "$2.bak" |
| 42 | mv "$2.bak" $2 |
Dandelion Mané | 0386a01 | 2017-03-10 14:43:23 -0800 | [diff] [blame] | 43 | } |
| 44 | |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 45 | function write_to_bazelrc() { |
| 46 | echo "$1" >> .tf_configure.bazelrc |
| 47 | } |
| 48 | |
| 49 | function write_action_env_to_bazelrc() { |
| 50 | write_to_bazelrc "build --action_env $1=\"$2\"" |
| 51 | } |
| 52 | |
A. Unique TensorFlower | 79789dd | 2017-04-27 04:47:01 -0800 | [diff] [blame] | 53 | function python_path { |
| 54 | "$PYTHON_BIN_PATH" - <<END |
| 55 | from __future__ import print_function |
| 56 | import site |
| 57 | import os |
| 58 | |
| 59 | try: |
| 60 | input = raw_input |
| 61 | except NameError: |
| 62 | pass |
| 63 | |
| 64 | python_paths = [] |
| 65 | if os.getenv('PYTHONPATH') is not None: |
| 66 | python_paths = os.getenv('PYTHONPATH').split(':') |
| 67 | try: |
| 68 | library_paths = site.getsitepackages() |
| 69 | except AttributeError: |
| 70 | from distutils.sysconfig import get_python_lib |
| 71 | library_paths = [get_python_lib()] |
| 72 | all_paths = set(python_paths + library_paths) |
| 73 | |
| 74 | paths = [] |
| 75 | for path in all_paths: |
| 76 | if os.path.isdir(path): |
| 77 | paths.append(path) |
| 78 | |
| 79 | print(",".join(paths)) |
| 80 | END |
| 81 | } |
| 82 | |
| 83 | function setup_python { |
| 84 | ## Set up python-related environment settings: |
| 85 | while true; do |
| 86 | fromuser="" |
| 87 | if [ -z "$PYTHON_BIN_PATH" ]; then |
| 88 | default_python_bin_path=$(which python || which python3 || true) |
| 89 | read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH |
| 90 | fromuser="1" |
| 91 | if [ -z "$PYTHON_BIN_PATH" ]; then |
| 92 | PYTHON_BIN_PATH=$default_python_bin_path |
| 93 | fi |
| 94 | fi |
| 95 | if [ -e "$PYTHON_BIN_PATH" ]; then |
| 96 | break |
| 97 | fi |
| 98 | echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2 |
| 99 | if [ -z "$fromuser" ]; then |
| 100 | exit 1 |
| 101 | fi |
| 102 | PYTHON_BIN_PATH="" |
| 103 | # Retry |
| 104 | done |
| 105 | |
| 106 | if [ -z "$PYTHON_LIB_PATH" ]; then |
| 107 | # Split python_path into an array of paths, this allows path containing spaces |
| 108 | IFS=',' |
| 109 | python_lib_path=($(python_path)) |
| 110 | unset IFS |
| 111 | |
| 112 | if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then |
| 113 | PYTHON_LIB_PATH=${python_lib_path[0]} |
| 114 | echo "Using python library path: $PYTHON_LIB_PATH" |
| 115 | |
| 116 | else |
| 117 | echo "Found possible Python library paths:" |
| 118 | for x in "${python_lib_path[@]}"; do |
| 119 | echo " $x" |
| 120 | done |
| 121 | set -- "${python_lib_path[@]}" |
| 122 | echo "Please input the desired Python library path to use. Default is ["$1"]" |
| 123 | read b || true |
| 124 | if [ "$b" == "" ]; then |
| 125 | PYTHON_LIB_PATH=${python_lib_path[0]} |
| 126 | echo "Using python library path: $PYTHON_LIB_PATH" |
| 127 | else |
| 128 | PYTHON_LIB_PATH="$b" |
| 129 | fi |
| 130 | fi |
| 131 | fi |
| 132 | |
| 133 | if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then |
| 134 | echo "PYTHON_BIN_PATH is not executable. Is it the python binary?" |
| 135 | exit 1 |
| 136 | fi |
| 137 | |
| 138 | local python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);') |
| 139 | if [ "$python_major_version" == "" ]; then |
| 140 | echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?" |
| 141 | exit 1 |
| 142 | fi |
| 143 | |
| 144 | # Convert python path to Windows style before writing into bazel.rc |
| 145 | if is_windows; then |
| 146 | PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")" |
| 147 | fi |
| 148 | |
| 149 | # Set-up env variables used by python_configure.bzl |
| 150 | write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH" |
| 151 | write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH" |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 152 | write_to_bazelrc "build --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" |
| 153 | write_to_bazelrc "build --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\"" |
A. Unique TensorFlower | 79789dd | 2017-04-27 04:47:01 -0800 | [diff] [blame] | 154 | write_to_bazelrc "build --force_python=py$python_major_version" |
| 155 | write_to_bazelrc "build --host_force_python=py$python_major_version" |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 156 | write_to_bazelrc "build --python${python_major_version}_path=\"$PYTHON_BIN_PATH\"" |
A. Unique TensorFlower | 79789dd | 2017-04-27 04:47:01 -0800 | [diff] [blame] | 157 | write_to_bazelrc "test --force_python=py$python_major_version" |
| 158 | write_to_bazelrc "test --host_force_python=py$python_major_version" |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 159 | write_to_bazelrc "test --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" |
| 160 | write_to_bazelrc "test --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\"" |
| 161 | write_to_bazelrc "run --define PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" |
| 162 | write_to_bazelrc "run --define PYTHON_LIB_PATH=\"$PYTHON_LIB_PATH\"" |
A. Unique TensorFlower | 79789dd | 2017-04-27 04:47:01 -0800 | [diff] [blame] | 163 | |
| 164 | # Write tools/python_bin_path.sh |
| 165 | echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh |
| 166 | } |
| 167 | |
A. Unique TensorFlower | abe0877 | 2017-06-07 11:34:47 -0700 | [diff] [blame] | 168 | function version { |
| 169 | echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | bazel version > bazel.version |
| 174 | curr_bazel_version=$(head -n 1 bazel.version | cut -d ' ' -f3) |
| 175 | rm -f bazel.version |
| 176 | |
| 177 | echo "You have bazel $curr_bazel_version installed." |
| 178 | if [ "$(version "$MIN_BAZEL_VERSION")" -gt "$(version "$curr_bazel_version")" ]; then |
| 179 | echo "Please upgrade your bazel installation to version $MIN_BAZEL_VERSION or higher to build TensorFlow!" |
| 180 | echo "Exiting..." |
| 181 | exit 1 |
| 182 | fi |
| 183 | |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 184 | # This file contains customized config settings. |
| 185 | rm -f .tf_configure.bazelrc |
| 186 | touch .tf_configure.bazelrc |
| 187 | touch .bazelrc |
Dan Ringwalt | 692fad2 | 2017-05-05 09:09:05 -0800 | [diff] [blame] | 188 | sed_in_place "/tf_configure/d" .bazelrc |
A. Unique TensorFlower | 8268476 | 2017-04-05 11:30:37 -0800 | [diff] [blame] | 189 | echo "import %workspace%/.tf_configure.bazelrc" >> .bazelrc |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 190 | |
Andrew Harp | 51dbc46 | 2017-01-27 14:42:30 -0800 | [diff] [blame] | 191 | # Delete any leftover BUILD files from the Makefile build, which would interfere |
| 192 | # with Bazel parsing. |
| 193 | MAKEFILE_DOWNLOAD_DIR=tensorflow/contrib/makefile/downloads |
| 194 | if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then |
| 195 | find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete |
| 196 | fi |
| 197 | |
A. Unique TensorFlower | 79789dd | 2017-04-27 04:47:01 -0800 | [diff] [blame] | 198 | setup_python |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 199 | |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 200 | ## Set up MKL related environment settings |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 201 | while [ "$TF_NEED_MKL" == "" ]; do |
| 202 | fromuser="" |
| 203 | read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT |
| 204 | fromuser="1" |
| 205 | case $INPUT in |
| 206 | [Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;; |
| 207 | [Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;; |
| 208 | "" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;; |
| 209 | * ) echo "Invalid selection: " $INPUT;; |
| 210 | esac |
| 211 | done |
| 212 | |
| 213 | OSNAME=`uname -s` |
| 214 | |
| 215 | if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL |
| 216 | while [ "$TF_DOWNLOAD_MKL" == "" ]; do |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 217 | fromuser="" |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 218 | read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 219 | fromuser="1" |
| 220 | case $INPUT in |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 221 | [Yy]* ) TF_DOWNLOAD_MKL=1;; |
| 222 | [Nn]* ) TF_DOWNLOAD_MKL=0;; |
| 223 | "" ) TF_DOWNLOAD_MKL=1;; |
| 224 | * ) echo "Invalid selection: " $INPUT; exit 1;; |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 225 | esac |
| 226 | done |
| 227 | |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 228 | if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 229 | DST=`dirname $0` |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 230 | ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz |
| 231 | GITHUB_RELEASE_TAG=v0.7 |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 232 | MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME" |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 233 | if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then |
| 234 | curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${MKLURL}" |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 235 | fi |
| 236 | tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/ |
| 237 | extracted_dir_name="${ARCHIVE_BASENAME%.*}" |
| 238 | MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name |
| 239 | MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"` |
| 240 | |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 241 | else |
| 242 | default_mkl_path=/opt/intel/mklml |
| 243 | fromuser="" |
| 244 | read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH |
| 245 | fromuser="1" |
| 246 | if [ -z "$MKL_INSTALL_PATH" ]; then |
| 247 | MKL_INSTALL_PATH=$default_mkl_path |
| 248 | fi |
| 249 | # Result returned from "read" will be used unexpanded. That make "~" unuseable. |
| 250 | # Going through one more level of expansion to handle that. |
| 251 | MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"` |
| 252 | fi |
| 253 | |
| 254 | if [ "$OSNAME" == "Linux" ]; then |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 255 | # Full MKL configuration |
| 256 | MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version? |
| 257 | MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION? |
| 258 | |
| 259 | # MKL-ML configuration |
| 260 | MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version? |
| 261 | MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION? |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 262 | elif [ "$OSNAME" == "Darwin" ]; then |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 263 | echo "Darwin is unsupported yet"; |
| 264 | exit 1 |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 265 | fi |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 266 | |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 267 | if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 268 | ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/ |
| 269 | ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/ |
| 270 | ln -sf $MKL_INSTALL_PATH/include third_party/mkl/ |
| 271 | ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 272 | loc=$(locate -e libdl.so.2 | sed -n 1p) |
| 273 | ln -sf $loc third_party/mkl/libdl.so.2 |
| 274 | elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then |
| 275 | ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/ |
| 276 | ln -sf $MKL_INSTALL_PATH/${MKL_RT_OMP_LIB_PATH} third_party/mkl/ |
| 277 | ln -sf $MKL_INSTALL_PATH/include third_party/mkl/ |
| 278 | ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include |
| 279 | loc=$(locate -e libdl.so.2 | sed -n 1p) |
| 280 | ln -sf $loc third_party/mkl/libdl.so.2 |
| 281 | else |
| 282 | echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} nor $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} exists"; |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 283 | exit 1 |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 284 | fi |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 285 | |
| 286 | cat > third_party/mkl/mkl.config <<EOF |
| 287 | # MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library |
| 288 | # files can be either in this directory, or under include/ and lib64/ |
| 289 | MKL_INSTALL_PATH=$MKL_INSTALL_PATH |
| 290 | EOF |
| 291 | |
Benoit Steiner | ee112cf | 2017-05-10 21:12:21 -0700 | [diff] [blame] | 292 | fi # TF_NEED_MKL |
| 293 | ## End MKL setup |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 294 | |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 295 | ## Set up architecture-dependent optimization flags. |
| 296 | if [ -z "$CC_OPT_FLAGS" ]; then |
| 297 | default_cc_opt_flags="-march=native" |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 298 | read -p "Please specify optimization flags to use during compilation when bazel option "\ |
| 299 | "\"--config=opt\" is specified [Default is $default_cc_opt_flags]: " CC_OPT_FLAGS |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 300 | if [ -z "$CC_OPT_FLAGS" ]; then |
| 301 | CC_OPT_FLAGS=$default_cc_opt_flags |
| 302 | fi |
| 303 | fi |
| 304 | |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 305 | if is_windows; then |
A. Unique TensorFlower | 95a954a | 2016-12-28 13:40:08 -0800 | [diff] [blame] | 306 | TF_NEED_GCP=0 |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 307 | TF_NEED_HDFS=0 |
Jonathan Hseu | 83c6e0c | 2017-01-11 16:39:35 -0800 | [diff] [blame] | 308 | TF_NEED_JEMALLOC=0 |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 309 | TF_NEED_OPENCL=0 |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 310 | TF_CUDA_CLANG=0 |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 311 | fi |
| 312 | |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 313 | if is_linux; then |
| 314 | while [ "$TF_NEED_JEMALLOC" == "" ]; do |
| 315 | read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\ |
| 316 | INPUT |
| 317 | case $INPUT in |
| 318 | [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;; |
| 319 | [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;; |
| 320 | "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;; |
| 321 | * ) echo "Invalid selection: " $INPUT;; |
| 322 | esac |
| 323 | done |
| 324 | else |
| 325 | TF_NEED_JEMALLOC=0 |
| 326 | fi |
Jonathan Hseu | 83c6e0c | 2017-01-11 16:39:35 -0800 | [diff] [blame] | 327 | |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 328 | if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 329 | write_to_bazelrc 'build --define with_jemalloc=true' |
Jonathan Hseu | 83c6e0c | 2017-01-11 16:39:35 -0800 | [diff] [blame] | 330 | fi |
| 331 | |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 332 | while [[ "$TF_NEED_GCP" == "" ]]; do |
A. Unique TensorFlower | 95a954a | 2016-12-28 13:40:08 -0800 | [diff] [blame] | 333 | read -p "Do you wish to build TensorFlow with "\ |
| 334 | "Google Cloud Platform support? [y/N] " INPUT |
| 335 | case $INPUT in |
| 336 | [Yy]* ) echo "Google Cloud Platform support will be enabled for "\ |
| 337 | "TensorFlow"; TF_NEED_GCP=1;; |
| 338 | [Nn]* ) echo "No Google Cloud Platform support will be enabled for "\ |
| 339 | "TensorFlow"; TF_NEED_GCP=0;; |
| 340 | "" ) echo "No Google Cloud Platform support will be enabled for "\ |
| 341 | "TensorFlow"; TF_NEED_GCP=0;; |
| 342 | * ) echo "Invalid selection: " $INPUT;; |
| 343 | esac |
| 344 | done |
| 345 | |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 346 | if [[ "$TF_NEED_GCP" == "1" ]]; then |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 347 | write_to_bazelrc 'build --define with_gcp_support=true' |
A. Unique TensorFlower | 95a954a | 2016-12-28 13:40:08 -0800 | [diff] [blame] | 348 | fi |
| 349 | |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 350 | while [[ "$TF_NEED_HDFS" == "" ]]; do |
Jonathan Hseu | 9f5b098 | 2016-09-19 11:14:58 -0800 | [diff] [blame] | 351 | read -p "Do you wish to build TensorFlow with "\ |
| 352 | "Hadoop File System support? [y/N] " INPUT |
| 353 | case $INPUT in |
| 354 | [Yy]* ) echo "Hadoop File System support will be enabled for "\ |
| 355 | "TensorFlow"; TF_NEED_HDFS=1;; |
| 356 | [Nn]* ) echo "No Hadoop File System support will be enabled for "\ |
| 357 | "TensorFlow"; TF_NEED_HDFS=0;; |
| 358 | "" ) echo "No Hadoop File System support will be enabled for "\ |
| 359 | "TensorFlow"; TF_NEED_HDFS=0;; |
| 360 | * ) echo "Invalid selection: " $INPUT;; |
| 361 | esac |
| 362 | done |
| 363 | |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 364 | if [[ "$TF_NEED_HDFS" == "1" ]]; then |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 365 | write_to_bazelrc 'build --define with_hdfs_support=true' |
Jonathan Hseu | 9f5b098 | 2016-09-19 11:14:58 -0800 | [diff] [blame] | 366 | fi |
| 367 | |
Peter Hawkins | 1e67c90 | 2017-01-09 12:04:37 -0800 | [diff] [blame] | 368 | ## Enable XLA. |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 369 | while [[ "$TF_ENABLE_XLA" == "" ]]; do |
Peter Hawkins | 1e67c90 | 2017-01-09 12:04:37 -0800 | [diff] [blame] | 370 | read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT |
| 371 | case $INPUT in |
| 372 | [Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;; |
| 373 | [Nn]* ) echo "No XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;; |
| 374 | "" ) echo "No XLA support will be enabled for TensorFlow"; TF_ENABLE_XLA=0;; |
| 375 | * ) echo "Invalid selection: " $INPUT;; |
| 376 | esac |
| 377 | done |
| 378 | |
Martin Wicke | bc456e3 | 2017-03-23 12:31:16 -0800 | [diff] [blame] | 379 | if [[ "$TF_ENABLE_XLA" == "1" ]]; then |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 380 | write_to_bazelrc 'build --define with_xla_support=true' |
Peter Hawkins | 1e67c90 | 2017-01-09 12:04:37 -0800 | [diff] [blame] | 381 | fi |
| 382 | |
Shanqing Cai | 3269423 | 2017-04-22 06:08:17 -0800 | [diff] [blame] | 383 | # Verbs configuration |
| 384 | while [ "$TF_NEED_VERBS" == "" ]; do |
| 385 | read -p "Do you wish to build TensorFlow with "\ |
| 386 | "VERBS support? [y/N] " INPUT |
| 387 | case $INPUT in |
| 388 | [Yy]* ) echo "VERBS support will be enabled for "\ |
| 389 | "TensorFlow"; TF_NEED_VERBS=1;; |
| 390 | [Nn]* ) echo "No VERBS support will be enabled for "\ |
| 391 | "TensorFlow"; TF_NEED_VERBS=0;; |
| 392 | "" ) echo "No VERBS support will be enabled for "\ |
| 393 | "TensorFlow"; TF_NEED_VERBS=0;; |
| 394 | * ) echo "Invalid selection: " $INPUT;; |
| 395 | esac |
| 396 | done |
| 397 | |
| 398 | if [[ "$TF_NEED_VERBS" == "1" ]]; then |
| 399 | write_to_bazelrc 'build --define with_verbs_support=true' |
| 400 | fi |
Peter Hawkins | 1e67c90 | 2017-01-09 12:04:37 -0800 | [diff] [blame] | 401 | |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 402 | # Append CC optimization flags to bazel.rc |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 403 | for opt in $CC_OPT_FLAGS; do |
Patrick Nguyen | 3bee923 | 2017-05-04 08:48:51 -0800 | [diff] [blame] | 404 | write_to_bazelrc "build:opt --cxxopt=$opt --copt=$opt" |
Martin Wicke | c4e3d4a | 2017-01-13 12:20:42 -0800 | [diff] [blame] | 405 | done |
| 406 | |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 407 | # Run the gen_git_source to create links where bazel can track dependencies for |
| 408 | # git hash propagation |
| 409 | GEN_GIT_SOURCE=tensorflow/tools/git/gen_git_source.py |
| 410 | chmod a+x ${GEN_GIT_SOURCE} |
Patrick Nguyen | c5ab3dd | 2016-10-20 12:09:18 -0800 | [diff] [blame] | 411 | "${PYTHON_BIN_PATH}" ${GEN_GIT_SOURCE} --configure "${SOURCE_BASE_DIR}" |
Andrew Selle | 09045e4 | 2016-09-06 08:19:04 -0800 | [diff] [blame] | 412 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 413 | ## Set up SYCL-related environment settings |
| 414 | while [ "$TF_NEED_OPENCL" == "" ]; do |
| 415 | read -p "Do you wish to build TensorFlow with OpenCL support? [y/N] " INPUT |
| 416 | case $INPUT in |
| 417 | [Yy]* ) echo "OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=1;; |
| 418 | [Nn]* ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;; |
| 419 | "" ) echo "No OpenCL support will be enabled for TensorFlow"; TF_NEED_OPENCL=0;; |
| 420 | * ) echo "Invalid selection: " $INPUT;; |
| 421 | esac |
| 422 | done |
| 423 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 424 | ## Set up Cuda-related environment settings |
| 425 | |
| 426 | while [ "$TF_NEED_CUDA" == "" ]; do |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 427 | 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] | 428 | case $INPUT in |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 429 | [Yy]* ) echo "CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=1;; |
| 430 | [Nn]* ) echo "No CUDA support will be enabled for TensorFlow"; TF_NEED_CUDA=0;; |
| 431 | "" ) 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] | 432 | * ) echo "Invalid selection: " $INPUT;; |
| 433 | esac |
| 434 | done |
| 435 | |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 436 | export TF_NEED_CUDA |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 437 | write_action_env_to_bazelrc "TF_NEED_CUDA" "$TF_NEED_CUDA" |
A. Unique TensorFlower | 8d393ea | 2017-03-30 07:38:55 -0800 | [diff] [blame] | 438 | |
Rohan Jain | aab0997 | 2017-01-05 14:39:17 -0800 | [diff] [blame] | 439 | export TF_NEED_OPENCL |
A. Unique TensorFlower | 8268476 | 2017-04-05 11:30:37 -0800 | [diff] [blame] | 440 | write_action_env_to_bazelrc "TF_NEED_OPENCL" "$TF_NEED_OPENCL" |
A. Unique TensorFlower | 8d393ea | 2017-03-30 07:38:55 -0800 | [diff] [blame] | 441 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 442 | if [ "$TF_NEED_CUDA" == "1" ]; then |
A. Unique TensorFlower | 8d393ea | 2017-03-30 07:38:55 -0800 | [diff] [blame] | 443 | while [[ "$TF_CUDA_CLANG" == "" ]]; do |
| 444 | read -p "Do you want to use clang as CUDA compiler? [y/N] " INPUT |
| 445 | case $INPUT in |
| 446 | [Yy]* ) echo "Clang will be used as CUDA compiler"; TF_CUDA_CLANG=1;; |
| 447 | [Nn]* ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;; |
| 448 | "" ) echo "nvcc will be used as CUDA compiler"; TF_CUDA_CLANG=0;; |
| 449 | * ) echo "Invalid selection: " $INPUT;; |
| 450 | esac |
| 451 | done |
| 452 | |
| 453 | export TF_CUDA_CLANG |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 454 | write_action_env_to_bazelrc "TF_CUDA_CLANG" "$TF_CUDA_CLANG" |
A. Unique TensorFlower | 8d393ea | 2017-03-30 07:38:55 -0800 | [diff] [blame] | 455 | |
A. Unique TensorFlower | 8d393ea | 2017-03-30 07:38:55 -0800 | [diff] [blame] | 456 | # Set up which clang we should use as the cuda / host compiler. |
| 457 | while [[ "$TF_CUDA_CLANG" == "1" ]] && true; do |
| 458 | fromuser="" |
| 459 | if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then |
| 460 | default_clang_host_compiler_path=$(which clang || true) |
| 461 | read -p "Please specify which clang should be used as device and host compiler. [Default is $default_clang_host_compiler_path]: " CLANG_CUDA_COMPILER_PATH |
| 462 | fromuser="1" |
| 463 | if [ -z "$CLANG_CUDA_COMPILER_PATH" ]; then |
| 464 | CLANG_CUDA_COMPILER_PATH="$default_clang_host_compiler_path" |
| 465 | fi |
| 466 | fi |
| 467 | if [ -e "$CLANG_CUDA_COMPILER_PATH" ]; then |
| 468 | export CLANG_CUDA_COMPILER_PATH |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 469 | write_action_env_to_bazelrc "CLANG_CUDA_COMPILER_PATH" "$CLANG_CUDA_COMPILER_PATH" |
A. Unique TensorFlower | 8d393ea | 2017-03-30 07:38:55 -0800 | [diff] [blame] | 470 | break |
| 471 | fi |
| 472 | echo "Invalid clang path. ${CLANG_CUDA_COMPILER_PATH} cannot be found" 1>&2 |
| 473 | if [ -z "$fromuser" ]; then |
| 474 | exit 1 |
| 475 | fi |
| 476 | CLANG_CUDA_COMPILER_PATH="" |
| 477 | # Retry |
| 478 | done |
| 479 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 480 | # Find out where the CUDA toolkit is installed |
| 481 | while true; do |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 482 | # Configure the Cuda SDK version to use. |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 483 | if [ -z "$TF_CUDA_VERSION" ]; then |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 484 | 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] | 485 | fi |
| 486 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 487 | fromuser="" |
| 488 | if [ -z "$CUDA_TOOLKIT_PATH" ]; then |
| 489 | default_cuda_path=/usr/local/cuda |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 490 | if is_windows; then |
| 491 | if [ -z "$CUDA_PATH" ]; then |
| 492 | default_cuda_path="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0" |
| 493 | else |
| 494 | default_cuda_path="$(cygpath -m "$CUDA_PATH")" |
| 495 | fi |
Dan Ringwalt | 692fad2 | 2017-05-05 09:09:05 -0800 | [diff] [blame] | 496 | elif is_linux; then |
| 497 | # If the default doesn't exist, try an alternative default. |
| 498 | if [ ! -d $default_cuda_path ] && [ -d /opt/cuda ]; then |
| 499 | default_cuda_path=/opt/cuda |
| 500 | fi |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 501 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 502 | 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] | 503 | fromuser="1" |
| 504 | if [ -z "$CUDA_TOOLKIT_PATH" ]; then |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 505 | CUDA_TOOLKIT_PATH="$default_cuda_path" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 506 | fi |
| 507 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 508 | |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 509 | if [[ -z "$TF_CUDA_VERSION" ]]; then |
| 510 | TF_CUDA_EXT="" |
| 511 | else |
| 512 | TF_CUDA_EXT=".$TF_CUDA_VERSION" |
| 513 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 514 | |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 515 | if is_windows; then |
| 516 | CUDA_RT_LIB_PATH="lib/x64/cudart.lib" |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 517 | elif is_linux; then |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 518 | CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}" |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 519 | elif is_macos; then |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 520 | CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib" |
| 521 | fi |
| 522 | |
| 523 | if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 524 | export CUDA_TOOLKIT_PATH |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 525 | write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "$CUDA_TOOLKIT_PATH" |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 526 | export TF_CUDA_VERSION |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 527 | write_action_env_to_bazelrc "TF_CUDA_VERSION" "$TF_CUDA_VERSION" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 528 | break |
| 529 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 530 | echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found" |
| 531 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 532 | if [ -z "$fromuser" ]; then |
| 533 | exit 1 |
| 534 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 535 | # Retry |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 536 | TF_CUDA_VERSION="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 537 | CUDA_TOOLKIT_PATH="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 538 | done |
| 539 | |
Dan Ringwalt | 692fad2 | 2017-05-05 09:09:05 -0800 | [diff] [blame] | 540 | # Set up which gcc nvcc should use as the host compiler |
| 541 | # No need to set this on Windows |
| 542 | while [[ "$TF_CUDA_CLANG" != "1" ]] && ! is_windows && true; do |
| 543 | fromuser="" |
| 544 | if [ -z "$GCC_HOST_COMPILER_PATH" ]; then |
| 545 | default_gcc_host_compiler_path=$(which gcc || true) |
| 546 | cuda_bin_symlink="$CUDA_TOOLKIT_PATH/bin/gcc" |
| 547 | if [ -L "$cuda_bin_symlink" ]; then |
| 548 | default_gcc_host_compiler_path=$(readlink $cuda_bin_symlink) |
| 549 | fi |
| 550 | 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 |
| 551 | fromuser="1" |
| 552 | if [ -z "$GCC_HOST_COMPILER_PATH" ]; then |
| 553 | GCC_HOST_COMPILER_PATH="$default_gcc_host_compiler_path" |
| 554 | fi |
| 555 | fi |
| 556 | if [ -e "$GCC_HOST_COMPILER_PATH" ]; then |
| 557 | export GCC_HOST_COMPILER_PATH |
| 558 | write_action_env_to_bazelrc "GCC_HOST_COMPILER_PATH" "$GCC_HOST_COMPILER_PATH" |
| 559 | break |
| 560 | fi |
| 561 | echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2 |
| 562 | if [ -z "$fromuser" ]; then |
| 563 | exit 1 |
| 564 | fi |
| 565 | GCC_HOST_COMPILER_PATH="" |
| 566 | # Retry |
| 567 | done |
| 568 | |
Martin Wicke | 916776a | 2016-01-14 07:30:00 -0800 | [diff] [blame] | 569 | # Find out where the cuDNN library is installed |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 570 | while true; do |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 571 | # Configure the cuDNN version to use. |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 572 | if [ -z "$TF_CUDNN_VERSION" ]; then |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 573 | 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] | 574 | fi |
| 575 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 576 | fromuser="" |
| 577 | if [ -z "$CUDNN_INSTALL_PATH" ]; then |
| 578 | default_cudnn_path=${CUDA_TOOLKIT_PATH} |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 579 | 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] | 580 | fromuser="1" |
| 581 | if [ -z "$CUDNN_INSTALL_PATH" ]; then |
| 582 | CUDNN_INSTALL_PATH=$default_cudnn_path |
| 583 | fi |
| 584 | # Result returned from "read" will be used unexpanded. That make "~" unuseable. |
| 585 | # Going through one more level of expansion to handle that. |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 586 | 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] | 587 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 588 | |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 589 | if [[ -z "$TF_CUDNN_VERSION" ]]; then |
| 590 | TF_CUDNN_EXT="" |
| 591 | else |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 592 | TF_CUDNN_EXT=".$TF_CUDNN_VERSION" |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 593 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 594 | |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 595 | if is_windows; then |
| 596 | CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib" |
| 597 | CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib" |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 598 | elif is_linux; then |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 599 | CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}" |
| 600 | CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}" |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 601 | elif is_macos; then |
Benoit Steiner | 639b4e7 | 2017-02-08 09:25:09 -0800 | [diff] [blame] | 602 | CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}.dylib" |
| 603 | CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}.dylib" |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 604 | fi |
| 605 | |
| 606 | 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] | 607 | export TF_CUDNN_VERSION |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 608 | write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION" |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 609 | export CUDNN_INSTALL_PATH |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 610 | write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH" |
Eugene Brevdo | 56f1d64 | 2016-03-10 17:18:30 -0800 | [diff] [blame] | 611 | break |
| 612 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 613 | |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 614 | if is_linux; then |
Vijay Vasudevan | 93a975e | 2017-02-17 17:05:49 -0800 | [diff] [blame] | 615 | if ! type ldconfig > /dev/null 2>&1; then |
| 616 | LDCONFIG_BIN=/sbin/ldconfig |
| 617 | else |
| 618 | LDCONFIG_BIN=ldconfig |
| 619 | fi |
| 620 | CUDNN_PATH_FROM_LDCONFIG="$($LDCONFIG_BIN -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')" |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 621 | if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 622 | export TF_CUDNN_VERSION |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 623 | write_action_env_to_bazelrc "TF_CUDNN_VERSION" "$TF_CUDNN_VERSION" |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 624 | export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})" |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 625 | write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "$CUDNN_INSTALL_PATH" |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 626 | break |
| 627 | fi |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 628 | fi |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 629 | echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:" |
| 630 | echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}" |
| 631 | echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}" |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 632 | if is_linux; then |
A. Unique TensorFlower | 8bf6ef1 | 2016-05-05 08:36:05 -0800 | [diff] [blame] | 633 | echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" |
| 634 | fi |
| 635 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 636 | if [ -z "$fromuser" ]; then |
| 637 | exit 1 |
| 638 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 639 | # Retry |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 640 | TF_CUDNN_VERSION="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 641 | CUDNN_INSTALL_PATH="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 642 | done |
| 643 | |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 644 | # Configure the compute capabilities that TensorFlow builds for. |
| 645 | # Since Cuda toolkit is not backward-compatible, this is not guaranteed to work. |
| 646 | while true; do |
| 647 | fromuser="" |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 648 | default_cuda_compute_capabilities="3.5,5.2" |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 649 | if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 650 | cat << EOF |
| 651 | Please specify a list of comma-separated Cuda compute capabilities you want to build with. |
| 652 | You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. |
| 653 | Please note that each additional compute capability significantly increases your build time and binary size. |
| 654 | EOF |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 655 | read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES |
| 656 | fromuser=1 |
| 657 | fi |
A. Unique TensorFlower | 2c598e8 | 2016-08-25 10:22:44 -0800 | [diff] [blame] | 658 | if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then |
| 659 | TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities |
| 660 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 661 | # Check whether all capabilities from the input is valid |
| 662 | COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ } |
| 663 | ALL_VALID=1 |
| 664 | for CAPABILITY in $COMPUTE_CAPABILITIES; do |
| 665 | if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then |
| 666 | echo "Invalid compute capability: " $CAPABILITY |
| 667 | ALL_VALID=0 |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 668 | break |
| 669 | fi |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 670 | done |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 671 | if [ "$ALL_VALID" == "0" ]; then |
| 672 | if [ -z "$fromuser" ]; then |
| 673 | exit 1 |
| 674 | fi |
| 675 | else |
A. Unique TensorFlower | b0bdff4 | 2016-08-26 12:50:48 -0800 | [diff] [blame] | 676 | export TF_CUDA_COMPUTE_CAPABILITIES |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 677 | write_action_env_to_bazelrc "TF_CUDA_COMPUTE_CAPABILITIES" "$TF_CUDA_COMPUTE_CAPABILITIES" |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 678 | break |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 679 | fi |
Vijay Vasudevan | fe056f0 | 2016-02-17 11:42:30 -0800 | [diff] [blame] | 680 | TF_CUDA_COMPUTE_CAPABILITIES="" |
| 681 | done |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 682 | |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 683 | if is_windows; then |
| 684 | # The following three variables are needed for MSVC toolchain configuration in Bazel |
| 685 | export CUDA_PATH="$CUDA_TOOLKIT_PATH" |
| 686 | export CUDA_COMPUTE_CAPABILITIES="$TF_CUDA_COMPUTE_CAPABILITIES" |
| 687 | export NO_WHOLE_ARCHIVE_OPTION=1 |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 688 | write_action_env_to_bazelrc "CUDA_PATH" "$CUDA_PATH" |
| 689 | write_action_env_to_bazelrc "CUDA_COMPUTE_CAPABILITIES" "$CUDA_COMPUTE_CAPABILITIES" |
| 690 | write_action_env_to_bazelrc "NO_WHOLE_ARCHIVE_OPTION" "1" |
Gunhan Gulsoy | 3cf88d3 | 2017-06-06 22:34:30 -0700 | [diff] [blame] | 691 | write_to_bazelrc "build --config=win-cuda" |
| 692 | write_to_bazelrc "test --config=win-cuda" |
| 693 | else |
| 694 | # If CUDA is enabled, always use GPU during build and test. |
| 695 | write_to_bazelrc "build --config=cuda" |
| 696 | write_to_bazelrc "test --config=cuda" |
Andrew Harp | 1cb9689 | 2016-12-08 20:05:49 -0800 | [diff] [blame] | 697 | fi |
| 698 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 699 | # end of if "$TF_NEED_CUDA" == "1" |
| 700 | fi |
| 701 | |
| 702 | # OpenCL configuration |
| 703 | |
| 704 | if [ "$TF_NEED_OPENCL" == "1" ]; then |
| 705 | |
| 706 | # Determine which C++ compiler should be used as the host compiler |
| 707 | while true; do |
| 708 | fromuser="" |
| 709 | if [ -z "$HOST_CXX_COMPILER" ]; then |
Jonathan Hseu | bed8383 | 2016-12-22 15:38:30 -0800 | [diff] [blame] | 710 | default_cxx_host_compiler=$(which clang++-3.6 || true) |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 711 | read -p "Please specify which C++ compiler should be used as the host C++ compiler. [Default is $default_cxx_host_compiler]: " HOST_CXX_COMPILER |
| 712 | fromuser="1" |
| 713 | if [ -z "$HOST_CXX_COMPILER" ]; then |
| 714 | HOST_CXX_COMPILER=$default_cxx_host_compiler |
| 715 | fi |
| 716 | fi |
| 717 | if [ -e "$HOST_CXX_COMPILER" ]; then |
| 718 | export HOST_CXX_COMPILER |
A. Unique TensorFlower | 8268476 | 2017-04-05 11:30:37 -0800 | [diff] [blame] | 719 | write_action_env_to_bazelrc "HOST_CXX_COMPILER" "$HOST_CXX_COMPILER" |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 720 | break |
| 721 | fi |
| 722 | echo "Invalid C++ compiler path. ${HOST_CXX_COMPILER} cannot be found" 1>&2 |
| 723 | if [ -z "$fromuser" ]; then |
| 724 | exit 1 |
| 725 | fi |
| 726 | HOST_CXX_COMPILER="" |
| 727 | # Retry |
| 728 | done |
| 729 | |
| 730 | # Determine which C compiler should be used as the host compiler |
| 731 | while true; do |
| 732 | fromuser="" |
| 733 | if [ -z "$HOST_C_COMPILER" ]; then |
Jonathan Hseu | bed8383 | 2016-12-22 15:38:30 -0800 | [diff] [blame] | 734 | default_c_host_compiler=$(which clang-3.6 || true) |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 735 | read -p "Please specify which C compiler should be used as the host C compiler. [Default is $default_c_host_compiler]: " HOST_C_COMPILER |
| 736 | fromuser="1" |
| 737 | if [ -z "$HOST_C_COMPILER" ]; then |
| 738 | HOST_C_COMPILER=$default_c_host_compiler |
| 739 | fi |
| 740 | fi |
| 741 | if [ -e "$HOST_C_COMPILER" ]; then |
| 742 | export HOST_C_COMPILER |
A. Unique TensorFlower | 8268476 | 2017-04-05 11:30:37 -0800 | [diff] [blame] | 743 | write_action_env_to_bazelrc "HOST_C_COMPILER" "$HOST_C_COMPILER" |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 744 | break |
| 745 | fi |
| 746 | echo "Invalid C compiler path. ${HOST_C_COMPILER} cannot be found" 1>&2 |
| 747 | if [ -z "$fromuser" ]; then |
| 748 | exit 1 |
| 749 | fi |
| 750 | HOST_C_COMPILER="" |
| 751 | # Retry |
| 752 | done |
| 753 | |
| 754 | while true; do |
| 755 | # Configure the OPENCL version to use. |
| 756 | TF_OPENCL_VERSION="1.2" |
| 757 | |
| 758 | # Point to ComputeCpp root |
| 759 | if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then |
| 760 | default_computecpp_toolkit_path=/usr/local/computecpp |
Martin Wicke | 2e4869a | 2016-12-14 15:46:53 -0800 | [diff] [blame] | 761 | 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] | 762 | fromuser="1" |
| 763 | if [ -z "$COMPUTECPP_TOOLKIT_PATH" ]; then |
| 764 | COMPUTECPP_TOOLKIT_PATH=$default_computecpp_toolkit_path |
| 765 | fi |
| 766 | fi |
| 767 | |
Jonathan Hseu | c058a01 | 2017-01-17 15:06:43 -0800 | [diff] [blame] | 768 | if is_linux; then |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 769 | SYCL_RT_LIB_PATH="lib/libComputeCpp.so" |
| 770 | fi |
| 771 | |
| 772 | if [ -e "${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH}" ]; then |
| 773 | export COMPUTECPP_TOOLKIT_PATH |
A. Unique TensorFlower | 8268476 | 2017-04-05 11:30:37 -0800 | [diff] [blame] | 774 | write_action_env_to_bazelrc "COMPUTECPP_TOOLKIT_PATH" "$COMPUTECPP_TOOLKIT_PATH" |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 775 | break |
| 776 | fi |
| 777 | echo "Invalid SYCL $TF_OPENCL_VERSION library path. ${COMPUTECPP_TOOLKIT_PATH}/${SYCL_RT_LIB_PATH} cannot be found" |
| 778 | |
| 779 | if [ -z "$fromuser" ]; then |
| 780 | exit 1 |
| 781 | fi |
| 782 | # Retry |
| 783 | TF_OPENCL_VERSION="" |
| 784 | COMPUTECPP_TOOLKIT_PATH="" |
| 785 | done |
| 786 | |
Benoit Steiner | a771598 | 2016-11-09 13:14:03 -0800 | [diff] [blame] | 787 | # end of if "$TF_NEED_OPENCL" == "1" |
| 788 | fi |
| 789 | |
A. Unique TensorFlower | ccbc899 | 2017-04-04 16:10:08 -0800 | [diff] [blame] | 790 | # TODO(gunan): Remove once bazel correctly handles changes in remote repositories. |
| 791 | bazel clean |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 792 | echo "Configuration finished" |