Skip to content

Commit 6d04d60

Browse files
authored
Merge pull request tensorflow#3269 from davidzchen/cuda-configure
Add cuda_configure repository rule to autodetect cuda.
2 parents 7ac844e + 353235e commit 6d04d60

35 files changed

+778
-658
lines changed

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ node_modules
99
/bazel-testlogs
1010
/bazel-tf
1111
/tensorflow/contrib/cmake/build
12-
/third_party/gpus/cuda/bin
13-
/third_party/gpus/cuda/cuda.config
14-
/third_party/gpus/cuda/extras
15-
/third_party/gpus/cuda/include
16-
/third_party/gpus/cuda/lib
17-
/third_party/gpus/cuda/lib64
18-
/third_party/gpus/cuda/nvvm
1912
/third_party/py/numpy/numpy_include
2013
/tools/bazel.rc
2114
/tools/python_bin_path.sh
@@ -24,4 +17,5 @@ node_modules
2417
/pip_test
2518
/_python_build
2619
*.pyc
27-
__pycache__
20+
__pycache__
21+
*.swp

configure

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ while [ "$TF_NEED_CUDA" == "" ]; do
8080
esac
8181
done
8282

83+
export TF_NEED_CUDA
8384
if [ "$TF_NEED_CUDA" == "0" ]; then
8485
echo "Configuration finished"
8586
exit
@@ -97,6 +98,7 @@ while true; do
9798
fi
9899
fi
99100
if [ -e "$GCC_HOST_COMPILER_PATH" ]; then
101+
export CC=$GCC_HOST_COMPILER_PATH
100102
break
101103
fi
102104
echo "Invalid gcc path. ${GCC_HOST_COMPILER_PATH} cannot be found" 1>&2
@@ -107,7 +109,6 @@ while true; do
107109
# Retry
108110
done
109111

110-
111112
# Find out where the CUDA toolkit is installed
112113
OSNAME=`uname -s`
113114

@@ -140,6 +141,8 @@ while true; do
140141
fi
141142

142143
if [ -e "${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH}" ]; then
144+
export CUDA_TOOLKIT_PATH
145+
export CUDA_VERSION=$TF_CUDA_VERSION
143146
break
144147
fi
145148
echo "Invalid path to CUDA $TF_CUDA_VERSION toolkit. ${CUDA_TOOLKIT_PATH}/${CUDA_RT_LIB_PATH} cannot be found"
@@ -200,13 +203,16 @@ while true; do
200203
fi
201204

202205
if [ -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_ALT_PATH}" -o -e "$CUDNN_INSTALL_PATH/${CUDA_DNN_LIB_PATH}" ]; then
206+
export CUDNN_VERSION=$TF_CUDNN_VERSION
207+
export CUDNN_INSTALL_PATH
203208
break
204209
fi
205210

206211
if [ "$OSNAME" == "Linux" ]; then
207212
CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
208213
if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
209-
CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
214+
export CUDNN_VERSION=$TF_CUDNN_VERSION
215+
export CUDNN_INSTALL_PATH="$(dirname ${CUDNN_PATH_FROM_LDCONFIG})"
210216
break
211217
fi
212218
fi
@@ -225,42 +231,11 @@ while true; do
225231
CUDNN_INSTALL_PATH=""
226232
done
227233

228-
cat > third_party/gpus/cuda/cuda.config <<EOF
229-
# CUDA_TOOLKIT_PATH refers to the CUDA toolkit.
230-
CUDA_TOOLKIT_PATH="$CUDA_TOOLKIT_PATH"
231-
# CUDNN_INSTALL_PATH refers to the cuDNN toolkit. The cuDNN header and library
232-
# files can be either in this directory, or under include/ and lib64/
233-
# directories separately.
234-
CUDNN_INSTALL_PATH="$CUDNN_INSTALL_PATH"
235-
236-
# The Cuda SDK version that should be used in this build (empty to use libcudart.so symlink)
237-
TF_CUDA_VERSION=$TF_CUDA_VERSION
238-
239-
# The Cudnn version that should be used in this build
240-
TF_CUDNN_VERSION=$TF_CUDNN_VERSION
241-
EOF
242-
243-
# Configure the gcc host compiler to use
244-
export WARNING=$DO_NOT_SUBMIT_WARNING
245-
perl -pi -e "s,CPU_COMPILER = \('.*'\),# \$ENV{WARNING}\nCPU_COMPILER = ('$GCC_HOST_COMPILER_PATH'),s" third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc
246-
perl -pi -e "s,GCC_HOST_COMPILER_PATH = \('.*'\),# \$ENV{WARNING}\nGCC_HOST_COMPILER_PATH = ('$GCC_HOST_COMPILER_PATH'),s" third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc
247-
248-
# Configure the platform name.
249-
perl -pi -e "s,PLATFORM = \".*\",PLATFORM = \"$OSNAME\",s" third_party/gpus/cuda/platform.bzl
250-
251-
# Configure the Cuda toolkit version to work with.
252-
perl -pi -e "s,(GetCudaVersion.*return )\"[0-9\.]*\",\1\"$TF_CUDA_VERSION\",s" tensorflow/stream_executor/dso_loader.cc
253-
perl -pi -e "s,CUDA_VERSION = \"[0-9\.]*\",CUDA_VERSION = \"$TF_CUDA_VERSION\",s" third_party/gpus/cuda/platform.bzl
254-
255-
# Configure the Cudnn version to work with.
256-
perl -pi -e "s,(GetCudnnVersion.*return )\"[0-9\.]*\",\1\"$TF_CUDNN_VERSION\",s" tensorflow/stream_executor/dso_loader.cc
257-
perl -pi -e "s,CUDNN_VERSION = \"[0-9\.]*\",CUDNN_VERSION = \"$TF_CUDNN_VERSION\",s" third_party/gpus/cuda/platform.bzl
258-
259-
260234
# Configure the compute capabilities that TensorFlow builds for.
261235
# Since Cuda toolkit is not backward-compatible, this is not guaranteed to work.
262236
while true; do
263237
fromuser=""
238+
default_cuda_compute_capabilities="3.5,5.2"
264239
if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
265240
cat << EOF
266241
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
@@ -270,6 +245,9 @@ EOF
270245
read -p "[Default is: \"3.5,5.2\"]: " TF_CUDA_COMPUTE_CAPABILITIES
271246
fromuser=1
272247
fi
248+
if [ -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
249+
TF_CUDA_COMPUTE_CAPABILITIES=$default_cuda_compute_capabilities
250+
fi
273251
# Check whether all capabilities from the input is valid
274252
COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES//,/ }
275253
ALL_VALID=1
@@ -285,34 +263,13 @@ EOF
285263
exit 1
286264
fi
287265
else
266+
export CUDA_COMPUTE_CAPABILITIES=$TF_CUDA_COMPUTE_CAPABILITIES
288267
break
289268
fi
290269
TF_CUDA_COMPUTE_CAPABILITIES=""
291270
done
292271

293-
if [ ! -z "$TF_CUDA_COMPUTE_CAPABILITIES" ]; then
294-
export WARNING=$DO_NOT_SUBMIT_WARNING
295-
function CudaGenCodeOpts() {
296-
OUTPUT=""
297-
for CAPABILITY in $@; do
298-
OUTPUT=${OUTPUT}" \"${CAPABILITY}\", "
299-
done
300-
echo $OUTPUT
301-
}
302-
export CUDA_GEN_CODES_OPTS=$(CudaGenCodeOpts ${TF_CUDA_COMPUTE_CAPABILITIES//,/ })
303-
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
304-
function CudaVersionOpts() {
305-
OUTPUT=""
306-
for CAPABILITY in $@; do
307-
OUTPUT=$OUTPUT"CudaVersion(\"${CAPABILITY}\"), "
308-
done
309-
echo $OUTPUT
310-
}
311-
export CUDA_VERSION_OPTS=$(CudaVersionOpts ${TF_CUDA_COMPUTE_CAPABILITIES//,/ })
312-
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
313-
fi
314-
315-
# Invoke the cuda_config.sh and set up the TensorFlow's canonical view of the Cuda libraries
316-
(cd third_party/gpus/cuda; ./cuda_config.sh;) || exit -1
272+
bazel clean --expunge
273+
bazel fetch //...
317274

318275
echo "Configuration finished"

tensorflow/core/common_runtime/gpu/gpu_device.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,9 @@ struct CudaVersion {
785785
int minor_part = -1;
786786
};
787787

788-
// "configure" uses the specific name to substitute the following string.
789-
// If you change it, make sure you modify "configure" as well.
790788
std::vector<CudaVersion> supported_cuda_compute_capabilities = {
791-
CudaVersion("3.5"), CudaVersion("5.2")};
789+
TF_CUDA_CAPABILITIES,
790+
};
792791

793792
std::vector<CudaVersion> GetSupportedCudaComputeCapabilities() {
794793
auto cuda_caps = supported_cuda_compute_capabilities;

tensorflow/core/kernels/lrn_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ limitations under the License.
3131
#endif
3232

3333
#if GOOGLE_CUDA
34-
#include "third_party/gpus/cuda/include/cuda.h"
34+
#include "cuda/include/cuda.h"
3535
#include "tensorflow/core/platform/stream_executor.h"
3636
#include "tensorflow/core/util/stream_executor_util.h"
3737
#endif // GOOGLE_CUDA

tensorflow/core/kernels/matmul_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
#include "tensorflow/core/kernels/fill_functor.h"
2626

2727
#if GOOGLE_CUDA
28-
#include "third_party/gpus/cuda/include/cuda.h"
28+
#include "cuda/include/cuda.h"
2929
#include "tensorflow/core/platform/stream_executor.h"
3030
#endif // GOOGLE_CUDA
3131

tensorflow/core/platform/default/build_config/BUILD

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports_files(["LICENSE"])
99

1010
load("//tensorflow:tensorflow.bzl", "tf_copts")
1111
load("//tensorflow:tensorflow.bzl", "tf_cuda_library")
12-
load("//third_party/gpus/cuda:platform.bzl", "cuda_library_path")
12+
load("@local_config_cuda//cuda:platform.bzl", "cuda_library_path")
1313

1414
cc_library(
1515
name = "gtest",
@@ -32,7 +32,7 @@ tf_cuda_library(
3232
deps = [
3333
"//tensorflow/stream_executor",
3434
] + select({
35-
"//third_party/gpus/cuda:darwin": ["IOKit"],
35+
"@local_config_cuda//cuda:darwin": ["IOKit"],
3636
"//conditions:default": [],
3737
}),
3838
)
@@ -91,20 +91,20 @@ filegroup(
9191
cc_library(
9292
name = "cuda",
9393
data = [
94-
"//third_party/gpus/cuda:{}".format(cuda_library_path("cudart")),
94+
"@local_config_cuda//cuda:{}".format(cuda_library_path("cudart")),
9595
],
9696
linkopts = select({
97-
"//third_party/gpus/cuda:darwin": [
98-
"-Wl,-rpath,third_party/gpus/cuda/lib",
99-
"-Wl,-rpath,third_party/gpus/cuda/extras/CUPTI/lib",
97+
"@local_config_cuda//cuda:darwin": [
98+
"-Wl,-rpath,../local_config_cuda/cuda/lib",
99+
"-Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib",
100100
],
101101
"//conditions:default": [
102-
"-Wl,-rpath,third_party/gpus/cuda/lib64",
103-
"-Wl,-rpath,third_party/gpus/cuda/extras/CUPTI/lib64",
102+
"-Wl,-rpath,../local_config_cuda/cuda/lib64",
103+
"-Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64",
104104
],
105105
}),
106106
deps = [
107-
"//third_party/gpus/cuda:cudart",
107+
"@local_config_cuda//cuda:cudart",
108108
],
109109
)
110110

tensorflow/core/platform/default/gpu/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ tf_cuda_library(
1515
copts = tf_copts(),
1616
cuda_deps = [
1717
"//tensorflow/core:stream_executor",
18-
"//third_party/gpus/cuda:cuda_headers",
19-
"//third_party/gpus/cuda:cupti_headers",
18+
"@local_config_cuda//cuda:cuda_headers",
19+
"@local_config_cuda//cuda:cupti_headers",
2020
],
21-
data = ["//third_party/gpus/cuda:cupti_dsos"],
21+
data = ["@local_config_cuda//cuda:cupti_dsos"],
2222
visibility = ["//visibility:public"],
2323
)

tensorflow/core/platform/default/gpu/cupti_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ limitations under the License.
2121
#include <stddef.h>
2222
#include <stdint.h>
2323

24-
#include "third_party/gpus/cuda/extras/CUPTI/include/cupti.h"
24+
#include "cuda/extras/CUPTI/include/cupti.h"
2525

2626
namespace perftools {
2727
namespace gputools {

tensorflow/core/util/port.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
#include "tensorflow/core/util/port.h"
1717

1818
#if GOOGLE_CUDA
19-
#include "third_party/gpus/cuda/include/cuda.h"
19+
#include "cuda/include/cuda.h"
2020
#endif
2121

2222
namespace tensorflow {

tensorflow/stream_executor/BUILD

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ cc_library(
2727
]),
2828
data = [
2929
"//tensorflow/core:cuda",
30-
"//third_party/gpus/cuda:cublas",
31-
"//third_party/gpus/cuda:cudnn",
32-
"//third_party/gpus/cuda:cufft",
30+
"@local_config_cuda//cuda:cublas",
31+
"@local_config_cuda//cuda:cudnn",
32+
"@local_config_cuda//cuda:cufft",
33+
"@local_config_cuda//cuda:curand",
3334
],
3435
linkopts = [
3536
"-ldl",
3637
],
3738
visibility = ["//visibility:public"],
3839
deps = [
3940
"//tensorflow/core:lib",
40-
"//third_party/gpus/cuda:cuda_headers",
41+
"@local_config_cuda//cuda:cuda_headers",
4142
],
4243
alwayslink = 1,
4344
)

0 commit comments

Comments
 (0)