OpenASIP  2.0
MinimalOpSet.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 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 MinimalOpSet.cc
26  *
27  * Explorer plugin that checks that given config or adf meets minimal opset
28  * requirements stated by minimal machine adf or user given reference adf.
29  *
30  * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
31  * @author Pekka Jääskeläinen 2011
32  * @note rating: red
33  */
34 
35 #include <vector>
36 #include <string>
38 #include "DSDBManager.hh"
39 #include "Machine.hh"
40 #include "CostEstimates.hh"
41 #include "HDBRegistry.hh"
42 #include "StringTools.hh"
43 #include "Exception.hh"
44 #include "Conversion.hh"
45 
46 #include "MinimalOpSetCheck.hh"
47 
48 //using namespace TTAProgram;
49 using namespace TTAMachine;
50 using namespace HDB;
51 
52 /**
53  * Explorer plugin that checks that given config or adf meets minimal opset
54  * requirements stated by minimal machine adf or user given reference adf.
55  *
56  * Supported parameters:
57  */
59  PLUGIN_DESCRIPTION("Minimal opset checker and fixer plugin.");
60 
62  adf_(""),
63  idf_(""),
64  printMissingOps_(false) {
65 
66  // compulsory parameters
67  // no compulsory parameters
68 
69  // parameters that have a default value
70  addParameter(adfPN_, STRING, false, adf_);
71  addParameter(idfPN_, STRING, false, idf_);
72  addParameter(printMissingOpsPN_, BOOL, false,
73  Conversion::toString(printMissingOps_));
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 false; }
80  virtual bool requiresApplication() const { return false; }
81 
82  /**
83  * Explorer plugin that checks that given config or adf meets minimal opset
84  * requirements stated by minimal machine adf or user given reference adf.
85  */
86  virtual std::vector<RowID>
87  explore(const RowID& configurationID, const unsigned int&) {
88  readParameters();
89  std::vector<RowID> result;
90  MinimalOpSetCheck minimalOpSetCheck = MinimalOpSetCheck();
91 
92  // make params for adf and idf, so no configuration needed
93  if (configurationID == 0 && adf_ == "") {
94  std::ostringstream msg(std::ostringstream::out);
95  msg << "No configuration nor adf defined. Use -s <confID> to "
96  << "define the configuration to be optimized or give adf "
97  << "as plugin parameter." << std::endl;
98  verboseLog(msg.str());
99  return result;
100  }
101 
102  DSDBManager& dsdb = db();
104  conf.architectureID = -1;
105  conf.hasImplementation = false;
106 
107  // load adf/idf from file if no configuration was given
108  if (configurationID == 0) {
109  if (!createConfig(adf_, idf_, dsdb, conf)) {
110  return result;
111  }
112  } else {
113  // if starting configuration given load it
114  conf = dsdb.configuration(configurationID);
115  }
116 
117  // load machine from configuration
118  // TODO: load machine from file is adf_ is specified.
119  Machine* mach = NULL;
120  try {
121  mach = dsdb.architecture(conf.architectureID);
122  } catch (const Exception& e) {
123  std::ostringstream msg(std::ostringstream::out);
124  msg << e.errorMessage() << std::endl;
125  verboseLog(msg.str());
126  return result;
127  }
128 
129  // check minimal opset and print missing ops
130  if (printMissingOps_) {
131  std::vector<std::string> missingOps;
132  minimalOpSetCheck.missingOperations(*mach, missingOps);
133  if (missingOps.empty()) {
134  std::cout << "MinimalOpSet: Configuration/machine has all"
135  << " the operations in the minimal opset already."
136  << std::endl;
137  return result;
138  }
139  for (unsigned int i = 0; i < missingOps.size(); ++i) {
140  std::cout << missingOps.at(i) + " : operation is missing."
141  << std::endl;
142  }
143  }
144 
145  // add FUs to the machine, so that it has all the operations in the
146  // minimal opset
147  try {
148  minimalOpSetCheck.fix(*mach);
149  } catch (const InvalidData& e) {
150  verboseLog("MinimalOpSet: Configuration/machine has all the"
151  "operations in the minimal opset already.")
152  return result;
153  }
154 
155  // create the result config
157  newConf.architectureID = dsdb.addArchitecture(*mach);
158  newConf.hasImplementation = false;
159 
160  // if old config had implementation create a new one for new config
161  if (conf.hasImplementation) {
162  createImplementation(newConf, newConf);
163  }
164 
165  CostEstimates estimates;
166  bool estimate = (newConf.hasImplementation ? true : false);
167  try {
168  if (!evaluate(newConf, estimates, estimate)) {
169  debugLog(std::string("Evaluate failed."));
170  return result;
171  }
172  } catch (const Exception& e) {
173  debugLog(std::string("Error in Evaluate plugin: ")
174  + e.errorMessage() + std::string(" ")
175  + e.errorMessageStack());
176  return result;
177  }
178 
179  RowID newConfID = addConfToDSDB(newConf);
180  if (newConfID != 0) {
181  result.push_back(newConfID);
182  }
183  return result;
184  }
185 
186 private:
187  // parameter name variables
188  static const std::string adfPN_;
189  static const std::string idfPN_;
190  static const std::string printMissingOpsPN_;
191 
192  // parameters
193  /// name of the adf file to evaluate
194  std::string adf_;
195  /// name of the idf file to evaluate
196  std::string idf_;
197  /// print missing ops
199 
200  /**
201  * Reads the parameters given to the plugin.
202  */
203  void readParameters() {
204  readCompulsoryParameter(adfPN_, adf_);
205  readCompulsoryParameter(idfPN_, idf_);
206  readCompulsoryParameter(printMissingOpsPN_, printMissingOps_);
207  }
208 
209 
210  /**
211  * Load adf and idf from files and store to given dsdb and config.
212  *
213  * @param adf Path of architecture definition file.
214  * @param idf Path of implementation definition file.
215  * @param dsdb Database where to store adf and idf.
216  * @param conf Configuration for adf/idf ids.
217  * @return True if creating config succeeded, else false.
218  */
220  const std::string& adf,
221  const std::string& idf,
222  DSDBManager& dsdb,
224 
225  assert(adf != "");
226 
227  IDF::MachineImplementation* idfo = NULL;
228  TTAMachine::Machine* mach = NULL;
229  try {
230  if (adf != "") {
232  conf.architectureID = dsdb.addArchitecture(*mach);
233  } else {
234  return false;
235  }
236  if (idf != "") {
238  conf.implementationID =
239  dsdb.addImplementation(*idfo, 0,0);
240  conf.hasImplementation = true;
241  } else {
242  conf.hasImplementation = false;
243  }
244  } catch (const Exception& e) {
245  std::ostringstream msg(std::ostringstream::out);
246  msg << "Error loading the adf/idf." << std::endl;
247  verboseLog(msg.str());
248  return false;
249  }
250  return true;
251  }
252 };
253 
254 // parameter names
255 const std::string MinimalOpSet::adfPN_("adf");
256 const std::string MinimalOpSet::idfPN_("idf");
257 const std::string MinimalOpSet::printMissingOpsPN_("print");
258 
MinimalOpSet::createConfig
bool createConfig(const std::string &adf, const std::string &idf, DSDBManager &dsdb, DSDBManager::MachineConfiguration &conf)
Definition: MinimalOpSet.cc:219
MinimalOpSet::adfPN_
static const std::string adfPN_
Definition: MinimalOpSet.cc:188
MinimalOpSetCheck
Definition: MinimalOpSetCheck.hh:53
MinimalOpSet::adf_
std::string adf_
name of the adf file to evaluate
Definition: MinimalOpSet.cc:194
HDB
Definition: CostDatabase.hh:49
MinimalOpSetCheck.hh
CostEstimates
Definition: CostEstimates.hh:57
MinimalOpSet::explore
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
Definition: MinimalOpSet.cc:87
Exception.hh
MinimalOpSetCheck::fix
virtual std::string fix(TTAMachine::Machine &machine) const
Definition: MinimalOpSetCheck.cc:298
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
DSDBManager::MachineConfiguration::hasImplementation
bool hasImplementation
Definition: DSDBManager.hh:80
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
MinimalOpSet::idf_
std::string idf_
name of the idf file to evaluate
Definition: MinimalOpSet.cc:196
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
StringTools.hh
assert
#define assert(condition)
Definition: Application.hh:86
DSDBManager::MachineConfiguration::implementationID
RowID implementationID
Definition: DSDBManager.hh:81
MinimalOpSet::idfPN_
static const std::string idfPN_
Definition: MinimalOpSet.cc:189
MinimalOpSet::requiresSimulationData
virtual bool requiresSimulationData() const
Definition: MinimalOpSet.cc:79
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
PLUGIN_DESCRIPTION
const std::string PLUGIN_DESCRIPTION
Definition: DefaultICDecoderPlugin.cc:917
InvalidData
Definition: Exception.hh:149
STRING
@ STRING
Definition: ExplorerPluginParameter.hh:40
EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
Definition: DesignSpaceExplorerPlugin.hh:125
Conversion.hh
CostEstimates.hh
MinimalOpSet::requiresApplication
virtual bool requiresApplication() const
Definition: MinimalOpSet.cc:80
MinimalOpSet::requiresHDB
virtual bool requiresHDB() const
Definition: MinimalOpSet.cc:78
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
MinimalOpSet::requiresStartingPointArchitecture
virtual bool requiresStartingPointArchitecture() const
Definition: MinimalOpSet.cc:76
MinimalOpSet::printMissingOps_
bool printMissingOps_
print missing ops
Definition: MinimalOpSet.cc:198
Machine.hh
Exception
Definition: Exception.hh:54
DSDBManager
Definition: DSDBManager.hh:76
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
DSDBManager.hh
MinimalOpSet::readParameters
void readParameters()
Definition: MinimalOpSet.cc:203
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
MinimalOpSet
Definition: MinimalOpSet.cc:58
DSDBManager::configuration
MachineConfiguration configuration(RowID id) const
Definition: DSDBManager.cc:361
MinimalOpSet::producesArchitecture
virtual bool producesArchitecture() const
Definition: MinimalOpSet.cc:77
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
MinimalOpSetCheck::missingOperations
void missingOperations(const TTAMachine::Machine &machine, std::vector< std::string > &missingOps) const
Definition: MinimalOpSetCheck.cc:213
TTAMachine
Definition: Assembler.hh:48
HDBRegistry.hh
debugLog
#define debugLog(text)
Definition: Application.hh:95
DSDBManager::MachineConfiguration::architectureID
RowID architectureID
Definition: DSDBManager.hh:79
MinimalOpSet::printMissingOpsPN_
static const std::string printMissingOpsPN_
Definition: MinimalOpSet.cc:190
MinimalOpSet::MinimalOpSet
MinimalOpSet()
Definition: MinimalOpSet.cc:61
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