Skip to content

Commit

Permalink
Remake tool for inserting FileCheck directives in HLO optimization-pa…
Browse files Browse the repository at this point in the history
…ss tests.

The tool previously required the user to perform most of the steps manually, only automating the replacement of hard-coded symbols with regex captures. It now automatically runs an optimizer on the test file, writes FileCheck directives based on the optimized HLO, replaces symbols with regex captures, and inserts the FileCheck directives above their respective test cases.

The step of replacing explicit symbols with regex captures has also been improved to support capturing function names and to only add disambiguation suffixes when necessary.

PiperOrigin-RevId: 726586730
  • Loading branch information
mrguenther authored and Google-ML-Automation committed Feb 13, 2025
1 parent c3b59c3 commit 0384136
Show file tree
Hide file tree
Showing 8 changed files with 1,584 additions and 192 deletions.
36 changes: 36 additions & 0 deletions xla/hlo/tools/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Tools and utilities that aid in XLA development and usage.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//xla:lit.bzl", "lit_test_suite")
load("//xla:strict.default.bzl", "py_strict_library", "py_strict_test")
load(
"//xla:xla.bzl",
"xla_cc_binary",
Expand Down Expand Up @@ -192,3 +194,37 @@ xla_cc_binary(
"//xla/hlo/tools/hlo_opt:opt_main",
],
)

py_strict_library(
name = "generate_hlo_test_checks",
srcs = ["generate_hlo_test_checks.py"],
srcs_version = "PY3",
)

py_strict_test(
name = "generate_hlo_test_checks_test",
srcs = ["generate_hlo_test_checks_test.py"],
data = [
"generate_hlo_test_checks_test_input.hlo",
"generate_hlo_test_checks_test_output.hlo",
":hlo-opt",
],
python_version = "PY3",
deps = [
":generate_hlo_test_checks",
"@absl_py//absl/testing:absltest",
],
)

# Whereas `:generate_hlo_test_checks_test` checks that the test-generation tool
# behaves as expected, this test verifies that the expected reference output
# from that test is itself a passing test.
lit_test_suite(
name = "generate_hlo_test_checks_meta_test",
srcs = ["generate_hlo_test_checks_test_output.hlo"],
cfg = "//xla:lit.cfg.py",
tools = [
"//xla/hlo/tools:hlo-opt",
"@llvm-project//llvm:FileCheck",
],
)
Loading

0 comments on commit 0384136

Please sign in to comment.