2
Macros for selecting with / without various GPU libraries. Most of these are meant to be used
3
directly by tensorflow in place of their build's own configure.py + bazel-gen system.
6
load("@bazel_skylib//lib:selects.bzl", "selects")
8
def if_cuda(if_true, if_false = []):
9
"""Helper for selecting based on the whether CUDA is configured. """
10
return selects.with_or({
11
"@//tools/config:cuda_enabled_and_capable": if_true,
12
"//conditions:default": if_false,
15
def if_tensorrt(if_true, if_false = []):
16
"""Helper for selecting based on the whether TensorRT is configured. """
18
"//conditions:default": if_false,
21
def if_rocm(if_true, if_false = []):
22
"""Helper for selecting based on the whether ROCM is configured. """
24
"//conditions:default": if_false,
27
def if_sycl(if_true, if_false = []):
28
"""Helper for selecting based on the whether SYCL/ComputeCPP is configured."""
30
# NOTE: Tensorflow expects some stange behavior (see their if_sycl) if we
31
# actually plan on supporting this at some point.
33
"//conditions:default": if_false,
36
def if_ccpp(if_true, if_false = []):
37
"""Helper for selecting based on the whether ComputeCPP is configured. """
39
"//conditions:default": if_false,
42
def cuda_default_copts():
43
return if_cuda(["-DGOOGLE_CUDA=1"])
45
def cuda_default_features():
46
return if_cuda(["-per_object_debug_info", "-use_header_modules", "cuda_clang"])
48
def rocm_default_copts():
49
return if_rocm(["-x", "rocm"])
51
def rocm_copts(opts = []):
52
return rocm_default_copts() + if_rocm(opts)
54
def cuda_is_configured():
55
# FIXME(dcollins): currently only used by tensorflow's xla stuff, which we aren't building. However bazel
56
# query hits it so this needs to be defined. Because bazel doesn't actually resolve config at macro expansion
57
# time, `select` can't be used here (since xla expects lists of strings and not lists of select objects).
58
# Instead, the xla build rules must be rewritten to use `if_cuda_is_configured`
61
def if_cuda_is_configured(x):
64
def if_rocm_is_configured(x):