OpenASIP 2.2
Loading...
Searching...
No Matches
InterpolatingRFEstimator.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 InterpolatingRFEstimator.cc
26 *
27 * Declaration of InterpolatingRFEstimator. A RF estimation plugin that
28 * estimates data generating cost database from the cost data stored in HDB.
29 * Estimate is interpolated if possible if no exact data values are found.
30 *
31 * @author Jari Mäntyneva 2006 (jari.mantyneva-no.spam-tut.fi)
32 * @note rating: red
33 */
35#include "Application.hh"
36#include "DataObject.hh"
37#include "Exception.hh"
38#include "HDBManager.hh"
39#include "BaseRegisterFile.hh"
40#include "RegisterFile.hh"
41#include "ExecutionTrace.hh"
42#include "CostDatabase.hh"
43#include "EntryKeyProperty.hh"
44#include "CostDBTypes.hh"
45#include "MatchType.hh"
46#include "RFArchitecture.hh"
47#include "FilterSearch.hh"
49#include "Conversion.hh"
50
51using namespace CostEstimator;
52using namespace HDB;
53using namespace TTAMachine;
54
56public:
61
63 }
64
66 "RF cost estimator plugin that estimates costs of RFs by generating"
67 "cost database from cost values of HDB and uses interpolation to "
68 "estimate the costs. In case there's no cost data available for the "
69 "given RF the plugin interpolates the estimate if possible.");
70
71public:
72
73 /**
74 * Estimates the register file's area by fetching cost data named 'area'
75 * from HDB.
76 */
79 const IDF::RFImplementationLocation& /*implementation*/,
80 AreaInGates& area,
81 HDB::HDBManager& hdb) {
82
83//#define DEBUG_AREA_ESTIMATION
84 try {
87 CostDBTypes::EntryTable::const_iterator i = results.begin();
88 area = 0.0;
89 // worst case area is returned
90 for (;i < results.end(); i++) {
91 for (int n = 0; n < (*i)->statisticsCount(); n++) {
92 if (area < (*i)->statistics(n).area()) {
93 area = (*i)->statistics(n).area();
94 }
95 }
96 }
97 } catch (Exception& e) {
98#ifdef DEBUG_AREA_ESTIMATION
99 std::cout << "Exception: " << e.name() << std::endl
100 << "Error message: " << e.errorMsg() << std::endl
101 << "File: " << e.fileName() << std::endl
102 <<" Line: " e.lineNum() << std::endl;
103#endif //DEBUG_AREA_ESTIMATION
104 return false;
105 }
106#ifdef DEBUG_AREA_ESTIMATION
108 << rf.name() << " area " << area << std::endl;
109#endif //DEBUG_AREA_ESTIMATION
110 return true;
111 }
112
113 /**
114 * Estimates the register file port write delay by fetching cost data
115 * named 'input_delay' from HDB.
116 *
117 * Assumes that all ports have the same input delay, that is, there is
118 * only one 'input_delay' entry for a RF in HDB.
119 */
120 bool
122 const TTAMachine::RFPort& port,
123 const IDF::RFImplementationLocation& /*implementation*/,
124 DelayInNanoSeconds& delay,
125 HDB::HDBManager& hdb) {
126
127//#define DEBUG_DELAY_ESTIMATION
128 try {
131
132 CostDBTypes::EntryTable::const_iterator i = results.begin();
133 delay = 0.0;
134 // worst case delay is returned
135 for (;i < results.end(); i++) {
136 for (int n = 0; n < (*i)->statisticsCount(); n++) {
137#ifndef UNIQUE_PORT_DELAY
138 if (delay < (*i)->statistics(n).delayPort("input_delay")) {
139 delay = (*i)->statistics(n).delayPort("input_delay");
140 }
141#endif // UNIQUE_PORT_DELAY
142#ifdef UNIQUE_PORT_DELAY
143 // this one is used if defferent ports of an unit
144 // can have different delays
145 if (delay < (*i)->statistics(n).delayPort(port.name())) {
146 delay = (*i)->statistics(n).delayPort(port.name());
147 }
148#endif // UNIQUE_PORT_DELAY
149 }
150 }
151 } catch (Exception& e) {
152#ifdef DEBUG_DELAY_ESTIMATION
153 Application::logStream() << "No input_delay data for register "
154 << "file "
155 << port.parentUnit()->name()
156 << " found in HDB." << std::endl;
157#endif // DEBUG_DELAY_ESTIMATION
158 return false;
159 }
160#ifdef DEBUG_DELAY_ESTIMATION
162 << port.name() << " (port) delay " << delay << std::endl;
163#endif // DEBUG_DELAY_ESTIMATION
164 return true;
165 }
166
167 /**
168 * Estimates the register file port read delay by fetching cost data
169 * named 'output_delay' from HDB.
170 *
171 * Assumes that all ports have the same output delay, that is, there is
172 * only one 'output_delay' entry for a RF in HDB.
173 */
174 bool
176 const TTAMachine::RFPort& port,
177 const IDF::RFImplementationLocation& /*implementation*/,
178 DelayInNanoSeconds& delay,
179 HDB::HDBManager& hdb) {
180
181//#define DEBUG_DELAY_ESTIMATION
182 try {
185 CostDBTypes::EntryTable::const_iterator i = results.begin();
186 delay = 0.0;
187 // worst case delay is returned
188 for (;i < results.end(); i++) {
189 for (int n = 0; n < (*i)->statisticsCount(); n++) {
190#ifndef UNIQUE_PORT_DELAY
191 if (delay < (*i)->statistics(n).delayPort("output_delay")) {
192 delay = (*i)->statistics(n).delayPort("output_delay");
193 }
194#endif // UNIQUE_PORT_DELAY
195#ifdef UNIQUE_PORT_DELAY
196 // this one is used if defferent ports of an unit
197 // can have different delays
198 if (delay < (*i)->statistics(n).delayPort(port.name())) {
199 delay = (*i)->statistics(n).delayPort(port.name());
200 }
201#endif // UNIQUE_PORT_DELAY
202 }
203 }
204 } catch (Exception& e) {
205#ifdef DEBUG_DELAY_ESTIMATION
206 Application::logStream() << "No output_delay data for register "
207 << "file "
208 << port.parentUnit()->name()
209 << " found in HDB." << std::endl;
210#endif // DEBUG_DELAY_ESTIMATION
211 return false;
212 }
213#ifdef DEBUG_DELAY_ESTIMATION
215 << port.name() << " (port) delay " << delay << std::endl;
216#endif // DEBUG_DELAY_ESTIMATION
217 return true;
218 }
219
220 /**
221 * Estimates the register file maximum computation delay by fetching
222 * cost data named 'computation_delay' from HDB.
223 */
224 bool
227 const IDF::RFImplementationLocation& /*implementation*/,
228 DelayInNanoSeconds& delay,
229 HDB::HDBManager& hdb) {
230
231//#define DEBUG_DELAY_ESTIMATION
232 try {
235 CostDBTypes::EntryTable::const_iterator i = results.begin();
236 delay = 0.0;
237 // the worst case is returned if found multiple results
238 for (;i < results.end(); i++) {
239 for (int n = 0; n < (*i)->statisticsCount(); n++) {
240 if (delay < (*i)->statistics(n).delay()) {
241 delay = (*i)->statistics(n).delay();
242 }
243 }
244 }
245 } catch (Exception& e) {
246 return false;
247 }
248#ifdef DEBUG_DELAY_ESTIMATION
250 << " computation delay "
251 << delay << std::endl;
252#endif // DEBUG_DELAY_ESTIMATION
253 return true;
254 }
255
256 /**
257 * Estimates the energy consumed by given RF.
258 *
259 * Estimate is done by computing the sum of all register file access
260 * type energies and RF idle energy. Register file access energies are
261 * stored with entries named 'rf_access_energy Nr Nw'. Nr is the number
262 * of read accesses, Nw the number of write accesses. For example,
263 * 'rf_access_energy 1 3' is the name of entry which tells how much
264 * energy is consumed by the RF in case RF is accessed simultaneously
265 * once for reading and trice for writing. Idle energy is stored in
266 * entry 'rf_idle_energy'.
267 */
271 const TTAProgram::Program&,
272 const ExecutionTrace& trace,
273 EnergyInMilliJoules& energy,
274 HDB::HDBManager& hdb) {
275
276//#define DEBUG_ENERGY_ESTIMATION
277 energy = 0.0;
278 ClockCycleCount cyclesWithRFAccess = 0;
280 try {
282 results = createSearch(rf);
283
284#ifdef DEBUG_ENERGY_ESTIMATION
286 << "## register file " << rf.name() << ": " << std::endl;
287#endif
288
292 const_iterator i = accessList->begin();
293 i != accessList->end(); ++i) {
294 const ExecutionTrace::ConcurrentRFAccessCount& accessCount =
295 *i;
296
297 const std::size_t reads = accessCount.get<0>();
298 const std::size_t writes = accessCount.get<1>();
299 const ClockCycleCount count = accessCount.get<2>();
300
301 const std::string dataName =
302 std::string("rf_access_energy ") +
303 Conversion::toString(reads) + " " +
304 Conversion::toString(writes);
305 try {
306 CostDBTypes::EntryTable::const_iterator i = results.begin();
307 for (;i < results.end(); i++) {
308
309 // if there are multilpe reults for the rf access
310 // energy, select the worst case
311 // @todo ensure that multiple result is not a bug
312 EnergyInMilliJoules energyTemp = 0.0;
313 for (int n = 0; n < (*i)->statisticsCount(); n++) {
314 if (((*i)->statistics(n).energyReadWrite(
315 reads, writes) * count) > energyTemp) {
316 energyTemp =
317 (*i)->statistics(n).energyReadWrite(
318 reads, writes) * count;
319 }
320#ifdef DEBUG_ENERGY_ESTIMATION
321 if (n > 0) {
323 << " NOTE: Multiple register access energy "
324 << "results found!"
325 << " "
326 << (*i)->statistics(n).energyReadWrite(
327 reads, writes)
328 << std::endl;
329 }
330#endif
331 }
332 energy += energyTemp;
333 }
334 cyclesWithRFAccess += count;
335 } catch (const KeyNotFound&) {
336 // if no data found, don't even try to estimate the area
337 delete accessList;
338 accessList = NULL;
340 << "Cost estimation data '" << dataName
341 << "' not found in HDB." << std::endl;
342 return false;
343 } catch (const Exception& e) {
344 delete accessList;
345 accessList = NULL;
347 return false;
348 }
349 }
350 delete accessList;
351 accessList = NULL;
352 } catch (const Exception& e) {
354 return false;
355 }
356
357 // add the cost of RF idling
358 const ClockCycleCount idleCycles =
359 trace.simulatedCycleCount() - cyclesWithRFAccess;
360 const std::string dataName = std::string("rf_idle_energy");
361
362 try {
363 CostDBTypes::EntryTable::const_iterator i = results.begin();
364 for (;i < results.end(); i++) {
365
366 // if there are multilpe reults for the rf idle energy,
367 // select the worst case
368 // @todo Ensure that multiple results is not a bug
369 EnergyInMilliJoules energyTemp = 0.0;
370 for (int n = 0; n < (*i)->statisticsCount(); n++) {
371 if (((*i)->statistics(n).energyIdle() * idleCycles) >
372 energyTemp) {
373
374 energyTemp =
375 (*i)->statistics(n).energyIdle() * idleCycles;
376 }
377#ifdef DEBUG_ENERGY_ESTIMATION
378 if (n > 0) {
380 << " NOTE: Multiple register idle energy "
381 << "results found!"
382 << " " << (*i)->statistics(n).energyIdle()
383 << std::endl;
384 }
385#endif
386 }
387 energy += energyTemp;
388 }
389 } catch (const KeyNotFound&) {
390 // if no data found, don't even try to estimate the area
392 << "Cost estimation data '" << dataName
393 << "' not found in HDB." << std::endl;
394 return false;
395 } catch (const Exception& e) {
397 return false;
398 }
399
400 return true;
401 }
402
403private:
404 /// Registry of cost databases.
406 /// Cost database being used.
408 /// Search strategy to be used with the cost database.
410 /// Entry key property of register file.
412 /// Search type for each entry type.
413 typedef std::map<
415 /// Types of matches used for searching entries from the cost database.
417 /// Table of types of match.
419
420/**
421 * Initializes the plugin.
422 *
423 * @param hdb The HDB to be used in searching entries. Cost database is created
424 * in basis of this HDB.
425 */
426void
435
436/**
437 * Creates a search to cost database to find entries matching the given
438 * register file.
439 *
440 * @param rf Register file which matches are searched.
441 * @return Returns entries that matched the register file.
442 */
446
447 RFArchitecture rfArch(&rf);
448
450 searchKey->addField(
451 new EntryKeyField(
452 new EntryKeyDataInt(rfArch.size()),
455 searchKey->addField(
456 new EntryKeyField(
457 new EntryKeyDataInt(rfArch.readPortCount()),
460 searchKey->addField(
461 new EntryKeyField(
462 new EntryKeyDataInt(rfArch.writePortCount()),
465 searchKey->addField(
466 new EntryKeyField(
467 new EntryKeyDataInt(rfArch.width()),
469 searchKey->addField(
470 new EntryKeyField(
471 new EntryKeyDataInt(rfArch.latency()),
473 searchKey->addField(
474 new EntryKeyField(
475 new EntryKeyDataInt(rfArch.bidirPortCount()),
478 searchKey->addField(
479 new EntryKeyField(
480 new EntryKeyDataInt(rfArch.maxReads()),
483 searchKey->addField(
484 new EntryKeyField(
485 new EntryKeyDataInt(rfArch.maxWrites()),
488 searchKey->addField(
489 new EntryKeyField(
490 new EntryKeyDataBool(rfArch.hasGuardSupport()),
493 searchKey->addField(
494 new EntryKeyField(
495 new EntryKeyDataInt(rfArch.guardLatency()),
498
499 // Perform a database query.
500 try {
501 results = costdb_->search(*searchKey, interpMatchType_);
502 } catch (Exception& e) {
503 delete searchKey;
504 searchKey = 0;
505 throw e;
506 }
507 delete searchKey;
508 searchKey = 0;
509 return results;
510}
511
512/**
513 * Creates types of matches used for searching cost database
514 * entries.
515 */
517
518 interpMatchType_.push_back(
519 new MatchType(
522 interpMatchType_.push_back(
523 new MatchType(
526 interpMatchType_.push_back(
527 new MatchType(
530 interpMatchType_.push_back(
531 new MatchType(
534 interpMatchType_.push_back(
535 new MatchType(
538 interpMatchType_.push_back(
539 new MatchType(
542 interpMatchType_.push_back(
543 new MatchType(
546 interpMatchType_.push_back(
547 new MatchType(
550 interpMatchType_.push_back(
551 new MatchType(
554 interpMatchType_.push_back(
555 new MatchType(
558}
559
560};
561
#define debugLog(text)
ExecutionTrace * trace
the execution trace database
#define EXPORT_RF_COST_ESTIMATOR_PLUGIN(PLUGIN_NAME__)
CycleCount ClockCycleCount
Alias for ClockCycleCount.
static std::ostream & logStream()
static std::string toString(const T &source)
void addField(EntryKeyField *field)
static const std::string EKF_READ_PORTS
Field type for number of read ports in an entry.
static const std::string EKF_MAX_WRITES
Field type for number of max simultaneous writes in an entry.
static const std::string EKF_BIDIR_PORTS
Field type for number of bidirectional ports in an entry.
static const std::string EKF_GUARD_SUPPORT
Field type for guard support in an entry.
std::vector< MatchType * > MatchTypeTable
Table of types of match.
static const std::string EKF_LATENCY
Field type for latency of an entry.
static const std::string EKF_GUARD_LATENCY
Field type for guard latency in an entry.
static const std::string EKF_MAX_READS
Field type for number of max simultaneous reads in an entry.
static const std::string EKF_WRITE_PORTS
Field type for number of write ports in an entry.
static const std::string EK_RFILE
Entry type for register files.
static const std::string EKF_NUM_REGISTERS
Field type for number of registers in an entry.
std::vector< CostDBEntry * > EntryTable
Table of database entries.
static const std::string EKF_BIT_WIDTH
Field type for bit width of an entry.
static CostDatabaseRegistry & instance()
CostDatabase & costDatabase(const HDB::HDBManager &hdb)
void setSearchStrategy(SearchStrategy *strategy)
CostDBTypes::EntryTable search(const CostDBEntryKey &searchKey, const CostDBTypes::MatchTypeTable &match) const
static EntryKeyProperty * find(std::string type)
EntryKeyFieldProperty * fieldProperty(std::string field) const
std::string fileName() const
std::string errorMessage() const
Definition Exception.cc:123
int lineNum() const
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
bool hasGuardSupport() const
bool estimateArea(const TTAMachine::BaseRegisterFile &rf, const IDF::RFImplementationLocation &, AreaInGates &area, HDB::HDBManager &hdb)
bool estimateEnergy(const TTAMachine::BaseRegisterFile &rf, const IDF::RFImplementationLocation &, const TTAProgram::Program &, const ExecutionTrace &trace, EnergyInMilliJoules &energy, HDB::HDBManager &hdb)
CostDatabaseRegistry * costDatabaseRegistry_
Registry of cost databases.
void initializeEstimator(const HDBManager &hdb)
CostDBTypes::MatchTypeTable interpMatchType_
Table of types of match.
DESCRIPTION("RF cost estimator plugin that estimates costs of RFs by generating" "cost database from cost values of HDB and uses interpolation to " "estimate the costs. In case there's no cost data available for the " "given RF the plugin interpolates the estimate if possible.")
EntryKeyProperty * rfileProperty_
Entry key property of register file.
MatchTypeMap searchTypes_
Types of matches used for searching entries from the cost database.
InterpolatingRFEstimator(const std::string &name)
std::map< const EntryKeyProperty *, CostDBTypes::MatchTypeTable > MatchTypeMap
Search type for each entry type.
CostDatabase * costdb_
Cost database being used.
SearchStrategy * strategy_
Search strategy to be used with the cost database.
CostDBTypes::EntryTable createSearch(const BaseRegisterFile &rf) const
bool estimateMaximumComputationDelay(const TTAMachine::BaseRegisterFile &rf, const IDF::RFImplementationLocation &, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
bool estimatePortReadDelay(const TTAMachine::RFPort &port, const IDF::RFImplementationLocation &, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
bool estimatePortWriteDelay(const TTAMachine::RFPort &port, const IDF::RFImplementationLocation &, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
virtual TCEString name() const
virtual std::string name() const
Definition Port.cc:141
BaseRegisterFile * parentUnit() const
Definition RFPort.cc:93
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