blob: f1c15f35c6627cf8b28946768bd6b9ce23800556 [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
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080047 # Configure the Cuda SDK version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080048 if [ -z "$TF_CUDA_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -080049 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 TensorFlower8a597482016-01-29 09:34:18 -080050 fi
51
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080052 fromuser=""
53 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
54 default_cuda_path=/usr/local/cuda
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080055 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 -080056 fromuser="1"
57 if [ -z "$CUDA_TOOLKIT_PATH" ]; then
58 CUDA_TOOLKIT_PATH=$default_cuda_path
59 fi
60 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -080061 if [[ -z "$TF_CUDA_VERSION" ]]; then
62 TF_CUDA_EXT=""
63 else
64 TF_CUDA_EXT=".$TF_CUDA_VERSION"
65 fi
66 if [ -e $CUDA_TOOLKIT_PATH/lib64/libcudart.so$TF_CUDA_EXT ]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080067 break
68 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -080069 echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. $CUDA_TOOLKIT_PATH/lib64/libcudart.so$TF_CUDA_EXT cannot be found"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080070 if [ -z "$fromuser" ]; then
71 exit 1
72 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -080073 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080074 TF_CUDA_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080075 CUDA_TOOLKIT_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080076done
77
Martin Wicke916776a2016-01-14 07:30:00 -080078# Find out where the cuDNN library is installed
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080079while true; do
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080080 # Configure the Cudnn version to use.
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080081 if [ -z "$TF_CUDNN_VERSION" ]; then
Vijay Vasudevanfe056f02016-02-17 11:42:30 -080082 read -p "Please specify the Cudnn version you want to use. [Leave empty to use system default]: " TF_CUDNN_VERSION
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080083 fi
84
Manjunath Kudlurf41959c2015-11-06 16:27:58 -080085 fromuser=""
86 if [ -z "$CUDNN_INSTALL_PATH" ]; then
87 default_cudnn_path=${CUDA_TOOLKIT_PATH}
A. Unique TensorFlower8a597482016-01-29 09:34:18 -080088 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 -080089 fromuser="1"
90 if [ -z "$CUDNN_INSTALL_PATH" ]; then
91 CUDNN_INSTALL_PATH=$default_cudnn_path
92 fi
93 # Result returned from "read" will be used unexpanded. That make "~" unuseable.
94 # Going through one more level of expansion to handle that.
95 CUDNN_INSTALL_PATH=$(bash -c "readlink -f $CUDNN_INSTALL_PATH")
96 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -080097 if [[ -z "$TF_CUDNN_VERSION" ]]; then
98 TF_CUDNN_EXT=""
99 else
100 TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
101 fi
102 if [ -e "$CUDNN_INSTALL_PATH/libcudnn.so${CUDNNEXT}" -o -e "$CUDNN_INSTALL_PATH/lib64/libcudnn.so${TF_CUDNN_EXT}" ]; then
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800103 break
104 fi
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800105 echo "Invalid path to cuDNN ${TF_CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800106 echo "$CUDNN_INSTALL_PATH/lib64/libcudnn.so${TF_CUDNN_EXT}"
107 echo "$CUDNN_INSTALL_PATH/libcudnn.so${TF_CUDNN_EXT}"
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800108 if [ -z "$fromuser" ]; then
109 exit 1
110 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800111 # Retry
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800112 TF_CUDNN_VERSION=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800113 CUDNN_INSTALL_PATH=""
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800114done
115
116cat > third_party/gpus/cuda/cuda.config <<EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800117# CUDA_TOOLKIT_PATH refers to the CUDA toolkit.
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800118CUDA_TOOLKIT_PATH="$CUDA_TOOLKIT_PATH"
119
Martin Wicke916776a2016-01-14 07:30:00 -0800120# CUDNN_INSTALL_PATH refers to the cuDNN toolkit. The cuDNN header and library
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800121# files can be either in this directory, or under include/ and lib64/
122# directories separately.
123CUDNN_INSTALL_PATH="$CUDNN_INSTALL_PATH"
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800124
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800125# The Cuda SDK version that should be used in this build (empty to use libcudart.so symlink)
126TF_CUDA_VERSION=$TF_CUDA_EXT
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800127
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800128# The Cudnn version that should be used in this build (empty to use libcudnn.so symlink)
129TF_CUDNN_VERSION=$TF_CUDNN_EXT
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800130
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800131EOF
132
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800133# Configure the Cuda toolkit version to work with.
134perl -pi -e "s,CUDA_VERSION = '[0-9\.]*',CUDA_VERSION = '$TF_CUDA_EXT',s" tensorflow/core/platform/default/build_config.bzl
135perl -pi -e "s,(GetCudaVersion.*return )\"[0-9\.]*\",\1\"$TF_CUDA_EXT\",s" tensorflow/stream_executor/dso_loader.cc
A. Unique TensorFlower8a597482016-01-29 09:34:18 -0800136
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800137# Configure the Cudnn version to work with.
138perl -pi -e "s,CUDNN_VERSION = '[0-9\.]*',CUDNN_VERSION = '$TF_CUDNN_EXT',s" tensorflow/core/platform/default/build_config.bzl
139perl -pi -e "s,(GetCudnnVersion.*return )\"[0-9\.]*\",\1\"$TF_CUDNN_EXT\",s" tensorflow/stream_executor/dso_loader.cc
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800140
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800141# Configure the compute capabilities that TensorFlow builds for.
142# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
143while true; do
144 fromuser=""
145 if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800146cat << EOF
147Please specify a list of comma-separated Cuda compute capabilities you want to build with.
148You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
149Please note that each additional compute capability significantly increases your build time and binary size.
150EOF
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800151 read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
152 fromuser=1
153 fi
154 # Check whether all capabilities from the input is valid
155 COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
156 ALL_VALID=1
157 for CAPABILITY in $COMPUTE_CAPABILITIES; do
158 if [[ ! "$CAPABILITY" =~ [0-9]+.[0-9]+ ]]; then
159 echo "Invalid compute capability: " $CAPABILITY
160 ALL_VALID=0
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800161 break
162 fi
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800163 done
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800164 if [ "$ALL_VALID" == "0" ]; then
165 if [ -z "$fromuser" ]; then
166 exit 1
167 fi
168 else
169 break
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800170 fi
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800171 TF_CUDA_COMPUTE_CAPABILITIES=""
172done
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800173
Vijay Vasudevanfe056f02016-02-17 11:42:30 -0800174if [ ! -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
175 export WARNING="Unofficial setting. DO NOT"" SUBMIT!!!"
176 function CudaGenCodeOpts() {
177 OUTPUT=""
178 for CAPABILITY in $@; do
179 OUTPUT=${OUTPUT}" \"${CAPABILITY}\", "
180 done
181 echo $OUTPUT
182 }
183 export CUDA_GEN_CODES_OPTS=$(CudaGenCodeOpts ${TF_CUDA_COMPUTE_CAPABILITIES//,/ })
184 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
185 function CudaVersionOpts() {
186 OUTPUT=""
187 for CAPABILITY in $@; do
188 OUTPUT=$OUTPUT"CudaVersion(\"${CAPABILITY}\"), "
189 done
190 echo $OUTPUT
191 }
192 export CUDA_VERSION_OPTS=$(CudaVersionOpts ${TF_CUDA_COMPUTE_CAPABILITIES//,/ })
193 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
Vijay Vasudevan4dffee72015-11-12 11:27:00 -0800194fi
195
Manjunath Kudlurf41959c2015-11-06 16:27:58 -0800196# Invoke the cuda_config.sh and set up the TensorFlow's canonical view of the Cuda libraries
197(cd third_party/gpus/cuda; ./cuda_config.sh;) || exit -1
198
199echo "Configuration finished"