1 | import os |
---|
2 | import sys |
---|
3 | import time |
---|
4 | import itertools |
---|
5 | import matplotlib.pyplot as plt |
---|
6 | import matplotlib.ticker as ticks |
---|
7 | import math |
---|
8 | from scipy import stats as st |
---|
9 | import numpy as np |
---|
10 | from enum import Enum |
---|
11 | from statistics import median |
---|
12 | |
---|
13 | import matplotlib |
---|
14 | matplotlib.use("pgf") |
---|
15 | matplotlib.rcParams.update({ |
---|
16 | "pgf.texsystem": "pdflatex", |
---|
17 | 'font.family': 'serif', |
---|
18 | 'text.usetex': True, |
---|
19 | 'pgf.rcfonts': False, |
---|
20 | 'font.size': 16 |
---|
21 | }) |
---|
22 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' )) |
---|
23 | |
---|
24 | readfile = open(sys.argv[1], "r") |
---|
25 | |
---|
26 | machineName = "" |
---|
27 | |
---|
28 | if len(sys.argv) > 2: |
---|
29 | machineName = sys.argv[2] |
---|
30 | |
---|
31 | # first line has num times per experiment |
---|
32 | line = readfile.readline() |
---|
33 | numTimes = int(line) |
---|
34 | |
---|
35 | # second line has processor args |
---|
36 | line = readfile.readline() |
---|
37 | procs = [] |
---|
38 | for val in line.split(): |
---|
39 | procs.append(int(val)) |
---|
40 | |
---|
41 | # 3rd line has processor for side_chan bench |
---|
42 | line = readfile.readline() |
---|
43 | sideChanProcs = [] |
---|
44 | for val in line.split(): |
---|
45 | sideChanProcs.append(int(val)) |
---|
46 | |
---|
47 | # 4th line has number of variants |
---|
48 | line = readfile.readline() |
---|
49 | names = line.split() |
---|
50 | numVariants = len(names) |
---|
51 | |
---|
52 | lines = (line.rstrip() for line in readfile) # All lines including the blank ones |
---|
53 | lines = (line for line in lines if line) # Non-blank lines |
---|
54 | |
---|
55 | def sci_format(x, pos): |
---|
56 | return '{:.1e}'.format(x).replace('+0', '') |
---|
57 | |
---|
58 | def sci_format_label(x): |
---|
59 | return '{:.2e}'.format(x).replace('+0', '') |
---|
60 | |
---|
61 | class Bench(Enum): |
---|
62 | Unset = 0 |
---|
63 | Contend2 = 1 |
---|
64 | Contend4 = 2 |
---|
65 | Contend8 = 3 |
---|
66 | Spin2 = 4 |
---|
67 | Spin4 = 5 |
---|
68 | Spin8 = 6 |
---|
69 | SideChan = 7 |
---|
70 | Future = 8 |
---|
71 | Order = 9 |
---|
72 | |
---|
73 | nameSet = False |
---|
74 | currBench = Bench.Unset # default val |
---|
75 | count = 0 |
---|
76 | procCount = 0 |
---|
77 | currVariant = 0 |
---|
78 | name = "" |
---|
79 | title = "" |
---|
80 | experiment_duration = 10.0 |
---|
81 | var_name = "" |
---|
82 | future_variants=["CFA", "uC++"] |
---|
83 | future_names=["OR", "AND", "AND-OR", "OR-AND"] |
---|
84 | future_data=[[0.0 for i in range(len(future_names))] for j in range(2)] |
---|
85 | future_bars=[[[0.0 for i in range(len(future_names))],[0.0 for k in range(len(future_names))]] for j in range(2)] |
---|
86 | curr_future=0 |
---|
87 | sendData = [0.0 for j in range(numVariants)] |
---|
88 | data = [[0.0 for i in range(len(procs))] for j in range(numVariants)] |
---|
89 | bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)] |
---|
90 | sideData = [[0.0 for i in range(len(sideChanProcs))] for j in range(numVariants)] |
---|
91 | sideBars = [[[0.0 for i in range(len(sideChanProcs))],[0.0 for k in range(len(sideChanProcs))]] for j in range(numVariants)] |
---|
92 | tempData = [0.0 for i in range(numTimes)] |
---|
93 | orderData = [0.0 for i in range(numVariants)] |
---|
94 | for idx, line in enumerate(lines): |
---|
95 | # print(line) |
---|
96 | |
---|
97 | if currBench == Bench.Unset: |
---|
98 | if line == "contend2:": |
---|
99 | name = "Contend_2" |
---|
100 | title = "2 Clause Contend" |
---|
101 | currBench = Bench.Contend2 |
---|
102 | elif line == "contend4:": |
---|
103 | name = "Contend_4" |
---|
104 | title = "4 Clause Contend" |
---|
105 | currBench = Bench.Contend4 |
---|
106 | elif line == "contend8:": |
---|
107 | name = "Contend_8" |
---|
108 | title = "8 Clause Contend" |
---|
109 | currBench = Bench.Contend8 |
---|
110 | elif line == "spin2:": |
---|
111 | name = "Spin_2" |
---|
112 | title = "2 Clause Spin" |
---|
113 | currBench = Bench.Spin2 |
---|
114 | elif line == "spin4:": |
---|
115 | name = "Spin_4" |
---|
116 | title = "4 Clause Spin" |
---|
117 | currBench = Bench.Spin4 |
---|
118 | elif line == "spin8:": |
---|
119 | name = "Spin_8" |
---|
120 | title = "8 Clause Spin" |
---|
121 | currBench = Bench.Spin8 |
---|
122 | elif line == "sidechan:": |
---|
123 | name = "Sidechan" |
---|
124 | currBench = Bench.SideChan |
---|
125 | elif line[0:6] == "future": |
---|
126 | name = "Future" |
---|
127 | title = "Future Synchronization" |
---|
128 | currBench = Bench.Future |
---|
129 | elif line == "order:": |
---|
130 | name = "order" |
---|
131 | currBench = Bench.Order |
---|
132 | else: |
---|
133 | print("Expected benchmark name") |
---|
134 | print("Line: " + line) |
---|
135 | sys.exit() |
---|
136 | continue |
---|
137 | |
---|
138 | if line[0:5] == "cores": |
---|
139 | continue |
---|
140 | |
---|
141 | if not nameSet: |
---|
142 | nameSet = True |
---|
143 | continue |
---|
144 | |
---|
145 | lineArr = line.split() |
---|
146 | tempData[count] = float(lineArr[-1]) / experiment_duration |
---|
147 | count += 1 |
---|
148 | |
---|
149 | if currBench == Bench.Future: |
---|
150 | if count == numTimes: |
---|
151 | currMedian = median( tempData ) |
---|
152 | future_data[currVariant][curr_future] = currMedian |
---|
153 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData)) |
---|
154 | future_bars[currVariant][0][curr_future] = currMedian - lower |
---|
155 | future_bars[currVariant][1][curr_future] = upper - currMedian |
---|
156 | count = 0 |
---|
157 | nameSet = False |
---|
158 | currVariant += 1 |
---|
159 | if currVariant == 2: |
---|
160 | curr_future += 1 |
---|
161 | # reset |
---|
162 | currBench = Bench.Unset |
---|
163 | currVariant = 0 |
---|
164 | if curr_future == len(future_names): |
---|
165 | x = np.arange(len(future_names)) # the label locations |
---|
166 | width = 0.45 # the width of the bars |
---|
167 | multiplier = .5 |
---|
168 | fig, ax = plt.subplots(layout='constrained') |
---|
169 | plt.title(title + " Benchmark") |
---|
170 | plt.ylabel("Throughput (statement completions per second)") |
---|
171 | plt.xlabel("Operation") |
---|
172 | ax.yaxis.set_major_formatter(ticks.FuncFormatter(sci_format)) |
---|
173 | for idx, arr in enumerate(future_data): |
---|
174 | offset = width * multiplier |
---|
175 | rects = ax.bar(x + offset, arr, width, label=future_variants[idx], yerr=[future_bars[idx][0], future_bars[idx][1]]) |
---|
176 | # ax.bar_label(rects, padding=3, fmt='%.1e') |
---|
177 | ax.bar_label(rects, padding=3, fmt=sci_format_label) |
---|
178 | multiplier += 1 |
---|
179 | plt.xticks(x + width, future_names) |
---|
180 | |
---|
181 | ax.legend(future_variants, loc='lower right') |
---|
182 | # fig.savefig("plots/" + machineName + name + ".png") |
---|
183 | plt.savefig("plots/" + machineName + name + ".pgf") |
---|
184 | fig.clf() |
---|
185 | |
---|
186 | elif currBench == Bench.Order: |
---|
187 | if count == numTimes: |
---|
188 | currMedian = median( tempData ) |
---|
189 | orderData[currVariant] = currMedian |
---|
190 | count = 0 |
---|
191 | currVariant += 1 |
---|
192 | procCount = 0 |
---|
193 | nameSet = False |
---|
194 | if currVariant == numVariants: |
---|
195 | fileName = "data/" + machineName + "Order" |
---|
196 | f = open(fileName, 'w') |
---|
197 | f.write(" & ".join(map(lambda a: str(int(a)), orderData))) |
---|
198 | |
---|
199 | # reset |
---|
200 | currBench = Bench.Unset |
---|
201 | currVariant = 0 |
---|
202 | |
---|
203 | elif currBench == Bench.SideChan: |
---|
204 | if count == numTimes: |
---|
205 | currMedian = median( tempData ) |
---|
206 | sideData[currVariant][procCount] = currMedian |
---|
207 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData)) |
---|
208 | sideBars[currVariant][0][procCount] = currMedian - lower |
---|
209 | sideBars[currVariant][1][procCount] = upper - currMedian |
---|
210 | count = 0 |
---|
211 | procCount += 1 |
---|
212 | if procCount == len(sideChanProcs): |
---|
213 | procCount = 0 |
---|
214 | nameSet = False |
---|
215 | currVariant += 1 |
---|
216 | |
---|
217 | if currVariant == numVariants: |
---|
218 | fig, ax = plt.subplots() |
---|
219 | plt.title(name + " Benchmark") |
---|
220 | plt.ylabel("Throughput (channel operations per second)") |
---|
221 | plt.xlabel("Cores") |
---|
222 | ax.yaxis.set_major_formatter(ticks.FuncFormatter(sci_format)) |
---|
223 | for idx, arr in enumerate(sideData): |
---|
224 | plt.errorbar( sideChanProcs, arr, [sideBars[idx][0], sideBars[idx][1]], capsize=2, marker=next(marker) ) |
---|
225 | plt.xticks(sideChanProcs) |
---|
226 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' )) |
---|
227 | # plt.yscale("log") |
---|
228 | ax.legend(names) |
---|
229 | # fig.savefig("plots/" + machineName + name + ".png") |
---|
230 | plt.savefig("plots/" + machineName + name + ".pgf") |
---|
231 | fig.clf() |
---|
232 | |
---|
233 | # reset |
---|
234 | currBench = Bench.Unset |
---|
235 | currVariant = 0 |
---|
236 | else: |
---|
237 | if count == numTimes: |
---|
238 | currMedian = median( tempData ) |
---|
239 | data[currVariant][procCount] = currMedian |
---|
240 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData)) |
---|
241 | bars[currVariant][0][procCount] = currMedian - lower |
---|
242 | bars[currVariant][1][procCount] = upper - currMedian |
---|
243 | count = 0 |
---|
244 | procCount += 1 |
---|
245 | |
---|
246 | if procCount == len(procs): |
---|
247 | procCount = 0 |
---|
248 | nameSet = False |
---|
249 | currVariant += 1 |
---|
250 | |
---|
251 | if currVariant == numVariants: |
---|
252 | fig, ax = plt.subplots(layout='constrained') |
---|
253 | plt.title(title + " Benchmark") |
---|
254 | plt.ylabel("Throughput (channel operations per second)") |
---|
255 | plt.xlabel("Cores") |
---|
256 | ax.yaxis.set_major_formatter(ticks.FuncFormatter(sci_format)) |
---|
257 | for idx, arr in enumerate(data): |
---|
258 | plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) ) |
---|
259 | plt.xticks(procs) |
---|
260 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' )) |
---|
261 | # plt.yscale("log") |
---|
262 | # plt.ylim(1, None) |
---|
263 | # ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter()) |
---|
264 | # else: |
---|
265 | # plt.ylim(0, None) |
---|
266 | ax.legend(names) |
---|
267 | # fig.savefig("plots/" + machineName + name + ".png") |
---|
268 | plt.savefig("plots/" + machineName + name + ".pgf") |
---|
269 | fig.clf() |
---|
270 | |
---|
271 | # reset |
---|
272 | currBench = Bench.Unset |
---|
273 | currVariant = 0 |
---|