aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/gpus/rocm/build_defs.bzl.tpl
blob: 08c59f95a077d01c58b54533fa3f083a5d5939a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Macros for building ROCm code.
def if_rocm(if_true, if_false = []):
    """Shorthand for select()'ing on whether we're building with ROCm.

    Returns a select statement which evaluates to if_true if we're building
    with ROCm enabled.  Otherwise, the select statement evaluates to if_false.

    """
    return select({
        "@local_config_rocm//rocm:using_hipcc": if_true,
        "//conditions:default": if_false
    })


def rocm_default_copts():
    """Default options for all ROCm compilations."""
    return if_rocm(["-x", "rocm"] + %{rocm_extra_copts})

def rocm_copts(opts = []):
    """Gets the appropriate set of copts for (maybe) ROCm compilation.

      If we're doing ROCm compilation, returns copts for our particular ROCm
      compiler.  If we're not doing ROCm compilation, returns an empty list.

      """
    return rocm_default_copts() + select({
        "//conditions:default": [],
        "@local_config_rocm//rocm:using_hipcc": ([
            "",
        ]),
    }) + if_rocm_is_configured(opts)

def rocm_is_configured():
    """Returns true if ROCm was enabled during the configure process."""
    return %{rocm_is_configured}

def if_rocm_is_configured(x):
    """Tests if the ROCm was enabled during the configure process.

    Unlike if_rocm(), this does not require that we are building with
    --config=rocm. Used to allow non-ROCm code to depend on ROCm libraries.
    """
    if rocm_is_configured():
      return x
    return []