Skip to content

Commit 9c62d88

Browse files
authored
[TOOLS] Improve generate-test-checks.py (#5300)
- Format the doc string using the `reStructuredText` format. - Lift the example instructions from the `.mlir.in` file to the docstring. Previously we matched the `module` keyword twice and encountered errors such as `assert len(output_segments) == len(source_segments),`. It's also fine to update the regex to something like `\bmodule` to solve the problem, but I think lifting it from the input file is just simpler.
1 parent e950d9a commit 9c62d88

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

test/TritonGPU/samples/descriptor-matmul-pipeline.mlir

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
// CHECK: #[[$ATTR_2:.+]] = #ttg.shared<{vec = 8, perPhase = 1, maxPhase = 8, order = [1, 0], hasLeadingOffset = true}>
1111
// CHECK: #[[$ATTR_3:.+]] = #ttg.shared<{vec = 1, perPhase = 1, maxPhase = 1, order = [0], hasLeadingOffset = false}>
1212
// CHECK: #[[$ATTR_4:.+]] = #ttg.shared<{vec = 8, perPhase = 1, maxPhase = 8, order = [0, 1], hasLeadingOffset = true}>
13-
// RUN: triton-opt %s -split-input-file -tritongpu-loop-scheduling -tritongpu-pipeline -canonicalize | FileCheck --dump-input-context=50 %s
13+
// To regenerate this test case, run the command
14+
// triton-opt test/TritonGPU/samples/descriptor-matmul-pipeline.mlir.in -tritongpu-loop-scheduling -tritongpu-pipeline -canonicalize | \
15+
// utils/generate-test-checks.py --source test/TritonGPU/samples/descriptor-matmul-pipeline.mlir.in --source_delim_regex="\bmodule" \
16+
// -o test/TritonGPU/samples/descriptor-matmul-pipeline.mlir
17+
// RUN: triton-opt %s -split-input-file -tritongpu-loop-scheduling -tritongpu-pipeline -canonicalize | FileCheck --dump-input-context=51 %s
1418
// CHECK-LABEL: tt.func public @matmul_kernel_with_descriptors(
1519
// CHECK-SAME: %[[VAL_0:.*]]: !tt.ptr<f16> {tt.divisibility = 16 : i32}, %[[VAL_1:.*]]: !tt.ptr<f16> {tt.divisibility = 16 : i32}, %[[VAL_2:.*]]: !tt.ptr<f16> {tt.divisibility = 16 : i32}, %[[VAL_3:.*]]: i32 {tt.divisibility = 16 : i32}, %[[VAL_4:.*]]: i32 {tt.divisibility = 16 : i32}, %[[VAL_5:.*]]: i32 {tt.divisibility = 16 : i32}) attributes {noinline = false} {
1620
// CHECK: %[[VAL_6:.*]] = arith.constant 2 : i32

test/TritonGPU/samples/descriptor-matmul-pipeline.mlir.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// To regenerate this test case, run the command
22
// triton-opt test/TritonGPU/samples/descriptor-matmul-pipeline.mlir.in -tritongpu-loop-scheduling -tritongpu-pipeline -canonicalize | \
3-
// utils/generate-test-checks.py --source test/TritonGPU/samples/descriptor-matmul-pipeline.mlir.in --source_delim_regex="module" \
3+
// utils/generate-test-checks.py --source test/TritonGPU/samples/descriptor-matmul-pipeline.mlir.in --source_delim_regex="\bmodule" \
44
// -o test/TritonGPU/samples/descriptor-matmul-pipeline.mlir
5-
// RUN: triton-opt %s -split-input-file -tritongpu-loop-scheduling -tritongpu-pipeline -canonicalize | FileCheck --dump-input-context=50 %s
5+
// RUN: triton-opt %s -split-input-file -tritongpu-loop-scheduling -tritongpu-pipeline -canonicalize | FileCheck --dump-input-context=51 %s
66
module attributes {"ttg.num-ctas" = 1 : i32, "ttg.num-warps" = 8 : i32, ttg.target = "cuda:90", "ttg.threads-per-warp" = 32 : i32} {
77
tt.func public @matmul_kernel_with_descriptors(%arg0: !tt.ptr<f16> {tt.divisibility = 16 : i32}, %arg1: !tt.ptr<f16> {tt.divisibility = 16 : i32}, %arg2: !tt.ptr<f16> {tt.divisibility = 16 : i32}, %arg3: i32 {tt.divisibility = 16 : i32}, %arg4: i32 {tt.divisibility = 16 : i32}, %arg5: i32 {tt.divisibility = 16 : i32}) attributes {noinline = false} {
88
%c8_i32 = arith.constant 8 : i32

utils/generate-test-checks.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
#!/usr/bin/env python3
2-
"""A script to generate FileCheck statements for mlir unit tests.
2+
"""
3+
===============================================================
4+
A script to generate FileCheck statements for mlir unit tests.
5+
===============================================================
36
47
This script is a utility to add FileCheck patterns to an mlir file.
58
6-
NOTE: The input .mlir is expected to be the output from the parser, not a
9+
NOTE: The input ``.mlir`` is expected to be the output from the parser, not a
710
stripped down variant.
811
912
Example usage:
10-
$ generate-test-checks.py foo.mlir
11-
$ mlir-opt foo.mlir -transformation | generate-test-checks.py
12-
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir
13-
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i
14-
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i --source_delim_regex='gpu.func @'
13+
14+
.. code-block:: shell
15+
16+
$ generate-test-checks.py foo.mlir
17+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py
18+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir
19+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i
20+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i --source_delim_regex='gpu.func @'
1521
1622
The script will heuristically generate CHECK/CHECK-LABEL commands for each line
1723
within the file. By default this script will also try to insert string
18-
substitution blocks for all SSA value names. If --source file is specified, the
24+
substitution blocks for all SSA value names. If ``--source file`` is specified, the
1925
script will attempt to insert the generated CHECKs to the source file by looking
20-
for line positions matched by --source_delim_regex.
26+
for line positions matched by ``--source_delim_regex``.
2127
2228
The script is designed to make adding checks to a test case fast, it is *not*
2329
designed to be authoritative about what constitutes a good test!

0 commit comments

Comments
 (0)