blob: f217de4e930485ddadbb1e13c491b814c9810c33 [file] [log] [blame]
Manjunath Kudlurf41959c2015-11-06 16:27:58 -08001#!/bin/bash
2
A. Unique TensorFlower8a597482016-01-29 09:34:18 -08003if [ "$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
5fi
6
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -08007## Set up python-related environment settings
8while 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
27done
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 Kudlurf41959c2015-11-06 16:27:58 -080032## Set up Cuda-related environment settings
33
34while [ "$TF_NEED_CUDA" == "" ]; do
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080035 read -p "Do you wish to build TensorFlow with GPU support? [y/N] " INPUT
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080036 case $INPUT in
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -080037 [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 Kudlurf41959c2015-11-06 16:27:58 -080040 * ) echo "Invalid selection: " $INPUT;;
41 esac
42done
43
44if [ "$TF_NEED_CUDA" == "0" ]; then
45 echo "Configuration finished"
46 exit
47fi
48
49# Find out where the CUDA toolkit is installed
50while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080051 # 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 Kudlurf41959c2015-11-06 16:27:58 -080062 fromuser=""
63 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
64 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080065 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 Kudlurf41959c2015-11-06 16:27:58 -080066 fromuser="1"
67 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
68 CUDA_TOOLKIT_PATH=$default_cuda_path
69 fi
70 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080071 if [ -e "$CUDA_TOOLKIT_PATH/lib64/libcudart.so.$TF_CUDA_VERSION" ]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080072 break
73 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080074 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/lib64/libcudart.so.$TF_CUDA_VERSION cannot be found"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080075 if [ -z "$fromuser" ]; then
76 exit 1
77 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080078 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080079 CUDA_TOOLKIT_PATH=""
80 # Retry
81done
82
Martin Wicke916776a2016-01-14 07:30:00 -080083# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080084while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080085 # 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 Kudlurf41959c2015-11-06 16:27:58 -080096 fromuser=""
97 if [ -z "$CUDNN_INSTALL_PATH" ]; then
98 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080099 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 Kudlurf41959c2015-11-06 16:27:58 -0800100 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 TensorFlower8a597482016-01-29 09:34:18 -0800108 if [ -e "$CUDNN_INSTALL_PATH/libcudnn.so.${TF_CUDNN_VERSION}" -o -e "$CUDNN_INSTALL_PATH/lib64/libcudnn.so.${TF_CUDNN_VERSION}" ]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800109 break
110 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800111 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 Kudlurf41959c2015-11-06 16:27:58 -0800114 if [ -z "$fromuser" ]; then
115 exit 1
116 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800117 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800118 CUDNN_INSTALL_PATH=""
119 # Retry
120done
121
122cat > third_party/gpus/cuda/cuda.config <<EOF
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800123# CUDA_TOOLKIT_PATH refers to the CUDA toolkit. Tensorflow requires Cuda $TF_CUDA_VERSION
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800124# at the moment.
125CUDA_TOOLKIT_PATH="$CUDA_TOOLKIT_PATH"
126
Martin Wicke916776a2016-01-14 07:30:00 -0800127# CUDNN_INSTALL_PATH refers to the cuDNN toolkit. The cuDNN header and library
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800128# files can be either in this directory, or under include/ and lib64/
129# directories separately.
130CUDNN_INSTALL_PATH="$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800131
132# The Cuda SDK version that should be used in this build
133TF_CUDA_VERSION=$TF_CUDA_VERSION
134
135# The Cudnn version that should be used in this build
136TF_CUDNN_VERSION=$TF_CUDNN_VERSION
137
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800138EOF
139
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800140function UnofficialSetting() {
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800141 # 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 Vasudevan4dffee72015-11-12 11:27:00 -0800148
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
154cat << EOF
155Please specify a list of comma-separated Cuda compute capabilities you want to build with.
156You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
157Please note that each additional compute capability significantly increases your build time and binary size.
158EOF
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.
206if [ "$TF_UNOFFICIAL_SETTING" == "1" ]; then
207 UnofficialSetting
208fi
209
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800210# 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
213echo "Configuration finished"