forked from Zhu-Zhenhua/MNSIM_V1.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_backup
351 lines (310 loc) · 15 KB
/
old_backup
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include<iostream>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<time.h>
#include<string>
#include"InputParameter.h"
#include"module.h"
#include"formula.h"
#include"global.h"
#include"function.h"
#include"Technology.h"
using namespace std;
InputParameter *inputParameter;
int count_my = 1;
double area,area_flags,latency,latency_multi,power_multi,power_flags,area_multi,power,energy,application,action_type,target;
double pulseposition = 0;
double cell_bit = 8;
double ** AAestrslt;
double ** AAAestrslt;
int row, row2;
//[17000][19];AAAestrslt[1100][19];
int mincount = 0;
double tech;
int err_count;
Technology *technology;
int main(int argc, char *argv[]) {
clock_t tic,toc;
tic=clock();
inputParameter = new InputParameter();
string inputFileName;
string outputFileName;
if (argc == 1) { //read configuration file
inputFileName = "SimConfig.txt";
outputFileName = "result.txt";
cout << "Default sim-config file (SimConfig.txt) is loaded" << endl;
cout << "Use default output file (result.txt)" << endl;
}
else if (argc == 2) {
inputFileName = argv[1];
cout << "User-defined sim-config file (" << inputFileName << ") is loaded" << endl;
cout << "Use default output file (result.txt)" << endl;
}
else if (argc == 3) {
inputFileName = argv[1];
outputFileName = argv[2];
cout << "User-defined sim-config file (" << inputFileName << ") is loaded" << endl;
cout << "Print output to result file (" << outputFileName << ")" << endl;
}
else {
cout << "Error: Please use the correct format as follows" << endl;
cout << " Use the default configuration: " << argv[0] << endl;
cout << " Use the customized configuration: " << argv[0] << " <.cfg file>" << endl;
exit(-1);
}
cout << endl;
//read configs & init configs
inputParameter->ReadInputParameterFromFile(inputFileName);
if (inputParameter->Application[0] == 'a' ||inputParameter->Application[0] == 'A')
application = 0;
else
application = 1;
if (inputParameter->Action_type[0] == 'c' || inputParameter->Action_type[0] == 'C') //calculate phase
action_type = 2;
else
action_type = 0;
//Behavior level estimation
//Unused part
switch (inputParameter->Target_Output[0]) {
case 'a':
target = 1;break;
case 'A':
target = 1;break;
case 'e':
target = 2;break;
case 'E':
target = 2;break;
case 'l':
target = 3;break;
case 'L':
target = 3;break;
case 'p':
target = 4;break;
case 'P':
target = 4;break;
}
technology = new Technology();
technology->Initialize(inputParameter->TranTech, HP/*inputParameter->deviceRoadmap*/);
Technology techHigh;
double alpha = 0;
if (inputParameter->TranTech > 200){ //choose the technology node and calculate the parameters
// TO-DO: technology node > 200 nm
}
else if (inputParameter->TranTech > 120) { // 120 nm < technology node <= 200 nm
techHigh.Initialize(200, HP/*inputParameter->deviceRoadmap*/);
alpha = (inputParameter->TranTech - 120.0) / 60;
}
else if (inputParameter->TranTech > 90) { // 90 nm < technology node <= 120 nm
techHigh.Initialize(120, HP/*inputParameter->deviceRoadmap*/);
alpha = (inputParameter->TranTech - 90.0) / 30;
}
else if (inputParameter->TranTech > 65) { // 65 nm < technology node <= 90 nm
techHigh.Initialize(90, HP/*inputParameter->deviceRoadmap*/);
alpha = (inputParameter->TranTech - 65.0) / 25;
}
else if (inputParameter->TranTech > 45) { // 45 nm < technology node <= 65 nm
techHigh.Initialize(65, HP/*inputParameter->deviceRoadmap*/);
alpha = (inputParameter->TranTech - 45.0) / 20;
}
else if (inputParameter->TranTech >= 32) { // 32 nm < technology node <= 45 nm
techHigh.Initialize(45, HP/*inputParameter->deviceRoadmap*/);
alpha = (inputParameter->TranTech - 32.0) / 13;
}
else if (inputParameter->TranTech >= 22) { // 22 nm < technology node <= 32 nm
techHigh.Initialize(32, HP/*inputParameter->deviceRoadmap*/);
alpha = (inputParameter->TranTech - 22.0) / 10;
}
else {
//TO-DO: technology node < 22 nm
}
technology->InterpolateWith(techHigh, alpha); //
// load tech
int tech = inputParameter->TranTech;
double minarea = 8e10;
double minenergy = 8e10;
double minpower = 8e10;
double minlatency = 8e10;
double minerr = 8e10;
//double mintarget[8]={0,0,minarea,minenergy,minlatency,minerr,minpower};
double mintarget[4]={minarea,minenergy,minlatency,minpower};
double input_err[200]={0};
row = (min(1,inputParameter->maxAdPos)-max(0,inputParameter->minAdPos)+1)*(min(16,inputParameter->maxBtLv)-max(0,inputParameter->minBtLv)+1)*(min(1,inputParameter->maxAdder)-max(0,inputParameter->minAdder)+1)*(log(inputParameter->maxXbarSize)/log(2)-log(inputParameter->minXbarSize)/log(2)+1)*128*inputParameter->AppScale+1;//*6 Decide by the size of crossbar
AAestrslt = new double* [row];
for(int i =0; i < row; i++)
AAestrslt[i] = new double [19];
for (double adposition=max(0,inputParameter->minAdPos);adposition<=min(1,inputParameter->maxAdPos);adposition++) {
for (double bit_level = max(0,inputParameter->minBtLv);(bit_level<=min(16,inputParameter->maxBtLv));bit_level++) {
for (double adderposition = max(0,inputParameter->minAdder);adderposition<=min(1,inputParameter->maxAdder);adderposition++) {
for (double linetech = 90;linetech<=90;linetech++) {//[18,22,28,36,45,65,90];
for (double celltype = 1;celltype<=1;celltype++) {
//pulseposition = 0;
for (double xbarsize = inputParameter->minXbarSize;xbarsize<=inputParameter->maxXbarSize;xbarsize*=2) {//[4,8,16,32,64,128,256]%,512,1024]
for (double read_sep = 1;read_sep<=128;read_sep++) {//xbarsize/128 : xbarsize/128 : xbarsize%8:8:xbarsize
if (xbarsize<inputParameter->minXbarSize || xbarsize > inputParameter->maxXbarSize)
cout<<"error:xbarsize over the limit"<<endl;
else
for (double netlevel = 1;netlevel<=inputParameter->AppScale;netlevel++) { //-1
if (bit_level != 0)
cell_bit = bit_level;
//calculate bandwidth
determin_sig(xbarsize,adderposition,inputParameter->sig_bit,cell_bit,adposition);
determin_net(xbarsize,inputParameter->NetScale[2*(int)netlevel-1-1],inputParameter->NetScale[2*(int)netlevel-1],signalsize);
unit_area_c(*technology,celltype,xbarsize,adposition,adderposition,pulseposition,inputParameter->sig_bit,application,inputParameter->rramtech,read_sep);
unit_latency_c(*technology,celltype,xbarsize,adposition,adderposition,pulseposition,action_type,inputParameter->sig_bit,read_sep);
unit_power_c(*technology,celltype,xbarsize,adposition,adderposition,pulseposition,action_type,inputParameter->sig_bit,application,inputParameter->maxRRang,netrow,xbar_latency,adda_latency,adder_latency,decoder_latency,write_latency,read_latency,read_sep);
periphery_area(*technology,xbarsize, netrow, netcolumn, adderposition,pulseposition,inputParameter->sig_bit,application);
periphery_latency_c( *technology,netrow, adderposition,pulseposition,inputParameter->sig_bit,application);
periphery_power_c(*technology,xbarsize, netrow, netcolumn, adderposition,pulseposition,inputParameter->sig_bit,application,adders_latency,neuron_latency,pulse_latency);
accuracy_c(xbarsize,linetech,inputParameter->sig_bit,cell_bit,inputParameter->maxRRang,input_err[(int)netlevel-1]);
input_err[(int)netlevel] = accuracy;
area = area_u * netrow * netcolumn + area_l + area_p ;//+ area_r + area_w;
//area_flags = area_flags * netrow * netcolumn;
if (adderposition == 0) {
energy = power_u * latency_u * netrow * netcolumn + power_l * latency_l + power_p * latency_p;// + power_r + power_w;
latency = latency_u + latency_l + latency_p;
latency_multi = latency_u;
}
else {
energy = power_u * latency_u * netrow * netcolumn + power_l * latency_l + power_p * latency_p;
latency = latency_u * netrow + latency_l + latency_p;
latency_multi = latency_u * netrow;
}
power_multi = power_u * netrow * netcolumn;
//power_flags = power_flags * netrow * netcolumn;
area_multi = area_u * netrow * netcolumn;
power = power_u * netrow * netcolumn + power_l + power_p ;
energy = power * latency;
equal(netlevel,area,energy,latency,power,accuracy,area_multi,power_multi,latency_multi,read_sep,adposition,bit_level,adderposition,pulseposition,linetech,celltype,xbarsize);
if (accuracy < minerr) {
minerr = accuracy;
err_count = count_my;
}
count_my = count_my + 1;
}
}
}
}
}
}
}
}
double design_space = count_my/inputParameter->AppScale;
//row2 = design_space*inputParameter->AppScale+1;
AAAestrslt = new double* [design_space];
for(int i =0; i < design_space; i++)
AAAestrslt[i] = new double [19];
for (int temp_count = 1;temp_count<=design_space;temp_count++) {
for(int netlevel_temp=1;netlevel_temp<=inputParameter->AppScale;netlevel_temp++) {
AAAestrslt[temp_count][1] = AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][1];
AAAestrslt[temp_count][2] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][2];
AAAestrslt[temp_count][3] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][3]*(inputParameter->Computation_Time[netlevel_temp-1]);
if(inputParameter->Pipeline == 0) //not pipelined
AAAestrslt[temp_count][4] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][4]*(inputParameter->Computation_Time[netlevel_temp-1]);
else if (netlevel_temp == 1)
AAAestrslt[temp_count][4] = AAestrslt[((temp_count-1) * inputParameter->AppScale + 1)][4]*(inputParameter->Computation_Time[0]);
else
AAAestrslt[temp_count][4] = (AAAestrslt[temp_count][4] > AAestrslt[((temp_count-1) * inputParameter->AppScale + netlevel_temp)][4]*(inputParameter->Computation_Time[netlevel_temp-1]))? AAAestrslt[temp_count][4] : AAestrslt[((temp_count-1) * inputParameter->AppScale + netlevel_temp)][4]*(inputParameter->Computation_Time[netlevel_temp-1]);
AAAestrslt[temp_count][5] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][5];
AAAestrslt[temp_count][6] = 0; //will update later
AAAestrslt[temp_count][7] = AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][7];
AAAestrslt[temp_count][8] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][8];
AAAestrslt[temp_count][9] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][9];
AAAestrslt[temp_count][10] += AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][10]*(inputParameter->Computation_Time[netlevel_temp-1]);
for(int i = 11;i<19;i++)
AAAestrslt[temp_count][i] = AAestrslt[((temp_count-1) * inputParameter->AppScale +netlevel_temp)][i];
}
//AAAestrslt(temp_count,3) =AAestrslt(((temp_count-1) * AppScale +1),3)*layer_computation_times(1);
//AAAestrslt[temp_count][4] = AAAestrslt[temp_count][4]/(double)inputParameter->AppScale;
//AAAestrslt[temp_count][6] = AAAestrslt[temp_count][6]/(double)inputParameter->AppScale;
//AAAestrslt[temp_count][7] = AAAestrslt[temp_count][7]/(double)inputParameter->AppScale;
//for(int i=10;i<=18;i++)
// AAAestrslt[temp_count][i] = AAAestrslt[temp_count][i]/(double)inputParameter->AppScale;
//AAAestrslt[temp_count][4] = max1(((temp_count-1) * inputParameter->AppScale+1),((temp_count-1) * inputParameter->AppScale+inputParameter->AppScale),4);
if (AAAestrslt[temp_count][target+1] < mintarget[target-1]){
mintarget[target-1] = AAAestrslt[temp_count][target+1];
mincount = temp_count;
}
/*
for (int target_tt=2;target_tt<=6;target_tt++)
if (AAAestrslt[temp_count][6]>1)
break;
else if (AAAestrslt[temp_count][target_tt] < mintarget[target_tt]) {
mintarget[target_tt] = AAAestrslt[temp_count][target_tt];
mincount[target_tt] = temp_count;
}*/
}
double optresult[17];
for (int i=1;i<6;i++)
optresult[i] = AAAestrslt[mincount][i+1];
for (int i=6;i<17;i++)
optresult[i] = AAAestrslt[mincount][i+2];
/*double optresult[10][18];
if (count_my>2) {
for(int i=2;i<=6;i++)
for(int j=2;j<=18;j++)
optresult[i-1][j-1] = AAAestrslt[mincount[i]][j];
for(int i=1;i<=5;i++)
for(int j=1;j<=3;j++)
optresult[i][j] = optresult[i][j]*1e6;*/
//unit: nm
//the data in the optresult[1,2,...] are area,energy,latency,power,accuracy,area_multi,power_multi,latency_multi,read_sep,adposition,bit_level,adderposition,pulseposition,linetech,celltype,xbarsize
ofstream fout;
fout.open(outputFileName,ios::out);
if(!fout.is_open())
cout<<"result.txt cannot be found!"<<endl;
else {
fout<<"area:"<<optresult[1][1]<<endl;
fout<<"energy:"<<optresult[1][2]<<endl;
fout<<"latency:"<<optresult[1][3]<<endl;
fout<<"power:"<<optresult[1][4]<<endl;
fout<<"accuracy:"<<optresult[1][5]<<endl;
fout<<"area_multi:"<<optresult[1][6]<<endl;
fout<<"power_multi:"<<optresult[1][7]<<endl;
fout<<"latency_multi:"<<optresult[1][8]<<endl;
fout<<"read_sep:"<<optresult[1][9]<<endl;
fout<<"adposition:"<<optresult[1][10]<<endl;
fout<<"bit_level:"<<optresult[1][11]<<endl;
fout<<"adderposition:"<<optresult[1][12]<<endl;
fout<<"pulseposition:"<<optresult[1][13]<<endl;
fout<<"linetech:"<<optresult[1][14]<<endl;
fout<<"celltype:"<<optresult[1][15]<<endl;
fout<<"xbarsize:"<<optresult[1][16]<<endl;
}
toc=clock();
cout<<"Run time: "<<(double)(toc-tic)/CLOCKS_PER_SEC<<"S"<<endl;
delete inputParameter;
delete AAestrslt;
delete AAAestrslt;
delete technology;
return 0;
}
void equal(double netlevel,double area,double energy,double latency,double power,double accuracy,double area_multi,double power_multi,double latency_multi,double read_sep,double adposition,double bit_level,double adderposition,double pulseposition,double linetech,double celltype,double xbarsize) {
AAestrslt[count_my][1] = netlevel;
AAestrslt[count_my][2] = area;
AAestrslt[count_my][3] = energy;
AAestrslt[count_my][4] = latency;
AAestrslt[count_my][5] = power;
AAestrslt[count_my][6] = accuracy;
AAestrslt[count_my][7] = d1;
AAestrslt[count_my][8] = area_multi;
AAestrslt[count_my][9] = power_multi;
AAestrslt[count_my][10] = latency_multi;
AAestrslt[count_my][11] = read_sep;
AAestrslt[count_my][12] = adposition;
AAestrslt[count_my][13] = bit_level;
AAestrslt[count_my][14] = adderposition;
AAestrslt[count_my][15] = pulseposition;
AAestrslt[count_my][16] = linetech;
AAestrslt[count_my][17] = celltype;
AAestrslt[count_my][18] = xbarsize;
}
double max1(int a,int b,int c) {
double i;
int j;
i=AAestrslt[b][4];
for(j=b;j<a;j++)
if(AAestrslt[j][4]>i)
i=AAestrslt[j][4];
return i;
}