xref: /aosp_15_r20/external/pytorch/third_party/tensorflow_cuda_bazel_build/cuda/build_defs.bzl (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# Macros for building CUDA code.
2def if_cuda(if_true, if_false = []):
3    """Shorthand for select()'ing on whether we're building with CUDA.
4
5    Returns a select statement which evaluates to if_true if we're building
6    with CUDA enabled.  Otherwise, the select statement evaluates to if_false.
7
8    """
9    return select({
10        "@local_config_cuda//cuda:using_clang": if_true,
11        "@local_config_cuda//cuda:using_nvcc": if_true,
12        "//conditions:default": if_false,
13    })
14
15def cuda_default_copts():
16    """Default options for all CUDA compilations."""
17    return if_cuda(["-x", "cuda", "-DGOOGLE_CUDA=1"] + [])
18
19def cuda_is_configured():
20    """Returns true if CUDA was enabled during the configure process."""
21    return True
22
23def if_cuda_is_configured(x):
24    """Tests if the CUDA was enabled during the configure process.
25
26    Unlike if_cuda(), this does not require that we are building with
27    --config=cuda. Used to allow non-CUDA code to depend on CUDA libraries.
28    """
29    if cuda_is_configured():
30        return x
31    return []
32