|
| 1 | +"""Macros for XNNPACK and YNNPACK.""" |
| 2 | + |
| 3 | +load("//xla:xla.default.bzl", "xla_cc_test") |
| 4 | +load("//xla/tsl:package_groups.bzl", "DEFAULT_LOAD_VISIBILITY") |
| 5 | + |
| 6 | +visibility(DEFAULT_LOAD_VISIBILITY) |
| 7 | + |
| 8 | +def if_ynnpack(if_true, if_false = []): |
| 9 | + """Selection based on whether we are building XLA with YNNPACK integration. |
| 10 | +
|
| 11 | + Args: |
| 12 | + if_true: Expression to evaluate if building with YNNPACK. |
| 13 | + if_false: Expression to evaluate if building without YNNPACK. |
| 14 | +
|
| 15 | + Returns: |
| 16 | + A select evaluating to either if_true or if_false as appropriate. |
| 17 | + """ |
| 18 | + return select({ |
| 19 | + # YNNPACK is not tested on Windows. |
| 20 | + "//xla/tsl:windows": if_false, |
| 21 | + "//conditions:default": if_true, |
| 22 | + }) |
| 23 | + |
| 24 | +def ynn_cc_test( |
| 25 | + srcs = [], |
| 26 | + deps = [], |
| 27 | + **kwargs): |
| 28 | + """xla_cc_test rule with empty src and deps if not building with YNNPACK.""" |
| 29 | + xla_cc_test( |
| 30 | + # CC_TEST_OK=Just defining `xla_cc_test` rule to be used in XLA. |
| 31 | + srcs = if_ynnpack(srcs), |
| 32 | + deps = if_ynnpack(if_true = deps, if_false = ["@com_google_googletest//:gtest_main"]), |
| 33 | + # If not building with YNNPACK, we don't have any tests linked. |
| 34 | + fail_if_no_test_linked = False, |
| 35 | + # If not building with YNNPACK, we don't have any tests defined either. |
| 36 | + fail_if_no_test_selected = False, |
| 37 | + **kwargs |
| 38 | + ) |
0 commit comments