forked from hclhkbu/NV-DVFS-Benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
energy_saving.py
193 lines (159 loc) · 7.27 KB
/
energy_saving.py
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
import pandas as pd
import numpy as np
import sys,os
import random
from settings import *
def energy_const(gpu, version):
csv_file = "csvs/analytical/results/%s-%s-qiang2018-dvfs.csv" % (gpu, version)
perf_data = pd.read_csv(csv_file, header = 0)
csv_file = "csvs/ml/%s-%s-xgboost-Power.csv" % (gpu, version)
pow_data = pd.read_csv(csv_file, header = 0)
if gpu == 'gtx980-low-dvfs':
GPUCONF = GTX980('low')
elif gpu == 'gtx1080ti-dvfs':
GPUCONF = GTX1080TI()
elif gpu == 'p100-dvfs':
GPUCONF = P100()
elif gpu == 'v100-dvfs':
GPUCONF = V100()
energy_data = pd.DataFrame([])
kernelset = perf_data['kernel'].drop_duplicates().reset_index(drop=True)
#print kernelset
coref_set = perf_data['coreF'].drop_duplicates().reset_index(drop=True)
memf_set = perf_data['memF'].drop_duplicates().reset_index(drop=True)
default_perf = perf_data[(perf_data['coreF'] == GPUCONF.CORE_FREQ) & (perf_data['memF'] == GPUCONF.MEM_FREQ)]
default_pow = pow_data[(pow_data['coreF'] == GPUCONF.CORE_FREQ) & (pow_data['memF'] == GPUCONF.MEM_FREQ)]
#print default_perf
#print default_pow
for coref in coref_set:
for memf in memf_set:
energy = []
for app in kernelset:
dPerf = default_perf[default_perf['kernel'] == app]["real"].tolist()[0] * 1.0e-6 / GPUCONF.CORE_FREQ
dPow = default_pow[default_pow['appName'] == app]["avg_power"].tolist()[0]
cPerf = perf_data[(perf_data['coreF'] == coref) & (perf_data['memF'] == memf) & (perf_data['kernel'] == app)]["real"].tolist()[0] * 1.0e-6 / coref
cPow = pow_data[(pow_data['coreF'] == coref) & (pow_data['memF'] == memf) & (pow_data['appName'] == app)]["avg_power"].tolist()[0]
#print app, coref, memf, dPerf, dPow, cPerf, cPow
curE = cPerf * cPow / (dPerf * dPow)
if (cPerf < dPerf) or (cPow > dPow):
energy.append(1.0)
else:
energy.append(curE)
#print coref, memf, "average energy:", np.mean(energy)
print coref, memf, "average saving:", np.mean([1.0 - item for item in energy])
def energy_best(gpu, version):
csv_file = "csvs/analytical/results/%s-%s-qiang2018-dvfs.csv" % (gpu, version)
perf_data = pd.read_csv(csv_file, header = 0)
csv_file = "csvs/ml/%s-%s-xgboost-Power.csv" % (gpu, version)
pow_data = pd.read_csv(csv_file, header = 0)
if gpu == 'gtx980-low-dvfs':
GPUCONF = GTX980('low')
elif gpu == 'gtx1080ti-dvfs':
GPUCONF = GTX1080TI()
elif gpu == 'p100-dvfs':
GPUCONF = P100()
elif gpu == 'v100-dvfs':
GPUCONF = V100()
energy_data = pd.DataFrame([])
kernelset = perf_data['kernel'].drop_duplicates().reset_index(drop=True)
#print kernelset
energy_data['appName'] = kernelset
energy_data['defaultE'] = None
energy_data['bestE'] = None
energy_data['bestC'] = None
energy_data['bestM'] = None
energy_data['predictE'] = None
energy_data['predictC'] = None
energy_data['predictM'] = None
perf_change = []
perf_dropoff = []
energy_perf_save = []
full_comp = []
full_mem = []
lack_wait = []
lack_no_wait = []
for idx, item in energy_data.iterrows():
cur_app = item.appName
cur_perf = perf_data[perf_data['kernel'] == cur_app]
cur_pow = pow_data[pow_data['appName'] == cur_app]
cur_perf = cur_perf.sort_values(by = ['kernel', 'coreF', 'memF']).reset_index(drop=True)
cur_pow = cur_pow.sort_values(by = ['appName', 'coreF', 'memF']).reset_index(drop=True)
#if cur_app == 'convolutionTexture':
# print cur_perf
# print cur_pow
cur_perf.real = cur_perf.real / 1.0e6 / cur_perf.coreF
cur_perf.predict = cur_perf.predict / 1.0e6 / cur_perf.coreF
measureE = cur_perf.real * cur_pow.avg_power
modelledE = cur_perf.predict * cur_pow.modelled_power
#print measureE
#print modelledE
defaultE_idx = cur_perf.index[(cur_perf['coreF'] == GPUCONF.CORE_FREQ) & (cur_perf['memF'] == GPUCONF.MEM_FREQ)].tolist()[0]
default_type = cur_perf.loc[defaultE_idx, 'type']
defaultE = measureE[defaultE_idx]
# get default performance
defaultPerf = cur_perf.real[defaultE_idx]
bestE = min(measureE)
bestE_idx = np.argmin(measureE)
bestC = cur_perf.loc[bestE_idx, 'coreF']
bestM = cur_perf.loc[bestE_idx, 'memF']
predictE_idx = np.argmin(modelledE)
predictC = cur_perf.loc[predictE_idx, 'coreF']
predictM = cur_perf.loc[predictE_idx, 'memF']
#predictE = min(modelledE)
predictE = measureE[predictE_idx]
predictPerf = cur_perf.real[predictE_idx]
item['defaultE'] = 1
item['bestE'] = bestE / defaultE
item['bestC'] = bestC
item['bestM'] = bestM
if predictE <= defaultE:
item['predictE'] = predictE / defaultE
else:
item['predictE'] = 1.0
item['predictC'] = predictC
item['predictM'] = predictM
#print cur_app, "best core freq.:", predictC, "best mem freq.:", predictM
#print cur_app, "best core freq.:", bestC, "best mem freq.:", bestM
print cur_app, "default type:", default_type
if default_type == "FULL_COMP":
full_comp.append(1 - item['predictE'])
elif default_type == 'FULL_MEM':
full_mem.append(1 - item['predictE'])
elif default_type == 'LACK_WAIT':
lack_wait.append(1 - item['predictE'])
elif default_type == 'LACK_NO_WAIT':
lack_no_wait.append(1 - item['predictE'])
#print cur_app, ":", predictPerf / defaultPerf - 1
if (predictPerf / defaultPerf - 1) <= 0.1:
if predictPerf <= defaultPerf:
#energy_perf_save.append(0.0)
#perf_dropoff.append(0.0)
pass
else:
energy_perf_save.append(1 - predictE / defaultE)
perf_dropoff.append(predictPerf / defaultPerf - 1)
#else:
# energy_perf_save.append(0.0)
# perf_dropoff.append(0.0)
perf_change.append(predictPerf / defaultPerf - 1)
#print perf_dropoff
#print energy_perf_save
print "performance changes:", perf_change
print "average dropoff:", np.mean(perf_dropoff)
print "average energy saving within 10%% performance sacrifice: %f.[max: %f]." % (np.mean(energy_perf_save), np.max(energy_perf_save))
print "FULL_COMP saving:", np.mean(full_comp)
print "FULL_MEM saving:", np.mean(full_mem)
print "LACK_WAIT saving:", np.mean(lack_wait)
print "LACK_NO_WAIT saving:", np.mean(lack_no_wait)
#print energy_data['predictE']
#print energy_data
print "average energy conservation:", np.mean(1 - energy_data['predictE']), "[max: %f]." % (1 - min(energy_data['predictE']))
if __name__ == '__main__':
#energy_best("gtx980-low-dvfs", "real-small-workload")
#energy_best("gtx1080ti-dvfs", "real")
#energy_best("p100-dvfs", "real")
energy_best("v100-dvfs", "real")
#energy_const("gtx980-low-dvfs", "real-small-workload")
#energy_const("gtx1080ti-dvfs", "real")
#energy_const("p100-dvfs", "real")
energy_const("v100-dvfs", "real")