Skip to content

Commit 5daec03

Browse files
authored
Merge pull request #281 from IntelPython/feature/add_devices_to_legend
Add devices to legend
2 parents b851eec + 9f56713 commit 5daec03

File tree

14 files changed

+135
-39
lines changed

14 files changed

+135
-39
lines changed

dpbench/console/report.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ def execute_report(args: Namespace, conn: sqlalchemy.Engine):
6262
print_report(
6363
conn=conn,
6464
run_id=args.run_id,
65-
implementations=args.implementations,
6665
comparison_pairs=comparison_pairs,
6766
)

dpbench/console/run.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import dpbench.config as cfg
1313
import dpbench.infrastructure as dpbi
1414
from dpbench.infrastructure.benchmark_runner import BenchmarkRunner, RunConfig
15+
from dpbench.infrastructure.datamodel import Postfix, store_postfix
16+
from dpbench.infrastructure.frameworks.fabric import build_framework
1517

1618
from ._namespace import Namespace
1719

@@ -149,6 +151,30 @@ def execute_run(args: Namespace, conn: sqlalchemy.Engine):
149151

150152
runner = BenchmarkRunner()
151153

154+
implementation_descriptions = {
155+
impl.postfix: impl.description for impl in cfg.GLOBAL.implementations
156+
}
157+
for implementation in args.implementations:
158+
framework_config = _find_framework_config(implementation)
159+
160+
if not framework_config:
161+
logging.error(
162+
f"Could not find framework for {implementation} implementation"
163+
)
164+
continue
165+
166+
framework = build_framework(framework_config)
167+
168+
store_postfix(
169+
conn=conn,
170+
postfix=Postfix(
171+
run_id=args.run_id,
172+
postfix=implementation,
173+
description=implementation_descriptions[implementation],
174+
device=framework.device_info,
175+
),
176+
)
177+
152178
for benchmark in cfg.GLOBAL.benchmarks:
153179
print("")
154180
print(
@@ -160,9 +186,6 @@ def execute_run(args: Namespace, conn: sqlalchemy.Engine):
160186
framework = _find_framework_config(implementation)
161187

162188
if not framework:
163-
logging.error(
164-
f"Could not find framework for {implementation} implementation"
165-
)
166189
continue
167190

168191
logging.info(

dpbench/infrastructure/datamodel.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ class Result(Base):
112112
)
113113

114114

115+
class Postfix(Base):
116+
__tablename__ = "postfixes"
117+
118+
run_id: Mapped[int] = mapped_column(ForeignKey("runs.id"))
119+
postfix: Mapped[str]
120+
description: Mapped[str]
121+
device: Mapped[str]
122+
123+
__table_args__ = (UniqueConstraint("run_id", "postfix"),)
124+
125+
115126
def create_connection(db_file) -> Engine:
116127
"""create a database connection to the SQLite database
117128
specified by db_file
@@ -164,9 +175,20 @@ def create_results_table(db_file: str):
164175
def store_results(conn: Engine, result: Result):
165176
"""creates result record in database.
166177
:param conn: sqlalchemy engine
167-
:param result: result resord to be inserted into db
178+
:param result: result record to be inserted into db
168179
:return:
169180
"""
170181
with Session(conn) as session:
171182
session.add(result)
172183
session.commit()
184+
185+
186+
def store_postfix(conn: Engine, postfix: Postfix):
187+
"""creates postfix record in database.
188+
:param conn: sqlalchemy engine
189+
:param postfix: postfix record to be inserted into db
190+
:return:
191+
"""
192+
with Session(conn) as session:
193+
session.add(postfix)
194+
session.commit()

dpbench/infrastructure/frameworks/dpcpp_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
2424

2525
try:
2626
self.sycl_device = self.info.sycl_device
27-
dpctl.SyclDevice(self.sycl_device)
27+
self.device_info = dpctl.SyclDevice(self.sycl_device).name
2828
except KeyError:
2929
pass
3030
except dpctl.SyclDeviceCreationError as sdce:

dpbench/infrastructure/frameworks/dpnp_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
2424

2525
try:
2626
self.sycl_device = self.info.sycl_device
27-
dpctl.SyclDevice(self.sycl_device)
27+
self.device_info = dpctl.SyclDevice(self.sycl_device).name
2828
except KeyError:
2929
pass
3030
except dpctl.SyclDeviceCreationError as sdce:

dpbench/infrastructure/frameworks/framework.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def __init__(
4141
self.info = config
4242
self.fname = self.info.simple_name
4343

44+
import cpuinfo
45+
46+
self.device_info = cpuinfo.get_cpu_info().get("brand_raw")
47+
4448
def device_filter_string(self) -> str:
4549
"""Returns the sycl device's filter string if the framework has an
4650
associated sycl device."""

dpbench/infrastructure/frameworks/numba_dpex_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
2424

2525
try:
2626
self.sycl_device = self.info.sycl_device
27-
dpctl.SyclDevice(self.sycl_device)
27+
self.device_info = dpctl.SyclDevice(self.sycl_device).name
2828
except dpctl.SyclDeviceCreationError as sdce:
2929
logging.exception(
3030
"Could not create a Sycl device using filter {} string".format(

dpbench/infrastructure/frameworks/numba_mlir_framework.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
2323
super().__init__(fname, config)
2424

2525
self.sycl_device = self.info.sycl_device
26+
if self.sycl_device:
27+
import dpctl
28+
29+
self.device_info = dpctl.SyclDevice(self.sycl_device).name
2630

2731
def copy_to_func(self) -> Callable:
2832
"""Returns the copy-method that should be used

dpbench/infrastructure/reporter.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2022 Intel Corp.
22
# SPDX-FileCopyrightText: 2022 Intel Corporation
33
#
4-
# SPDX-License-Identifier: Apache 2.0
54
# SPDX-License-Identifier: Apache-2.0
65

76
"""The module generates reports for implementation summary and timing summary
@@ -10,7 +9,6 @@
109

1110
import dataclasses
1211
import logging
13-
import pathlib
1412
from typing import Final, Union
1513

1614
import pandas as pd
@@ -82,8 +80,23 @@ def generate_header(conn: sqlalchemy.Engine, run_id: int):
8280
print("==================================")
8381

8482

85-
def generate_legend(legends: pd.DataFrame):
86-
"""prints legend section"""
83+
def generate_legend(conn: sqlalchemy.Engine, run_id: int) -> list[str]:
84+
"""prints legend section and returns implementation list"""
85+
sql = (
86+
sqlalchemy.select(
87+
dm.Postfix.postfix,
88+
dm.Postfix.description,
89+
dm.Postfix.device,
90+
)
91+
.order_by(dm.Postfix.postfix)
92+
.where(dm.Postfix.run_id == run_id)
93+
)
94+
95+
legends = pd.read_sql_query(
96+
sql=sql,
97+
con=conn.connect(),
98+
)
99+
87100
formatters = {}
88101
for col in legends.select_dtypes("object"):
89102
len_max = legends[col].str.len().max()
@@ -94,6 +107,8 @@ def generate_legend(legends: pd.DataFrame):
94107
print(legends.to_string(formatters=formatters))
95108
print("")
96109

110+
return legends["postfix"].values.tolist()
111+
97112

98113
def generate_summary(data: pd.DataFrame):
99114
"""prints summary section"""
@@ -108,11 +123,6 @@ def generate_impl_summary_report(
108123
implementations: list[str],
109124
):
110125
"""generate implementation summary report with status of each benchmark"""
111-
legends = read_legends()
112-
113-
generate_header(conn, run_id)
114-
generate_legend(legends)
115-
116126
columns = [
117127
func.max(dm.Result.input_size_human).label("input_size"),
118128
dm.Result.benchmark,
@@ -157,15 +167,8 @@ def generate_performance_report(
157167
conn: sqlalchemy.Engine,
158168
run_id: int,
159169
implementations: list[str],
160-
headless=False,
161170
):
162171
"""generate performance report with median times for each benchmark"""
163-
legends = read_legends()
164-
165-
if not headless:
166-
generate_header(conn, run_id)
167-
generate_legend(legends)
168-
169172
columns = [
170173
func.max(dm.Result.input_size_human).label("input_size"),
171174
dm.Result.benchmark,
@@ -222,18 +225,11 @@ def generate_comparison_report(
222225
run_id: int,
223226
implementations: list[str],
224227
comparison_pairs: list[tuple[str, str]],
225-
headless=False,
226228
):
227229
"""generate comparison report with median times for each benchmark"""
228230
if len(comparison_pairs) == 0:
229231
return
230232

231-
legends = read_legends()
232-
233-
if not headless:
234-
generate_header(conn, run_id)
235-
generate_legend(legends)
236-
237233
columns = [
238234
func.max(dm.Result.input_size_human).label("input_size"),
239235
dm.Result.benchmark,
@@ -331,14 +327,10 @@ def get_unexpected_failures(
331327
def print_report(
332328
conn: sqlalchemy.Engine,
333329
run_id: int,
334-
implementations: set[str],
335330
comparison_pairs: list[tuple[str, str]] = [],
336331
):
337-
if not implementations:
338-
implementations = {impl.postfix for impl in cfg.GLOBAL.implementations}
339-
340-
implementations = list(implementations)
341-
implementations.sort()
332+
generate_header(conn, run_id)
333+
implementations = generate_legend(conn, run_id)
342334

343335
generate_impl_summary_report(
344336
conn, run_id=run_id, implementations=implementations
@@ -348,15 +340,13 @@ def print_report(
348340
conn,
349341
run_id=run_id,
350342
implementations=implementations,
351-
headless=True,
352343
)
353344

354345
generate_comparison_report(
355346
conn,
356347
run_id=run_id,
357348
implementations=implementations,
358349
comparison_pairs=comparison_pairs,
359-
headless=True,
360350
)
361351

362352
unexpected_failures = get_unexpected_failures(conn, run_id=run_id)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Add postfixes
6+
7+
Revision ID: c1afe59771e9
8+
Revises: 6477ee64f532
9+
Create Date: 2023-06-20 19:55:37.386101
10+
11+
"""
12+
import sqlalchemy as sa
13+
from alembic import op
14+
15+
# revision identifiers, used by Alembic.
16+
revision = "c1afe59771e9"
17+
down_revision = "6477ee64f532"
18+
branch_labels = None
19+
depends_on = None
20+
21+
22+
def upgrade() -> None:
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.create_table(
25+
"postfixes",
26+
sa.Column("run_id", sa.Integer(), nullable=False),
27+
sa.Column("postfix", sa.String(), nullable=False),
28+
sa.Column("description", sa.String(), nullable=False),
29+
sa.Column("device", sa.String(), nullable=False),
30+
sa.Column("id", sa.Integer(), nullable=False),
31+
sa.Column(
32+
"created_at",
33+
sa.Integer(),
34+
server_default=sa.text("(strftime('%s','now'))"),
35+
nullable=False,
36+
),
37+
sa.ForeignKeyConstraint(
38+
["run_id"],
39+
["runs.id"],
40+
),
41+
sa.PrimaryKeyConstraint("id"),
42+
sa.UniqueConstraint("run_id", "postfix"),
43+
)
44+
# ### end Alembic commands ###
45+
46+
47+
def downgrade() -> None:
48+
# ### commands auto generated by Alembic - please adjust! ###
49+
op.drop_table("postfixes")
50+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)