OpenASIP  2.0
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 
44 using namespace CostEstimator;
45 
47 public:
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 
61 public:
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
134  debugLog(e.errorMessage());
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
174  debugLog(e.errorMessage());
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
211  debugLog(e.errorMessage());
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;
288  debugLog(e.errorMessage());
289  return false;
290  }
291  }
292  delete accessList;
293  accessList = NULL;
294  } catch (const Exception& e) {
295  debugLog(e.errorMessage());
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) {
324  debugLog(e.errorMessage());
325  return false;
326  }
327 
328  return true;
329  }
330 
331 
332 };
333 
CostEstimator::RFCostEstimationPlugin
Definition: RFCostEstimationPlugin.hh:67
IDF::UnitImplementationLocation
Definition: UnitImplementationLocation.hh:48
StrictMatchRFEstimator::estimateEnergy
bool estimateEnergy(const TTAMachine::BaseRegisterFile &rf, const IDF::RFImplementationLocation &implementation, const TTAProgram::Program &, const ExecutionTrace &trace, EnergyInMilliJoules &energy, HDB::HDBManager &hdb)
Definition: StrictMatchRFEstimator.cc:230
BaseRegisterFile.hh
TTAProgram::Program
Definition: Program.hh:63
StrictMatchRFEstimator::estimateArea
bool estimateArea(const TTAMachine::BaseRegisterFile &, const IDF::RFImplementationLocation &implementation, AreaInGates &area, HDB::HDBManager &hdb)
Definition: StrictMatchRFEstimator.cc:67
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
Exception.hh
DESCRIPTION
#define DESCRIPTION(TEXT__)
Definition: FUCostEstimationPlugin.hh:129
implementation
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:61
DataObject
Definition: DataObject.hh:50
CostEstimator::AreaInGates
double AreaInGates
type for area values in equivalent gates
Definition: CostEstimatorTypes.hh:35
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
Conversion::toString
static std::string toString(const T &source)
TTAMachine::RFPort
Definition: RFPort.hh:45
DataObject::doubleValue
virtual double doubleValue() const
Definition: DataObject.cc:386
HDB::HDBManager::rfCostEstimationData
DataObject rfCostEstimationData(const std::string &valueName, RowID implementationId, const std::string &pluginName) const
Definition: HDBManager.cc:3345
CostEstimator::EnergyInMilliJoules
double EnergyInMilliJoules
type for consumed energy in milli joules
Definition: CostEstimatorTypes.hh:37
StrictMatchRFEstimator::StrictMatchRFEstimator
StrictMatchRFEstimator(const std::string &name)
Definition: StrictMatchRFEstimator.cc:48
TTAMachine::BaseRegisterFile
Definition: BaseRegisterFile.hh:48
EXPORT_RF_COST_ESTIMATOR_PLUGIN
#define EXPORT_RF_COST_ESTIMATOR_PLUGIN(PLUGIN_NAME__)
Definition: RFCostEstimationPlugin.hh:108
StrictMatchRFEstimator::estimatePortReadDelay
bool estimatePortReadDelay(const TTAMachine::RFPort &, const IDF::RFImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
Definition: StrictMatchRFEstimator.cc:149
Conversion.hh
ExecutionTrace
Definition: ExecutionTrace.hh:56
Application.hh
StrictMatchRFEstimator
Definition: StrictMatchRFEstimator.cc:46
HDB::HDBManager
Definition: HDBManager.hh:82
Exception
Definition: Exception.hh:54
DataObject.hh
StrictMatchRFEstimator::estimateMaximumComputationDelay
bool estimateMaximumComputationDelay(const TTAMachine::BaseRegisterFile &, const IDF::RFImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
Definition: StrictMatchRFEstimator.cc:186
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ExecutionTrace::registerFileAccessCounts
ConcurrentRFAccessCountList * registerFileAccessCounts(RegisterFileID registerFile) const
Definition: ExecutionTrace.cc:505
CostEstimator::DelayInNanoSeconds
double DelayInNanoSeconds
type for propagation delays in nano seconds
Definition: CostEstimatorTypes.hh:39
ExecutionTrace::simulatedCycleCount
ClockCycleCount simulatedCycleCount() const
Definition: ExecutionTrace.cc:764
trace
ExecutionTrace * trace
the execution trace database
Definition: EstimatorCmdLineUI.cc:66
ExecutionTrace::ConcurrentRFAccessCount
boost::tuple< RegisterAccessCount, RegisterAccessCount, ClockCycleCount > ConcurrentRFAccessCount
type to be used as a key for storing concurrent RF access info
Definition: ExecutionTrace.hh:105
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
ExecutionTrace::ConcurrentRFAccessCountList
std::list< ConcurrentRFAccessCount > ConcurrentRFAccessCountList
type to be used for a list of concurrent RF accesses
Definition: ExecutionTrace.hh:108
KeyNotFound
Definition: Exception.hh:285
StrictMatchRFEstimator::estimatePortWriteDelay
bool estimatePortWriteDelay(const TTAMachine::RFPort &, const IDF::RFImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
Definition: StrictMatchRFEstimator.cc:108
HDBManager.hh
CostEstimator
Definition: CostEstimationPlugin.cc:36
debugLog
#define debugLog(text)
Definition: Application.hh:95
StrictMatchRFEstimator::~StrictMatchRFEstimator
virtual ~StrictMatchRFEstimator()
Definition: StrictMatchRFEstimator.cc:52
RFCostEstimationPlugin.hh
ExecutionTrace.hh