-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
202 lines (154 loc) · 6.9 KB
/
Copy pathplot.py
File metadata and controls
202 lines (154 loc) · 6.9 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import matplotlib.pyplot as plt
import numpy as np
import h5py
import argparse
import os
def get_data(path, l2, l1, cycles):
files = os.listdir(path)
print(files)
cores = []
data = []
for file in files:
print('File:', os.path.join(path, file))
f = h5py.File(os.path.join(path, file), 'r')
dset = f["stats"]["root"]
count = 0
for i in range(len(dset[-1]['wimpy'])-1, -1, -1):
if dset[-1]['wimpy'][i]['cycles'] == 0:
count +=1
else:
break
print('Number of used cores:', len(dset[-1]['wimpy'])-count)
cores.append(len(dset[-1]['wimpy'])-count)
current_data = []
for string in l2:
try:
current_data.append(np.sum(dset[-1]['l2_wimpy'][string]))
except:
current_data.append(0)
for string in l1:
try:
print(f"caught {string}")
current_data.append(np.sum(dset[-1]['l1d_wimpy'][string]))
except:
print(f"except {string}")
current_data.append(0)
if cycles:
used_cores = dset[-1]['wimpy'][:len(dset[-1]['wimpy'])-count]
current_data.append(np.average(used_cores['cycles']))
print(current_data)
data.append(current_data)
return data, cores
def create_bar_graph(coup_path, regular_path, name, l2, l1, cycles):
script_dir = os.path.dirname(os.path.abspath(__file__))
coup_path = os.path.join(script_dir, coup_path)
regular_path = os.path.join(script_dir, regular_path)
if not os.path.exists(coup_path):
print(coup_path, 'was not reconized as a path')
return
if not os.path.exists(regular_path):
print(regular_path, 'was not reconized as a path')
return
if(not os.path.exists('plots')):
os.mkdir('plots')
coup_data, coup_cores = get_data(coup_path, l2, l1, cycles)
regular_data, regular_cores = get_data(regular_path, l2, l1, cycles)
sorted_index = np.argsort(coup_cores)
coup_cores = [coup_cores[i] for i in sorted_index]
coup_data = [coup_data[i] for i in sorted_index]
sorted_index = np.argsort(regular_cores)
regular_cores = [regular_cores[i] for i in sorted_index]
regular_data = [regular_data[i] for i in sorted_index]
# l2 data
for k in range(len(l2)):
fig = plt.figure()
fig.suptitle(name+' '+l2[k], fontsize=16)
ax = fig.add_subplot(111)
cData = [coup_data[j][k] for j in range(len(coup_data))]
rData = [regular_data[j][k] for j in range(len(regular_data))]
ax.plot(coup_cores, cData, label='coup') # Plot the chart
ax.plot(regular_cores, rData, label='regular') # Plot the chart
ax.set_xlabel('Number of cores')
ax.set_ylabel('Count')
ax.set_xticks(regular_cores)
fig.legend(loc=2, prop={'size': 8})
print('should be saving a file')
fig.tight_layout()
fig.savefig('plots/l2_'+name+'_'+l2[k]+".png", format='png', dpi=600)
# L1 data
ik = 0
while ik < len(l1):
i = len(l2) + ik
fig = plt.figure()
fig.suptitle(name+' '+l1[ik], fontsize=16)
ax = fig.add_subplot(111)
cData = [coup_data[j][i] for j in range(len(coup_data))]
rData = [regular_data[j][i] for j in range(len(regular_data))]
ax.plot(coup_cores, cData, label='coup') # Plot the chart
ax.plot(regular_cores, rData, label='regular') # Plot the chart
ax.set_xticks(regular_cores)
fig.legend(loc=2, prop={'size': 8})
ax.set_xlabel('Number of cores')
ax.set_ylabel('Count')
print('should be saving a file')
fig.tight_layout()
fig.savefig('plots/l1_'+name+'_'+l1[ik]+".png", format='png', dpi=600)
ik+=1
#check if cycles graph should be made
if cycles:
i = len(l1) + len(l2)
fig = plt.figure()
fig.suptitle(name+' Average Cycles', fontsize=16)
ax = fig.add_subplot(111)
Data = [regular_data[j][i]/coup_data[j][i] for j in range(len(coup_data))]
ax.plot(coup_cores, Data) # Plot the chart
ax.set_xticks(regular_cores)
ax.set_xlabel('Number of cores')
ax.set_ylabel('Speedup')
print('should be saving a file')
fig.tight_layout()
fig.savefig('plots/l1_'+name+'_Average Cycles'+".png", format='png', dpi=600)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("coup", help="The relative path to the folder with the coup stats h5 files", type=str)
parser.add_argument("regular", help="The relative path to the folder with the non-coup stats h5 files", type=str)
parser.add_argument("name", help="Name that the png that will be created", type=str)
parser.add_argument("-l2", nargs='+', help="all the l2 arguments you want to make graphs for")
parser.add_argument("-l1", nargs='+', help="all the l1 arguments you want to make graphs for")
parser.add_argument("-average_cycles", help="Do you have to make a graph comaring average cycles", type=bool)
args = parser.parse_args()
create_bar_graph(args.coup, args.regular, args.name, args.l2, args.l1, args.average_cycles)
# i = 0
# for j, core in enumerate(coup_cores):
# if coup_cores[j] != regular_cores[j]:
# print("Benchmarks don't have the same cores")
# ax.bar(i, coup_data[j], color='C'+str(1))
# i +=1
# ax.bar(i, regular_data[j], color='C'+str(2))
# i+=2
# def create_fig(cCores, rCores, cData, rData, index, ax):
# #ax.title.set_text(data_labels[index%3])
# cData = [cData[i][index] for i in range(len(cData))]
# rData = [rData[i][index] for i in range(len(rData))]
# ax.plot(cCores, cData, label='coup') # Plot the chart
# ax.plot(rCores, rData, label='regular') # Plot the chart
# ax.set_xticks(cCores, rCores)
# ax.legend(loc=2, prop={'size': 8})
# return
# print('coup data and cores')
# print(coup_data, coup_cores)
# print('regular data and cores')
# print(regular_data, regular_cores)
# row = int(len(data)/2)
# col = len(data) - row
# axs = fig.subplots(1, len(data))
#
# axs[i].title.set_text(data[i])
# cData = [coup_data[j][i] for j in range(len(coup_data))]
# rData = [regular_data[j][i] for j in range(len(regular_data))]
# axs[i].plot(coup_cores, cData, label='coup') # Plot the chart
# axs[i].plot(regular_cores, rData, label='regular') # Plot the chart
# print(coup_cores, regular_cores)
# axs[i].set_xticks(regular_cores)
# axs[i].legend(loc=2, prop={'size': 8})
# axs[i].set_box_aspect(1)