From 05171e08d49c9032bc6a90224a1c4e8f2d6cd57c Mon Sep 17 00:00:00 2001 From: David Galiffi Date: Thu, 20 Mar 2025 15:18:25 -0400 Subject: [PATCH] Add extra validation to the openmp target ctest (#141) Update openmp-target ctest. - Add a validation step to check the proto file for the offloaded kernel name - Update the validation script to add an option to validate a substring of the perfetto label rather than an exact match. [ROCm/rocprofiler-systems commit: 9b7d70fcc8144a8211b7e0486c6aac09ee3c6789] --- .../tests/rocprof-sys-openmp-tests.cmake | 10 ++++- .../tests/validate-perfetto-proto.py | 44 ++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/projects/rocprofiler-systems/tests/rocprof-sys-openmp-tests.cmake b/projects/rocprofiler-systems/tests/rocprof-sys-openmp-tests.cmake index 18c4cd027f..b4e8b58566 100644 --- a/projects/rocprofiler-systems/tests/rocprof-sys-openmp-tests.cmake +++ b/projects/rocprofiler-systems/tests/rocprof-sys-openmp-tests.cmake @@ -44,7 +44,15 @@ rocprofiler_systems_add_test( TARGET openmp-target GPU ON LABELS "openmp;openmp-target" - ENVIRONMENT "${_ompt_environment}") + ENVIRONMENT + "${_ompt_environment};ROCPROFSYS_ROCM_DOMAINS=hip_runtime_api,kernel_dispatch") + +rocprofiler_systems_add_validation_test( + NAME openmp-target-sampling + PERFETTO_METRIC "rocm_kernel_dispatch" + PERFETTO_FILE "perfetto-trace.proto" + LABELS "openmp;openmp-target" + ARGS --label-substrings Z4vmulIiEvPT_S1_S1_i_l51.kd -c 12 -d 0 -p) set(_ompt_sampling_environ "${_ompt_environment}" diff --git a/projects/rocprofiler-systems/tests/validate-perfetto-proto.py b/projects/rocprofiler-systems/tests/validate-perfetto-proto.py index 66c57e8c9a..15167a0656 100755 --- a/projects/rocprofiler-systems/tests/validate-perfetto-proto.py +++ b/projects/rocprofiler-systems/tests/validate-perfetto-proto.py @@ -42,7 +42,7 @@ def load_trace(inp, max_tries=5, retry_wait=1, bin_path=None): return tp -def validate_perfetto(data, labels, counts, depths): +def validate_perfetto(data, labels, counts, depths, useSubstringForLabels=False): """ Validates the given perfetto data against expected labels, counts, and depths. @@ -52,7 +52,8 @@ def validate_perfetto(data, labels, counts, depths): labels (list of str): A list of expected labels. counts (list of int): A list of expected counts corresponding to the labels. depths (list of int): A list of expected depths corresponding to the labels. - + useSubstringForLabels (bool): If True, checks if the label in data contains + the expected label as a substring. If False, checks for exact matches. Raises: RuntimeError: If any of the labels, counts, or depths in the data do not match the expected values. @@ -75,8 +76,15 @@ def validate_perfetto(data, labels, counts, depths): _count = ditr["count"] _depth = ditr["depth"] - if _label != eitr[0]: - raise RuntimeError(f"Mismatched prefix: {_label} vs. {eitr[0]}") + if useSubstringForLabels: + if eitr[0] not in _label: + raise RuntimeError( + f"Mismatched prefix: {_label} does not contain {eitr[0]}" + ) + else: + if _label != eitr[0]: + raise RuntimeError(f"Mismatched prefix: {_label} vs. {eitr[0]}") + if _count != eitr[1]: raise RuntimeError(f"Mismatched count: {_count} vs. {eitr[1]}") if _depth != eitr[2]: @@ -87,7 +95,12 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( - "-l", "--labels", nargs="+", type=str, help="Expected labels", default=[] + "-l", + "--labels", + nargs="+", + type=str, + help="Expected labels. Not to be used with '-s'", + default=[], ) parser.add_argument( "-c", "--counts", nargs="+", type=int, help="Expected counts", default=[] @@ -95,6 +108,14 @@ if __name__ == "__main__": parser.add_argument( "-d", "--depths", nargs="+", type=int, help="Expected depths", default=[] ) + parser.add_argument( + "-s", + "--label-substrings", + nargs="+", + type=str, + help="Expected labels substrings. Not to be used with '-l'", + default=[], + ) parser.add_argument( "-m", "--categories", nargs="+", help="Perfetto categories", default=[] ) @@ -129,7 +150,15 @@ if __name__ == "__main__": args = parser.parse_args() - if len(args.labels) != len(args.counts) or len(args.labels) != len(args.depths): + # check for mutually exclusive arguments + if args.labels and args.label_substrings: + raise RuntimeError( + "Cannot specify both expected labels and expected label substrings" + ) + + labels = args.labels if args.labels else args.label_substrings + + if len(labels) != len(args.counts) or len(labels) != len(args.depths): raise RuntimeError( "The same number of labels, counts, and depths must be specified" ) @@ -176,9 +205,10 @@ if __name__ == "__main__": try: validate_perfetto( perfetto_data, - args.labels, + labels, args.counts, args.depths, + useSubstringForLabels=args.label_substrings is not None, ) except RuntimeError as e: