github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/toolchains/preconfig/centos6/cuda10.1-cudnn7/cuda/build_defs.bzl (about)

     1  """Macros for building CUDA code."""
     2  
     3  def if_cuda(if_true, if_false = []):
     4      """Shorthand for select()'ing on whether we're building with CUDA.
     5  
     6      Returns a select statement which evaluates to if_true if we're building
     7      with CUDA enabled.  Otherwise, the select statement evaluates to if_false.
     8  
     9      """
    10      return select({
    11          "@local_config_cuda//cuda:using_nvcc": if_true,
    12          "@local_config_cuda//cuda:using_clang": if_true,
    13          "//conditions:default": if_false,
    14      })
    15  
    16  def cuda_default_copts():
    17      """Default options for all CUDA compilations."""
    18      return if_cuda(["-x", "cuda", "-DGOOGLE_CUDA=1"] + [])
    19  
    20  def cuda_is_configured():
    21      """Returns true if CUDA was enabled during the configure process."""
    22      return True
    23  
    24  def if_cuda_is_configured(x):
    25      """Tests if the CUDA was enabled during the configure process.
    26  
    27      Unlike if_cuda(), this does not require that we are building with
    28      --config=cuda. Used to allow non-CUDA code to depend on CUDA libraries.
    29      """
    30      if cuda_is_configured():
    31          return select({"//conditions:default": x})
    32      return select({"//conditions:default": []})
    33  
    34  def cuda_header_library(
    35          name,
    36          hdrs,
    37          include_prefix = None,
    38          strip_include_prefix = None,
    39          deps = [],
    40          **kwargs):
    41      """Generates a cc_library containing both virtual and system include paths.
    42  
    43      Generates both a header-only target with virtual includes plus the full
    44      target without virtual includes. This works around the fact that bazel can't
    45      mix 'includes' and 'include_prefix' in the same target."""
    46  
    47      native.cc_library(
    48          name = name + "_virtual",
    49          hdrs = hdrs,
    50          include_prefix = include_prefix,
    51          strip_include_prefix = strip_include_prefix,
    52          deps = deps,
    53          visibility = ["//visibility:private"],
    54      )
    55  
    56      native.cc_library(
    57          name = name,
    58          textual_hdrs = hdrs,
    59          deps = deps + [":%s_virtual" % name],
    60          **kwargs
    61      )