OpenASIP 2.2
Loading...
Searching...
No Matches
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;
49using namespace TTAMachine;
50using 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_(""),
65
66 // compulsory parameters
67 // no compulsory parameters
68
69 // parameters that have a default value
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&) {
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
186private:
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 */
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
255const std::string MinimalOpSet::adfPN_("adf");
256const std::string MinimalOpSet::idfPN_("idf");
257const std::string MinimalOpSet::printMissingOpsPN_("print");
258
#define debugLog(text)
#define verboseLog(text)
#define assert(condition)
int RowID
Type definition of row ID in relational databases.
Definition DBTypes.hh:37
#define EXPORT_DESIGN_SPACE_EXPLORER_PLUGIN(PLUGIN_NAME__)
find Finds info of the inner loops in the false
#define BOOL()
static std::string toString(const T &source)
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)
void readCompulsoryParameter(const std::string paramName, T &param) const
void addParameter(TCEString name, ExplorerPluginParameterType type, bool compulsory=true, TCEString defaultValue="", TCEString description="")
RowID addConfToDSDB(const DSDBManager::MachineConfiguration &conf)
bool createImplementation(const DSDBManager::MachineConfiguration &conf, DSDBManager::MachineConfiguration &newConf, const double &frequency=0.0, const double &maxArea=0.0, const bool &createEstimates=true, const std::string &icDec="DefaultICDecoder", const std::string &icDecHDB="asic_130nm_1.5V.hdb")
virtual DSDBManager & db()
virtual bool evaluate(const DSDBManager::MachineConfiguration &configuration, CostEstimates &results=dummyEstimate_, bool estimate=false)
std::string errorMessageStack(bool messagesOnly=false) const
Definition Exception.cc:138
std::string errorMessage() const
Definition Exception.cc:123
static MachineImplementation * loadFromIDF(const std::string &idfFileName)
virtual std::string fix(TTAMachine::Machine &machine) const
void missingOperations(const TTAMachine::Machine &machine, std::vector< std::string > &missingOps) const
bool createConfig(const std::string &adf, const std::string &idf, DSDBManager &dsdb, DSDBManager::MachineConfiguration &conf)
std::string idf_
name of the idf file to evaluate
static const std::string printMissingOpsPN_
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
virtual bool requiresStartingPointArchitecture() const
static const std::string adfPN_
std::string adf_
name of the adf file to evaluate
virtual bool requiresApplication() const
virtual bool producesArchitecture() const
virtual bool requiresSimulationData() const
static const std::string idfPN_
void readParameters()
bool printMissingOps_
print missing ops
PLUGIN_DESCRIPTION("Minimal opset checker and fixer plugin.")
virtual bool requiresHDB() const
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899