OpenASIP 2.2
Loading...
Searching...
No Matches
CostDBEntryStats.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 CostDBEntryStats.cc
26 *
27 * Implementation of CostDBEntryStats class.
28 *
29 * @author Tommi Rantanen 2003 (tommi.rantanen-no.spam-tut.fi)
30 * @author Jari Mäntyneva 2005 (jari.mantyneva-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include <map>
35#include <string>
36
37#include "Application.hh"
38#include "CostDBEntryStats.hh"
39
40using std::string;
41using std::map;
42
43// warning: is it possible that operation can have one of the
44// following names?
45const std::string CostDBEntryStats::ENERGY_ACTIVE = "(active)";
46const std::string CostDBEntryStats::ENERGY_IDLE = "(idle)";
47const std::string CostDBEntryStats::ENERGY_READ = "(read)";
48const std::string CostDBEntryStats::ENERGY_WRITE = "(write)";
49const std::string CostDBEntryStats::ENERGY_READ_WRITE = "(rd,wr)";
50
51
52/**
53 * Constructor.
54 *
55 * @param areaData area.
56 * @param internalDelayData Components internal delay.
57 */
58CostDBEntryStats::CostDBEntryStats(double areaData, double internalDelayData) :
59 area_(areaData), delay_(internalDelayData) {
60}
61
62/**
63 * Constructor.
64 *
65 * Combines two statistics into one using coefficient as a weighting
66 * factor on interpolating the statistics. For example, if weighting
67 * factor is 0.4, the first area 100 and the second 200, area of new
68 * statistics will be 140. delay and energy will be handled similarly.
69 *
70 * @param stats1 First statistics.
71 * @param stats2 Second statistics.
72 * @param coefficient Weighting factor.
73 * @exception KeyNotFound Thrown in case that the two statistics won't contain
74 * equal keys.
75 */
77 const CostDBEntryStats& stats1, const CostDBEntryStats& stats2,
78 double coefficient) {
79 area_ = stats1.area() + coefficient * (stats2.area() - stats1.area());
80 delay_ = stats1.delay() + coefficient * (stats2.delay() - stats1.delay());
81
82 for (EnergyMap::const_iterator i = stats1.energies_.begin();
83 i != stats1.energies_.end(); i++) {
84
85 string key = (*i).first;
86 double energy1 = (*i).second;
87 double energy2 = stats2.findEnergy(key);
88
89 double energy = energy1 + coefficient * (energy2 - energy1);
90
91 addEnergy(key, energy);
92 }
93
94 // checks that the energy keys are equal in both statistics
95 for (EnergyMap::const_iterator i = stats2.energies_.begin();
96 i != stats2.energies_.end(); i++) {
97
98 string key = (*i).first;
99 // checks if the energy exist for the key
100 stats1.findEnergy(key);
101 }
102 // check also keys of the other stats
103 for (EnergyMap::const_iterator i = stats1.energies_.begin();
104 i != stats1.energies_.end(); i++) {
105
106 string key = (*i).first;
107 // checks if the energy exist for the key
108 stats2.findEnergy(key);
109 }
110
111 for (DelayMap::const_iterator i = stats1.delays_.begin();
112 i != stats1.delays_.end(); i++) {
113
114 string key = (*i).first;
115 double delay1 = (*i).second;
116 double delay2 = stats2.findDelay(key);
117
118 double delay = delay1 + coefficient * (delay2 - delay1);
119
120 addDelay(key, delay);
121 }
122
123 // checks that the delay keys are equal in both statistics
124 for (DelayMap::const_iterator i = stats2.delays_.begin();
125 i != stats2.delays_.end(); i++) {
126
127 string key = (*i).first;
128 // checks if the delay exist for the key
129 stats1.findDelay(key);
130 }
131 // check also keys of the other stats
132 for (DelayMap::const_iterator i = stats1.delays_.begin();
133 i != stats1.delays_.end(); i++) {
134
135 string key = (*i).first;
136 // checks if the delay exist for the key
137 stats2.findDelay(key);
138 }
139}
140
141/**
142 * Destructor.
143 */
146
147/**
148 * Returns the copy of the statistics.
149 *
150 * @return Copy of statistics.
151 */
154
155 CostDBEntryStats* newStats = createStats();
156
157 for (EnergyMap::const_iterator i = energies_.begin();
158 i != energies_.end(); i++) {
159
160 newStats->addEnergy((*i).first, (*i).second);
161 }
162 for (DelayMap::const_iterator i = delays_.begin();
163 i != delays_.end(); i++) {
164
165 newStats->setDelay((*i).first, (*i).second);
166 }
167
168 return newStats;
169}
170
171/**
172 * Create correct type of statistics.
173 *
174 * @return Correct type of statistics.
175 */
178
179 return new CostDBEntryStats(area(), delay());
180}
181
182/**
183 * Returns the energy of an entry in an active cycle.
184 *
185 * @return The energy of an entry in an active cycle.
186 * @exception WrongSubclass Never thrown.
187 * @exception KeyNotFound Thrown if active energy is not set.
188 */
189double
193
194/**
195 * Returns the energy of an entry in an idle cycle.
196 *
197 * @return The energy of an entry in an idle cycle.
198 * @exception WrongSubclass Never thrown by this function.
199 * @exception KeyNotFound Thrown if idle enrgy is not set.
200 */
201double
205
206/**
207 * Returns the energy of an entry when given operation is executed.
208 *
209 * The function will fail since this class should be used for entries
210 * which do not have operation set as a search key.
211 *
212 * @param name The name of the operation.
213 * @return The energy of an entry when given operation is executed.
214 * @exception WrongSubclass An illegal function was called for this
215 * instance.
216 * @exception KeyNotFound No energy matching the string found.
217 */
218double
219CostDBEntryStats::energyOperation(const std::string&) const {
220 throw WrongSubclass(__FILE__, __LINE__,
221 "CostDBEntryStats::energyOperation");
222 return 0.0; // stupid return statement to make compiler quiet
223}
224
225/**
226 * Checks whether the energy exists for the given operation.
227 *
228 * @param name name of the operation.
229 * @return True if the energy exists for the given operation.
230 * @exception WrongSubclass An illegal function was called for this
231 * instance.
232 */
233bool
234CostDBEntryStats::hasEnergyOperation(const std::string&) const {
235 throw WrongSubclass(__FILE__, __LINE__,
236 "CostDBEntryStats::hasEnergyOperation");
237 return false; // stupid return statement to make compiler quiet
238}
239
240/**
241 * Returns the read energy of an entry.
242 *
243 * @return The read energy of an entry.
244 * @exception WrongSubclass An illegal function was called for this
245 * instance.
246 * @exception KeyNotFound Never thrown by this function.
247 */
248double
250 throw WrongSubclass(__FILE__, __LINE__,
251 "CostDBEntryStats::energyRead");
252 return 0.0; // stupid return statement to make compiler quiet
253}
254
255/**
256 * Returns the write energy of an entry.
257 *
258 * @return The write energy of an entry.
259 * @exception WrongSubclass An illegal function was called for this
260 * instance.
261 * @exception KeyNotFound Never thrown by this function.
262 */
263double
265 throw WrongSubclass(__FILE__, __LINE__,
266 "CostDBEntryStats::energyRead");
267 return 0.0; // stupid return statement to make compiler quiet
268}
269
270/**
271 * Returns the reads and writes energy of an entry.
272 *
273 * @param reads The number of simultaneus reads done for the unit.
274 * @param writes The number of simultaneus writes done for the unit.
275 * @return The reads and writes energy of an entry.
276 * @exception WrongSubclass An illegal function was called for this
277 * instance.
278 * @exception KeyNotFound Never thrown by this function.
279 */
280double
282 throw WrongSubclass(__FILE__, __LINE__,
283 "CostDBEntryStats::energyReadsWrites");
284 return 0.0; // stupid return statement to make compiler quiet
285}
286
287/**
288 * Checks whether the energy exists for a given key.
289 *
290 * @param key The key.
291 * @return True if energy exists for a given key, otherwise false.
292 */
293bool
294CostDBEntryStats::hasEnergy(const std::string& key) const {
295
296 EnergyMap::const_iterator i = energies_.find(key);
297 return i != energies_.end();
298}
299
300/**
301 * Returns the energy of an entry for a given key.
302 *
303 * @param key The key.
304 * @return The energy of an entry in an active cycle.
305 * @exception KeyNotFound Requested key was not found.
306 */
307double
308CostDBEntryStats::findEnergy(const std::string& key) const {
309 EnergyMap::const_iterator i = energies_.find(key);
310 if (i == energies_.end()) {
311 throw KeyNotFound(__FILE__, __LINE__, "CostDBEntryStats::findEnergy");
312 }
313 return i->second;
314}
315
316/**
317 * Set the energy of an entry in an active cycle.
318 *
319 * @param energy The energy of an entry in an active cycle.
320 * @exception WrongSubclass Never thrown by this function.
321 */
322void
324 EnergyMap::iterator iter = energies_.find(ENERGY_ACTIVE);
325 if (iter != energies_.end()) {
326 energies_.erase(iter);
327 }
328 addEnergy(ENERGY_ACTIVE, energy);
329}
330
331/**
332 * Set the energy of an entry in an idle cycle.
333 *
334 * @param energy The energy of an entry in an idle cycle.
335 * @exception WrongSubclass Never thrown by this function.
336 */
337void
339 EnergyMap::iterator iter = energies_.find(ENERGY_IDLE);
340 if (iter != energies_.end()) {
341 energies_.erase(iter);
342 }
343 addEnergy(ENERGY_IDLE, energy);
344}
345
346/**
347 * Set the energy of an entry when given operation is executed.
348 *
349 * The function will fail since this class should be used for entries
350 * which do not have operation set as a search key.
351 *
352 * @param name name of the operation.
353 * @param energy The energy of an entry when given operation is executed.
354 * @exception WrongSubclass An illegal function was called for this
355 * instance.
356 */
357void
358CostDBEntryStats::setEnergyOperation(const std::string&, double) {
359 throw WrongSubclass(__FILE__, __LINE__,
360 "CostDBEntryStats::setEnergyOperation");
361}
362
363/**
364 * Set the read energy of an entry.
365 *
366 * @param energy The read energy of an entry.
367 * @exception WrongSubclass An illegal function was called for this
368 * instance.
369 */
370void
372 throw WrongSubclass(__FILE__, __LINE__,
373 "CostDBEntryStats::setEnergyRead");
374}
375
376/**
377 * Set the write energy of an entry.
378 *
379 * @param energy The write energy of an entry.
380 * @exception WrongSubclass An illegal function was called for this
381 * instance.
382 */
383void
385 throw WrongSubclass(__FILE__, __LINE__,
386 "CostDBEntryStats::setEnergyWrite");
387}
388
389/**
390 * Set the reads and writes energy of an entry.
391 *
392 * @param energy The reads and writes energy of an entry.
393 * @param reads The number of reads of the unit.
394 * @param writes The number of writes of the unit.
395 * @exception WrongSubclass An illegal function was called for this
396 * instance.
397 */
398void
400 throw WrongSubclass(__FILE__, __LINE__,
401 "CostDBEntryStats::setEnergyReadsWrites");
402}
403
404/**
405 * Set the energy of an entry for a given key.
406 *
407 * Removes the old value.
408 *
409 * @param key The key.
410 * @param energy The energy of an entry for a given key.
411 */
412void
413CostDBEntryStats::addEnergy(const std::string& key, double energy) {
414
415 // if old value for energy is found it is removed first
416 EnergyMap::iterator iter = energies_.find(key);
417 if (iter != energies_.end()) {
418 energies_.erase(iter);
419 }
420 std::pair<const std::string, double> energyKey =
421 std::pair<const std::string, double>(key, energy);
422 energies_.insert(energyKey);
423}
424
425/**
426 * Returns the delay of given port is usage an an input/output.
427 *
428 * @param port The name of the port.
429 * @return The delay of an entry when given port is used.
430 * @exception WrongSubclass Never thrown by this function.
431 * @exception KeyNotFound Thrown if delay for given port is not set.
432 */
433double
434CostDBEntryStats::delayPort(const std::string& port) const {
435 return findDelay(port);
436}
437
438/**
439 * Set the delay of an input/output port usage.
440 *
441 * @param port Name of the input/output port.
442 * @param delay The delay of an input/ouput when using the given port.
443 * @exception WrongSubclass Never thrown by this function.
444 */
445void
446CostDBEntryStats::setDelay(const std::string& port, double delay) {
447 addDelay(port, delay);
448}
449
450/**
451 * Returns the input/output delay of an entry usign given key as an
452 * input/output port.
453 *
454 * @param key The key.
455 * @return The input/output delay using the given port.
456 * @exception KeyNotFound Requested key was not found.
457 */
458double
459CostDBEntryStats::findDelay(const std::string& key) const {
460 DelayMap::const_iterator i = delays_.find(key);
461
462 if (i == delays_.end()) {
463 throw KeyNotFound(__FILE__, __LINE__, "CostDBEntryStats::findDelay");
464 }
465 return i->second;
466}
467
468/**
469 * Set the delay of an entry for a given key.
470 *
471 * Removes the old value.
472 *
473 * @param key The key.
474 * @param delay The delay of an entry for a given key.
475 */
476void
477CostDBEntryStats::addDelay(const std::string& key, double delay) {
478
479 // if old value for delay is found it is removed first
480 DelayMap::iterator iter = delays_.find(key);
481 if (iter != delays_.end()) {
482 delays_.erase(iter);
483 }
484 std::pair<const std::string, double> delayKey =
485 std::pair<const std::string, double>(key, delay);
486 delays_.insert(delayKey);
487}
488
489/**
490 * Checks whether the delay exists for a given key.
491 *
492 * @param key The key.
493 * @return True if delay exists for a given key, otherwise false.
494 */
495bool
496CostDBEntryStats::hasDelay(const std::string& key) const {
497
498 DelayMap::const_iterator i = delays_.find(key);
499 return i != delays_.end();
500}
virtual void setEnergyRead(double energy)
CostDBEntryStats(double areaData, double internalDelayData)
virtual double energyIdle() const
virtual void setEnergyOperation(const std::string &name, double energy)
virtual CostDBEntryStats * createStats() const
virtual CostDBEntryStats * copy() const
static const std::string ENERGY_ACTIVE
String for active energy.
virtual double findDelay(const std::string &key) const
virtual bool hasDelay(const std::string &key) const
virtual void addDelay(const std::string &name, double delay)
static const std::string ENERGY_READ_WRITE
String for reads and writes energy.
virtual double findEnergy(const std::string &key) const
virtual double delayPort(const std::string &port) const
DelayMap delays_
input and output delays in nanoseconds.
double delay_
delay in nanoseconds.
virtual bool hasEnergyOperation(const std::string &name) const
virtual double energyWrite() const
virtual void setEnergyReadWrite(int reads, int writes, double energy)
EnergyMap energies_
Energies of one specific type of usage of a resource. Usually the map contains energies for active an...
virtual double energyActive() const
virtual double delay() const
virtual void setEnergyIdle(double energy)
virtual void setEnergyWrite(double energy)
virtual double energyReadWrite(int reads, int writes) const
static const std::string ENERGY_READ
String for read energy.
double area_
area in gates.
virtual double energyRead() const
virtual void setEnergyActive(double energy)
virtual void setDelay(const std::string &port, double delay)
virtual bool hasEnergy(const std::string &key) const
static const std::string ENERGY_WRITE
String for write energy.
virtual void addEnergy(const std::string &name, double energy)
virtual double energyOperation(const std::string &name) const
virtual double area() const
static const std::string ENERGY_IDLE
String for idle energy.