-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
138 lines (108 loc) · 4.31 KB
/
plot.py
File metadata and controls
138 lines (108 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
import json
import re
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
KERNEL_BENCHMARKS = ["Godunov", "TimeStep", "ConsToPrim", "PrimToCons"]
ALL_BENCHMARKS = KERNEL_BENCHMARKS
ALL_BENCHMARKS.append("EulerSimulation")
# ---------------------------------------------------------
# Config
# ---------------------------------------------------------
FILES={
"a100": "./results/ruche/a100/[412780]_ALL-a100_bm_a100.json",
"v100": "./results/ruche/v100/[412885]_ALL-v100_bm_v100.json",
"skx": "./results/ruche/skx/[419180]_ALL-skx_bm_skx.json",
}
# each tuple is (slower, faster) → speedup = time[slower] / time[faster]
SPEEDUPS = [
("v100", "a100"),
]
OUT_DIR = "results/plots"
# ---------------------------------------------------------
# Load
# ---------------------------------------------------------
def load(path, benchmarks):
with open(path) as f:
data = json.load(f)["benchmarks"]
rows = []
for b in data:
name = b["name"]
match = next((bm for bm in benchmarks if bm in name), None)
if match is None:
continue
rows.append({
"benchmark": match,
"size": int(name.split("/")[-1]),
"time": b["cpu_time"],
"cells_per_second": b.get("cells_per_second"),
"bytes_per_second": b.get("bytes_per_second"),
})
return pd.DataFrame(rows)
# ---------------------------------------------------------
# Plot
# ---------------------------------------------------------
def plot_time(files, speedups, out_dir):
out_dir = Path(out_dir)
out_dir.mkdir(parents=True, exist_ok=True)
datasets = {label: load(path, ALL_BENCHMARKS) for label, path in files.items()}
for bm in ALL_BENCHMARKS:
fig, ax1 = plt.subplots(figsize=(9, 5))
ax2 = ax1.twinx()
# --- times ---
for label, df in datasets.items():
sub = df[df["benchmark"] == bm].sort_values("size")
if sub.empty:
continue
ax1.plot(sub["size"], sub["time"], marker="o", label=label)
# --- speedups ---
for slow, fast in speedups:
if slow not in datasets or fast not in datasets:
continue
df_slow = datasets[slow][datasets[slow]["benchmark"] == bm].sort_values("size")
df_fast = datasets[fast][datasets[fast]["benchmark"] == bm].sort_values("size")
merged = df_slow.merge(df_fast, on="size", suffixes=(f"_{slow}", f"_{fast}"))
merged["speedup"] = merged[f"time_{slow}"] / merged[f"time_{fast}"]
ax2.plot(merged["size"], merged["speedup"], linestyle="--",
marker="s", label=f"{slow}→{fast} speedup", color="red")
ax1.set_title(bm)
ax1.set_xlabel("nx")
ax1.set_ylabel("Time (ns)")
ax2.set_ylabel("Speedup v100/a100")
ax2.axhline(1.0, color="gray", linewidth=0.8, linestyle=":")
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(lines1 + lines2, labels1 + labels2, fontsize=8)
ax1.grid(True)
ax1.set_yscale("log", base=2)
plt.tight_layout()
path = out_dir / f"{bm}_times.png"
plt.savefig(path, dpi=200)
plt.close()
print("saved:", path)
def plot_items(files,out_dir):
out_dir = Path(out_dir)
out_dir.mkdir(parents=True, exist_ok=True)
datasets = {label: load(path, KERNEL_BENCHMARKS) for label, path in files.items()}
for bm in KERNEL_BENCHMARKS:
fig, ax1 = plt.subplots(figsize=(9, 5))
# --- cells_per_second ---
for label, df in datasets.items():
sub = df[df["benchmark"] == bm].sort_values("size")
if sub.empty:
continue
ax1.plot(sub["size"], sub["cells_per_second"], marker="o", label=label)
ax1.set_title(bm)
ax1.set_xlabel("nx")
ax1.set_ylabel("cells/s")
lines1, labels1 = ax1.get_legend_handles_labels()
ax1.legend(lines1, labels1, fontsize=8)
ax1.grid(True)
plt.tight_layout()
path = out_dir / f"{bm}_items.png"
plt.savefig(path, dpi=200)
plt.close()
print("saved:", path)
plot_time(FILES, SPEEDUPS, OUT_DIR)
plot_items(FILES, OUT_DIR)