-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
105 lines (86 loc) · 3.1 KB
/
Copy pathplot.py
File metadata and controls
105 lines (86 loc) · 3.1 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
#!/usr/bin/env python3
import csv
import sys
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
CSV = sys.argv[1] if len(sys.argv) > 1 else "./resources/bench.csv"
def load(path):
with open(path) as f:
return list(csv.DictReader(f))
def where(rows, **kv):
out = []
for r in rows:
if all(r[k] == v for k, v in kv.items()):
out.append(r)
return out
def save(fig, name):
fig.tight_layout()
fig.savefig(name, dpi=120)
plt.close(fig)
print("wrote", name)
def chart_utilization(rows):
r = where(rows, kind="array_size")
labels = [f"{x['R']}x{x['C']}" for x in r]
util = [float(x["utilization"]) * 100 for x in r]
fig, ax = plt.subplots(figsize=(6, 4))
ax.bar(labels, util, color="#4C72B0")
ax.set_xlabel("array size (R x C)")
ax.set_ylabel("MAC utilization (%)")
ax.set_title("utilization vs array size (M=N=32, K=64)")
for i, v in enumerate(util):
ax.text(i, v + 0.4, f"{v:.1f}", ha="center", fontsize=9)
save(fig, "chart_utilization.png")
def chart_dataflow(rows):
r = where(rows, kind="dataflow")
labels = [x["dataflow"] for x in r]
cycles = [int(x["total_cycles"]) for x in r]
fig, ax = plt.subplots(figsize=(5, 4))
ax.bar(labels, cycles, color=["#4C72B0", "#DD8452"])
ax.set_ylabel("total cycles")
ax.set_title("OS vs WS, same GEMM (32x32x64, 8x8 array)")
for i, v in enumerate(cycles):
ax.text(i, v, str(v), ha="center", va="bottom", fontsize=9)
save(fig, "chart_dataflow.png")
def chart_sched(rows):
r = where(rows, kind="sched")
shapes, naive, pipe = [], [], []
for x in r:
if x["sched"] != "naive":
continue
shapes.append(f"{x['M']}x{x['N']}x{x['K']}")
naive.append(int(x["total_cycles"]))
for x in where(r, sched="pipelined"):
pipe.append(int(x["total_cycles"]))
idx = range(len(shapes))
w = 0.38
fig, ax = plt.subplots(figsize=(7, 4))
ax.bar([i - w / 2 for i in idx], naive, w, label="naive", color="#C44E52")
ax.bar([i + w / 2 for i in idx], pipe, w, label="pipelined", color="#55A868")
ax.set_xticks(list(idx))
ax.set_xticklabels(shapes)
ax.set_ylabel("total cycles")
ax.set_title("naive vs pipelined (double-buffered)")
ax.legend()
save(fig, "chart_sched.png")
def chart_vs_cpu(rows):
r = where(rows, kind="vs_cpu")
labels = [f"{x['M']}x{x['N']}x{x['K']}" for x in r]
speed = [float(x["speedup_vs_cpu"]) for x in r]
fig, ax = plt.subplots(figsize=(7, 4))
ax.bar(labels, speed, color="#8172B3")
ax.axhline(64, ls="--", color="gray", lw=1)
ax.text(0, 64, " 64x ceiling (R*C MACs/cycle)", va="bottom", fontsize=8, color="gray")
ax.set_ylabel("speedup vs scalar CPU")
ax.set_title("accelerator vs scalar CPU (pipelined, 8x8 array)")
for i, v in enumerate(speed):
ax.text(i, v + 0.5, f"{v:.1f}x", ha="center", fontsize=9)
save(fig, "chart_vs_cpu.png")
def main():
rows = load(CSV)
chart_utilization(rows)
chart_dataflow(rows)
chart_sched(rows)
chart_vs_cpu(rows)
if __name__ == "__main__":
main()