OpenASIP 2.2
Loading...
Searching...
No Matches
ComponentAdder.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 ComponentAdder.cc
26 *
27 * Explorer plugin that adds machine components to a given machine.
28 *
29 * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
30 * @author Pekka Jääskeläinen 2011
31 * @note rating: red
32 */
33
34#include <vector>
35#include <string>
37#include "DSDBManager.hh"
38#include "Machine.hh"
39#include "HDBRegistry.hh"
40#include "StringTools.hh"
41#include "RFPort.hh"
43#include "Exception.hh"
44#include "Conversion.hh"
45
46//using namespace TTAProgram;
47using namespace TTAMachine;
48using namespace HDB;
49using std::endl;
50
51/**
52 * Explorer plugin that adds machine components to a given machine.
53 *
54 * Supported parameters:
55 * - rf_size, number of registers in one register file, default is 4
56 * - max_rfs, maximum number of register files in the machine, default is 16
57 * - rf_reads, number of register read ports in register files, default is 1
58 * - rf_writes, number of register write ports in register file, default is 1
59 * - build_idf, if parameter is set the idf file is built, not set as default
60 * - adf, if idf is wanted to generated to some arhitecture, no default value.
61 * If adf parameter is given the idf is built.
62 */
64 PLUGIN_DESCRIPTION("Explorer plugin that adds machine components to a "
65 "given machine.");
66
68 RFName_("rf"),
69 RFCount_(1),
70 RFSize_(4),
71 RFReadPorts_(1),
73 adf_(""),
75
76 // compulsory parameters
77 // no compulsory parameters
78
79 // parameters that have a default value
87 }
88
89 virtual bool requiresStartingPointArchitecture() const { return false; }
90 virtual bool producesArchitecture() const { return true; }
91 virtual bool requiresHDB() const { return false; }
92 virtual bool requiresSimulationData() const { return true; }
93 virtual bool requiresApplication() const { return false; }
94
95 /**
96 * Explorer plugin that adds machine components to a given machine with
97 * adf parameter or with configuration id in dsdb.
98 */
99 virtual std::vector<RowID>
100 explore(const RowID& configurationID, const unsigned int&) {
102 std::vector<RowID> result;
103
104 // check if adf given
105 if (configurationID == 0 && adf_ == "") {
106 std::ostringstream msg(std::ostringstream::out);
107 msg << "No configuration nor adf defined. Use -s <confID> to "
108 << "define the configuration to be optimized or give adf "
109 << "as plugin parameter." << endl;
110 verboseLog(msg.str());
111 return result;
112 }
113
114 DSDBManager& dsdb = db();
116 conf.hasImplementation = false;
117 TTAMachine::Machine* mach = NULL;
118
119 // load the adf from file or from dsdb
120 try {
121 if (adf_ != "") {
123 } else {
124 conf = dsdb.configuration(configurationID);
125 mach = dsdb.architecture(conf.architectureID);
126 }
127 } catch (const Exception& e) {
128 std::ostringstream msg(std::ostringstream::out);
129 msg << "Error loading the adf." << std::endl;
130 verboseLog(msg.str());
131 return result;
132 }
133 assert(mach != NULL);
134
135 // add components
136 addComponents(mach);
137
138 if (buildIdf_) {
139 try {
140 // add idf to configuration
141 selector_.selectComponentsToConf(conf, dsdb, mach);
142 } catch (const Exception& e) {
143 std::ostringstream msg(std::ostringstream::out);
144 msg << e.errorMessage()
145 << " " << e.fileName()
146 << " " << e.lineNum() << std::endl;
147 verboseLog(msg.str());
148 }
149 } else {
150 conf.hasImplementation = false;
151 }
152
153 // add machine to configuration
154 conf.architectureID = dsdb.addArchitecture(*mach);
155
156 // add new configuration to dsdb
157 RowID confID = dsdb.addConfiguration(conf);
158 result.push_back(confID);
159 return result;
160 }
161
162private:
163 /// Selector used by the plugin.
165
166 static const std::string RFNamePN_;
167 static const std::string RFCountPN_;
168 static const std::string RFSizePN_;
169 static const std::string RFReadPortsPN_;
170 static const std::string RFWritePortsPN_;
171 static const std::string adfPN_;
172 static const std::string buildIdfPN_;
173
174 // register file variables
175 std::string RFName_;
180 /// name of the adf file if wanted to use idf generation
181 std::string adf_;
182 /// do we build idf
184
185 /**
186 * Reads the parameters given to the plugin.
187 */
197
198
199 /**
200 * Builds the machine in basis of the analyzed data from the applications.
201 *
202 * @return The initial machine of NULL if an error occurred.
203 */
205 // add register files
206 addRegisterFiles(mach);
207 }
208
209
210 /**
211 * Adds register file(s) to the machine
212 *
213 * TODO: add type and guard latency setting
214 *
215 * @return void
216 */
218 for (int i = 0; i < RFCount_; i++) {
219 std::string RFName = RFName_ + Conversion::toString(i);
220
222 mach->registerFileNavigator();
223 if (RFNav.hasItem(RFName)) {
224 RFName = RFName_ + Conversion::toString(i+RFNav.count());
225 }
226
228 RFName, RFSize_, 32, RFReadPorts_, RFWritePorts_, 0,
230 for (int n = 0; n < RFReadPorts_; n++) {
231 new TTAMachine::RFPort("read" +
232 Conversion::toString( + 1), *rf);
233 }
234 for (int n = 0; n < RFWritePorts_; n++) {
235 new TTAMachine::RFPort("write" +
236 Conversion::toString(n + 1), *rf);
237 }
238 try {
239 mach->addRegisterFile(*rf);
240 } catch (const ComponentAlreadyExists& e) {
241 verboseLog("ComponentAdder: Tried to add RF with a already"
242 "existing name (" + RFName)
244 }
245 }
246 }
247};
248
249// parameters
250const std::string ComponentAdder::RFNamePN_("rf_name");
251const std::string ComponentAdder::RFCountPN_("rf_count");
252const std::string ComponentAdder::RFSizePN_("rf_size");
253const std::string ComponentAdder::RFReadPortsPN_("rf_reads");
254const std::string ComponentAdder::RFWritePortsPN_("rf_writes");
255const std::string ComponentAdder::adfPN_("adf");
256const std::string ComponentAdder::buildIdfPN_("build_idf");
257
#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 UINT(OPERAND)
Definition OSAL.hh:313
#define BOOL()
static void exitProgram(const int status=EXIT_SUCCESS)
static const std::string RFSizePN_
std::string adf_
name of the adf file if wanted to use idf generation
static const std::string RFCountPN_
void addComponents(TTAMachine::Machine *mach)
static const std::string RFReadPortsPN_
void addRegisterFiles(TTAMachine::Machine *mach)
virtual bool requiresApplication() const
static const std::string buildIdfPN_
virtual bool requiresSimulationData() const
ComponentImplementationSelector selector_
Selector used by the plugin.
virtual std::vector< RowID > explore(const RowID &configurationID, const unsigned int &)
PLUGIN_DESCRIPTION("Explorer plugin that adds machine components to a " "given machine.")
virtual bool requiresStartingPointArchitecture() const
std::string RFName_
static const std::string RFNamePN_
static const std::string RFWritePortsPN_
bool buildIdf_
do we build idf
virtual bool producesArchitecture() const
virtual bool requiresHDB() const
static const std::string adfPN_
void selectComponentsToConf(DSDBManager::MachineConfiguration &conf, DSDBManager &dsdb, TTAMachine::Machine *mach=NULL, const std::string &icDecoder="ic_hdb", const std::string &icDecoderHDB="asic_130nm_1.5V.hdb", const double &frequency=0, const double &maxArea=0)
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 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
bool hasItem(const std::string &name) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual void addRegisterFile(RegisterFile &unit)
Definition Machine.cc:236
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899
@ NORMAL
Used for general register allocation.