Skip to content

Commit b6f37ab

Browse files
Internal build change.
PiperOrigin-RevId: 899910788
1 parent 79ad55d commit b6f37ab

5 files changed

Lines changed: 134 additions & 56 deletions

File tree

‎build_tools/lint/tags.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@
9898
"xla_gb200": "Runs on a gb200.",
9999
"xla_gb300": "Runs on a gb300.",
100100
"xla_rtx6000pro": "Runs on an rtx6000pro.",
101+
"xla_device_p100": "Runs on a p100.",
102+
"xla_device_v100": "Runs on a v100.",
103+
"xla_device_a100": "Runs on an a100.",
104+
"xla_device_h100": "Runs on an h100.",
105+
"xla_device_b200": "Runs on a b200.",
106+
"xla_device_gb200": "Runs on a gb200.",
107+
"xla_device_gb300": "Runs on a gb300.",
108+
"xla_device_rtx6000pro": "Runs on an rtx6000pro.",
101109
# Below tags are consumed by `xla_test`.
102110
"test_migrated_to_hlo_runner_pjrt": (
103111
"Adds the appropriate `xla/tests:pjrt_$BACKEND_client_registry` to the"

‎xla/BUILD‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,8 @@ bzl_library(
15351535
name = "lit_bzl",
15361536
srcs = ["lit.bzl"],
15371537
deps = [
1538+
":native_test_bzl",
1539+
":platform_native_rule_bzl",
15381540
"//xla/tests:build_defs_bzl",
15391541
"@rules_cc//cc/common",
15401542
# copybara:uncomment "@rules_python//python:defs_bzl",
@@ -1546,4 +1548,27 @@ bzl_library(
15461548
],
15471549
)
15481550

1551+
bzl_library(
1552+
name = "native_test_bzl",
1553+
srcs = ["native_test.bzl"],
1554+
visibility = ["//visibility:private"],
1555+
deps = ["//xla/tsl:package_groups_bzl"],
1556+
)
1557+
1558+
bzl_library(
1559+
name = "platform_native_rule_bzl",
1560+
srcs = if_google(
1561+
["platform_native_rule.google.bzl"],
1562+
["platform_native_rule.default.bzl"],
1563+
),
1564+
visibility = ["//visibility:private"],
1565+
deps = [
1566+
":native_test_bzl",
1567+
"//xla/tsl:package_groups_bzl",
1568+
] + if_google([
1569+
"//third_party/bazel_rules/rules_platform/platform_test:defs_bzl",
1570+
"//xla/tests:build_defs_bzl",
1571+
]),
1572+
)
1573+
15491574
xla_bzl_library()

‎xla/lit.bzl‎

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
load("@bazel_skylib//lib:paths.bzl", "paths")
44
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
55
load("@xla//third_party/rules_python/python:defs.bzl", "py_binary")
6+
load(
7+
"//xla:native_test.bzl",
8+
"native_test",
9+
)
10+
load(
11+
"//xla:platform_native_rule.default.bzl",
12+
"platform_native_rule",
13+
)
614
load(
715
"//xla/tests:build_defs.bzl",
816
"prepare_gpu_backend_data",
@@ -65,6 +73,7 @@ def lit_test_suite(
6573
exec_properties = {},
6674
tags = [],
6775
gpu_suffix = "",
76+
native_test_rule = native_test,
6877
**kwargs):
6978
"""Creates one lit test per source file and a test suite that bundles them.
7079
@@ -98,6 +107,8 @@ def lit_test_suite(
98107
requirement to run on a GPU.
99108
gpu_suffix: string. A suffix derived from the gpu name that can be added
100109
to make (file) names unique.
110+
native_test_rule: callable. A rule or macro to create the test target,
111+
instead of `native_test`.
101112
**kwargs: additional keyword arguments to pass to all generated rules.
102113
103114
See https://llvm.org/docs/CommandGuide/lit.html for details on lit
@@ -132,6 +143,7 @@ def lit_test_suite(
132143
hermetic_cuda_data_dir = hermetic_cuda_data_dir,
133144
exec_properties = exec_properties,
134145
gpu_suffix = gpu_suffix,
146+
native_test_rule = native_test_rule,
135147
**kwargs
136148
)
137149

@@ -314,8 +326,10 @@ def lit_device_test(
314326
"XLA_TEST_DEVICE": device,
315327
"XLA_TEST_MODIFIERS": ",".join(modifiers),
316328
})
329+
this_backend_tags = ["xla_%s" % backend, "xla_device_%s" % backend] + tags + backend_tags.get(backend, [])
330+
test_name = "%s_%s" % (name, backend)
317331
lit_test_suite(
318-
name = "%s_%s" % (name, backend),
332+
name = test_name,
319333
srcs = srcs,
320334
cfg = cfg,
321335
tools = tools,
@@ -328,8 +342,9 @@ def lit_device_test(
328342
tags_override = tags_override,
329343
hermetic_cuda_data_dir = hermetic_cuda_data_dir,
330344
exec_properties = exec_properties,
331-
tags = ["xla_%s" % backend] + tags + backend_tags.get(backend, []),
345+
tags = this_backend_tags,
332346
gpu_suffix = "_%s" % (backend),
347+
native_test_rule = platform_native_rule(name = test_name, backend = backend),
333348
**kwargs
334349
)
335350

@@ -363,6 +378,7 @@ def lit_test(
363378
hermetic_cuda_data_dir = None,
364379
exec_properties = {},
365380
gpu_suffix = "",
381+
native_test_rule = native_test,
366382
**kwargs):
367383
"""Runs a single test file with LLVM's lit tool.
368384
@@ -393,6 +409,8 @@ def lit_test(
393409
requirement to run on a GPU.
394410
gpu_suffix: string. A suffix derived from the gpu name that can be added
395411
to make (file) names unique.
412+
native_test_rule: callable. A rule or macro to create the test target,
413+
instead of `native_test`.
396414
**kwargs: additional keyword arguments to pass to all generated rules.
397415
398416
See https://llvm.org/docs/CommandGuide/lit.html for details on lit
@@ -470,7 +488,7 @@ def lit_test(
470488
)
471489
test_file = output_file
472490

473-
native_test(
491+
native_test_rule(
474492
name = name,
475493
src = lit_name,
476494
args = [
@@ -498,37 +516,6 @@ def lit_test(
498516
**kwargs
499517
)
500518

501-
def _shared_impl(ctx):
502-
out = ctx.attr.out
503-
if not out:
504-
out = ctx.attr.name
505-
output = ctx.actions.declare_file(out)
506-
ctx.actions.symlink(
507-
target_file = ctx.executable.src,
508-
output = output,
509-
is_executable = True,
510-
)
511-
512-
runfiles = ctx.runfiles(files = ctx.files.data)
513-
514-
# For Bazel 4.x support. Drop when Bazel 4.x is no longer supported
515-
to_merge = ([d[DefaultInfo].default_runfiles for d in ctx.attr.data] +
516-
[ctx.attr.src[DefaultInfo].default_runfiles])
517-
if hasattr(runfiles, "merge_all"):
518-
runfiles = runfiles.merge_all(to_merge)
519-
else:
520-
for m in to_merge:
521-
runfiles = runfiles.merge(m)
522-
return DefaultInfo(
523-
executable = output,
524-
files = depset([output]),
525-
runfiles = runfiles,
526-
)
527-
528-
def _native_test_impl(ctx):
529-
default_info = _shared_impl(ctx)
530-
return [default_info, testing.TestEnvironment(ctx.attr.env)]
531-
532519
def _tools_on_path_impl(ctx):
533520
runfiles = ctx.runfiles()
534521

@@ -592,25 +579,3 @@ _tools_on_path = rule(
592579
# We have to manually set "env" on the test rule because the builtin one is only
593580
# available in native rules. See
594581
# https://docs.bazel.build/versions/main/be/common-definitions.html#test.env
595-
_TEST_ATTRS = {
596-
"src": attr.label(
597-
executable = True,
598-
allow_files = True,
599-
mandatory = True,
600-
cfg = "target",
601-
),
602-
"data": attr.label_list(allow_files = True),
603-
# "out" is attr.string instead of attr.output, so that it is select()'able.
604-
"out": attr.string(),
605-
"env": attr.string_dict(
606-
doc = "Mirrors the common env attribute that otherwise is" +
607-
" only available on native rules. See" +
608-
" https://docs.bazel.build/versions/main/be/common-definitions.html#test.env",
609-
),
610-
}
611-
612-
native_test = rule(
613-
implementation = _native_test_impl,
614-
attrs = _TEST_ATTRS,
615-
test = True,
616-
)

‎xla/native_test.bzl‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Native test rule for LIT tests."""
2+
3+
load("//xla/tsl:package_groups.bzl", "DEFAULT_LOAD_VISIBILITY")
4+
5+
visibility(DEFAULT_LOAD_VISIBILITY)
6+
7+
def _shared_impl(ctx):
8+
out = ctx.attr.out
9+
if not out:
10+
out = ctx.attr.name
11+
output = ctx.actions.declare_file(out)
12+
ctx.actions.symlink(
13+
target_file = ctx.executable.src,
14+
output = output,
15+
is_executable = True,
16+
)
17+
18+
runfiles = ctx.runfiles(files = ctx.files.data)
19+
20+
# For Bazel 4.x support. Drop when Bazel 4.x is no longer supported
21+
to_merge = ([d[DefaultInfo].default_runfiles for d in ctx.attr.data] +
22+
[ctx.attr.src[DefaultInfo].default_runfiles])
23+
if hasattr(runfiles, "merge_all"):
24+
runfiles = runfiles.merge_all(to_merge)
25+
else:
26+
for m in to_merge:
27+
runfiles = runfiles.merge(m)
28+
return DefaultInfo(
29+
executable = output,
30+
files = depset([output]),
31+
runfiles = runfiles,
32+
)
33+
34+
def _native_test_impl(ctx):
35+
default_info = _shared_impl(ctx)
36+
return [default_info, testing.TestEnvironment(ctx.attr.env)]
37+
38+
_TEST_ATTRS = {
39+
"src": attr.label(
40+
executable = True,
41+
allow_files = True,
42+
mandatory = True,
43+
cfg = "target",
44+
),
45+
"data": attr.label_list(allow_files = True),
46+
# "out" is attr.string instead of attr.output, so that it is select()'able.
47+
"out": attr.string(),
48+
"env": attr.string_dict(
49+
doc = "Mirrors the common env attribute that otherwise is" +
50+
" only available on native rules. See" +
51+
" https://docs.bazel.build/versions/main/be/common-definitions.html#test.env",
52+
),
53+
}
54+
55+
native_test = rule(
56+
implementation = _native_test_impl,
57+
attrs = _TEST_ATTRS,
58+
test = True,
59+
doc = "Rule to create a symlink to a test executable for LIT tests.",
60+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Default platform native rule wrapper (passthrough for OSS)."""
2+
3+
load("//xla:native_test.bzl", "native_test")
4+
load("//xla/tsl:package_groups.bzl", "DEFAULT_LOAD_VISIBILITY")
5+
6+
visibility(DEFAULT_LOAD_VISIBILITY)
7+
8+
def platform_native_rule(
9+
name, # @unused
10+
backend): # @unused
11+
"""Factory function returning a lambda that simply calls native_test.
12+
13+
Args:
14+
name: string. Ignored.
15+
backend: string. Ignored.
16+
17+
Returns:
18+
A lambda function that takes `name` and `**kwargs` and calls `native_test`.
19+
"""
20+
return lambda name, **kwargs: native_test(name = name, **kwargs)

0 commit comments

Comments
 (0)
⌂ 换网址