OpenASIP  2.0
ImplementationSelector.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 ImplementationSelector.cc
26  *
27  * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
28  * @note rating: red
29  */
30 
31 #include <vector>
32 #include <string>
34 #include "DSDBManager.hh"
35 #include "Machine.hh"
36 #include "TestApplication.hh"
37 #include "Program.hh"
38 #include "Instruction.hh"
39 #include "Move.hh"
40 #include "Terminal.hh"
41 #include "Operation.hh"
42 #include "StaticProgramAnalyzer.hh"
44 #include "HDBRegistry.hh"
46 #include "ControlUnit.hh"
47 #include "HWOperation.hh"
48 #include "StringTools.hh"
49 #include "ADFSerializer.hh"
50 #include "IDFSerializer.hh"
51 #include "Segment.hh"
52 #include "RFPort.hh"
53 #include "FullyConnectedCheck.hh"
54 #include "TemplateSlot.hh"
55 #include "CostEstimates.hh"
56 #include "Application.hh"
57 #include "Guard.hh"
58 #include "Exception.hh"
59 
60 using namespace TTAProgram;
61 using namespace TTAMachine;
62 using namespace HDB;
63 using std::cerr;
64 using std::endl;
65 using std::map;
66 
67 /**
68  * Explorer plugin that selects implementations for units in a given adf.
69  * Creates a new config with a idf.
70  *
71  * Supported parameters:
72  * - ic_dec, name of the ic decoder plugin, default is DefaultICDecoder
73  * - ic_hdb, name of the HDB that is used in IC estimation,
74  * default is asic_130nm_1.5V.hdb
75  * - adf, if idf is wanted to generated to some arhitecture, no default value.
76  * If adf parameter is given the idf is built.
77  */
79  PLUGIN_DESCRIPTION("Creates implementation for the given machine.");
80 
82  icDec_("DefaultICDecoder"),
83  icDecHDB_("asic_130nm_1.5V.hdb"),
84  adf_("") {
85 
86  // compulsory parameters
87  // no compulsory parameters
88 
89  // parameters that have a default value
90  addParameter(icDecPN_, STRING, false, icDec_);
91  addParameter(icDecHDBPN_, STRING, false, icDecHDB_);
92  addParameter(adfPN_, STRING, false, adf_);
93  }
94 
95  virtual bool requiresStartingPointArchitecture() const { return true; }
96  virtual bool producesArchitecture() const { return false; }
97  virtual bool requiresHDB() const { return true; }
98  virtual bool requiresSimulationData() const { return false; }
99  virtual bool requiresApplication() const { return false; }
100 
101  /**
102  */
103  virtual std::vector<RowID>
104  explore(const RowID& configurationID, const unsigned int&) {
105  readParameters();
106  setupSelector();
107  std::vector<RowID> result;
108 
109  // check if adf given
110  if (configurationID == 0 && adf_ == "") {
111  std::ostringstream msg(std::ostringstream::out);
112  msg << "No configuration nor adf defined. Use -s <confID> to "
113  << "define the configuration to be optimized or give adf "
114  << "as plugin parameter." << endl;
115  verboseLog(msg.str());
116  return result;
117  }
118 
119  DSDBManager& dsdb = db();
121  conf.hasImplementation = false;
122  TTAMachine::Machine* mach = NULL;
123 
124  // load the adf from file or from dsdb
125  try {
126  if (adf_ != "") {
128  } else {
129  conf = dsdb.configuration(configurationID);
130  mach = dsdb.architecture(conf.architectureID);
131  }
132  } catch (const Exception& e) {
133  std::ostringstream msg(std::ostringstream::out);
134  msg << "Error loading the adf." << std::endl;
135  verboseLog(msg.str());
136  return result;
137  }
138 
139  IDF::MachineImplementation* idf = NULL;
140  try {
141  // building the idf
142  idf = selector_.selectComponents(mach, icDec_, icDecHDB_);
143  } catch (const Exception& e) {
144  std::ostringstream msg(std::ostringstream::out);
145  msg << e.errorMessage()
146  << " " << e.fileName()
147  << " " << e.lineNum() << std::endl;
148  verboseLog(msg.str());
149  return result;
150  }
151 
152  // create a new configuration
153 
154  try {
155  conf.architectureID = dsdb.addArchitecture(*mach);
156  } catch (const RelationalDBException& e) {
157  std::ostringstream msg(std::ostringstream::out);
158  msg << "Error while adding ADF to the dsdb. "
159  << "ADF probably too big." << endl;
160  verboseLog(msg.str());
161  return result;
162  }
163  conf.implementationID = dsdb.addImplementation(*idf, 0, 0);
164  conf.hasImplementation = true;
165 
166  RowID confID = dsdb.addConfiguration(conf);
167  result.push_back(confID);
168 
169  return result;
170  }
171 
172 private:
173  /// Selector used by the plugin.
175 
176  // parameter names
177  static const std::string icDecPN_;
178  static const std::string icDecHDBPN_;
179  static const std::string adfPN_;
180 
181  // parameters
182  /// name of the ic decoder plugin for idf
183  std::string icDec_;
184  /// name of the hdb used by ic decoder
185  std::string icDecHDB_;
186  /// name of the adf file if wanted to use idf generation
187  std::string adf_;
188 
189 
190  /**
191  * Reads the parameters given to the plugin.
192  */
193  void readParameters() {
194  readOptionalParameter(icDecPN_, icDec_);
195  readOptionalParameter(icDecHDBPN_, icDecHDB_);
196  readOptionalParameter(adfPN_, adf_);
197  }
198 
199 
200  /**
201  * Sets up the component implementation selector by adding the HDBs.
202  */
203  void setupSelector() {
204  HDBRegistry& hdbRegistry = HDBRegistry::instance();
205 
206  // if HDBRegistry contains no HDBManagers load from default paths
207  if (hdbRegistry.hdbCount() == 0) {
208  hdbRegistry.loadFromSearchPaths();
209  }
210 
211  // give all HDBs from registry to the selector to select from
212  for (int i = 0; i < hdbRegistry.hdbCount(); i++) {
213  HDBManager* hdb = &hdbRegistry.hdb(i);
214  selector_.addHDB(*hdb);
215  }
216  }
217 };
218 
219 // parameter names
220 const std::string ImplementationSelector::icDecPN_("ic_dec");
221 const std::string ImplementationSelector::icDecHDBPN_("ic_hdb");
222 const std::string ImplementationSelector::adfPN_("adf");
223 
ImplementationSelector::icDec_
std::string icDec_
name of the ic decoder plugin for idf
Definition: ImplementationSelector.cc:183
TTAProgram
Definition: Estimator.hh:65
Exception::lineNum
int lineNum() const
ImplementationSelector::producesArchitecture
virtual bool producesArchitecture() const
Definition: ImplementationSelector.cc:96
ComponentImplementationSelector::addHDB
void addHDB(const HDB::HDBManager &hdb)
Definition: ComponentImplementationSelector.cc:83
HDB
Definition: CostDatabase.hh:49
RelationalDBException
Definition: Exception.hh:692
Exception.hh
ImplementationSelector::explore
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
Definition: ImplementationSelector.cc:104
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
DSDBManager::MachineConfiguration::hasImplementation
bool hasImplementation
Definition: DSDBManager.hh:80
ICDecoderEstimatorPlugin.hh
ImplementationSelector::requiresStartingPointArchitecture
virtual bool requiresStartingPointArchitecture() const
Definition: ImplementationSelector.cc:95
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
ImplementationSelector::requiresHDB
virtual bool requiresHDB() const
Definition: ImplementationSelector.cc:97
HDB::HDBRegistry::hdb
CachedHDBManager & hdb(const std::string fileName)
Definition: HDBRegistry.cc:80
StaticProgramAnalyzer.hh
Terminal.hh
DesignSpaceExplorerPlugin.hh
FullyConnectedCheck.hh
verboseLog
#define verboseLog(text)
Definition: Application.hh:115
ImplementationSelector::setupSelector
void setupSelector()
Definition: ImplementationSelector.cc:203
Exception::fileName
std::string fileName() const
StringTools.hh
TemplateSlot.hh
DSDBManager::MachineConfiguration::implementationID
RowID implementationID
Definition: DSDBManager.hh:81
Segment.hh
HDB::HDBRegistry
Definition: HDBRegistry.hh:46
ImplementationSelector::adfPN_
static const std::string adfPN_
Definition: ImplementationSelector.cc:179
HWOperation.hh
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
PLUGIN_DESCRIPTION
const std::string PLUGIN_DESCRIPTION
Definition: DefaultICDecoderPlugin.cc:917
ImplementationSelector::requiresApplication
virtual bool requiresApplication() const
Definition: ImplementationSelector.cc:99
Instruction.hh
STRING
@ STRING
Definition: ExplorerPluginParameter.hh:40
EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
Definition: DesignSpaceExplorerPlugin.hh:125
CostEstimates.hh
ImplementationSelector::icDecPN_
static const std::string icDecPN_
Definition: ImplementationSelector.cc:177
Application.hh
ImplementationSelector
Definition: ImplementationSelector.cc:78
Guard.hh
HDB::HDBManager
Definition: HDBManager.hh:82
Operation.hh
ImplementationSelector::readParameters
void readParameters()
Definition: ImplementationSelector.cc:193
Machine.hh
Exception
Definition: Exception.hh:54
DSDBManager
Definition: DSDBManager.hh:76
ComponentImplementationSelector.hh
ImplementationSelector::requiresSimulationData
virtual bool requiresSimulationData() const
Definition: ImplementationSelector.cc:98
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
HDB::HDBRegistry::hdbCount
int hdbCount()
Definition: HDBRegistry.cc:135
DSDBManager.hh
DSDBManager::addConfiguration
RowID addConfiguration(const MachineConfiguration &conf)
Definition: DSDBManager.cc:299
ImplementationSelector::icDecHDBPN_
static const std::string icDecHDBPN_
Definition: ImplementationSelector.cc:178
ComponentImplementationSelector
Definition: ComponentImplementationSelector.hh:74
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
ImplementationSelector::ImplementationSelector
ImplementationSelector()
Definition: ImplementationSelector.cc:81
DSDBManager::configuration
MachineConfiguration configuration(RowID id) const
Definition: DSDBManager.cc:361
ImplementationSelector::adf_
std::string adf_
name of the adf file if wanted to use idf generation
Definition: ImplementationSelector.cc:187
ADFSerializer.hh
Program.hh
ControlUnit.hh
HDB::HDBRegistry::loadFromSearchPaths
void loadFromSearchPaths()
Definition: HDBRegistry.cc:146
RFPort.hh
Move.hh
TTAMachine
Definition: Assembler.hh:48
HDBRegistry.hh
DSDBManager::MachineConfiguration::architectureID
RowID architectureID
Definition: DSDBManager.hh:79
ImplementationSelector::selector_
ComponentImplementationSelector selector_
Selector used by the plugin.
Definition: ImplementationSelector.cc:174
DSDBManager::addImplementation
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
Definition: DSDBManager.cc:252
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
TTAMachine::Machine
Definition: Machine.hh:73
ImplementationSelector::icDecHDB_
std::string icDecHDB_
name of the hdb used by ic decoder
Definition: ImplementationSelector.cc:185
TestApplication.hh
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905
IDFSerializer.hh