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