OpenASIP 2.2
Loading...
Searching...
No Matches
StrictMatchRFEstimator.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file StrictMatchRFEstimator.cc
26 *
27 * Declaration of StrictMatchRFEstimator. A RF estimation plugin that
28 * estimates data only by fetching prestored cost data of the units.
29 * It does not perform any kind of linearization etc. to try to estimate
30 * a RF that has not direct cost data in HDB.
31 *
32 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
33 * @note rating: red
34 */
36#include "Application.hh"
37#include "DataObject.hh"
38#include "Exception.hh"
39#include "HDBManager.hh"
40#include "BaseRegisterFile.hh"
41#include "ExecutionTrace.hh"
42#include "Conversion.hh"
43
44using namespace CostEstimator;
45
47public:
48 StrictMatchRFEstimator(const std::string& name) :
50 }
51
53 }
54
56 "Simple RF cost estimator plugin that estimates costs of RFs "
57 "simply by looking up direct matches from HDB. In case there's "
58 "no cost data available for the given RF, it's unable to estimate "
59 "it by using linearization etc.");
60
61public:
62
63 /**
64 * Estimates the register file's area by fetching cost data named 'area'
65 * from HDB.
66 */
68 const TTAMachine::BaseRegisterFile& /*rf*/,
70 AreaInGates& area,
71 HDB::HDBManager& hdb) {
72
73//#define DEBUG_AREA_ESTIMATION
74
75 try {
76 // simply fetch the area data of the FU, if any
77 DataObject areaFromDB = hdb.rfCostEstimationData(
78 "area", implementation.id(), name_);
79 area = areaFromDB.doubleValue();
80#ifdef DEBUG_AREA_ESTIMATION
82 << rf.name() << " area " << area << std::endl;
83#endif
84 return true;
85 } catch (const KeyNotFound&) {
86 // if no area data found, don't even try to estimate the area
87 // somehow
88 Application::logStream() << "No area data found in HDB.";
89
90 return false;
91 } catch (const Exception& e) {
92 // for example, if doubleValue() conversion failed, then it's
93 // a problem with HDB contents
95 return false;
96 }
97 return false;
98 }
99
100 /**
101 * Estimates the register file port write delay by fetching cost data
102 * named 'input_delay' from HDB.
103 *
104 * Assumes that all ports have the same input delay, that is, there is
105 * only one 'input_delay' entry for a RF in HDB.
106 */
107 bool
109 const TTAMachine::RFPort& /*port*/,
111 DelayInNanoSeconds& delay,
112 HDB::HDBManager& hdb) {
113
114//#define DEBUG_DELAY_ESTIMATION
115 try {
116 // simply fetch the delay data of the RF port, if any
117 DataObject delayFromDB = hdb.rfCostEstimationData(
118 "input_delay", implementation.id(), name_);
119 delay = delayFromDB.doubleValue();
120#ifdef DEBUG_DELAY_ESTIMATION
122 << port.name() << " write delay " << delay << std::endl;
123#endif
124 return true;
125 } catch (const KeyNotFound&) {
126 // if no data found, don't even try to estimate the area
128 << "No input_delay cost data found for RF "
129 << implementation.id() << ", plugin " << name_ << std::endl;
130 return false;
131 } catch (const Exception& e) {
132 // for example, if doubleValue() conversion failed, then it's
133 // a problem with HDB contents
135 return false;
136 }
137
138 return false;
139 }
140
141 /**
142 * Estimates the register file port read delay by fetching cost data
143 * named 'output_delay' from HDB.
144 *
145 * Assumes that all ports have the same output delay, that is, there is
146 * only one 'output_delay' entry for a RF in HDB.
147 */
148 bool
150 const TTAMachine::RFPort& /*port*/,
152 DelayInNanoSeconds& delay,
153 HDB::HDBManager& hdb) {
154
155 try {
156 // simply fetch the delay data of the RF port, if any
157 DataObject delayFromDB = hdb.rfCostEstimationData(
158 "output_delay", implementation.id(), name_);
159 delay = delayFromDB.doubleValue();
160#ifdef DEBUG_DELAY_ESTIMATION
162 << port.name() << " read delay " << delay << std::endl;
163#endif
164 return true;
165 } catch (const KeyNotFound&) {
166 // if no data found, don't even try to estimate the area
168 << "No output_delay cost data found for RF "
169 << implementation.id() << ", plugin " << name_ << std::endl;
170 return false;
171 } catch (const Exception& e) {
172 // for example, if doubleValue() conversion failed, then it's
173 // a problem with HDB contents
175 return false;
176 }
177
178 return false;
179 }
180
181 /**
182 * Estimates the register file maximum computation delay by fetching
183 * cost data named 'computation_delay' from HDB.
184 */
185 bool
187 const TTAMachine::BaseRegisterFile& /*rf*/,
189 DelayInNanoSeconds& delay,
190 HDB::HDBManager& hdb) {
191
192 try {
193 // simply fetch the delay data of the RF, if any
194 DataObject delayFromDB = hdb.rfCostEstimationData(
195 "computation_delay", implementation.id(), name_);
196 delay = delayFromDB.doubleValue();
197#ifdef DEBUG_DELAY_ESTIMATION
199 << rf.name() << " computation delay " << delay << std::endl;
200#endif
201 return true;
202 } catch (const KeyNotFound&) {
203 // if no data found, don't even try to estimate the area
205 << "No computation_delay cost data found for RF "
206 << implementation.id() << ", plugin " << name_ << std::endl;
207 return false;
208 } catch (const Exception& e) {
209 // for example, if doubleValue() conversion failed, then it's
210 // a problem with HDB contents
212 return false;
213 }
214
215 return false;
216 }
217
218 /**
219 * Estimates the energy consumed by given RF.
220 *
221 * Estimate is done by computing the sum of all register file access
222 * type energies and RF idle energy. Register file access energies are
223 * stored with entries named 'rf_access_energy Nr Nw'. Nr is the number
224 * of read accesses, Nw the number of write accesses. For example,
225 * 'rf_access_energy 1 3' is the name of entry which tells how much
226 * energy is consumed by the RF in case RF is accessed simultaneously
227 * once for reading and trice for writing. Idle energy is stored in
228 * entry 'rf_idle_energy'.
229 */
233 const TTAProgram::Program&,
234 const ExecutionTrace& trace,
235 EnergyInMilliJoules& energy,
236 HDB::HDBManager& hdb) {
237
238//#define DEBUG_ENERGY_ESTIMATION
239
240 energy = 0.0;
241 ClockCycleCount cyclesWithRFAccess = 0;
242#ifdef DEBUG_ENERGY_ESTIMATION
244 << "## register file " << rf.name() << ": " << std::endl;
245#endif
246 try {
250 const_iterator i = accessList->begin();
251 i != accessList->end(); ++i) {
252 const ExecutionTrace::ConcurrentRFAccessCount& accessCount =
253 *i;
254
255 const std::size_t reads = accessCount.get<0>();
256 const std::size_t writes = accessCount.get<1>();
257 const ClockCycleCount count = accessCount.get<2>();
258 const std::string dataName =
259 std::string("rf_access_energy ") +
260 Conversion::toString(reads) + " " +
261 Conversion::toString(writes);
262
263 try {
264 DataObject energyFromDB = hdb.rfCostEstimationData(
265 dataName, implementation.id(), name_);
266 EnergyInMilliJoules energyOfAccess =
267 energyFromDB.doubleValue()*count;
268#ifdef DEBUG_ENERGY_ESTIMATION
270 << "## reads " << accessCount.get<0>() << " "
271 << "writes " << accessCount.get<1>() << " = "
272 << energyFromDB.doubleValue() << " times "
273 << count << " = " << energyOfAccess << std::endl;
274#endif
275 energy += energyOfAccess;
276 cyclesWithRFAccess += count;
277 } catch (const KeyNotFound&) {
278 // if no data found, don't even try to estimate the area
279 delete accessList;
280 accessList = NULL;
282 << "Cost estimation data '" << dataName
283 << "' not found in HDB." << std::endl;
284 return false;
285 } catch (const Exception& e) {
286 delete accessList;
287 accessList = NULL;
289 return false;
290 }
291 }
292 delete accessList;
293 accessList = NULL;
294 } catch (const Exception& e) {
296 return false;
297 }
298
299 // add the cost of RF idling
300 const ClockCycleCount idleCycles =
301 trace.simulatedCycleCount() - cyclesWithRFAccess;
302 const std::string dataName = std::string("rf_idle_energy");
303
304 try {
305 DataObject energyFromDB = hdb.rfCostEstimationData(
306 dataName, implementation.id(), name_);
307 EnergyInMilliJoules idleEnergy =
308 energyFromDB.doubleValue()*idleCycles;
309#ifdef DEBUG_ENERGY_ESTIMATION
311 << "## idle energy " << energyFromDB.doubleValue() << " times "
312 << idleCycles << " = " << idleEnergy << std::endl;
313
314#endif
315 energy += idleEnergy;
316
317 } catch (const KeyNotFound&) {
318 // if no data found, don't even try to estimate the area
320 << "Cost estimation data '" << dataName
321 << "' not found in HDB." << std::endl;
322 return false;
323 } catch (const Exception& e) {
325 return false;
326 }
327
328 return true;
329 }
330
331
332};
333
#define debugLog(text)
ExecutionTrace * trace
the execution trace database
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
#define EXPORT_RF_COST_ESTIMATOR_PLUGIN(PLUGIN_NAME__)
CycleCount ClockCycleCount
Alias for ClockCycleCount.
static std::ostream & logStream()
static std::string toString(const T &source)
std::string name_
the name of the plugin class in the HDB; used to identify cost data
virtual double doubleValue() const
std::string errorMessage() const
Definition Exception.cc:123
std::list< ConcurrentRFAccessCount > ConcurrentRFAccessCountList
type to be used for a list of concurrent RF accesses
boost::tuple< RegisterAccessCount, RegisterAccessCount, ClockCycleCount > ConcurrentRFAccessCount
type to be used as a key for storing concurrent RF access info
ClockCycleCount simulatedCycleCount() const
ConcurrentRFAccessCountList * registerFileAccessCounts(RegisterFileID registerFile) const
DataObject rfCostEstimationData(const std::string &valueName, RowID implementationId, const std::string &pluginName) const
bool estimateEnergy(const TTAMachine::BaseRegisterFile &rf, const IDF::RFImplementationLocation &implementation, const TTAProgram::Program &, const ExecutionTrace &trace, EnergyInMilliJoules &energy, HDB::HDBManager &hdb)
StrictMatchRFEstimator(const std::string &name)
bool estimateArea(const TTAMachine::BaseRegisterFile &, const IDF::RFImplementationLocation &implementation, AreaInGates &area, HDB::HDBManager &hdb)
DESCRIPTION("Simple RF cost estimator plugin that estimates costs of RFs " "simply by looking up direct matches from HDB. In case there's " "no cost data available for the given RF, it's unable to estimate " "it by using linearization etc.")
bool estimatePortWriteDelay(const TTAMachine::RFPort &, const IDF::RFImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
bool estimatePortReadDelay(const TTAMachine::RFPort &, const IDF::RFImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
bool estimateMaximumComputationDelay(const TTAMachine::BaseRegisterFile &, const IDF::RFImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
virtual TCEString name() const
double AreaInGates
type for area values in equivalent gates
double DelayInNanoSeconds
type for propagation delays in nano seconds
double EnergyInMilliJoules
type for consumed energy in milli joules