Macro to create a separate virtual include target for CUDA headers.
Generate prettier copy rules. PiperOrigin-RevId: 247978439
This commit is contained in:
parent
51b572c7cf
commit
10fc95918e
46
third_party/gpus/cuda/BUILD.tpl
vendored
46
third_party/gpus/cuda/BUILD.tpl
vendored
@ -1,3 +1,5 @@
|
||||
load(":build_defs.bzl", "cuda_header_library")
|
||||
|
||||
licenses(["restricted"]) # MPL2, portions GPL v3, LGPL v3, BSD-like
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
@ -35,33 +37,17 @@ config_setting(
|
||||
values = {"cpu": "freebsd"},
|
||||
)
|
||||
|
||||
# Provides CUDA headers for '#include "third_party/gpus/cuda/include/cuda.h"'
|
||||
# All clients including TensorFlow should use these directives.
|
||||
cc_library(
|
||||
name = "cuda_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cuda_headers",
|
||||
hdrs = [
|
||||
"cuda/cuda_config.h",
|
||||
":cuda-include"
|
||||
],
|
||||
include_prefix = "third_party/gpus",
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
# Provides CUDA headers for '#include <cuda.h>'.
|
||||
# CUDA itself as well as Eigen use these directives.
|
||||
cc_library(
|
||||
name = "cuda_headers",
|
||||
textual_hdrs = [
|
||||
# TODO(csigg): change references to third_party/gpus/cuda/cuda_config.h
|
||||
# (e.g. in the PIP build script) and then remove cuda_config.h.
|
||||
"cuda/cuda_config.h",
|
||||
":cuda-include"
|
||||
],
|
||||
includes = [
|
||||
".", # required to include cuda/cuda/cuda_config.h as cuda/config.h
|
||||
"cuda/include",
|
||||
],
|
||||
deps = [":cuda_virtual_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@ -88,20 +74,13 @@ cc_library(
|
||||
linkstatic = 1,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cublas_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cublas_headers",
|
||||
hdrs = [":cublas-include"],
|
||||
include_prefix = "third_party/gpus/cuda/include",
|
||||
strip_include_prefix = "cublas/include",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cublas_headers",
|
||||
textual_hdrs = [":cublas-include"],
|
||||
includes = ["cublas/include"],
|
||||
deps = [":cublas_virtual_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@ -160,19 +139,12 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cupti_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cupti_headers",
|
||||
hdrs = [":cuda-extras"],
|
||||
include_prefix="third_party/gpus",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cupti_headers",
|
||||
textual_hdrs = [":cuda-extras"],
|
||||
includes = ["cuda/extras/CUPTI/include/"],
|
||||
deps = [":cupti_virtual_headers"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
47
third_party/gpus/cuda/BUILD.windows.tpl
vendored
47
third_party/gpus/cuda/BUILD.windows.tpl
vendored
@ -1,3 +1,5 @@
|
||||
load(":build_defs.bzl", "cuda_header_library")
|
||||
|
||||
licenses(["restricted"]) # MPL2, portions GPL v3, LGPL v3, BSD-like
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
@ -37,33 +39,18 @@ config_setting(
|
||||
|
||||
# Provides CUDA headers for '#include "third_party/gpus/cuda/include/cuda.h"'
|
||||
# All clients including TensorFlow should use these directives.
|
||||
cc_library(
|
||||
name = "cuda_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cuda_headers",
|
||||
hdrs = [
|
||||
"cuda/cuda_config.h",
|
||||
":cuda-include"
|
||||
],
|
||||
include_prefix = "third_party/gpus",
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
# Provides CUDA headers for '#include <cuda.h>'.
|
||||
# CUDA itself as well as Eigen use these directives.
|
||||
cc_library(
|
||||
name = "cuda_headers",
|
||||
textual_hdrs = [
|
||||
# TODO(csigg): change references to third_party/gpus/cuda/cuda_config.h
|
||||
# (e.g. in the PIP build script) and then remove cuda_config.h.
|
||||
"cuda/cuda_config.h",
|
||||
":cuda-include"
|
||||
],
|
||||
includes = [
|
||||
".", # required to include cuda/cuda/cuda_config.h as cuda/config.h
|
||||
"cuda/include",
|
||||
],
|
||||
)
|
||||
deps = [":cuda_virtual_headers"],
|
||||
)
|
||||
|
||||
cc_import(
|
||||
name = "cudart_static",
|
||||
@ -88,20 +75,13 @@ cc_import(
|
||||
system_provided = 1,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
cuda_header_library(
|
||||
name = "cublas_virtual_headers",
|
||||
hdrs = [":cublas-include"],
|
||||
include_prefix = "third_party/gpus/cuda/include",
|
||||
strip_include_prefix = "cublas/include",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cublas_headers",
|
||||
textual_hdrs = [":cublas-include"],
|
||||
includes = ["cublas/include"],
|
||||
deps = [":cublas_virtual_headers"],
|
||||
strip_include_prefix = "cublas/include",
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_import(
|
||||
@ -154,19 +134,12 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cupti_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cupti_headers",
|
||||
hdrs = [":cuda-extras"],
|
||||
include_prefix="third_party/gpus",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cupti_headers",
|
||||
textual_hdrs = [":cuda-extras"],
|
||||
includes = ["cuda/extras/CUPTI/include/"],
|
||||
deps = [":cupti_virtual_headers"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_import(
|
||||
|
35
third_party/gpus/cuda/build_defs.bzl.tpl
vendored
35
third_party/gpus/cuda/build_defs.bzl.tpl
vendored
@ -9,15 +9,13 @@ def if_cuda(if_true, if_false = []):
|
||||
return select({
|
||||
"@local_config_cuda//cuda:using_nvcc": if_true,
|
||||
"@local_config_cuda//cuda:using_clang": if_true,
|
||||
"//conditions:default": if_false
|
||||
"//conditions:default": if_false,
|
||||
})
|
||||
|
||||
|
||||
def cuda_default_copts():
|
||||
"""Default options for all CUDA compilations."""
|
||||
return if_cuda(["-x", "cuda", "-DGOOGLE_CUDA=1"] + %{cuda_extra_copts})
|
||||
|
||||
|
||||
def cuda_is_configured():
|
||||
"""Returns true if CUDA was enabled during the configure process."""
|
||||
return %{cuda_is_configured}
|
||||
@ -29,5 +27,34 @@ def if_cuda_is_configured(x):
|
||||
--config=cuda. Used to allow non-CUDA code to depend on CUDA libraries.
|
||||
"""
|
||||
if cuda_is_configured():
|
||||
return x
|
||||
return x
|
||||
return []
|
||||
|
||||
def cuda_header_library(
|
||||
name,
|
||||
hdrs,
|
||||
include_prefix = None,
|
||||
strip_include_prefix = None,
|
||||
deps = [],
|
||||
**kwargs):
|
||||
"""Generates a cc_library containing both virtual and system include paths.
|
||||
|
||||
Generates both a header-only target with virtual includes plus the full
|
||||
target without virtual includes. This works around the fact that bazel can't
|
||||
mix 'includes' and 'include_prefix' in the same target."""
|
||||
|
||||
native.cc_library(
|
||||
name = name + "_virtual",
|
||||
hdrs = hdrs,
|
||||
include_prefix = include_prefix,
|
||||
strip_include_prefix = strip_include_prefix,
|
||||
deps = deps,
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
native.cc_library(
|
||||
name = name,
|
||||
textual_hdrs = hdrs,
|
||||
deps = deps + [":%s_virtual" % name],
|
||||
**kwargs
|
||||
)
|
||||
|
4
third_party/gpus/cuda_configure.bzl
vendored
4
third_party/gpus/cuda_configure.bzl
vendored
@ -879,7 +879,7 @@ def make_copy_files_rule(repository_ctx, name, srcs, outs):
|
||||
|
||||
# Copy files.
|
||||
for src, out in zip(srcs, outs):
|
||||
cmds.append('cp -f "%s" $(location %s)' % (src, out))
|
||||
cmds.append('cp -f "%s" "$(location %s)"' % (src, out))
|
||||
outs = [(' "%s",' % out) for out in outs]
|
||||
return """genrule(
|
||||
name = "%s",
|
||||
@ -887,7 +887,7 @@ def make_copy_files_rule(repository_ctx, name, srcs, outs):
|
||||
%s
|
||||
],
|
||||
cmd = \"""%s \""",
|
||||
)""" % (name, "\n".join(outs), " && ".join(cmds))
|
||||
)""" % (name, "\n".join(outs), " && \\\n".join(cmds))
|
||||
|
||||
def make_copy_dir_rule(repository_ctx, name, src_dir, out_dir):
|
||||
"""Returns a rule to recursively copy a directory."""
|
||||
|
@ -1,3 +1,5 @@
|
||||
load(":build_defs.bzl", "cuda_header_library")
|
||||
|
||||
licenses(["restricted"]) # MPL2, portions GPL v3, LGPL v3, BSD-like
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
@ -35,33 +37,17 @@ config_setting(
|
||||
values = {"cpu": "freebsd"},
|
||||
)
|
||||
|
||||
# Provides CUDA headers for '#include "third_party/gpus/cuda/include/cuda.h"'
|
||||
# All clients including TensorFlow should use these directives.
|
||||
cc_library(
|
||||
name = "cuda_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cuda_headers",
|
||||
hdrs = [
|
||||
"cuda/cuda_config.h",
|
||||
":cuda-include",
|
||||
],
|
||||
include_prefix = "third_party/gpus",
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
# Provides CUDA headers for '#include <cuda.h>'.
|
||||
# CUDA itself as well as Eigen use these directives.
|
||||
cc_library(
|
||||
name = "cuda_headers",
|
||||
includes = [
|
||||
".", # required to include cuda/cuda/cuda_config.h as cuda/config.h
|
||||
"cuda/include",
|
||||
],
|
||||
textual_hdrs = [
|
||||
# TODO(csigg): change references to third_party/gpus/cuda/cuda_config.h
|
||||
# (e.g. in the PIP build script) and then remove cuda_config.h.
|
||||
"cuda/cuda_config.h",
|
||||
":cuda-include",
|
||||
],
|
||||
deps = [":cuda_virtual_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@ -88,20 +74,13 @@ cc_library(
|
||||
linkstatic = 1,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cublas_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cublas_headers",
|
||||
hdrs = [":cublas-include"],
|
||||
include_prefix = "third_party/gpus/cuda/include",
|
||||
strip_include_prefix = "cublas/include",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cublas_headers",
|
||||
includes = ["cublas/include"],
|
||||
textual_hdrs = [":cublas-include"],
|
||||
deps = [":cublas_virtual_headers"],
|
||||
strip_include_prefix = "cublas/include",
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@ -160,19 +139,12 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cupti_virtual_headers",
|
||||
cuda_header_library(
|
||||
name = "cupti_headers",
|
||||
hdrs = [":cuda-extras"],
|
||||
include_prefix = "third_party/gpus",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "cupti_headers",
|
||||
includes = ["cuda/extras/CUPTI/include/"],
|
||||
textual_hdrs = [":cuda-extras"],
|
||||
deps = [":cupti_virtual_headers"],
|
||||
deps = [":cuda_headers"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@ -1237,7 +1209,9 @@ genrule(
|
||||
"cublas/include/cublas_v2.h",
|
||||
"cublas/include/cublas_api.h",
|
||||
],
|
||||
cmd = """cp -f "/usr/local/cuda-10.0/include/cublas.h" $(location cublas/include/cublas.h) && cp -f "/usr/local/cuda-10.0/include/cublas_v2.h" $(location cublas/include/cublas_v2.h) && cp -f "/usr/local/cuda-10.0/include/cublas_api.h" $(location cublas/include/cublas_api.h) """,
|
||||
cmd = """cp -f "/usr/local/cuda-10.0/include/cublas.h" "$(location cublas/include/cublas.h)" && \
|
||||
cp -f "/usr/local/cuda-10.0/include/cublas_v2.h" "$(location cublas/include/cublas_v2.h)" && \
|
||||
cp -f "/usr/local/cuda-10.0/include/cublas_api.h" "$(location cublas/include/cublas_api.h)" """,
|
||||
)
|
||||
|
||||
genrule(
|
||||
@ -1254,7 +1228,16 @@ genrule(
|
||||
"cuda/lib/libcupti.so.10.0",
|
||||
"cuda/lib/libcusparse.so.10.0",
|
||||
],
|
||||
cmd = """cp -f "/usr/local/cuda-10.0/lib64/stubs/libcuda.so" $(location cuda/lib/libcuda.so) && cp -f "/usr/local/cuda-10.0/lib64/libcudart.so.10.0" $(location cuda/lib/libcudart.so.10.0) && cp -f "/usr/local/cuda-10.0/lib64/libcudart_static.a" $(location cuda/lib/libcudart_static.a) && cp -f "/usr/local/cuda-10.0/lib64/libcublas.so.10.0" $(location cuda/lib/libcublas.so.10.0) && cp -f "/usr/local/cuda-10.0/lib64/libcusolver.so.10.0" $(location cuda/lib/libcusolver.so.10.0) && cp -f "/usr/local/cuda-10.0/lib64/libcurand.so.10.0" $(location cuda/lib/libcurand.so.10.0) && cp -f "/usr/local/cuda-10.0/lib64/libcufft.so.10.0" $(location cuda/lib/libcufft.so.10.0) && cp -f "/usr/lib/x86_64-linux-gnu/libcudnn.so.7" $(location cuda/lib/libcudnn.so.7) && cp -f "/usr/local/cuda-10.0/extras/CUPTI/lib64/libcupti.so.10.0" $(location cuda/lib/libcupti.so.10.0) && cp -f "/usr/local/cuda-10.0/lib64/libcusparse.so.10.0" $(location cuda/lib/libcusparse.so.10.0) """,
|
||||
cmd = """cp -f "/usr/local/cuda-10.0/lib64/stubs/libcuda.so" "$(location cuda/lib/libcuda.so)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcudart.so.10.0" "$(location cuda/lib/libcudart.so.10.0)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcudart_static.a" "$(location cuda/lib/libcudart_static.a)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcublas.so.10.0" "$(location cuda/lib/libcublas.so.10.0)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcusolver.so.10.0" "$(location cuda/lib/libcusolver.so.10.0)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcurand.so.10.0" "$(location cuda/lib/libcurand.so.10.0)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcufft.so.10.0" "$(location cuda/lib/libcufft.so.10.0)" && \
|
||||
cp -f "/usr/lib/x86_64-linux-gnu/libcudnn.so.7" "$(location cuda/lib/libcudnn.so.7)" && \
|
||||
cp -f "/usr/local/cuda-10.0/extras/CUPTI/lib64/libcupti.so.10.0" "$(location cuda/lib/libcupti.so.10.0)" && \
|
||||
cp -f "/usr/local/cuda-10.0/lib64/libcusparse.so.10.0" "$(location cuda/lib/libcusparse.so.10.0)" """,
|
||||
)
|
||||
|
||||
genrule(
|
||||
@ -1286,5 +1269,5 @@ genrule(
|
||||
outs = [
|
||||
"cudnn/include/cudnn.h",
|
||||
],
|
||||
cmd = """cp -f "/usr/include/cudnn.h" $(location cudnn/include/cudnn.h) """,
|
||||
cmd = """cp -f "/usr/include/cudnn.h" "$(location cudnn/include/cudnn.h)" """,
|
||||
)
|
||||
|
@ -29,3 +29,32 @@ def if_cuda_is_configured(x):
|
||||
if cuda_is_configured():
|
||||
return x
|
||||
return []
|
||||
|
||||
def cuda_header_library(
|
||||
name,
|
||||
hdrs,
|
||||
include_prefix = None,
|
||||
strip_include_prefix = None,
|
||||
deps = [],
|
||||
**kwargs):
|
||||
"""Generates a cc_library containing both virtual and system include paths.
|
||||
|
||||
Generates both a header-only target with virtual includes plus the full
|
||||
target without virtual includes. This works around the fact that bazel can't
|
||||
mix 'includes' and 'include_prefix' in the same target."""
|
||||
|
||||
native.cc_library(
|
||||
name = name + "_virtual",
|
||||
hdrs = hdrs,
|
||||
include_prefix = include_prefix,
|
||||
strip_include_prefix = strip_include_prefix,
|
||||
deps = deps,
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
native.cc_library(
|
||||
name = name,
|
||||
textual_hdrs = hdrs,
|
||||
deps = deps + [":%s_virtual" % name],
|
||||
**kwargs
|
||||
)
|
||||
|
@ -34,7 +34,8 @@ genrule(
|
||||
"tensorrt/lib/libnvinfer.so.5",
|
||||
"tensorrt/lib/libnvinfer_plugin.so.5",
|
||||
],
|
||||
cmd = """cp -f "/usr/lib/x86_64-linux-gnu/libnvinfer.so.5" $(location tensorrt/lib/libnvinfer.so.5) && cp -f "/usr/lib/x86_64-linux-gnu/libnvinfer_plugin.so.5" $(location tensorrt/lib/libnvinfer_plugin.so.5) """,
|
||||
cmd = """cp -f "/usr/lib/x86_64-linux-gnu/libnvinfer.so.5" "$(location tensorrt/lib/libnvinfer.so.5)" && \
|
||||
cp -f "/usr/lib/x86_64-linux-gnu/libnvinfer_plugin.so.5" "$(location tensorrt/lib/libnvinfer_plugin.so.5)" """,
|
||||
)
|
||||
|
||||
genrule(
|
||||
@ -44,5 +45,7 @@ genrule(
|
||||
"tensorrt/include/NvUtils.h",
|
||||
"tensorrt/include/NvInferPlugin.h",
|
||||
],
|
||||
cmd = """cp -f "/usr/include/x86_64-linux-gnu/NvInfer.h" $(location tensorrt/include/NvInfer.h) && cp -f "/usr/include/x86_64-linux-gnu/NvUtils.h" $(location tensorrt/include/NvUtils.h) && cp -f "/usr/include/x86_64-linux-gnu/NvInferPlugin.h" $(location tensorrt/include/NvInferPlugin.h) """,
|
||||
cmd = """cp -f "/usr/include/x86_64-linux-gnu/NvInfer.h" "$(location tensorrt/include/NvInfer.h)" && \
|
||||
cp -f "/usr/include/x86_64-linux-gnu/NvUtils.h" "$(location tensorrt/include/NvUtils.h)" && \
|
||||
cp -f "/usr/include/x86_64-linux-gnu/NvInferPlugin.h" "$(location tensorrt/include/NvInferPlugin.h)" """,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user