blob: b64d4693bb2dccd61df0147209af8900d4683639 [file] [log] [blame]
Manjunath Kudlurf41959c2015-11-06 16:27:58 -08001#!/bin/bash
2
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -08003## Set up python-related environment settings
4while 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
23done
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 Kudlurf41959c2015-11-06 16:27:58 -080028## Set up Cuda-related environment settings
29
30while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080031 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080032 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080033 [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 Kudlurf41959c2015-11-06 16:27:58 -080036 * ) echo "Invalid selection: " $INPUT;;
37 esac
38done
39
40if [ "$TF_NEED_CUDA" == "0" ]; then
41 echo "Configuration finished"
42 exit
43fi
44
45# Find out where the CUDA toolkit is installed
46while 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
65done
66
Martin Wicke916776a2016-01-14 07:30:00 -080067# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080068while true; do
69 fromuser=""
70 if [ -z "$CUDNN_INSTALL_PATH" ]; then
71 default_cudnn_path=${CUDA_TOOLKIT_PATH}
Martin Wicke916776a2016-01-14 07:30:00 -080072 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 Kudlurf41959c2015-11-06 16:27:58 -080073 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 Wicke916776a2016-01-14 07:30:00 -080084 echo "Invalid path to cuDNN v2 toolkit. Neither of the following two files can be found:"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080085 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
92done
93
94cat > 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.
97CUDA_TOOLKIT_PATH="$CUDA_TOOLKIT_PATH"
98
Martin Wicke916776a2016-01-14 07:30:00 -080099# CUDNN_INSTALL_PATH refers to the cuDNN toolkit. The cuDNN header and library
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800100# files can be either in this directory, or under include/ and lib64/
101# directories separately.
102CUDNN_INSTALL_PATH="$CUDNN_INSTALL_PATH"
103EOF
104
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800105function UnofficialSetting() {
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -0800106 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 Vasudevan4dffee72015-11-12 11:27:00 -0800107
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
113cat << EOF
114Please specify a list of comma-separated Cuda compute capabilities you want to build with.
115You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
116Please note that each additional compute capability significantly increases your build time and binary size.
117EOF
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.
165if [ "$TF_UNOFFICIAL_SETTING" == "1" ]; then
166 UnofficialSetting
167fi
168
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800169# 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
172echo "Configuration finished"