forked from henryzh/3D_NVM_Tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutputDriver.cpp
272 lines (238 loc) · 9.24 KB
/
OutputDriver.cpp
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
//Copyright (c) 2015-2016, UT-Battelle, LLC. See LICENSE file in the top-level directory
// This file contains code from NVSim, (c) 2012-2013, Pennsylvania State University
//and Hewlett-Packard Company. See LICENSE_NVSim file in the top-level directory.
//No part of DESTINY Project, including this file, may be copied,
//modified, propagated, or distributed except according to the terms
//contained in the LICENSE file.
#include "OutputDriver.h"
#include "global.h"
#include "formula.h"
#include <math.h>
OutputDriver::OutputDriver() : FunctionUnit(){
initialized = false;
invalid = false;
}
OutputDriver::~OutputDriver() {
// TODO Auto-generated destructor stub
}
void OutputDriver::Initialize(double _logicEffort, double _inputCap, double _outputCap, double _outputRes,
bool _inv, BufferDesignTarget _areaOptimizationLevel, double _minDriverCurrent) {
if (initialized)
cout << "[Output Driver] Warning: Already initialized!" << endl;
logicEffort = _logicEffort;
inputCap = _inputCap;
outputCap = _outputCap;
outputRes = _outputRes;
inv = _inv;
areaOptimizationLevel = _areaOptimizationLevel;
minDriverCurrent = _minDriverCurrent;
double minNMOSDriverWidth = minDriverCurrent / tech->currentOnNmos[inputParameter->temperature - 300];
minNMOSDriverWidth = MAX(MIN_NMOS_SIZE * tech->featureSize, minNMOSDriverWidth);
if (minNMOSDriverWidth > inputParameter->maxNmosSize * tech->featureSize) {
invalid = true;
return;
}
int optimalNumStage;
if (areaOptimizationLevel == latency_first) {
double F = MAX(1, logicEffort * outputCap / inputCap); /* Total logic effort */
optimalNumStage = MAX(0, (int)(log(F) / log(OPT_F) + 0.5) - 1);
if ((optimalNumStage % 2) ^ inv) /* If odd, add 1 */
optimalNumStage += 1;
if (optimalNumStage > MAX_INV_CHAIN_LEN) {/* Exceed maximum stages */
if (WARNING)
cout << "[WARNING] Exceed maximum inverter chain length!" << endl;
optimalNumStage = MAX_INV_CHAIN_LEN;
}
numStage = optimalNumStage;
double f = pow(F, 1.0 / (optimalNumStage + 1)); /* Logic effort per stage */
double inputCapLast = outputCap / f;
widthNMOS[optimalNumStage-1] = MAX(MIN_NMOS_SIZE * tech->featureSize,
inputCapLast / CalculateGateCap(1/*meter*/, *tech) / (1.0 + tech->pnSizeRatio));
if (widthNMOS[optimalNumStage-1] > inputParameter->maxNmosSize * tech->featureSize) {
if (WARNING)
cout << "[WARNING] Exceed maximum NMOS size!" << endl;
widthNMOS[optimalNumStage-1] = inputParameter->maxNmosSize * tech->featureSize;
/* re-Calculate the logic effort */
double capLastStage = CalculateGateCap((1 + tech->pnSizeRatio) * inputParameter->maxNmosSize * tech->featureSize, *tech);
F = logicEffort * capLastStage / inputCap;
f = pow(F, 1.0 / (optimalNumStage));
}
if (widthNMOS[optimalNumStage-1] < minNMOSDriverWidth) {
/* the last level Inv can not provide minimum current so that the Inv chain can't only decided by Logic Effort */
areaOptimizationLevel = latency_area_trade_off;
} else {
widthPMOS[optimalNumStage-1] = widthNMOS[optimalNumStage-1] * tech->pnSizeRatio;
for (int i = optimalNumStage-2; i >= 0; i--) {
widthNMOS[i] = widthNMOS[i+1] / f;
if (widthNMOS[i] < MIN_NMOS_SIZE * tech->featureSize) {
if (WARNING)
cout << "[WARNING] Exceed minimum NMOS size!" << endl;
widthNMOS[i] = MIN_NMOS_SIZE * tech->featureSize;
}
widthPMOS[i] = widthNMOS[i] * tech->pnSizeRatio;
}
}
}
if (areaOptimizationLevel == latency_area_trade_off){
double newOutputCap = CalculateGateCap(minNMOSDriverWidth, *tech) * (1.0 + tech->pnSizeRatio);
double F = MAX(1, logicEffort * newOutputCap / inputCap); /* Total logic effort */
optimalNumStage = MAX(0, (int)(log(F) / log(OPT_F) + 0.5) - 1);
if (!((optimalNumStage % 2) ^ inv)) /* If even, add 1 */
optimalNumStage += 1;
if (optimalNumStage > MAX_INV_CHAIN_LEN) {/* Exceed maximum stages */
if (WARNING)
cout << "[WARNING] Exceed maximum inverter chain length!" << endl;
optimalNumStage = MAX_INV_CHAIN_LEN;
}
numStage = optimalNumStage + 1;
widthNMOS[optimalNumStage] = minNMOSDriverWidth;
widthPMOS[optimalNumStage] = widthNMOS[optimalNumStage] * tech->pnSizeRatio;
double f = pow(F, 1.0 / (optimalNumStage + 1)); /* Logic effort per stage */
for (int i = optimalNumStage - 1; i >= 0; i--) {
widthNMOS[i] = widthNMOS[i+1] / f;
if (widthNMOS[i] < MIN_NMOS_SIZE * tech->featureSize) {
if (WARNING)
cout << "[WARNING] Exceed minimum NMOS size!" << endl;
widthNMOS[i] = MIN_NMOS_SIZE * tech->featureSize;
}
widthPMOS[i] = widthNMOS[i] * tech->pnSizeRatio;
}
} else if (areaOptimizationLevel == area_first) {
optimalNumStage = 1;
numStage = 1;
widthNMOS[optimalNumStage - 1] = MAX(MIN_NMOS_SIZE * tech->featureSize, minNMOSDriverWidth);
if (widthNMOS[optimalNumStage - 1] > AREA_OPT_CONSTRAIN * inputParameter->maxNmosSize * tech->featureSize) {
invalid = true;
return;
}
widthPMOS[optimalNumStage - 1] = widthNMOS[optimalNumStage - 1] * tech->pnSizeRatio;
}
/* Restore the original buffer design style */
areaOptimizationLevel = _areaOptimizationLevel;
initialized = true;
}
void OutputDriver::CalculateArea() {
if (!initialized) {
cout << "[Output Driver] Error: Require initialization first!" << endl;
} else if (invalid) {
height = width = area = invalid_value;
} else {
double totalHeight = 0;
double totalWidth = 0;
double h, w;
for (int i = 0; i < numStage; i++) {
CalculateGateArea(INV, 1, widthNMOS[i], widthPMOS[i], tech->featureSize*40, *tech, &h, &w);
totalHeight = MAX(totalHeight, h);
totalWidth += w;
}
height = totalHeight;
width = totalWidth;
area = height * width;
}
}
void OutputDriver::CalculateRC() {
if (!initialized) {
cout << "[Output Driver] Error: Require initialization first!" << endl;
} else if (invalid) {
; // nothing to do if invalid
} else if (numStage == 0) {
capInput[0] = 0;
} else {
for (int i = 0; i < numStage; i++) {
CalculateGateCapacitance(INV, 1, widthNMOS[i], widthPMOS[i], tech->featureSize * MAX_TRANSISTOR_HEIGHT, *tech, &(capInput[i]), &(capOutput[i]));
}
}
}
void OutputDriver::CalculateLatency(double _rampInput) {
if (!initialized) {
cout << "[Output Driver] Error: Require initialization first!" << endl;
} else if (invalid) {
readLatency = writeLatency = invalid_value;
} else {
rampInput = _rampInput;
double resPullDown;
double capLoad;
double tr; /* time constant */
double gm; /* transconductance */
double beta; /* for horowitz calculation */
double temp;
readLatency = 0;
for (int i = 0; i < numStage - 1; i++) {
resPullDown = CalculateOnResistance(widthNMOS[i], NMOS, inputParameter->temperature, *tech);
capLoad = capOutput[i] + capInput[i+1];
tr = resPullDown * capLoad;
gm = CalculateTransconductance(widthNMOS[i], NMOS, *tech);
beta = 1 / (resPullDown * gm);
readLatency += horowitz(tr, beta, rampInput, &temp);
rampInput = temp; /* for next stage */
}
/* Last level inverter */
resPullDown = CalculateOnResistance(widthNMOS[numStage-1], NMOS, inputParameter->temperature, *tech);
capLoad = capOutput[numStage-1] + outputCap;
tr = resPullDown * capLoad + outputCap * outputRes / 2;
gm = CalculateTransconductance(widthNMOS[numStage-1], NMOS, *tech);
beta = 1 / (resPullDown * gm);
readLatency += horowitz(tr, beta, rampInput, &rampOutput);
rampInput = _rampInput;
writeLatency = readLatency;
}
}
void OutputDriver::CalculatePower() {
if (!initialized) {
cout << "[Output Driver] Error: Require initialization first!" << endl;
} else if (invalid) {
readDynamicEnergy = writeDynamicEnergy = leakage = invalid_value;
} else {
/* Leakage power */
leakage = 0;
for (int i = 0; i < numStage; i++) {
leakage += CalculateGateLeakage(INV, 1, widthNMOS[i], widthPMOS[i], inputParameter->temperature, *tech)
* tech->vdd;
}
/* Dynamic energy */
readDynamicEnergy = 0;
double capLoad;
for (int i = 0; i < numStage - 1; i++) {
capLoad = capOutput[i] + capInput[i+1];
readDynamicEnergy += capLoad * tech->vdd * tech->vdd;
}
capLoad = capOutput[numStage-1] + outputCap; /* outputCap here means the final load capacitance */
readDynamicEnergy += capLoad * tech->vdd * tech->vdd;
writeDynamicEnergy = readDynamicEnergy;
}
}
void OutputDriver::PrintProperty() {
cout << "Output Driver Properties:" << endl;
FunctionUnit::PrintProperty();
cout << "Number of inverter stage: " << numStage << endl;
}
OutputDriver & OutputDriver::operator=(const OutputDriver &rhs) {
height = rhs.height;
width = rhs.width;
area = rhs.area;
readLatency = rhs.readLatency;
writeLatency = rhs.writeLatency;
readDynamicEnergy = rhs.readDynamicEnergy;
writeDynamicEnergy = rhs.writeDynamicEnergy;
resetLatency = rhs.resetLatency;
setLatency = rhs.setLatency;
resetDynamicEnergy = rhs.resetDynamicEnergy;
setDynamicEnergy = rhs.setDynamicEnergy;
cellReadEnergy = rhs.cellReadEnergy;
cellSetEnergy = rhs.cellSetEnergy;
cellResetEnergy = rhs.cellResetEnergy;
leakage = rhs.leakage;
initialized = rhs.initialized;
invalid = rhs.invalid;
logicEffort = rhs.logicEffort;
inputCap = rhs.inputCap;
outputCap = rhs.outputCap;
outputRes = rhs.outputRes;
inv = rhs.inv;
numStage = rhs.numStage;
areaOptimizationLevel = rhs.areaOptimizationLevel;
minDriverCurrent = rhs.minDriverCurrent;
rampInput = rhs.rampInput;
rampOutput = rhs.rampOutput;
return *this;
}