OpenASIP  2.0
StrictMatchFUEstimator.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 StrictMatchFUEstimator.cc
26  *
27  * Declaration of StrictMatchFUEstimator. An FU estimation plugin that
28  * estimates FUs simply by fetching pre-stored cost data of the units
29  * from HDB. It does not perform any kind of linearization etc. to
30  * estimate an FU 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 "FunctionUnit.hh"
41 #include "ExecutionTrace.hh"
42 #include "StringTools.hh"
43 
44 using namespace CostEstimator;
45 
47 public:
48  StrictMatchFUEstimator(const std::string& name) :
50  }
51 
53  }
54 
56  "Simple FU cost estimator plugin that estimates costs of FUs "
57  "simply by looking up direct matches from HDB. In case there's "
58  "no cost data available for the given FU, it's unable to estimate "
59  "it by using linearization etc.");
60 
61 public:
62 
63  /**
64  * Estimates the function unit's area by fetching cost data named 'area'
65  * from HDB.
66  */
68  const TTAMachine::FunctionUnit& /*fu*/,
70  AreaInGates& area,
71  HDB::HDBManager& hdb) {
72 //#define DEBUG_AREA_ESTIMATION
73  try {
74  // simply fetch the area data of the FU, if any
75  DataObject areaFromDB = hdb.fuCostEstimationData(
76  "area", implementation.id(), name_);
77  area = areaFromDB.doubleValue();
78 #ifdef DEBUG_AREA_ESTIMATION
80  << fu.name() << " area " << area << std::endl;
81 #endif
82  return true;
83  } catch (const KeyNotFound&) {
84  // if no area data found, don't even try to estimate the area
85  // somehow
86  return false;
87  } catch (const Exception& e) {
88  // for example, if doubleValue() conversion failed, then it's
89  // a problem with HDB contents
91  return false;
92  }
93  return false;
94  }
95 
96  /**
97  * Estimates the function unit port write delay by fetching cost data
98  * named 'input_delay' from HDB.
99  *
100  * Assumes that all ports have the same input delay, that is, there is
101  * only one 'input_delay' entry for a FU in HDB.
102  */
103  bool
105  const TTAMachine::FUPort&,
107  DelayInNanoSeconds& delay,
108  HDB::HDBManager& hdb) {
109 
110  try {
111  // simply fetch the delay data of the FU port, if any
112  DataObject delayFromDB = hdb.fuCostEstimationData(
113  "input_delay", implementation.id(), name_);
114  delay = delayFromDB.doubleValue();
115  return true;
116  } catch (const KeyNotFound&) {
117  // if no data found, don't even try to estimate the area
119  << "No input_delay cost data found for FU "
120  << implementation.id() << ", plugin " << name_ << std::endl;
121  return false;
122  } catch (const Exception& e) {
123  // for example, if doubleValue() conversion failed, then it's
124  // a problem with HDB contents
125  debugLog(e.errorMessage());
126  return false;
127  }
128 
129  return false;
130  }
131 
132  /**
133  * Estimates the function unit port read delay by fetching cost data
134  * named 'output_delay' from HDB.
135  *
136  * Assumes that all ports have the same output delay, that is, there is
137  * only one 'output_delay' entry for a FU in HDB.
138  */
139  bool
141  const TTAMachine::FUPort&,
143  DelayInNanoSeconds& delay,
144  HDB::HDBManager& hdb) {
145 
146  try {
147  // simply fetch the delay data of the FU port, if any
148  DataObject delayFromDB = hdb.fuCostEstimationData(
149  "output_delay", implementation.id(), name_);
150  delay = delayFromDB.doubleValue();
151  return true;
152  } catch (const KeyNotFound&) {
153  // if no data found, don't even try to estimate the area
155  << "No output_delay cost data found for FU "
156  << implementation.id() << ", plugin " << name_ << std::endl;
157  return false;
158  } catch (const Exception& e) {
159  // for example, if doubleValue() conversion failed, then it's
160  // a problem with HDB contents
161  debugLog(e.errorMessage());
162  return false;
163  }
164 
165  return false;
166  }
167 
168  /**
169  * Estimates the function unit maximum computation delay by fetching
170  * cost data named 'computation_delay' from HDB.
171  */
173  const TTAMachine::FunctionUnit& /*architecture*/,
175  DelayInNanoSeconds& delay,
176  HDB::HDBManager& hdb) {
177 
178  try {
179  // simply fetch the delay data of the FU port, if any
180  DataObject delayFromDB = hdb.fuCostEstimationData(
181  "computation_delay", implementation.id(), name_);
182  delay = delayFromDB.doubleValue();
183  return true;
184  } catch (const KeyNotFound&) {
185  // if no data found, don't even try to estimate the area
187  << "No computation_delay cost data found for FU "
188  << implementation.id() << ", plugin " << name_ << std::endl;
189  return false;
190  } catch (const Exception& e) {
191  // for example, if doubleValue() conversion failed, then it's
192  // a problem with HDB contents
193  debugLog(e.errorMessage());
194  return false;
195  }
196 
197  return false;
198  }
199 
200  /**
201  * Estimates the energy consumed by given FU.
202  *
203  * Estimate is done by computing the sum of all operation execution
204  * energies and FU idle energy. Operation execution energies are stored
205  * with entries named 'operation_execution_energy operation_name'. The
206  * idle energy is in entry named 'fu_idle_energy'.
207  */
208  virtual bool estimateEnergy(
209  const TTAMachine::FunctionUnit& fu,
211  const TTAProgram::Program& /*program*/,
212  const ExecutionTrace& trace,
213  EnergyInMilliJoules& energy,
214  HDB::HDBManager& hdb) {
215 
216 //#define DEBUG_ENERGY_ESTIMATION
217  energy = 0.0;
218  ClockCycleCount cyclesWithFUAccess = 0;
219 #ifdef DEBUG_ENERGY_ESTIMATION
221  << "## function unit " << fu.name() << ": " << std::endl;
222 #endif
223  try {
227  const_iterator i = operationTriggers->begin();
228  i != operationTriggers->end(); ++i) {
229 
230  const ExecutionTrace::FUOperationTriggerCount& triggerCount =
231  *i;
232 
233  const ExecutionTrace::OperationID operation =
234  StringTools::stringToLower(triggerCount.get<0>());
235 
237  triggerCount.get<1>();
238 
239  const std::string dataName =
240  std::string("operation_execution_energy ") +
241  operation;
242 
243  try {
244  DataObject energyFromDB = hdb.fuCostEstimationData(
245  dataName, implementation.id(), name_);
246  EnergyInMilliJoules energyOfAccess =
247  energyFromDB.doubleValue()*count;
248 #ifdef DEBUG_ENERGY_ESTIMATION
250  << "## " << operation << " = "
251  << energyFromDB.doubleValue() << " times "
252  << count << " = " << energyOfAccess << std::endl;
253 #endif
254  energy += energyOfAccess;
255  cyclesWithFUAccess += count;
256  } catch (const KeyNotFound&) {
257  // if no data found, don't even try to estimate the energy
258  delete operationTriggers;
259  operationTriggers = NULL;
261  << "Cost estimation data '" << dataName
262  << "' not found in HDB." << std::endl;
263  return false;
264  } catch (const Exception& e) {
265  delete operationTriggers;
266  operationTriggers = NULL;
267  debugLog(e.errorMessage());
268  return false;
269  }
270 
271  }
272  delete operationTriggers;
273  operationTriggers = NULL;
274  } catch (const Exception& e) {
275  debugLog(e.errorMessage());
276  return false;
277  }
278 
279  // add the cost of FU idling
280  const ClockCycleCount idleCycles =
281  trace.simulatedCycleCount() - cyclesWithFUAccess;
282  const std::string dataName = std::string("fu_idle_energy");
283 
284  try {
285  DataObject energyFromDB = hdb.fuCostEstimationData(
286  dataName, implementation.id(), name_);
287  EnergyInMilliJoules idleEnergy =
288  energyFromDB.doubleValue()*idleCycles;
289 #ifdef DEBUG_ENERGY_ESTIMATION
291  << "## idle energy " << energyFromDB.doubleValue() << " times "
292  << idleCycles << " = " << idleEnergy << std::endl;
293 
294 #endif
295  energy += idleEnergy;
296 
297  } catch (const KeyNotFound&) {
298  // if no data found, don't even try to estimate the energy
300  << "Cost estimation data '" << dataName
301  << "' for FU with id " << implementation.id()
302  << " not found in HDB." << std::endl;
303  return false;
304  } catch (const Exception& e) {
305  debugLog(e.errorMessage());
306  return false;
307  }
308 
309  return true;
310  }
311 
312 };
313 
IDF::UnitImplementationLocation
Definition: UnitImplementationLocation.hh:48
TTAProgram::Program
Definition: Program.hh:63
ExecutionTrace::OperationTriggerCount
ClockCycleCount OperationTriggerCount
a type for operation trigger counts
Definition: ExecutionTrace.hh:93
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
StrictMatchFUEstimator::estimatePortWriteDelay
bool estimatePortWriteDelay(const TTAMachine::FUPort &, const IDF::FUImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
Definition: StrictMatchFUEstimator.cc:104
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
StrictMatchFUEstimator
Definition: StrictMatchFUEstimator.cc:46
ExecutionTrace::FUOperationTriggerCountList
std::list< FUOperationTriggerCount > FUOperationTriggerCountList
type to be used for lists of function operation execution counts
Definition: ExecutionTrace.hh:116
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
StrictMatchFUEstimator::estimateEnergy
virtual bool estimateEnergy(const TTAMachine::FunctionUnit &fu, const IDF::FUImplementationLocation &implementation, const TTAProgram::Program &, const ExecutionTrace &trace, EnergyInMilliJoules &energy, HDB::HDBManager &hdb)
Definition: StrictMatchFUEstimator.cc:208
FUCostEstimationPlugin.hh
DataObject::doubleValue
virtual double doubleValue() const
Definition: DataObject.cc:386
CostEstimator::EnergyInMilliJoules
double EnergyInMilliJoules
type for consumed energy in milli joules
Definition: CostEstimatorTypes.hh:37
StringTools.hh
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
CostEstimator::FUCostEstimationPlugin
Definition: FUCostEstimationPlugin.hh:66
StrictMatchFUEstimator::~StrictMatchFUEstimator
virtual ~StrictMatchFUEstimator()
Definition: StrictMatchFUEstimator.cc:52
StrictMatchFUEstimator::estimateMaximumComputationDelay
bool estimateMaximumComputationDelay(const TTAMachine::FunctionUnit &, const IDF::FUImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
Definition: StrictMatchFUEstimator.cc:172
EXPORT_FU_COST_ESTIMATOR_PLUGIN
#define EXPORT_FU_COST_ESTIMATOR_PLUGIN(PLUGIN_NAME__)
Definition: FUCostEstimationPlugin.hh:107
ExecutionTrace
Definition: ExecutionTrace.hh:56
Application.hh
StrictMatchFUEstimator::estimatePortReadDelay
bool estimatePortReadDelay(const TTAMachine::FUPort &, const IDF::FUImplementationLocation &implementation, DelayInNanoSeconds &delay, HDB::HDBManager &hdb)
Definition: StrictMatchFUEstimator.cc:140
HDB::HDBManager
Definition: HDBManager.hh:82
ExecutionTrace::OperationID
std::string OperationID
a type for storing operation identifiers
Definition: ExecutionTrace.hh:75
Exception
Definition: Exception.hh:54
DataObject.hh
StrictMatchFUEstimator::estimateArea
bool estimateArea(const TTAMachine::FunctionUnit &, const IDF::FUImplementationLocation &implementation, AreaInGates &area, HDB::HDBManager &hdb)
Definition: StrictMatchFUEstimator.cc:67
ExecutionTrace::functionUnitOperationTriggerCounts
FUOperationTriggerCountList * functionUnitOperationTriggerCounts(FunctionUnitID functionUnit) const
Definition: ExecutionTrace.cc:591
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
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
StrictMatchFUEstimator::StrictMatchFUEstimator
StrictMatchFUEstimator(const std::string &name)
Definition: StrictMatchFUEstimator.cc:48
HDB::HDBManager::fuCostEstimationData
DataObject fuCostEstimationData(const std::string &valueName, RowID implementationId, const std::string &pluginName) const
Definition: HDBManager.cc:3289
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
KeyNotFound
Definition: Exception.hh:285
HDBManager.hh
ExecutionTrace::FUOperationTriggerCount
boost::tuple< OperationID, OperationTriggerCount > FUOperationTriggerCount
type to be used as a key for storing function unit operation execution counts
Definition: ExecutionTrace.hh:113
CostEstimator
Definition: CostEstimationPlugin.cc:36
debugLog
#define debugLog(text)
Definition: Application.hh:95
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
FunctionUnit.hh
ExecutionTrace.hh