OpenASIP  2.0
Evaluate.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 Evaluate.cc
26  *
27  * Explorer plugin that evaluates the given configuration.
28  *
29  * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <vector>
34 #include <set>
35 #include <string>
37 #include "DSDBManager.hh"
38 #include "Machine.hh"
39 #include "CostEstimates.hh"
40 #include "HDBRegistry.hh"
41 #include "StringTools.hh"
42 #include "Exception.hh"
43 #include "Conversion.hh"
44 
45 #include <iostream>
46 #include <iomanip>
47 
48 //using namespace TTAProgram;
49 using namespace TTAMachine;
50 using namespace HDB;
51 using std::endl;
52 using std::cout;
53 using std::setw;
54 
55 /**
56  * Explorer plugin that evaluates a configuration and estimates it if the
57  * configuration has an implementation.
58  */
60  PLUGIN_DESCRIPTION("Evaluates and/or estimates a configuration.");
61 
63  adf_(""),
64  idf_(""),
65  print_(true) {
66 
67  // compulsory parameters
68  // no compulsory parameters
69 
70  // parameters that have a default value
71  addParameter(adfPN_, STRING, false, adf_);
72  addParameter(idfPN_, STRING, false, idf_);
73  addParameter(printPN_, BOOL, false, Conversion::toString(print_));
74  }
75 
76  virtual bool requiresStartingPointArchitecture() const { return false; }
77  virtual bool producesArchitecture() const { return false; }
78  virtual bool requiresHDB() const { return false; }
79  virtual bool requiresSimulationData() const { return true; }
80 
81  virtual std::vector<RowID>
82  explore(const RowID& configurationID, const unsigned int&) {
83  readParameters();
84  std::vector<RowID> result;
85 
86  // make params for adf and idf, so no configuration needed
87  if (configurationID == 0 && adf_ == "") {
88  std::ostringstream msg(std::ostringstream::out);
89  msg << "No configuration nor adf defined. Use -s <confID> to "
90  << "define the configuration to be optimized or give adf "
91  << "as plugin parameter." << endl;
92  verboseLog(msg.str());
93  return result;
94  }
95 
96  DSDBManager& dsdb = db();
98 
99  // load adf/idf from file if no configuration was given
100  if (configurationID == 0) {
101  if (!createConfig(adf_, idf_, dsdb, conf)) {
102  return result;
103  }
104  } else {
105  // if starting configuration given load it
106  conf = dsdb.configuration(configurationID);
107  }
108 
109  CostEstimates estimates;
110  bool estimate = (conf.hasImplementation ? true : false);
111  try {
112  if (!evaluate(conf, estimates, estimate)) {
113  verboseLog(std::string("Evaluate failed."))
114  return result;
115  }
116  } catch (const Exception& e) {
117  debugLog(std::string("Error in Evaluate plugin: ")
118  + e.errorMessage() + std::string(" ")
119  + e.errorMessageStack());
120  return result;
121  }
122 
123  verboseLogC(std::string("Evalution OK, ")
124  + (estimate ? "with" : "without") + " estimation.",1)
125 
126  if (print_ && estimate) {
127  printEstimates(estimates, conf);
128  }
129 
130  // add new configuration to the database
131  if (configurationID == 0) {
132  RowID newConfID = addConfToDSDB(conf);
133  if (newConfID != 0) {
134  result.push_back(newConfID);
135  }
136  }
137  return result;
138  }
139 
140 private:
141  // parameter names
142  static const std::string adfPN_;
143  static const std::string idfPN_;
144  static const std::string printPN_;
145 
146  // parameters
147  /// name of the adf file to evaluate
148  std::string adf_;
149  /// name of the idf file to evaluate
150  std::string idf_;
151  /// print evaluation results
152  bool print_;
153 
154  /**
155  * Reads the parameters given to the plugin.
156  */
157  void readParameters() {
158  // optional parameters
159  readOptionalParameter(adfPN_, adf_);
160  readOptionalParameter(idfPN_, idf_);
161  readOptionalParameter(printPN_, print_);
162  }
163 
164 
165  /**
166  * Load adf and idf from files and store to given dsdb and config.
167  *
168  * @param adf Path of architecture definition file.
169  * @param idf Path of implementation definition file.
170  * @param dsdb Database where to store adf and idf.
171  * @param conf Configuration for adf/idf ids.
172  * @return True if creating config succeeded, else false.
173  */
175  const std::string& adf,
176  const std::string& idf,
177  DSDBManager& dsdb,
179 
180  assert(adf != "");
181 
182  IDF::MachineImplementation* idfo = NULL;
183  TTAMachine::Machine* mach = NULL;
184  try {
185  if (adf != "") {
187  conf.architectureID = dsdb.addArchitecture(*mach);
188  } else {
189  return false;
190  }
191  if (idf != "") {
193  conf.implementationID =
194  dsdb.addImplementation(*idfo, 0,0);
195  conf.hasImplementation = true;
196  } else {
197  conf.hasImplementation = false;
198  }
199  } catch (const Exception& e) {
200  std::ostringstream msg(std::ostringstream::out);
201  msg << "Error loading the adf/idf." << std::endl;
202  verboseLog(msg.str());
203  delete mach;
204  return false;
205  }
206  delete mach;
207  return true;
208  }
209 
210 
211  /**
212  * Print estimates
213  *
214  * @param estimates The cost estimates to be printed.
215  */
217  const CostEstimates& estimates,
218  const DSDBManager::MachineConfiguration& configuration) {
219  std::ostream& log = std::cout;
220  log.flags(std::ios::left);
221  int fw = 27;
222 
223  log << setw(fw) << "Area: " << estimates.area() << endl;
224  log << setw(fw) << "Longest path delay: " <<
225  estimates.longestPathDelay() << endl;
226  for (int i = 0; i < estimates.energies(); ++i) {
227  log << "application " << i << setw(14) << " energy: " <<
228  estimates.energy(i) << endl;
229  }
230 
231  std::vector<ClockCycleCount> cycleCounts =
232  db().cycleCounts(configuration);
233 
234  for (int i = 0; i < (int)cycleCounts.size(); ++i) {
235  log << "application " << i << " cycle count: " <<
236  cycleCounts.at(i) << endl;
237  }
238  }
239 };
240 
241 // parameters
242 const std::string Evaluate::adfPN_("adf");
243 const std::string Evaluate::idfPN_("idf");
244 const std::string Evaluate::printPN_("print");
245 
Evaluate::Evaluate
Evaluate()
Definition: Evaluate.cc:62
HDB
Definition: CostDatabase.hh:49
CostEstimates
Definition: CostEstimates.hh:57
Exception.hh
DSDBManager::MachineConfiguration::hasImplementation
bool hasImplementation
Definition: DSDBManager.hh:80
Evaluate::requiresSimulationData
virtual bool requiresSimulationData() const
Definition: Evaluate.cc:79
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
Evaluate::createConfig
bool createConfig(const std::string &adf, const std::string &idf, DSDBManager &dsdb, DSDBManager::MachineConfiguration &conf)
Definition: Evaluate.cc:174
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
CostEstimates::energy
double energy(int index) const
Definition: CostEstimates.cc:138
Evaluate::explore
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
Definition: Evaluate.cc:82
CostEstimates::energies
int energies() const
Definition: CostEstimates.cc:124
Evaluate::idf_
std::string idf_
name of the idf file to evaluate
Definition: Evaluate.cc:150
Conversion::toString
static std::string toString(const T &source)
DesignSpaceExplorerPlugin.hh
verboseLog
#define verboseLog(text)
Definition: Application.hh:115
BOOL
@ BOOL
Definition: ExplorerPluginParameter.hh:40
Evaluate
Definition: Evaluate.cc:59
Evaluate::readParameters
void readParameters()
Definition: Evaluate.cc:157
StringTools.hh
assert
#define assert(condition)
Definition: Application.hh:86
DSDBManager::MachineConfiguration::implementationID
RowID implementationID
Definition: DSDBManager.hh:81
Evaluate::printPN_
static const std::string printPN_
Definition: Evaluate.cc:144
CostEstimates::longestPathDelay
double longestPathDelay() const
Definition: CostEstimates.cc:112
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
PLUGIN_DESCRIPTION
const std::string PLUGIN_DESCRIPTION
Definition: DefaultICDecoderPlugin.cc:917
Evaluate::print_
bool print_
print evaluation results
Definition: Evaluate.cc:152
Evaluate::idfPN_
static const std::string idfPN_
Definition: Evaluate.cc:143
STRING
@ STRING
Definition: ExplorerPluginParameter.hh:40
EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
Definition: DesignSpaceExplorerPlugin.hh:125
verboseLogC
#define verboseLogC(text, neededVerbosity)
Definition: Application.hh:110
Conversion.hh
CostEstimates.hh
Evaluate::producesArchitecture
virtual bool producesArchitecture() const
Definition: Evaluate.cc:77
Evaluate::requiresHDB
virtual bool requiresHDB() const
Definition: Evaluate.cc:78
Evaluate::printEstimates
void printEstimates(const CostEstimates &estimates, const DSDBManager::MachineConfiguration &configuration)
Definition: Evaluate.cc:216
CostEstimates::area
double area() const
Definition: CostEstimates.cc:101
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
Evaluate::adf_
std::string adf_
name of the adf file to evaluate
Definition: Evaluate.cc:148
Machine.hh
Exception
Definition: Exception.hh:54
DSDBManager
Definition: DSDBManager.hh:76
Evaluate::requiresStartingPointArchitecture
virtual bool requiresStartingPointArchitecture() const
Definition: Evaluate.cc:76
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
DSDBManager.hh
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
DSDBManager::configuration
MachineConfiguration configuration(RowID id) const
Definition: DSDBManager.cc:361
Evaluate::adfPN_
static const std::string adfPN_
Definition: Evaluate.cc:142
TTAMachine
Definition: Assembler.hh:48
HDBRegistry.hh
debugLog
#define debugLog(text)
Definition: Application.hh:95
DSDBManager::MachineConfiguration::architectureID
RowID architectureID
Definition: DSDBManager.hh:79
DSDBManager::addImplementation
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
Definition: DSDBManager.cc:252
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
IDF::MachineImplementation::loadFromIDF
static MachineImplementation * loadFromIDF(const std::string &idfFileName)
Definition: MachineImplementation.cc:1524
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905