Skip to content

Commit 08b0d3b

Browse files
authored
Merge pull request #1211 from Pinata-Consulting/plot-running-times
Plot running times
2 parents 3f9740e + bb41e1c commit 08b0d3b

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import subprocess
2+
import os
3+
import re
4+
from matplotlib import pyplot as plt
5+
import numpy as np
6+
from matplotlib import cm
7+
import itertools
8+
9+
def run():
10+
test_design = 'make DESIGN_CONFIG=designs/asap7/mock-array/config.mk'
11+
12+
times = []
13+
14+
# measure three variables at the time.
15+
measurements = {'datawidth': (('MOCK_ARRAY_DATAWIDTH',), (8,)),
16+
'arraysize': (('MOCK_ARRAY_WIDTH', 'MOCK_ARRAY_HEIGHT'), (8,)),
17+
'pitches': (('MOCK_ARRAY_TABLE',), ('8 8 4 4 5 5',)),
18+
'elementsize': (('MOCK_ARRAY_SCALE',), (45, 80, 160, 320, 640))}
19+
measure_ids = sorted(measurements.keys())
20+
21+
for measurement in itertools.product(*map(lambda key: measurements[key][1], measure_ids)):
22+
variant = '-'.join(map(str, measurement)).replace(' ', '-')
23+
print(f'testiong {variant}')
24+
env_change = {'FLOW_VARIANT': variant}
25+
for e in itertools.chain(*map(lambda measure: map(lambda var: {var: measure[1]}, measurements[measure[0]][0]),
26+
zip(measure_ids, measurement))):
27+
u = dict(map(lambda item: (item[0], str(item[1])), e.items()))
28+
env_change.update(u)
29+
env = os.environ.copy()
30+
env.update(env_change)
31+
32+
if not os.path.exists(f'results/asap7/mock-array_Element/{variant}/'):
33+
print(f"Measuring {variant}")
34+
for cmd in (test_design + ' verilog', test_design,):
35+
returncode = subprocess.call(cmd,
36+
env=env,
37+
shell=True)
38+
if returncode != 0:
39+
print("Skipping variant, doesn't compile: " + variant)
40+
result = subprocess.check_output(test_design + " elapsed", shell=True, env=env).decode('utf-8')
41+
42+
# Modify pattern to capture the stage of interest
43+
# Log Elapsed seconds
44+
# logname 40
45+
pattern = r'^5_2_route\s+(\d+)$'
46+
match = re.search(pattern, result, re.MULTILINE)
47+
if match is None:
48+
print("Variant skipped: " + variant)
49+
continue
50+
value = int(match.group(1))
51+
sample = list(measurement) + [value]
52+
print(' '.join(map(str, sample)))
53+
times.append(sample)
54+
55+
dimensions = sum(map(lambda id: len(measurements[id][1]) > 1, measure_ids))
56+
if dimensions == 3:
57+
# 4 dimensional plot
58+
# plt.rcParams["figure.figsize"] = [7.00, 3.50]
59+
plt.rcParams["figure.autolayout"] = True
60+
fig = plt.figure()
61+
ax = fig.add_subplot(111, projection='3d')
62+
63+
transposed = list(map(list, zip(*times)))
64+
65+
norm = plt.Normalize(min(transposed[-1]), max(transposed[-1]))
66+
colors = cm.viridis(norm(transposed[-1]))
67+
68+
cbar = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cm.viridis), ax=ax)
69+
cbar.set_label("running time/seconds")
70+
71+
img = ax.scatter(*transposed, c=colors, alpha=1)
72+
73+
ax.set_xlabel(measure_ids[0])
74+
ax.set_ylabel(measure_ids[1])
75+
ax.set_zlabel(measure_ids[2])
76+
plt.show()
77+
elif dimensions == 1:
78+
list(enumerate(map(lambda id: len(measurements[id][1]) > 1, measure_ids)))
79+
measure = next((i for i, e in enumerate(map(lambda id: len(measurements[id][1]) > 1, measure_ids)) if e), -1)
80+
81+
fig, ax = plt.subplots()
82+
x = np.array(list(map(lambda m: m[measure], times)))
83+
y = np.array(list(map(lambda m: m[-1], times)))
84+
85+
# Calculate the best-fit line
86+
# slope, intercept = np.polyfit(x, y, 1)
87+
# trendline = slope * x + intercept
88+
89+
# Create the plot
90+
ax.plot(x, y, marker='o', color='red', label='detailed route/seconds') # Plot the data points
91+
# ax.plot(x, trendline, '-', label='Trendline') # Plot the trendline
92+
93+
# Customize the plot
94+
ax.set_xlabel(measure_ids[measure])
95+
ax.set_ylabel("Running time / seconds")
96+
#ax.set_yscale('log')
97+
ax.set_title("Detailed routing time")
98+
ax.legend()
99+
100+
# Display the plot
101+
plt.show()
102+
103+
104+
105+
if __name__ == '__main__':
106+
run()

0 commit comments

Comments
 (0)