OpenASIP 2.2
Loading...
Searching...
No Matches
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;
49using namespace TTAMachine;
50using namespace HDB;
51using std::endl;
52using std::cout;
53using 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
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&) {
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
140private:
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 */
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
242const std::string Evaluate::adfPN_("adf");
243const std::string Evaluate::idfPN_("idf");
244const std::string Evaluate::printPN_("print");
245
#define debugLog(text)
#define verboseLog(text)
#define verboseLogC(text, neededVerbosity)
#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__)
#define BOOL()
static std::string toString(const T &source)
int energies() const
double energy(int index) const
double area() const
double longestPathDelay() const
RowID addArchitecture(const TTAMachine::Machine &mom)
MachineConfiguration configuration(RowID id) const
std::vector< ClockCycleCount > cycleCounts(const MachineConfiguration &conf) const
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
void readOptionalParameter(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)
virtual DSDBManager & db()
virtual bool evaluate(const DSDBManager::MachineConfiguration &configuration, CostEstimates &results=dummyEstimate_, bool estimate=false)
virtual bool requiresSimulationData() const
Definition Evaluate.cc:79
void readParameters()
Definition Evaluate.cc:157
void printEstimates(const CostEstimates &estimates, const DSDBManager::MachineConfiguration &configuration)
Definition Evaluate.cc:216
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
Definition Evaluate.cc:82
bool print_
print evaluation results
Definition Evaluate.cc:152
static const std::string printPN_
Definition Evaluate.cc:144
std::string idf_
name of the idf file to evaluate
Definition Evaluate.cc:150
bool createConfig(const std::string &adf, const std::string &idf, DSDBManager &dsdb, DSDBManager::MachineConfiguration &conf)
Definition Evaluate.cc:174
std::string adf_
name of the adf file to evaluate
Definition Evaluate.cc:148
static const std::string idfPN_
Definition Evaluate.cc:143
virtual bool requiresHDB() const
Definition Evaluate.cc:78
virtual bool requiresStartingPointArchitecture() const
Definition Evaluate.cc:76
virtual bool producesArchitecture() const
Definition Evaluate.cc:77
PLUGIN_DESCRIPTION("Evaluates and/or estimates a configuration.")
static const std::string adfPN_
Definition Evaluate.cc:142
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)
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899