forked from mpalesi/nocnn
-
Notifications
You must be signed in to change notification settings - Fork 2
/
estimation.h
223 lines (171 loc) · 6.2 KB
/
estimation.h
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#ifndef __ESTIMATION_H__
#define __ESTIMATION_H__
#include <vector>
#include "noc.h"
#include "cnn.h"
using namespace std;
// ----------------------------------------------------------------------
typedef struct LayerStat
{
long comm_latency;
long comp_latency;
long mmem_latency;
double comm_wired_energy;
double comm_wireless_energy;
double comm_grs_energy;
double comp_energy;
double lmem_energy;
double mmem_energy;
double lmem_energy_leakage;
double mmem_energy_leakage;
double comm_wired_energy_leakage;
double comm_wireless_energy_leakage;
double comm_grs_energy_leakage;
double comp_energy_leakage;
int active_cores;
long ops_per_core;
long main_memory_traffic_load_w;
long main_memory_traffic_load_ifm;
long main_memory_traffic_store_ofm;
void reset() {
comm_latency = 0;
comp_latency = 0;
mmem_latency = 0;
comm_wired_energy = 0.0;
comm_wireless_energy = 0.0;
comm_grs_energy = 0.0;
comp_energy = 0.0;
lmem_energy = 0.0;
mmem_energy = 0.0;
lmem_energy_leakage = 0.0;
mmem_energy_leakage = 0.0;
comm_wired_energy_leakage = 0.0;
comm_wireless_energy_leakage = 0.0;
comm_grs_energy_leakage = 0.0;
comp_energy_leakage = 0.0;
active_cores = 0;
ops_per_core = 0;
main_memory_traffic_load_w = 0;
main_memory_traffic_load_ifm = 0;
main_memory_traffic_store_ofm = 0;
}
void addLatencyComponents(TLatencyComponents lc) {
comm_latency += lc.l_comm;
mmem_latency += lc.l_mmem;
comp_latency += lc.l_comp;
}
void addEnergyComponents(TEnergyComponents ec) {
comm_wired_energy += ec.e_comm_wired;
comm_wireless_energy += ec.e_comm_wireless;
comm_grs_energy += ec.e_comm_grs;
comp_energy += ec.e_comp;
lmem_energy += ec.e_lmem;
mmem_energy += ec.e_mmem;
lmem_energy_leakage += ec.e_lmem_leakage;
mmem_energy_leakage += ec.e_mmem_leakage;
comm_wired_energy_leakage += ec.e_comm_wired_leakage;
comm_wireless_energy_leakage += ec.e_comm_wireless_leakage;
comm_grs_energy_leakage += ec.e_comm_grs_leakage;
comp_energy_leakage += ec.e_comp_leakage;
}
} TLayerStat;
typedef struct GlobalStats
{
long total_comm_latency;
long total_comp_latency;
long total_mmem_latency;
double total_comm_wired_energy;
double total_comm_wireless_energy;
double total_comm_grs_energy;
double total_comp_energy;
double total_mmem_energy;
double total_lmem_energy;
double total_mmem_energy_leakage;
double total_lmem_energy_leakage;
double total_comm_wired_energy_leakage;
double total_comm_wireless_energy_leakage;
double total_comm_grs_energy_leakage;
double total_comp_energy_leakage;
long total_main_memory_traffic_load_w;
long total_main_memory_traffic_load_ifm;
long total_main_memory_traffic_store_ofm;
vector<TLayerStat> layer_stats;
void reset() {
total_comm_latency = 0;
total_comp_latency = 0;
total_mmem_latency = 0;
total_comm_wired_energy = 0.0;
total_comm_wireless_energy = 0.0;
total_comm_grs_energy = 0.0;
total_comp_energy = 0.0;
total_mmem_energy = 0.0;
total_lmem_energy = 0.0;
total_mmem_energy_leakage = 0.0;
total_lmem_energy_leakage = 0.0;
total_comm_wired_energy_leakage = 0.0;
total_comm_wireless_energy_leakage = 0.0;
total_comm_grs_energy_leakage = 0.0;
total_comp_energy_leakage = 0.0;
total_main_memory_traffic_load_w = 0;
total_main_memory_traffic_load_ifm = 0;
total_main_memory_traffic_store_ofm = 0;
layer_stats.clear();
}
void addLayerStat(TLayerStat& ls) {
layer_stats.push_back(ls);
total_comm_latency += ls.comm_latency;
total_comp_latency += ls.comp_latency;
total_mmem_latency += ls.mmem_latency;
total_comm_wired_energy += ls.comm_wired_energy;
total_comm_wireless_energy += ls.comm_wireless_energy;
total_comm_grs_energy += ls.comm_grs_energy;
total_comp_energy += ls.comp_energy;
total_mmem_energy += ls.mmem_energy;
total_lmem_energy += ls.lmem_energy;
total_mmem_energy_leakage += ls.mmem_energy_leakage;
total_lmem_energy_leakage += ls.lmem_energy_leakage;
total_comm_wired_energy_leakage += ls.comm_wired_energy_leakage;
total_comm_wireless_energy_leakage += ls.comm_wireless_energy_leakage;
total_comm_grs_energy_leakage += ls.comm_grs_energy_leakage;
total_comp_energy_leakage += ls.comp_energy_leakage;
total_main_memory_traffic_load_w += ls.main_memory_traffic_load_w;
total_main_memory_traffic_load_ifm += ls.main_memory_traffic_load_ifm;
total_main_memory_traffic_store_ofm += ls.main_memory_traffic_store_ofm;
}
} TGlobalStats;
// ----------------------------------------------------------------------
typedef struct HistorySample
{
int nactive_cores;
int per_core_fm_size;
void setSample(int nac, long pcfms) {
nactive_cores = nac;
per_core_fm_size = pcfms;
}
} THistorySample;
// ----------------------------------------------------------------------
class Estimation
{
public:
Estimation(NoC& _noc, CNN& _cnn) : noc(_noc), cnn(_cnn) { }
bool stime(TGlobalStats& stats);
void showStats(TGlobalStats& stats);
NoC noc;
CNN cnn;
private:
bool stime(int layer_no, TLayer& layer, TLayerStat& layer_stat);
void stimeLeakage(TLayerStat& layer_stat);
void stimeConv(int layer_no, TLayer& layer, TLayerStat& layer_stat, bool depthwiseconv);
void stimeFC(int layer_no, TLayer& layer, TLayerStat& layer_stat);
void stimePool(int layer_no, TLayer& layer, TLayerStat& layer_stat);
int requiredCores(int ntasks);
void stimeLoadFeatureMap(int layer_no, TLayer& layer,
TLayerStat& layer_stat,
int nactive_cores,
bool depthwiseconv);
void stimeStoreFeatureMap(TLayer& layer, TLayerStat& layer_stat,
int nactive_cores);
void hline(int n, char c);
vector<THistorySample> history;
};
#endif