OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
DesignSpaceExplorer Class Reference

#include <DesignSpaceExplorer.hh>

Inheritance diagram for DesignSpaceExplorer:
Inheritance graph
Collaboration diagram for DesignSpaceExplorer:
Collaboration graph

Public Member Functions

 DesignSpaceExplorer ()
 
virtual ~DesignSpaceExplorer ()
 
virtual void setDSDB (DSDBManager &dsdb)
 
virtual bool evaluate (const DSDBManager::MachineConfiguration &configuration, CostEstimates &results=dummyEstimate_, bool estimate=false)
 
virtual DSDBManagerdb ()
 
std::vector< DesignSpaceExplorerPlugin * > getPlugins ()
 
RowID createImplementationAndStore (const DSDBManager::MachineConfiguration &conf, 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")
 
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")
 
IDF::MachineImplementationselectComponents (const TTAMachine::Machine &mach, const double &frequency=0.0, const double &maxArea=0.0, const std::string &icDec="DefaultICDecoder", const std::string &icDecHDB="asic_130nm_1.5V.hdb") const
 
void createEstimateData (const TTAMachine::Machine &mach, const IDF::MachineImplementation &idf, CostEstimator::AreaInGates &area, CostEstimator::DelayInNanoSeconds &longestPathDelay)
 
RowID addConfToDSDB (const DSDBManager::MachineConfiguration &conf)
 

Static Public Member Functions

static DesignSpaceExplorerPluginloadExplorerPlugin (const std::string &pluginName, DSDBManager *dsdb=NULL)
 

Protected Member Functions

TTAProgram::Programschedule (const std::string applicationFile, TTAMachine::Machine &machine, TCEString paramOptions="-O3")
 
const ExecutionTracesimulate (const TTAProgram::Program &program, const TTAMachine::Machine &machine, const TestApplication &testApplication, const ClockCycleCount &maxCycles, ClockCycleCount &runnedCycles, const bool tracing, const bool useCompiledSimulation=false, std::vector< ClockCycleCount > *executionCounts=NULL)
 

Private Attributes

DSDBManagerdsdb_
 Design space database where results are stored.
 
CostEstimator::Estimator estimator_
 The estimator frontend.
 
std::ostringstream * oStream_
 Output stream.
 

Static Private Attributes

static PluginTools pluginTool_
 The plugin tool.
 
static CostEstimates dummyEstimate_
 Used for the default evaluate() argument.
 

Detailed Description

Design space explorer interface provides methods to automatically evaluate machine configurations and select best implementations to the processor components according the test applications set in Design Space Database (DSDB).

Definition at line 70 of file DesignSpaceExplorer.hh.

Constructor & Destructor Documentation

◆ DesignSpaceExplorer()

DesignSpaceExplorer::DesignSpaceExplorer ( )

The constructor.

Definition at line 84 of file DesignSpaceExplorer.cc.

84 {
85
86 //schedulingPlan_ =
87 // SchedulingPlan::loadFromFile(Environment::oldGccSchedulerConf());
88 oStream_ = new std::ostringstream;
90}
std::ostringstream * oStream_
Output stream.
static void setOutputStream(std::ostream &newOutputStream)

References oStream_, and OperationGlobals::setOutputStream().

Here is the call graph for this function:

◆ ~DesignSpaceExplorer()

DesignSpaceExplorer::~DesignSpaceExplorer ( )
virtual

The destructor.

Definition at line 95 of file DesignSpaceExplorer.cc.

95 {
96
97 //delete schedulingPlan_;
98 //schedulingPlan_ = NULL;
99 delete oStream_;
100 oStream_ = NULL;
101}

References oStream_.

Member Function Documentation

◆ addConfToDSDB()

RowID DesignSpaceExplorer::addConfToDSDB ( const DSDBManager::MachineConfiguration conf)

Add given configuration to the database.

Parameters
confConfiguration to be added to the database.
dsdbDatabase where to add the configuration.
Returns
RowID Row ID of the config in the database. 0 if adding failed.

Definition at line 794 of file DesignSpaceExplorer.cc.

795 {
796
797 try {
798 return dsdb_->addConfiguration(conf);
799 } catch (const Exception& e) {
801 return 0;
802 }
803}
#define debugLog(text)
RowID addConfiguration(const MachineConfiguration &conf)
DSDBManager * dsdb_
Design space database where results are stored.
std::string errorMessage() const
Definition Exception.cc:123

References DSDBManager::addConfiguration(), debugLog, dsdb_, and Exception::errorMessage().

Referenced by createImplementationAndStore(), Evaluate::explore(), and MinimalOpSet::explore().

Here is the call graph for this function:

◆ createEstimateData()

void DesignSpaceExplorer::createEstimateData ( const TTAMachine::Machine mach,
const IDF::MachineImplementation idf,
CostEstimator::AreaInGates area,
CostEstimator::DelayInNanoSeconds longestPathDelay 
)

creates estimate data for machine and idf.

Parameters
machMachine mathcing given idf.
idfImplementation definition for given machine.
areaEstimated area cost.
longestPathDelayEstimated longest path delay.

Definition at line 774 of file DesignSpaceExplorer.cc.

778 {
779
780 area = estimator_.totalArea(mach, idf);
781 longestPathDelay = estimator_.longestPath(mach, idf);
782}
AreaInGates totalArea(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation)
area estimation functions
Definition Estimator.cc:84
DelayInNanoSeconds longestPath(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation)
delay estimation functions
Definition Estimator.cc:915
CostEstimator::Estimator estimator_
The estimator frontend.

References estimator_, CostEstimator::Estimator::longestPath(), and CostEstimator::Estimator::totalArea().

Referenced by createImplementation(), createImplementationAndStore(), and evaluate().

Here is the call graph for this function:

◆ createImplementation()

bool DesignSpaceExplorer::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" 
)

Selects components for a machine and ands them to a given config.

Parameters
confMachineConfiguration of which architecture is used.
newConfMachineConfiguration where idf is to be added.
frequencyThe minimum frequency of the implementations.
maxAreaMaximum area for implementations.
createEstimatesBoolean for creating estimates.
icDecIC decoder to be used.
icDecHDBIC decoder HDB file.
Returns
RowID of the new machine configuration having adf and idf.

Definition at line 689 of file DesignSpaceExplorer.cc.

696 {
697
699 IDF::MachineImplementation* idf = NULL;
700
701 idf = selectComponents(*mach, frequency, maxArea, icDec, icDecHDB);
702 if (!idf) {
703 return false;
704 }
705
707 CostEstimator::DelayInNanoSeconds longestPathDelay = 0;
708 if (createEstimates) {
709 createEstimateData(*mach, *idf, area, longestPathDelay);
710 }
711
712 delete mach;
713 mach = NULL;
714
715 newConf.architectureID = conf.architectureID;
716 newConf.implementationID = dsdb_->addImplementation(*idf, longestPathDelay, area);
717 newConf.hasImplementation = true;
718
719 // idf written to the dsdb so it can be deleted
720 delete idf;
721 idf = NULL;
722 return true;
723}
TTAMachine::Machine * architecture(RowID id) const
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
IDF::MachineImplementation * selectComponents(const TTAMachine::Machine &mach, const double &frequency=0.0, const double &maxArea=0.0, const std::string &icDec="DefaultICDecoder", const std::string &icDecHDB="asic_130nm_1.5V.hdb") const
void createEstimateData(const TTAMachine::Machine &mach, const IDF::MachineImplementation &idf, CostEstimator::AreaInGates &area, CostEstimator::DelayInNanoSeconds &longestPathDelay)
double AreaInGates
type for area values in equivalent gates
double DelayInNanoSeconds
type for propagation delays in nano seconds

References DSDBManager::addImplementation(), DSDBManager::architecture(), DSDBManager::MachineConfiguration::architectureID, createEstimateData(), dsdb_, DSDBManager::MachineConfiguration::hasImplementation, DSDBManager::MachineConfiguration::implementationID, and selectComponents().

Referenced by MinimalOpSet::explore(), and SimpleICOptimizer::explore().

Here is the call graph for this function:

◆ createImplementationAndStore()

RowID DesignSpaceExplorer::createImplementationAndStore ( const DSDBManager::MachineConfiguration conf,
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" 
)

Selects components for a machine and creates a new configuration.

Also stores the new configuration to the dsdb and returns it's rowID.

Parameters
confMachineConfiguration of which architecture is used.
frequencyThe minimum frequency of the implementations.
maxAreaMaximum area for implementations.
createEstimatesBoolean for creating estimates.
icDecIC decoder to be used.
icDecHDBIC decoder HDB file.
Returns
RowID of the new machine configuration having adf and idf.

Definition at line 636 of file DesignSpaceExplorer.cc.

642 {
643
645 IDF::MachineImplementation* idf = NULL;
646
647 idf = selectComponents(*mach, frequency, maxArea, icDec, icDecHDB);
648 if (!idf) {
649 return 0;
650 }
651
653 CostEstimator::DelayInNanoSeconds longestPathDelay = 0;
654 if (createEstimates) {
655 createEstimateData(*mach, *idf, area, longestPathDelay);
656 }
657
658 delete mach;
659 mach = NULL;
660
662 newConf.architectureID = conf.architectureID;
663
664 newConf.implementationID =
665 dsdb_->addImplementation(*idf, longestPathDelay, area);
666 newConf.hasImplementation = true;
667
668 // idf written to the dsdb so it can be deleted
669 delete idf;
670 idf = NULL;
671
672 return addConfToDSDB(newConf);
673}
RowID addConfToDSDB(const DSDBManager::MachineConfiguration &conf)

References addConfToDSDB(), DSDBManager::addImplementation(), DSDBManager::architecture(), DSDBManager::MachineConfiguration::architectureID, createEstimateData(), dsdb_, DSDBManager::MachineConfiguration::hasImplementation, DSDBManager::MachineConfiguration::implementationID, and selectComponents().

Referenced by FrequencySweepExplorer::explore().

Here is the call graph for this function:

◆ db()

DSDBManager & DesignSpaceExplorer::db ( )
virtual

◆ evaluate()

bool DesignSpaceExplorer::evaluate ( const DSDBManager::MachineConfiguration configuration,
CostEstimates result = dummyEstimate_,
bool  estimate = false 
)
virtual

Evaluates one processor configuration (architecture+implementation pair).

Evaluates the total area and the longest path delay of the current processor configuration (architecture+implementation pair) and also the energy consumed in each program in the DSDB with this processor configuration. Also configurations without implementation can be evaluated but no cost estimations are performed so the CostEstimate object won't include area, energy and longest path delay estimations. Estimation is not included either if the estimate flag is set to false.

Parameters
configurationMachine configuration (architecture, implementation).
resultCostEstimates object where the configuration cost estimates are stored if the evaluation succeeds.
estimateFlag indicating that the evaluate will also estimate the given configuration.
Exceptions
InvalidDatathrown in case there are flaws in the application configuration which leads to evaluation failure.
Returns
Returns true if the evaluation succeeds false otherwise.

Definition at line 135 of file DesignSpaceExplorer.cc.

137 {
138
139 TTAMachine::Machine* adf = NULL;
140 IDF::MachineImplementation* idf = NULL;
141 if (configuration.hasImplementation) {
142 adf = dsdb_->architecture(configuration.architectureID);
143 idf = dsdb_->implementation(configuration.implementationID);
144 } else {
145 adf = dsdb_->architecture(configuration.architectureID);
146 }
147
148 try {
149 // program independent estimations
150 if (configuration.hasImplementation && estimate) {
151
152 // estimate total area and longest path delay
153 CostEstimator::AreaInGates totalArea = 0;
154 CostEstimator::DelayInNanoSeconds longestPathDelay = 0;
155 createEstimateData(*adf, *idf, totalArea, longestPathDelay);
156
157 dsdb_->setAreaEstimate(configuration.implementationID, totalArea);
158 result.setArea(totalArea);
159
161 configuration.implementationID, longestPathDelay);
162 result.setLongestPathDelay(longestPathDelay);
163 }
164
165 // get all programs from the dsdb
166 set<RowID> applicationIDs = dsdb_->applicationIDs();
167 for (set<RowID>::const_iterator i = applicationIDs.begin();
168 i != applicationIDs.end(); i++) {
169
170 if (dsdb_->isUnschedulable((*i), configuration.architectureID)) {
171 return false;
172 }
173
174 if (!estimate &&
175 dsdb_->hasCycleCount(*i, configuration.architectureID)) {
176 // this configuration has been compiled+simulated previously,
177 // the old cycle count can be reused for this app
178 continue;
179 }
180
181 string applicationPath = dsdb_->applicationPath(*i);
182 TestApplication testApplication(applicationPath);
183
184 std::string applicationFile = testApplication.applicationPath();
185
186 // test that program is found
187 if (applicationFile.length() < 1) {
188 delete adf;
189 adf = NULL;
190 delete idf;
191 idf = NULL;
192 throw InvalidData(
193 __FILE__, __LINE__, __func__,
194 (boost::format(
195 "No program found from application dir '%s'")
196 % applicationPath).str());
197 return false;
198 }
199
200#if (!defined(HAVE_CXX11) && !defined(HAVE_CXX0X))
201 std::auto_ptr<TTAProgram::Program> scheduledProgram(
202 schedule(applicationFile, *adf));
203#else
204 std::unique_ptr<TTAProgram::Program> scheduledProgram(
205 schedule(applicationFile, *adf));
206#endif
207
208 if (scheduledProgram.get() == NULL) {
209 dsdb_->setUnschedulable((*i), configuration.architectureID);
210 delete adf;
211 adf = NULL;
212 delete idf;
213 idf = NULL;
214 return false;
215 }
216
217 bool hasFunctionsOfInterest =
218 testApplication.hasFunctionsOfInterest();
219 std::vector<ClockCycleCount> instructionExecutionCounts;
220
221 // simulate the scheduled program
222 ClockCycleCount totalCycleCount;
223 const ExecutionTrace* traceDB = NULL;
224 if (configuration.hasImplementation && estimate) {
225 traceDB = simulate(
226 *scheduledProgram, *adf, testApplication, 0,
227 totalCycleCount, true, false,
228 hasFunctionsOfInterest ? &instructionExecutionCounts
229 : nullptr);
230 } else {
231 simulate(
232 *scheduledProgram, *adf, testApplication, 0,
233 totalCycleCount, false, false,
234 hasFunctionsOfInterest ? &instructionExecutionCounts
235 : nullptr);
236 }
237
238 //std::cerr << "DEBUG: simulated" << std::endl;
239 // verify the simulation
240 if (testApplication.hasCorrectOutput()) {
241 string correctResult =
242 StringTools::trim(testApplication.correctOutput());
243 string resultString = StringTools::trim(oStream_->str());
244 if (resultString != correctResult) {
245 std::cerr << "Simulation FAILED, possible bug in scheduler!"
246 << std::endl;
247 std::cerr << "Architecture id in DSDB:" << std::endl;
248 std::cerr << configuration.architectureID << std::endl;
249 std::cerr << "use sqlite3 to find out which configuration "
250 << "has that id to get the machine written to "
251 << "ADF." << std::endl;
252 // @todo Do a method into DSDBManager to find out the
253 // configuration ID.
254 std::cerr << "********** result found:" << std::endl;
255 std::cerr << resultString << std::endl;
256 std::cerr << "********** expected result:" << std::endl;
257 std::cerr << correctResult << std::endl;
258 std::cerr << "**********" << std::endl;
259 delete idf;
260 idf = NULL;
261 delete adf;
262 adf = NULL;
263 return false;
264 }
265 // std::cerr << "DEBUG: simulation OK" << std::endl;
266 // reset the stream pointer in to the beginning and empty the
267 // stream
268 oStream_->str("");
269 oStream_->seekp(0);
270 }
271
272 // Accumulate the cycle counts from functions of interest,
273 // if defined in the application.
274 ClockCycleCount cycleCountOfInterest = totalCycleCount;
275 if (hasFunctionsOfInterest) {
276 cycleCountOfInterest = (ClockCycleCount)(0);
277 size_t instructionCount =
278 scheduledProgram->instructionVector().size();
279 assert(instructionExecutionCounts.size() == instructionCount);
280 auto& interestingProcedures =
281 testApplication.functionsOfInterest();
282 for (const auto& procName : interestingProcedures) {
283 if (!scheduledProgram->hasProcedure(procName)) continue;
285 scheduledProgram->procedure(procName);
286 ClockCycleCount procCycles = 0;
287 for (auto i = proc.startAddress().location();
288 i <= proc.endAddress().location(); ++i) {
289 procCycles += instructionExecutionCounts[i];
290 }
293 << "[Procedure: " << procName
294 << ", size: " << proc.instructionCount()
295 << " cc: " << procCycles << "] " << std::endl;
296 }
297 cycleCountOfInterest += procCycles;
298 }
299 }
300
301 // add simulated cycle count to dsdb
303 (*i), configuration.architectureID, cycleCountOfInterest);
304
305 if (configuration.hasImplementation && estimate) {
306 // energy estimate the simulated program
307 EnergyInMilliJoules programEnergy =
309 *adf, *idf, *scheduledProgram, *traceDB);
311 (*i), configuration.implementationID, programEnergy);
312 result.setEnergy(*scheduledProgram, programEnergy);
313 }
314 delete traceDB;
315 traceDB = NULL;
316 }
317 } catch (const Exception& e) {
318 delete adf;
319 adf = NULL;
320 delete idf;
321 idf = NULL;
323 return false;
324 }
325 delete idf;
326 idf = NULL;
327 delete adf;
328 adf = NULL;
329 return true;
330}
#define __func__
#define assert(condition)
CycleCount ClockCycleCount
Alias for ClockCycleCount.
static bool increasedVerbose()
static std::ostream & logStream()
void setLongestPathDelay(double delay)
void setArea(double area)
void setEnergy(const TTAProgram::Program &program, double energy)
EnergyInMilliJoules totalEnergy(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation, const TTAProgram::Program &program, const ExecutionTrace &traceDB)
energy estimation functions
Definition Estimator.cc:433
void setAreaEstimate(RowID implementation, CostEstimator::AreaInGates area)
std::set< RowID > applicationIDs() const
IDF::MachineImplementation * implementation(RowID id) const
void setUnschedulable(RowID application, RowID architecture)
void setLongestPathDelayEstimate(RowID implementation, double delay)
std::string applicationPath(RowID id) const
bool hasCycleCount(RowID application, RowID architecture) const
void addCycleCount(RowID application, RowID architecture, ClockCycleCount count)
bool isUnschedulable(RowID application, RowID architecture) const
void addEnergyEstimate(RowID application, RowID implementation, double energyEstimate)
const ExecutionTrace * simulate(const TTAProgram::Program &program, const TTAMachine::Machine &machine, const TestApplication &testApplication, const ClockCycleCount &maxCycles, ClockCycleCount &runnedCycles, const bool tracing, const bool useCompiledSimulation=false, std::vector< ClockCycleCount > *executionCounts=NULL)
TTAProgram::Program * schedule(const std::string applicationFile, TTAMachine::Machine &machine, TCEString paramOptions="-O3")
std::string errorMessageStack(bool messagesOnly=false) const
Definition Exception.cc:138
static std::string trim(const std::string &source)
InstructionAddress location() const
virtual Address endAddress() const
virtual int instructionCount() const
virtual Address startAddress() const
double EnergyInMilliJoules
type for consumed energy in milli joules

References __func__, DSDBManager::addCycleCount(), DSDBManager::addEnergyEstimate(), DSDBManager::applicationIDs(), TestApplication::applicationPath(), DSDBManager::applicationPath(), DSDBManager::architecture(), DSDBManager::MachineConfiguration::architectureID, assert, TestApplication::correctOutput(), createEstimateData(), debugLog, dsdb_, TTAProgram::CodeSnippet::endAddress(), Exception::errorMessageStack(), estimator_, TestApplication::functionsOfInterest(), TestApplication::hasCorrectOutput(), DSDBManager::hasCycleCount(), TestApplication::hasFunctionsOfInterest(), DSDBManager::MachineConfiguration::hasImplementation, DSDBManager::implementation(), DSDBManager::MachineConfiguration::implementationID, Application::increasedVerbose(), TTAProgram::CodeSnippet::instructionCount(), DSDBManager::isUnschedulable(), TTAProgram::Address::location(), Application::logStream(), oStream_, schedule(), CostEstimates::setArea(), DSDBManager::setAreaEstimate(), CostEstimates::setEnergy(), CostEstimates::setLongestPathDelay(), DSDBManager::setLongestPathDelayEstimate(), DSDBManager::setUnschedulable(), simulate(), TTAProgram::CodeSnippet::startAddress(), CostEstimator::Estimator::totalEnergy(), and StringTools::trim().

Referenced by MinimizeMachine::evalNewConfigWithoutImplementation(), Evaluate::explore(), GrowMachine::explore(), MinimalOpSet::explore(), ConnectionSweeper::explore(), SimpleICOptimizer::explore(), MinimizeMachine::minimizeBuses(), MinimizeMachine::minimizeFunctionUnits(), MinimizeMachine::minimizeMachine(), MinimizeMachine::minimizeRegisterFiles(), ConnectionSweeper::removeAllConnections(), and ConnectionSweeper::removeLeastNecessaryConnections().

Here is the call graph for this function:

◆ getPlugins()

std::vector< DesignSpaceExplorerPlugin * > DesignSpaceExplorer::getPlugins ( )

Parses the plugin search directories and loads all available plugins

Definition at line 596 of file DesignSpaceExplorer.cc.

596 {
597
598 std::vector<DesignSpaceExplorerPlugin*> plugins;
599 vector<string> found_plugins;
600 vector<string> searchPaths = Environment::explorerPluginPaths();
601 for (vector<string>::const_iterator iter = searchPaths.begin();
602 iter != searchPaths.end(); iter++) {
603
604 if (FileSystem::fileExists(*iter)) {
605 FileSystem::findFromDirectory(".*\\.so$", *iter, found_plugins);
606 }
607 }
608 for (unsigned int i = 0; i < found_plugins.size(); ++i) {
609 std::string pluginName = FileSystem::fileNameBody(found_plugins[i]);
610 DesignSpaceExplorerPlugin* plugin = loadExplorerPlugin(pluginName, NULL);
611 if (!plugin) {
612 continue;
613 }
614
615 plugins.push_back(plugin);
616 }
617
618 return plugins;
619}
static DesignSpaceExplorerPlugin * loadExplorerPlugin(const std::string &pluginName, DSDBManager *dsdb=NULL)
static std::vector< std::string > explorerPluginPaths()
static bool findFromDirectory(const std::string &regex, const std::string &directory, STLCONT &found)
static std::string fileNameBody(const std::string &fileName)
static bool fileExists(const std::string fileName)

References Environment::explorerPluginPaths(), FileSystem::fileExists(), FileSystem::fileNameBody(), FileSystem::findFromDirectory(), and loadExplorerPlugin().

Here is the call graph for this function:

◆ loadExplorerPlugin()

DesignSpaceExplorerPlugin * DesignSpaceExplorer::loadExplorerPlugin ( const std::string &  pluginName,
DSDBManager dsdb = NULL 
)
static

Loads the given explorer plugin from the default search pathes of the explorer plugins.

Searches for file named the plugin with an extension ".so". e.g. if the plugin is namen SimplePlugin is the file SimplePlugin.so loaded. Plugins are searched from the default search pathes of explorer plugins.

Parameters
pluginNameName of the plugin to be loaded.
dsdbDSDBManager to be used by the plugin.
Returns
Returns the loaded DesignSpacsExplorerPlugin instance.
Exceptions
FileNotFoundIf the given plugin is not found from the search paths of explorer plugins.
DynamicLibraryExceptionIf the dynamic library cannot be opened.

Definition at line 566 of file DesignSpaceExplorer.cc.

567 {
568 string pluginFileName = pluginName + ".so";
569 vector<string> searchPaths = Environment::explorerPluginPaths();
570 for (vector<string>::const_iterator iter = searchPaths.begin();
571 iter != searchPaths.end(); iter++) {
572
573 if (FileSystem::fileExists(*iter)) {
575 }
576 }
577 pluginTool_.registerModule(pluginFileName);
578 DesignSpaceExplorerPlugin* (*pluginCreator)();
580 "create_explorer_plugin_" + pluginName, pluginCreator,
581 pluginFileName);
582
583 DesignSpaceExplorerPlugin* plugin = pluginCreator();
584 if (dsdb) {
585 plugin->setDSDB(*dsdb);
586 }
587 return plugin;
588}
virtual void setDSDB(DSDBManager &dsdb)
static PluginTools pluginTool_
The plugin tool.
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
void addSearchPath(const std::string &searchPath)
void registerModule(const std::string &module)

References PluginTools::addSearchPath(), Environment::explorerPluginPaths(), FileSystem::fileExists(), PluginTools::importSymbol(), pluginTool_, PluginTools::registerModule(), and setDSDB().

Referenced by BlocksConnectICCmd::Do(), VLIWConnectICCmd::Do(), ADFCombiner::explore(), FrequencySweepExplorer::explore(), SimpleICOptimizer::explore(), getPlugins(), and loadExplorerPlugin().

Here is the call graph for this function:

◆ schedule()

TTAProgram::Program * DesignSpaceExplorer::schedule ( const std::string  bytecodeFile,
TTAMachine::Machine target,
TCEString  paramOptions = "-O3" 
)
protected

Compiles the given application bytecode file on the given target machine.

Parameters
bytecodeFileBytecode filename with path.
targetThe machine to compile the sequential program against.
paramOptionsCompiler options (if cmdline options are not given)
Returns
Scheduled parallel program or NULL if scheduler produced exeption.

Definition at line 354 of file DesignSpaceExplorer.cc.

357 {
358
359 TCEString compilerOptions;
360
363 if (options != NULL) {
364 if (options->compilerOptions()) {
365 compilerOptions = options->compilerOptionsString();
366 // use compiler options given by method parameters (-O3 by default)
367 } else {
368 compilerOptions = paramOptions;
369 }
370 }
371 // If compiler options did not provide optimization, we use default.
372 if (compilerOptions.find("-O") == std::string::npos) {
373 compilerOptions += " -O3";
374 }
375 static const std::string DS = FileSystem::DIRECTORY_SEPARATOR;
376
377 // create temp directory for the target machine
378 std::string tmpDir = FileSystem::createTempDirectory();
379
380 // write machine to a file for tcecc
381 std::string adf = tmpDir + DS + "mach.adf";
382 std::string tpef = tmpDir + DS + "program.tpef";
383 ADFSerializer serializer;
384 serializer.setDestinationFile(adf);
385 try {
386 serializer.writeMachine(target);
387 } catch (const SerializerException& exception) {
389 throw IOException(
390 __FILE__, __LINE__, __func__, exception.errorMessage());
391 }
392 // call tcecc to compile, link and schedule the program
393 std::vector<std::string> tceccOutputLines;
394 std::string tceccPath = Environment::tceCompiler();
395 std::string tceccCommand = tceccPath + " "
396 + compilerOptions + " --no-link -a " + adf + " -o "
397 + tpef + " " + bytecodeFile + " --no-plugin-cache 2>&1";
398
399 const bool debug = Application::verboseLevel() > 0;
400
401 Application::runShellCommandAndGetOutput(tceccCommand, tceccOutputLines);
402
403 if (debug && tceccOutputLines.size() > 0) {
404 for (unsigned int i = 0; i < tceccOutputLines.size(); ++i) {
405 std::cout << tceccOutputLines.at(i) << std::endl;
406 }
407 }
408
409 // check if tcecc produced any tpef output
411 if (debug) {
412 std::cout << "failed command: " << tceccCommand << std::endl
413 << "temporary directory left for inspection at: "
414 << tmpDir << std::endl;
415 } else {
417 }
418 return NULL;
419 }
420
421 TTAProgram::Program* prog = NULL;
422 try {
423 prog = TTAProgram::Program::loadFromTPEF(tpef, target);
424 } catch (const Exception& e) {
426 IOException error(__FILE__, __LINE__,__func__, e.errorMessage());
427 error.setCause(e);
428 throw error;
429 }
431 return prog;
432}
#define DS
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
void writeMachine(const TTAMachine::Machine &machine)
static CmdLineOptions * cmdLineOptions()
static int runShellCommandAndGetOutput(const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)
static int verboseLevel()
static std::string tceCompiler()
static bool fileIsReadable(const std::string fileName)
static bool removeFileOrDirectory(const std::string &path)
static const std::string DIRECTORY_SEPARATOR
static std::string createTempDirectory(const std::string &path="/tmp", const std::string &tempDirPrefix="tmp_tce_")
static Program * loadFromTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition Program.cc:1112
void setDestinationFile(const std::string &fileName)

References __func__, Application::cmdLineOptions(), FileSystem::createTempDirectory(), FileSystem::DIRECTORY_SEPARATOR, DS, Exception::errorMessage(), FileSystem::fileExists(), FileSystem::fileIsReadable(), TTAProgram::Program::loadFromTPEF(), options, FileSystem::removeFileOrDirectory(), Application::runShellCommandAndGetOutput(), Exception::setCause(), XMLSerializer::setDestinationFile(), Environment::tceCompiler(), Application::verboseLevel(), and ADFSerializer::writeMachine().

Referenced by evaluate(), and SimpleICOptimizer::explore().

Here is the call graph for this function:

◆ selectComponents()

IDF::MachineImplementation * DesignSpaceExplorer::selectComponents ( const TTAMachine::Machine mach,
const double &  frequency = 0.0,
const double &  maxArea = 0.0,
const std::string &  icDec = "DefaultICDecoder",
const std::string &  icDecHDB = "asic_130nm_1.5V.hdb" 
) const

Selects components for a machine, creates a idf.

Parameters
machTarget machine for which components are selected.
frequencyThe minimum frequency of the implementations.
maxAreaMaximum area for implementations.
icDecIC decoder to be used.
icDecHDBIC decoder HDB file.
Returns
Machine Implementation pointer if ok, else NULL.

Definition at line 737 of file DesignSpaceExplorer.cc.

742 {
743
745 IDF::MachineImplementation* idf = NULL;
746
747 try {
748 // TODO: check that idf is deleted when it has been written to the
749 // dsdb, and not in use anymore (selectComponents reserves it with
750 // new)
751 idf = impSelector.selectComponents(&mach, icDec,
752 icDecHDB, frequency, maxArea);
753 } catch (const Exception& e) {
755 if (idf != NULL) {
756 delete idf;
757 idf = NULL;
758 }
759 }
760
761 return idf;
762}
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)

References debugLog, Exception::errorMessage(), and ComponentImplementationSelector::selectComponents().

Referenced by createImplementation(), and createImplementationAndStore().

Here is the call graph for this function:

◆ setDSDB()

void DesignSpaceExplorer::setDSDB ( DSDBManager dsdb)
virtual

Sets new design space database.

Parameters
dsdbDesign space database to be used with the explorer.

Definition at line 109 of file DesignSpaceExplorer.cc.

109 {
110
111 dsdb_ = &dsdb;
112}

References dsdb_.

Referenced by BlocksConnectICCmd::Do(), VLIWConnectICCmd::Do(), GrowMachine::explore(), loadExplorerPlugin(), MinimizeMachine::minimizeBuses(), MinimizeMachine::minimizeFunctionUnits(), MinimizeMachine::minimizeRegisterFiles(), and CallExplorerPluginWindow::onRun().

◆ simulate()

const ExecutionTrace * DesignSpaceExplorer::simulate ( const TTAProgram::Program program,
const TTAMachine::Machine machine,
const TestApplication testApplication,
const ClockCycleCount maxCycles,
ClockCycleCount runnedCycles,
const bool  tracing,
const bool  useCompiledSimulation = false,
std::vector< ClockCycleCount > *  instructionExecutionCounts = NULL 
)
protected

Simulates the parallel program.

Simulates the target machine as long as the program runs or the maximum cycle count is reached. If maximum cycle count is reached an exception is thrown.

Parameters
programSequential program.
machineTarget machine.
testApplicationTest application directory.
maxCyclesMaximum amount of clock cycles that program is allowed to run. Not used by this implementation.
runnedCyclesSimulated cycle amount is stored here.
tracingFlag indicating is the tracing used.
Returns
Execution trace of the program.
Exceptions
ExceptionAll exceptions produced by simulator engine except SimulationCycleLimitReached in case of max cycles are reached without program finishing and SimulationTimeOut in case of simulation is killed after simulating maximum time that is currently 10h.

Definition at line 455 of file DesignSpaceExplorer.cc.

460 {
461 // initialize the simulator
462 SimulatorFrontend simulator(
463 useCompiledSimulation ?
465 SimulatorFrontend::SIM_NORMAL);
466
467 // setting simulator timeout in seconds
468 simulator.setTimeout(480);
469
470 // use memory file in sqlite
471 // TODO: should use a tmp dir as now TraceDB produces multiple
472 // text files, thus only the SQL part goes to memory
473 const string traceFile = ":memory:";
474 simulator.forceTraceDBFileName(traceFile);
475 if (!useCompiledSimulation)
476 simulator.setRFAccessTracing(tracing);
477 simulator.setUtilizationDataSaving(tracing);
478 simulator.setExecutionTracing(tracing);
479
480 simulator.loadMachine(machine);
481 simulator.loadProgram(program);
482 // run the 'setup.sh' in the test application directory
483 testApplication.setupSimulation();
484 // if there is 'simulate.ttasim' file in the application dir we use that
485 if (testApplication.hasSimulateTTASim()) {
486 std::string command = "";
487 std::istream* input = testApplication.simulateTTASim();
488 BaseLineReader reader(*input, *oStream_);
489 reader.initialize();
490 reader.setPromptPrinting(false);
491 SimulatorInterpreterContext interpreterContext(simulator);
492 SimulatorInterpreter interpreter(0, NULL, interpreterContext, reader);
493 while (!interpreter.isQuitCommandGiven()) {
494 try {
495 command = reader.readLine();
496 } catch (const EndOfFile&) {
497 interpreter.interpret(SIM_INTERP_QUIT_COMMAND);
498 if (interpreter.result().size() > 0) {
499 *oStream_ << interpreter.result() << std::endl;
500 }
501 break;
502 }
503 command = StringTools::trim(command);
504 if (command == "") {
505 continue;
506 }
507 interpreter.interpret(command);
508 if (interpreter.result().size() > 0) {
509 *oStream_ << interpreter.result() << std::endl;
510 }
511 }
512 delete input;
513 input = NULL;
514 } else {
515 // no 'simulate.ttasim' file
516 BaseLineReader reader(std::cin, *oStream_);
517 reader.initialize();
518 SimulatorInterpreterContext interpreterContext(simulator);
519 SimulatorInterpreter interpreter(0, NULL, interpreterContext, reader);
520 simulator.run();
521 if (interpreter.result().size() > 0) {
522 *oStream_ << interpreter.result() << std::endl;
523 }
524 }
525
526 runnedCycles = simulator.cycleCount();
527
528 int instructionCount = program.instructionVector().size();
529 if (instructionExecutionCounts != nullptr) {
530 instructionExecutionCounts->resize(instructionCount, 0);
531 for (int i = 0; i < instructionCount; ++i) {
532 (*instructionExecutionCounts)[i] =
534 }
535 }
536
537 // Flush data collected during simulation to the trace file.
538 const ExecutionTrace* db = NULL;
539 if (tracing) {
540 db = simulator.lastTraceDB();
541 }
542
543 simulator.killSimulation();
544
545 return db;
546}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
#define SIM_INTERP_QUIT_COMMAND
The command used to quit the command line interface.
virtual DSDBManager & db()
ClockCycleCount executionCount() const
ExecutionTrace * lastTraceDB(int core=-1)
@ SIM_COMPILED
Compiled, faster simulation.
virtual void loadMachine(const std::string &fileName)
ClockCycleCount cycleCount() const
void forceTraceDBFileName(const std::string &fileName)
void setUtilizationDataSaving(bool value)
void setRFAccessTracing(bool value)
void setTimeout(unsigned int value)
virtual void loadProgram(const std::string &fileName)
const ExecutableInstruction & executableInstructionAt(InstructionAddress address) const
virtual void killSimulation()
void setExecutionTracing(bool value)
bool hasSimulateTTASim() const
std::istream * simulateTTASim() const
void setupSimulation() const

References SimulatorFrontend::cycleCount(), db(), SimulatorFrontend::executableInstructionAt(), ExecutableInstruction::executionCount(), SimulatorFrontend::forceTraceDBFileName(), TestApplication::hasSimulateTTASim(), BaseLineReader::initialize(), TclInterpreter::interpret(), SimulatorInterpreter::isQuitCommandGiven(), SimulatorFrontend::killSimulation(), SimulatorFrontend::lastTraceDB(), SimulatorFrontend::loadMachine(), SimulatorFrontend::loadProgram(), machine, oStream_, program, BaseLineReader::readLine(), ScriptInterpreter::result(), SimulatorFrontend::run(), SimulatorFrontend::setExecutionTracing(), BaseLineReader::setPromptPrinting(), SimulatorFrontend::setRFAccessTracing(), SimulatorFrontend::setTimeout(), TestApplication::setupSimulation(), SimulatorFrontend::setUtilizationDataSaving(), SimulatorFrontend::SIM_COMPILED, SIM_INTERP_QUIT_COMMAND, SimulatorFrontend::SIM_NORMAL, TestApplication::simulateTTASim(), and StringTools::trim().

Referenced by evaluate().

Here is the call graph for this function:

Member Data Documentation

◆ dsdb_

DSDBManager* DesignSpaceExplorer::dsdb_
private

Design space database where results are stored.

Definition at line 131 of file DesignSpaceExplorer.hh.

Referenced by addConfToDSDB(), createImplementation(), createImplementationAndStore(), db(), evaluate(), and setDSDB().

◆ dummyEstimate_

CostEstimates DesignSpaceExplorer::dummyEstimate_
staticprivate

Used for the default evaluate() argument.

Definition at line 139 of file DesignSpaceExplorer.hh.

◆ estimator_

CostEstimator::Estimator DesignSpaceExplorer::estimator_
private

The estimator frontend.

Definition at line 135 of file DesignSpaceExplorer.hh.

Referenced by createEstimateData(), and evaluate().

◆ oStream_

std::ostringstream* DesignSpaceExplorer::oStream_
private

Output stream.

Definition at line 137 of file DesignSpaceExplorer.hh.

Referenced by DesignSpaceExplorer(), evaluate(), simulate(), and ~DesignSpaceExplorer().

◆ pluginTool_

PluginTools DesignSpaceExplorer::pluginTool_
staticprivate

The plugin tool.

Definition at line 133 of file DesignSpaceExplorer.hh.

Referenced by loadExplorerPlugin().


The documentation for this class was generated from the following files: