OpenASIP 2.2
Loading...
Searching...
No Matches
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"
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"
54#include "TemplateSlot.hh"
55#include "CostEstimates.hh"
56#include "Application.hh"
57#include "Guard.hh"
58#include "Exception.hh"
59
60using namespace TTAProgram;
61using namespace TTAMachine;
62using namespace HDB;
63using std::cerr;
64using std::endl;
65using 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
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&) {
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
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
172private:
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 */
198
199
200 /**
201 * Sets up the component implementation selector by adding the HDBs.
202 */
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
220const std::string ImplementationSelector::icDecPN_("ic_dec");
221const std::string ImplementationSelector::icDecHDBPN_("ic_hdb");
222const std::string ImplementationSelector::adfPN_("adf");
223
#define verboseLog(text)
int RowID
Type definition of row ID in relational databases.
Definition DBTypes.hh:37
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
IDF::MachineImplementation * selectComponents(const TTAMachine::Machine *mach, const std::string &icDecoder="ic_hdb", const std::string &icDecoderHDB="asic_130nm_1.5V.hdb", const double &frequency=0, const double &maxArea=0)
RowID addArchitecture(const TTAMachine::Machine &mom)
TTAMachine::Machine * architecture(RowID id) const
MachineConfiguration configuration(RowID id) const
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
RowID addConfiguration(const MachineConfiguration &conf)
void readOptionalParameter(const std::string paramName, T &param) const
void addParameter(TCEString name, ExplorerPluginParameterType type, bool compulsory=true, TCEString defaultValue="", TCEString description="")
virtual DSDBManager & db()
std::string fileName() const
std::string errorMessage() const
Definition Exception.cc:123
int lineNum() const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
void loadFromSearchPaths()
static const std::string icDecPN_
static const std::string adfPN_
std::string icDec_
name of the ic decoder plugin for idf
virtual bool requiresApplication() const
ComponentImplementationSelector selector_
Selector used by the plugin.
std::string adf_
name of the adf file if wanted to use idf generation
virtual bool producesArchitecture() const
virtual bool requiresHDB() const
static const std::string icDecHDBPN_
virtual bool requiresSimulationData() const
virtual bool requiresStartingPointArchitecture() const
std::string icDecHDB_
name of the hdb used by ic decoder
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
PLUGIN_DESCRIPTION("Creates implementation for the given machine.")
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899