|
| 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 | + # Log Elapsed seconds |
| 43 | + # 2_6_pdn 40 |
| 44 | + # 3_1_place_gp_skip_io 1 |
| 45 | + # 3_2_place_iop 1 |
| 46 | + # 3_3_place_gp 5 |
| 47 | + # 3_4_resizer 2 |
| 48 | + # 3_5_opendp 3 |
| 49 | + # 4_1_cts 5 |
| 50 | + # 4_2_cts_fillcell 3 |
| 51 | + # 5_1_fastroute 5 |
| 52 | + # 5_2_TritonRoute 297 |
| 53 | + # 6_1_merge 3 |
| 54 | + # 6_report 67 |
| 55 | + pattern = r'^5_2_TritonRoute\s+(\d+)$' |
| 56 | + match = re.search(pattern, result, re.MULTILINE) |
| 57 | + if match is None: |
| 58 | + print("Variant skipped: " + variant) |
| 59 | + continue |
| 60 | + value = int(match.group(1)) |
| 61 | + sample = list(measurement) + [value] |
| 62 | + print(' '.join(map(str, sample))) |
| 63 | + times.append(sample) |
| 64 | + |
| 65 | + dimensions = sum(map(lambda id: len(measurements[id][1]) > 1, measure_ids)) |
| 66 | + if dimensions == 3: |
| 67 | + # 4 dimensional plot |
| 68 | + # plt.rcParams["figure.figsize"] = [7.00, 3.50] |
| 69 | + plt.rcParams["figure.autolayout"] = True |
| 70 | + fig = plt.figure() |
| 71 | + ax = fig.add_subplot(111, projection='3d') |
| 72 | + |
| 73 | + transposed = list(map(list, zip(*times))) |
| 74 | + |
| 75 | + norm = plt.Normalize(min(transposed[-1]), max(transposed[-1])) |
| 76 | + colors = cm.viridis(norm(transposed[-1])) |
| 77 | + |
| 78 | + cbar = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cm.viridis), ax=ax) |
| 79 | + cbar.set_label("running time/seconds") |
| 80 | + |
| 81 | + img = ax.scatter(*transposed, c=colors, alpha=1) |
| 82 | + |
| 83 | + ax.set_xlabel(measure_ids[0]) |
| 84 | + ax.set_ylabel(measure_ids[1]) |
| 85 | + ax.set_zlabel(measure_ids[2]) |
| 86 | + plt.show() |
| 87 | + elif dimensions == 1: |
| 88 | + list(enumerate(map(lambda id: len(measurements[id][1]) > 1, measure_ids))) |
| 89 | + measure = next((i for i, e in enumerate(map(lambda id: len(measurements[id][1]) > 1, measure_ids)) if e), -1) |
| 90 | + |
| 91 | + fig, ax = plt.subplots() |
| 92 | + x = np.array(list(map(lambda m: m[measure], times))) |
| 93 | + y = np.array(list(map(lambda m: m[-1], times))) |
| 94 | + |
| 95 | + # Calculate the best-fit line |
| 96 | + # slope, intercept = np.polyfit(x, y, 1) |
| 97 | + # trendline = slope * x + intercept |
| 98 | + |
| 99 | + # Create the plot |
| 100 | + ax.plot(x, y, marker='o', color='red', label='detailed route/seconds') # Plot the data points |
| 101 | + # ax.plot(x, trendline, '-', label='Trendline') # Plot the trendline |
| 102 | + |
| 103 | + # Customize the plot |
| 104 | + ax.set_xlabel(measure_ids[measure]) |
| 105 | + ax.set_ylabel("Running time / seconds") |
| 106 | + #ax.set_yscale('log') |
| 107 | + ax.set_title("Detailed routing time") |
| 108 | + ax.legend() |
| 109 | + |
| 110 | + # Display the plot |
| 111 | + plt.show() |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +if __name__ == '__main__': |
| 116 | + run() |
0 commit comments