Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 3 | if [ "$TF_UNOFFICIAL_SETTING" == "1" ]; then |
| 4 | echo -e "\nWARNING: You are configuring unofficial settings in TensorFlow. Because some external libraries are not backward compatible, these settings are largely untested and unsupported. \n" 1>&2 |
| 5 | fi |
| 6 | |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 7 | ## Set up python-related environment settings |
| 8 | while true; do |
| 9 | fromuser="" |
| 10 | if [ -z "$PYTHON_BIN_PATH" ]; then |
| 11 | default_python_bin_path=$(which python) |
| 12 | read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH |
| 13 | fromuser="1" |
| 14 | if [ -z "$PYTHON_BIN_PATH" ]; then |
| 15 | PYTHON_BIN_PATH=$default_python_bin_path |
| 16 | fi |
| 17 | fi |
| 18 | if [ -e "$PYTHON_BIN_PATH" ]; then |
| 19 | break |
| 20 | fi |
| 21 | echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2 |
| 22 | if [ -z "$fromuser" ]; then |
| 23 | exit 1 |
| 24 | fi |
| 25 | PYTHON_BIN_PATH="" |
| 26 | # Retry |
| 27 | done |
| 28 | |
| 29 | # Invoke python_config and set up symlinks to python includes |
| 30 | (./util/python/python_config.sh --setup "$PYTHON_BIN_PATH";) || exit -1 |
| 31 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 32 | ## Set up Cuda-related environment settings |
| 33 | |
| 34 | while [ "$TF_NEED_CUDA" == "" ]; do |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 35 | read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 36 | case $INPUT in |
Vijay Vasudevan | bf6b536 | 2015-12-02 15:04:40 -0800 | [diff] [blame] | 37 | [Yy]* ) echo "GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=1;; |
| 38 | [Nn]* ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;; |
| 39 | "" ) echo "No GPU support will be enabled for TensorFlow"; TF_NEED_CUDA=0;; |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 40 | * ) echo "Invalid selection: " $INPUT;; |
| 41 | esac |
| 42 | done |
| 43 | |
| 44 | if [ "$TF_NEED_CUDA" == "0" ]; then |
| 45 | echo "Configuration finished" |
| 46 | exit |
| 47 | fi |
| 48 | |
| 49 | # Find out where the CUDA toolkit is installed |
| 50 | while true; do |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 51 | # Configure the Cuda SDK version to use. |
| 52 | default_cuda_version="7.0" |
| 53 | if [ "$TF_UNOFFICIAL_SETTING" == "1" ]; then |
| 54 | if [ -z "$TF_CUDA_VERSION" ]; then |
| 55 | read -p "Please specify the Cuda SDK version you want to use. [Default is $default_cuda_version]: " TF_CUDA_VERSION |
| 56 | fi |
| 57 | fi |
| 58 | if [ -z "$TF_CUDA_VERSION" ]; then |
| 59 | TF_CUDA_VERSION=$default_cuda_version |
| 60 | fi |
| 61 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 62 | fromuser="" |
| 63 | if [ -z "$CUDA_TOOLKIT_PATH" ]; then |
| 64 | default_cuda_path=/usr/local/cuda |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 65 | 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] | 66 | fromuser="1" |
| 67 | if [ -z "$CUDA_TOOLKIT_PATH" ]; then |
| 68 | CUDA_TOOLKIT_PATH=$default_cuda_path |
| 69 | fi |
| 70 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 71 | if [ -e "$CUDA_TOOLKIT_PATH/lib64/libcudart.so.$TF_CUDA_VERSION" ]; then |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 72 | break |
| 73 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 74 | echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/lib64/libcudart.so.$TF_CUDA_VERSION cannot be found" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 75 | if [ -z "$fromuser" ]; then |
| 76 | exit 1 |
| 77 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 78 | TF_CUDA_VERSION="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 79 | CUDA_TOOLKIT_PATH="" |
| 80 | # Retry |
| 81 | done |
| 82 | |
Martin Wicke | 916776a | 2016-01-14 07:30:00 -0800 | [diff] [blame] | 83 | # Find out where the cuDNN library is installed |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 84 | while true; do |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 85 | # Configure the Cudnn version to use. |
| 86 | default_cudnn_version="6.5" |
| 87 | if [ "$TF_UNOFFICIAL_SETTING" == "1" ]; then |
| 88 | if [ -z "$TF_CUDNN_VERSION" ]; then |
| 89 | read -p "Please specify the Cudnn version you want to use. [Default is $default_cudnn_version]: " TF_CUDNN_VERSION |
| 90 | fi |
| 91 | fi |
| 92 | if [ -z "$TF_CUDNN_VERSION" ]; then |
| 93 | TF_CUDNN_VERSION=$default_cudnn_version |
| 94 | fi |
| 95 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 96 | fromuser="" |
| 97 | if [ -z "$CUDNN_INSTALL_PATH" ]; then |
| 98 | default_cudnn_path=${CUDA_TOOLKIT_PATH} |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 99 | 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] | 100 | fromuser="1" |
| 101 | if [ -z "$CUDNN_INSTALL_PATH" ]; then |
| 102 | CUDNN_INSTALL_PATH=$default_cudnn_path |
| 103 | fi |
| 104 | # Result returned from "read" will be used unexpanded. That make "~" unuseable. |
| 105 | # Going through one more level of expansion to handle that. |
| 106 | CUDNN_INSTALL_PATH=$(bash -c "readlink -f $CUDNN_INSTALL_PATH") |
| 107 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 108 | if [ -e "$CUDNN_INSTALL_PATH/libcudnn.so.${TF_CUDNN_VERSION}" -o -e "$CUDNN_INSTALL_PATH/lib64/libcudnn.so.${TF_CUDNN_VERSION}" ]; then |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 109 | break |
| 110 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 111 | echo "Invalid path to cuDNN ${TF_CUDNN_VERSION} toolkit. Neither of the following two files can be found:" |
| 112 | echo "$CUDNN_INSTALL_PATH/lib64/libcudnn.so.${TF_CUDNN_VERSION}" |
| 113 | echo "$CUDNN_INSTALL_PATH/libcudnn.so.${TF_CUDNN_VERSION}" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 114 | if [ -z "$fromuser" ]; then |
| 115 | exit 1 |
| 116 | fi |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 117 | TF_CUDNN_VERSION="" |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 118 | CUDNN_INSTALL_PATH="" |
| 119 | # Retry |
| 120 | done |
| 121 | |
| 122 | cat > third_party/gpus/cuda/cuda.config <<EOF |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 123 | # CUDA_TOOLKIT_PATH refers to the CUDA toolkit. Tensorflow requires Cuda $TF_CUDA_VERSION |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 124 | # at the moment. |
| 125 | CUDA_TOOLKIT_PATH="$CUDA_TOOLKIT_PATH" |
| 126 | |
Martin Wicke | 916776a | 2016-01-14 07:30:00 -0800 | [diff] [blame] | 127 | # CUDNN_INSTALL_PATH refers to the cuDNN toolkit. The cuDNN header and library |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 128 | # files can be either in this directory, or under include/ and lib64/ |
| 129 | # directories separately. |
| 130 | CUDNN_INSTALL_PATH="$CUDNN_INSTALL_PATH" |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 131 | |
| 132 | # The Cuda SDK version that should be used in this build |
| 133 | TF_CUDA_VERSION=$TF_CUDA_VERSION |
| 134 | |
| 135 | # The Cudnn version that should be used in this build |
| 136 | TF_CUDNN_VERSION=$TF_CUDNN_VERSION |
| 137 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 138 | EOF |
| 139 | |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 140 | function UnofficialSetting() { |
A. Unique TensorFlower | 8a59748 | 2016-01-29 09:34:18 -0800 | [diff] [blame] | 141 | # Configure the Cuda toolkit version to work with. |
| 142 | perl -pi -e "s,CUDA_VERSION = '[0-9\.]*',CUDA_VERSION = '$TF_CUDA_VERSION',s" tensorflow/core/platform/default/build_config.bzl |
| 143 | perl -pi -e "s,(GetCudaVersion.*return )\"[0-9\.]*\",\1\"$TF_CUDA_VERSION\",s" tensorflow/stream_executor/dso_loader.cc |
| 144 | |
| 145 | # Configure the Cudnn version to work with. |
| 146 | perl -pi -e "s,CUDNN_VERSION = '[0-9\.]*',CUDNN_VERSION = '$TF_CUDNN_VERSION',s" tensorflow/core/platform/default/build_config.bzl |
| 147 | perl -pi -e "s,(GetCudnnVersion.*return )\"[0-9\.]*\",\1\"$TF_CUDNN_VERSION\",s" tensorflow/stream_executor/dso_loader.cc |
Vijay Vasudevan | 4dffee7 | 2015-11-12 11:27:00 -0800 | [diff] [blame] | 148 | |
| 149 | # Configure the compute capabilities that TensorFlow builds for. |
| 150 | # Since Cuda toolkit is not backward-compatible, this is not guaranteed to work. |
| 151 | while true; do |
| 152 | fromuser="" |
| 153 | if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then |
| 154 | cat << EOF |
| 155 | Please specify a list of comma-separated Cuda compute capabilities you want to build with. |
| 156 | You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. |
| 157 | Please note that each additional compute capability significantly increases your build time and binary size. |
| 158 | EOF |
| 159 | read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES |
| 160 | fromuser=1 |
| 161 | fi |
| 162 | # Check whether all capabilities from the input is valid |
| 163 | COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ } |
| 164 | ALL_VALID=1 |
| 165 | for CAPABILITY in $COMPUTE_CAPABILITIES; do |
| 166 | if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then |
| 167 | echo "Invalid compute capability: " $CAPABILITY |
| 168 | ALL_VALID=0 |
| 169 | break |
| 170 | fi |
| 171 | done |
| 172 | if [ "$ALL_VALID" == "0" ]; then |
| 173 | if [ -z "$fromuser" ]; then |
| 174 | exit 1 |
| 175 | fi |
| 176 | else |
| 177 | break |
| 178 | fi |
| 179 | TF_CUDA_COMPUTE_CAPABILITIES="" |
| 180 | done |
| 181 | |
| 182 | if [ ! -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then |
| 183 | export WARNING="Unofficial setting. DO NOT"" SUBMIT!!!" |
| 184 | function CudaGenCodeOpts() { |
| 185 | OUTPUT="" |
| 186 | for CAPABILITY in $@; do |
| 187 | OUTPUT=${OUTPUT}" \"${CAPABILITY}\", " |
| 188 | done |
| 189 | echo $OUTPUT |
| 190 | } |
| 191 | export CUDA_GEN_CODES_OPTS=$(CudaGenCodeOpts ${TF_CUDA_COMPUTE_CAPABILITIES//,/ }) |
| 192 | perl -pi -0 -e 's,\n( *)([^\n]*supported_cuda_compute_capabilities\s*=\s*\[).*?(\]),\n\1# $ENV{WARNING}\n\1\2$ENV{CUDA_GEN_CODES_OPTS}\3,s' third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc |
| 193 | function CudaVersionOpts() { |
| 194 | OUTPUT="" |
| 195 | for CAPABILITY in $@; do |
| 196 | OUTPUT=$OUTPUT"CudaVersion(\"${CAPABILITY}\"), " |
| 197 | done |
| 198 | echo $OUTPUT |
| 199 | } |
| 200 | export CUDA_VERSION_OPTS=$(CudaVersionOpts ${TF_CUDA_COMPUTE_CAPABILITIES//,/ }) |
| 201 | perl -pi -0 -e 's,\n( *)([^\n]*supported_cuda_compute_capabilities\s*=\s*\{).*?(\}),\n\1// $ENV{WARNING}\n\1\2$ENV{CUDA_VERSION_OPTS}\3,s' tensorflow/core/common_runtime/gpu/gpu_device.cc |
| 202 | fi |
| 203 | } |
| 204 | |
| 205 | # Only run the unofficial settings when users explicitly choose to. |
| 206 | if [ "$TF_UNOFFICIAL_SETTING" == "1" ]; then |
| 207 | UnofficialSetting |
| 208 | fi |
| 209 | |
Manjunath Kudlur | f41959c | 2015-11-06 16:27:58 -0800 | [diff] [blame] | 210 | # Invoke the cuda_config.sh and set up the TensorFlow's canonical view of the Cuda libraries |
| 211 | (cd third_party/gpus/cuda; ./cuda_config.sh;) || exit -1 |
| 212 | |
| 213 | echo "Configuration finished" |