Skip to content

Commit ff00adc

Browse files
PatKaminlslusarczyk
andcommitted
Apply lslusarczyk's comments
Co-authored-by: Łukasz Ślusarczyk <[email protected]>
1 parent 43b0b80 commit ff00adc

File tree

1 file changed

+80
-29
lines changed

1 file changed

+80
-29
lines changed

devops/scripts/benchmarks/benches/compute_metadata.py

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,50 @@
1010
ensuring consistency between benchmark group membership and group metadata definitions.
1111
"""
1212

13+
from collections import namedtuple
1314
from typing import Dict, List
1415

1516
from utils.result import BenchmarkMetadata
1617

1718
from .base import Benchmark
1819

1920

21+
def string_consts(cls):
22+
"""Decorator to convert string-annotated class attributes to string constants."""
23+
for key, value in cls.__annotations__.items():
24+
if value is str:
25+
setattr(cls, key, key)
26+
return cls
27+
28+
29+
@string_consts
30+
class Tags:
31+
"""String constants for benchmark tags to prevent typos."""
32+
33+
submit: str
34+
micro: str
35+
SYCL: str
36+
UR: str
37+
L0: str
38+
graph: str
39+
memory: str
40+
proxy: str
41+
finalize: str
42+
43+
44+
BaseGroupMetadata = namedtuple(
45+
"BaseGroupMetadata",
46+
[
47+
"description",
48+
"notes",
49+
"unstable",
50+
"tags",
51+
"range_min",
52+
"range_max",
53+
],
54+
defaults=(None, None, None, [], None, None),
55+
)
56+
2057
class ComputeMetadataGenerator:
2158
"""
2259
Generates metadata for Compute Benchmark groups.
@@ -28,23 +65,35 @@ class ComputeMetadataGenerator:
2865
def __init__(self):
2966
# Base metadata for core groups
3067
self._base_group_metadata = {
31-
"SubmitKernel": {
32-
"description": "Measures CPU time overhead of submitting kernels through different APIs.",
33-
"notes": (
68+
"SubmitKernel": BaseGroupMetadata(
69+
description="Measures CPU time overhead of submitting kernels through different APIs.",
70+
notes=(
3471
"Each layer builds on top of the previous layer, adding functionality and overhead.\n"
3572
"The first layer is the Level Zero API, the second is the Unified Runtime API, and the third is the SYCL API.\n"
3673
"The UR v2 adapter noticeably reduces UR layer overhead, also improving SYCL performance.\n"
3774
"Work is ongoing to reduce the overhead of the SYCL API\n"
3875
),
39-
"tags": ["submit", "micro", "SYCL", "UR", "L0"],
40-
"range_min": 0.0,
41-
},
42-
"SinKernelGraph": {
43-
"unstable": "This benchmark combines both eager and graph execution, and may not be representative of real use cases.",
44-
"tags": ["submit", "memory", "proxy", "SYCL", "UR", "L0", "graph"],
45-
},
46-
"SubmitGraph": {"tags": ["submit", "micro", "SYCL", "UR", "L0", "graph"]},
47-
"FinalizeGraph": {"tags": ["finalize", "micro", "SYCL", "graph"]},
76+
tags=[Tags.submit, Tags.micro, Tags.SYCL, Tags.UR, Tags.L0],
77+
range_min=0.0,
78+
),
79+
"SinKernelGraph": BaseGroupMetadata(
80+
unstable="This benchmark combines both eager and graph execution, and may not be representative of real use cases.",
81+
tags=[
82+
Tags.submit,
83+
Tags.memory,
84+
Tags.proxy,
85+
Tags.SYCL,
86+
Tags.UR,
87+
Tags.L0,
88+
Tags.graph,
89+
],
90+
),
91+
"SubmitGraph": BaseGroupMetadata(
92+
tags=[Tags.submit, Tags.micro, Tags.SYCL, Tags.UR, Tags.L0, Tags.graph]
93+
),
94+
"FinalizeGraph": BaseGroupMetadata(
95+
tags=[Tags.finalize, Tags.micro, Tags.SYCL, Tags.graph]
96+
),
4897
}
4998

5099
def generate_metadata_from_benchmarks(
@@ -62,26 +111,28 @@ def generate_metadata_from_benchmarks(
62111
metadata = {}
63112
# Discover all group names from actual benchmarks
64113
for benchmark in benchmarks:
65-
if hasattr(benchmark, "explicit_group") and callable(
66-
benchmark.explicit_group
67-
):
68-
group_name = benchmark.explicit_group()
69-
if group_name:
70-
self._generate_metadata(metadata, group_name)
114+
group_name = benchmark.explicit_group()
115+
if group_name and group_name not in metadata:
116+
metadata[group_name] = self._generate_metadata(group_name)
71117

72118
return metadata
73119

74-
def _generate_metadata(
75-
self, metadata: Dict[str, BenchmarkMetadata], group_name: str
76-
):
77-
base_metadata = self._base_group_metadata.get(group_name.split()[0], {})
78-
metadata[group_name] = BenchmarkMetadata(
120+
def _generate_metadata(self, group_name: str) -> BenchmarkMetadata:
121+
"""
122+
Generate metadata for a specific benchmark group.
123+
Args:
124+
group_name: Name of the benchmark group
125+
"""
126+
base_metadata = self._base_group_metadata.get(
127+
group_name.split()[0], BaseGroupMetadata()
128+
)
129+
return BenchmarkMetadata(
79130
type="group",
80-
description=base_metadata.get("description"),
81-
notes=base_metadata.get("notes"),
82-
unstable=base_metadata.get("unstable"),
83-
tags=base_metadata.get("tags", []),
84-
range_min=base_metadata.get("range_min"),
85-
range_max=base_metadata.get("range_max"),
131+
description=base_metadata.description,
132+
notes=base_metadata.notes,
133+
unstable=base_metadata.unstable,
134+
tags=base_metadata.tags,
135+
range_min=base_metadata.range_min,
136+
range_max=base_metadata.range_max,
86137
explicit_group=group_name,
87138
)

0 commit comments

Comments
 (0)