Repository navigation
Expand file tree
/
Copy pathplot.py
More file actions
executable file
·58 lines (52 loc) · 2.03 KB
/
Copy pathplot.py
File metadata and controls
executable file
·58 lines (52 loc) · 2.03 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
#!/usr/bin/env python3
"""
plot.py — turn results/raw/timings.csv into the two charts the README references.
Usage: python plot.py
Deps: pip install matplotlib pandas
"""
import csv, os
import matplotlib.pyplot as plt
CSV = "results/raw/timings.csv"
OUT = "results"
os.makedirs(OUT, exist_ok=True)
# --- load: keep the LAST row per kernel (your latest measurement) ---
rows = {}
with open(CSV) as f:
for r in csv.reader(f):
if not r or r[0].startswith("#"):
continue
name, M, N, K, gflops, pct, ms, err = r
rows[name] = dict(name=name, gflops=float(gflops),
pct=float(pct), ms=float(ms))
# sort by version number in the name (v0, v1, ...)
data = sorted(rows.values(), key=lambda d: d["name"])
names = [d["name"] for d in data]
pcts = [d["pct"] for d in data]
gflops = [d["gflops"] for d in data]
# --- chart 1: % of cuBLAS (the money chart) ---
plt.figure(figsize=(9, 4.5))
bars = plt.bar(names, pcts)
plt.axhline(100, ls="--", lw=1, color="gray")
plt.text(len(names)-0.5, 101, "cuBLAS", ha="right", color="gray")
plt.ylabel("% of cuBLAS")
plt.title("SGEMM optimization: % of cuBLAS by stage (M=N=K=4096)")
plt.xticks(rotation=30, ha="right")
for b, p in zip(bars, pcts):
plt.text(b.get_x()+b.get_width()/2, p+1, f"{p:.0f}%", ha="center", fontsize=8)
plt.tight_layout()
plt.savefig(f"{OUT}/percent_of_cublas.png", dpi=150)
print(f"wrote {OUT}/percent_of_cublas.png")
# --- chart 2: GFLOPS ladder ---
plt.figure(figsize=(9, 4.5))
plt.plot(names, gflops, marker="o")
plt.ylabel("GFLOPS")
plt.title("SGEMM optimization: GFLOPS by stage")
plt.xticks(rotation=30, ha="right")
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig(f"{OUT}/gflops_ladder.png", dpi=150)
print(f"wrote {OUT}/gflops_ladder.png")
# NOTE: for a true roofline (results/roofline.png), plot each kernel's
# arithmetic intensity (x) vs achieved GFLOP/s (y) on log-log axes, with the
# memory roof (slope = peak BW) and compute roof (flat = peak FLOP/s). Pull AI
# from your ncu reports. Left as a Week-9 exercise.