OpenASIP  2.0
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. More...
 
CostEstimator::Estimator estimator_
 The estimator frontend. More...
 
std::ostringstream * oStream_
 Output stream. More...
 

Static Private Attributes

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

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 82 of file DesignSpaceExplorer.cc.

82  {
83 
84  //schedulingPlan_ =
85  // SchedulingPlan::loadFromFile(Environment::oldGccSchedulerConf());
86  oStream_ = new std::ostringstream;
88 }

References OperationGlobals::setOutputStream().

Here is the call graph for this function:

◆ ~DesignSpaceExplorer()

DesignSpaceExplorer::~DesignSpaceExplorer ( )
virtual

The destructor.

Definition at line 93 of file DesignSpaceExplorer.cc.

93  {
94 
95  //delete schedulingPlan_;
96  //schedulingPlan_ = NULL;
97  delete oStream_;
98  oStream_ = NULL;
99 }

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 755 of file DesignSpaceExplorer.cc.

756  {
757 
758  try {
759  return dsdb_->addConfiguration(conf);
760  } catch (const Exception& e) {
761  debugLog(e.errorMessage());
762  return 0;
763  }
764 }

References debugLog, and Exception::errorMessage().

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 735 of file DesignSpaceExplorer.cc.

739  {
740 
741  area = estimator_.totalArea(mach, idf);
742  longestPathDelay = estimator_.longestPath(mach, idf);
743 }

◆ 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 650 of file DesignSpaceExplorer.cc.

657  {
658 
660  IDF::MachineImplementation* idf = NULL;
661 
662  idf = selectComponents(*mach, frequency, maxArea, icDec, icDecHDB);
663  if (!idf) {
664  return false;
665  }
666 
668  CostEstimator::DelayInNanoSeconds longestPathDelay = 0;
669  if (createEstimates) {
670  createEstimateData(*mach, *idf, area, longestPathDelay);
671  }
672 
673  delete mach;
674  mach = NULL;
675 
676  newConf.architectureID = conf.architectureID;
677  newConf.implementationID = dsdb_->addImplementation(*idf, longestPathDelay, area);
678  newConf.hasImplementation = true;
679 
680  // idf written to the dsdb so it can be deleted
681  delete idf;
682  idf = NULL;
683  return true;
684 }

References DSDBManager::MachineConfiguration::architectureID, DSDBManager::MachineConfiguration::hasImplementation, and DSDBManager::MachineConfiguration::implementationID.

◆ 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 597 of file DesignSpaceExplorer.cc.

603  {
604 
606  IDF::MachineImplementation* idf = NULL;
607 
608  idf = selectComponents(*mach, frequency, maxArea, icDec, icDecHDB);
609  if (!idf) {
610  return 0;
611  }
612 
614  CostEstimator::DelayInNanoSeconds longestPathDelay = 0;
615  if (createEstimates) {
616  createEstimateData(*mach, *idf, area, longestPathDelay);
617  }
618 
619  delete mach;
620  mach = NULL;
621 
623  newConf.architectureID = conf.architectureID;
624 
625  newConf.implementationID =
626  dsdb_->addImplementation(*idf, longestPathDelay, area);
627  newConf.hasImplementation = true;
628 
629  // idf written to the dsdb so it can be deleted
630  delete idf;
631  idf = NULL;
632 
633  return addConfToDSDB(newConf);
634 }

References DSDBManager::MachineConfiguration::architectureID, DSDBManager::MachineConfiguration::hasImplementation, and DSDBManager::MachineConfiguration::implementationID.

◆ db()

DSDBManager & DesignSpaceExplorer::db ( )
virtual

Returns the DSDBManager of the current exploration process.

Returns
The DSDBManager of the current exploration process.

Definition at line 300 of file DesignSpaceExplorer.cc.

300  {
301 
302  return *dsdb_;
303 }

◆ 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 133 of file DesignSpaceExplorer.cc.

135  {
136 
137  TTAMachine::Machine* adf = NULL;
138  IDF::MachineImplementation* idf = NULL;
139  if (configuration.hasImplementation) {
140  adf = dsdb_->architecture(configuration.architectureID);
141  idf = dsdb_->implementation(configuration.implementationID);
142  } else {
143  adf = dsdb_->architecture(configuration.architectureID);
144  }
145 
146  try {
147  // program independent estimations
148  if (configuration.hasImplementation && estimate) {
149 
150  // estimate total area and longest path delay
151  CostEstimator::AreaInGates totalArea = 0;
152  CostEstimator::DelayInNanoSeconds longestPathDelay = 0;
153  createEstimateData(*adf, *idf, totalArea, longestPathDelay);
154 
155  dsdb_->setAreaEstimate(configuration.implementationID, totalArea);
156  result.setArea(totalArea);
157 
159  configuration.implementationID, longestPathDelay);
160  result.setLongestPathDelay(longestPathDelay);
161  }
162 
163  // get all programs from the dsdb
164  set<RowID> applicationIDs = dsdb_->applicationIDs();
165  for (set<RowID>::const_iterator i = applicationIDs.begin();
166  i != applicationIDs.end(); i++) {
167 
168  if (dsdb_->isUnschedulable((*i), configuration.architectureID)) {
169  return false;
170  }
171 
172  if (!estimate &&
173  dsdb_->hasCycleCount(*i, configuration.architectureID)) {
174  // this configuration has been compiled+simulated previously,
175  // the old cycle count can be reused for this app
176  continue;
177  }
178 
179  string applicationPath = dsdb_->applicationPath(*i);
180  TestApplication testApplication(applicationPath);
181 
182  std::string applicationFile = testApplication.applicationPath();
183 
184  // test that program is found
185  if (applicationFile.length() < 1) {
186  delete adf;
187  adf = NULL;
188  delete idf;
189  idf = NULL;
190  throw InvalidData(
191  __FILE__, __LINE__, __func__,
192  (boost::format(
193  "No program found from application dir '%s'")
194  % applicationPath).str());
195  return false;
196  }
197 
198 #if (!defined(HAVE_CXX11) && !defined(HAVE_CXX0X))
199  std::auto_ptr<TTAProgram::Program> scheduledProgram(
200  schedule(applicationFile, *adf));
201 #else
202  std::unique_ptr<TTAProgram::Program> scheduledProgram(
203  schedule(applicationFile, *adf));
204 #endif
205 
206  if (scheduledProgram.get() == NULL) {
207  dsdb_->setUnschedulable((*i), configuration.architectureID);
208  delete adf;
209  adf = NULL;
210  delete idf;
211  idf = NULL;
212  return false;
213  }
214 
215  // simulate the scheduled program
216  ClockCycleCount runnedCycles;
217  const ExecutionTrace* traceDB = NULL;
218  if (configuration.hasImplementation && estimate) {
219  traceDB = simulate(
220  *scheduledProgram, *adf, testApplication, 0, runnedCycles,
221  true);
222  } else {
223  simulate(
224  *scheduledProgram, *adf, testApplication, 0, runnedCycles,
225  false);
226  }
227 
228  //std::cerr << "DEBUG: simulated" << std::endl;
229  // verify the simulation
230  if (testApplication.hasCorrectOutput()) {
231  string correctResult = testApplication.correctOutput();
232  string resultString = oStream_->str();
233  if (resultString != correctResult) {
234  std::cerr << "Simulation FAILED, possible bug in scheduler!"
235  << std::endl;
236  std::cerr << "Architecture id in DSDB:" << std::endl;
237  std::cerr << configuration.architectureID << std::endl;
238  std::cerr << "use sqlite3 to find out which configuration "
239  << "has that id to get the machine written to "
240  << "ADF." << std::endl;
241  // @todo Do a method into DSDBManager to find out the
242  // configuration ID.
243  std::cerr << "********** result found:" << std::endl;
244  std::cerr << resultString << std::endl;
245  std::cerr << "********** expected result:" << std::endl;
246  std::cerr << correctResult << std::endl;
247  std::cerr << "**********" << std::endl;
248  delete idf;
249  idf = NULL;
250  delete adf;
251  adf = NULL;
252  return false;
253  }
254  //std::cerr << "DEBUG: simulation OK" << std::endl;
255  // reset the stream pointer in to the beginning and empty the
256  // stream
257  oStream_->str("");
258  oStream_->seekp(0);
259  }
260 
261  // add simulated cycle count to dsdb
263  (*i), configuration.architectureID,
264  runnedCycles);
265 
266  if (configuration.hasImplementation && estimate) {
267  // energy estimate the simulated program
268  EnergyInMilliJoules programEnergy =
270  *adf, *idf, *scheduledProgram, *traceDB);
272  (*i), configuration.implementationID, programEnergy);
273  result.setEnergy(*scheduledProgram, programEnergy);
274  }
275  delete traceDB;
276  traceDB = NULL;
277  }
278  } catch (const Exception& e) {
279  delete adf;
280  adf = NULL;
281  delete idf;
282  idf = NULL;
284  return false;
285  }
286  delete idf;
287  idf = NULL;
288  delete adf;
289  adf = NULL;
290  return true;
291 }

References __func__, TestApplication::applicationPath(), DSDBManager::MachineConfiguration::architectureID, TestApplication::correctOutput(), debugLog, Exception::errorMessageStack(), TestApplication::hasCorrectOutput(), DSDBManager::MachineConfiguration::hasImplementation, DSDBManager::MachineConfiguration::implementationID, CostEstimates::setArea(), CostEstimates::setEnergy(), and CostEstimates::setLongestPathDelay().

Referenced by MinimizeMachine::evalNewConfigWithoutImplementation(), GrowMachine::explore(), MinimizeMachine::minimizeBuses(), MinimizeMachine::minimizeFunctionUnits(), and MinimizeMachine::minimizeRegisterFiles().

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 557 of file DesignSpaceExplorer.cc.

557  {
558 
559  std::vector<DesignSpaceExplorerPlugin*> plugins;
560  vector<string> found_plugins;
561  vector<string> searchPaths = Environment::explorerPluginPaths();
562  for (vector<string>::const_iterator iter = searchPaths.begin();
563  iter != searchPaths.end(); iter++) {
564 
565  if (FileSystem::fileExists(*iter)) {
566  FileSystem::findFromDirectory(".*\\.so$", *iter, found_plugins);
567  }
568  }
569  for (unsigned int i = 0; i < found_plugins.size(); ++i) {
570  std::string pluginName = FileSystem::fileNameBody(found_plugins[i]);
571  DesignSpaceExplorerPlugin* plugin = loadExplorerPlugin(pluginName, NULL);
572  if (!plugin) {
573  continue;
574  }
575 
576  plugins.push_back(plugin);
577  }
578 
579  return plugins;
580 }

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 527 of file DesignSpaceExplorer.cc.

528  {
529  string pluginFileName = pluginName + ".so";
530  vector<string> searchPaths = Environment::explorerPluginPaths();
531  for (vector<string>::const_iterator iter = searchPaths.begin();
532  iter != searchPaths.end(); iter++) {
533 
534  if (FileSystem::fileExists(*iter)) {
535  pluginTool_.addSearchPath(*iter);
536  }
537  }
538  pluginTool_.registerModule(pluginFileName);
539  DesignSpaceExplorerPlugin* (*pluginCreator)();
541  "create_explorer_plugin_" + pluginName, pluginCreator,
542  pluginFileName);
543 
544  DesignSpaceExplorerPlugin* plugin = pluginCreator();
545  if (dsdb) {
546  plugin->setDSDB(*dsdb);
547  }
548  return plugin;
549 }

References Environment::explorerPluginPaths(), FileSystem::fileExists(), and setDSDB().

Referenced by BlocksConnectICCmd::Do(), VLIWConnectICCmd::Do(), SimpleICOptimizer::explore(), ADFCombiner::explore(), FrequencySweepExplorer::explore(), 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 315 of file DesignSpaceExplorer.cc.

318  {
319 
320  TCEString compilerOptions;
321 
324  if (options != NULL) {
325  if (options->compilerOptions()) {
326  compilerOptions = options->compilerOptionsString();
327  // use compiler options given by method parameters (-O3 by default)
328  } else {
329  compilerOptions = paramOptions;
330  }
331  }
332  // If compiler options did not provide optimization, we use default.
333  if (compilerOptions.find("-O") == std::string::npos) {
334  compilerOptions += " -O3";
335  }
336  static const std::string DS = FileSystem::DIRECTORY_SEPARATOR;
337 
338  // create temp directory for the target machine
339  std::string tmpDir = FileSystem::createTempDirectory();
340 
341  // write machine to a file for tcecc
342  std::string adf = tmpDir + DS + "mach.adf";
343  std::string tpef = tmpDir + DS + "program.tpef";
344  ADFSerializer serializer;
345  serializer.setDestinationFile(adf);
346  try {
347  serializer.writeMachine(target);
348  } catch (const SerializerException& exception) {
350  throw IOException(
351  __FILE__, __LINE__, __func__, exception.errorMessage());
352  }
353  // call tcecc to compile, link and schedule the program
354  std::vector<std::string> tceccOutputLines;
355  std::string tceccPath = Environment::tceCompiler();
356  std::string tceccCommand = tceccPath + " "
357  + compilerOptions + " --no-link -a " + adf + " -o "
358  + tpef + " " + bytecodeFile + " --no-plugin-cache 2>&1";
359 
360  const bool debug = Application::verboseLevel() > 0;
361 
362  Application::runShellCommandAndGetOutput(tceccCommand, tceccOutputLines);
363 
364  if (debug && tceccOutputLines.size() > 0) {
365  for (unsigned int i = 0; i < tceccOutputLines.size(); ++i) {
366  std::cout << tceccOutputLines.at(i) << std::endl;
367  }
368  }
369 
370  // check if tcecc produced any tpef output
371  if (!(FileSystem::fileExists(tpef) && FileSystem::fileIsReadable(tpef))) {
372  if (debug) {
373  std::cout << "failed command: " << tceccCommand << std::endl
374  << "temporary directory left for inspection at: "
375  << tmpDir << std::endl;
376  } else {
378  }
379  return NULL;
380  }
381 
382  TTAProgram::Program* prog = NULL;
383  try {
384  prog = TTAProgram::Program::loadFromTPEF(tpef, target);
385  } catch (const Exception& e) {
387  IOException error(__FILE__, __LINE__,__func__, e.errorMessage());
388  error.setCause(e);
389  throw error;
390  }
392  return prog;
393 }

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 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 698 of file DesignSpaceExplorer.cc.

703  {
704 
706  IDF::MachineImplementation* idf = NULL;
707 
708  try {
709  // TODO: check that idf is deleted when it has been written to the
710  // dsdb, and not in use anymore (selectComponents reserves it with
711  // new)
712  idf = impSelector.selectComponents(&mach, icDec,
713  icDecHDB, frequency, maxArea);
714  } catch (const Exception& e) {
715  debugLog(e.errorMessage());
716  if (idf != NULL) {
717  delete idf;
718  idf = NULL;
719  }
720  }
721 
722  return idf;
723 }

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

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 107 of file DesignSpaceExplorer.cc.

107  {
108 
109  dsdb_ = &dsdb;
110 }

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

◆ 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 > *  executionCounts = 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 416 of file DesignSpaceExplorer.cc.

421  {
422  // initialize the simulator
423  SimulatorFrontend simulator(
424  useCompiledSimulation ?
427 
428  // setting simulator timeout in seconds
429  simulator.setTimeout(480);
430 
431  // use memory file in sqlite
432  // TODO: should use a tmp dir as now TraceDB produces multiple
433  // text files, thus only the SQL part goes to memory
434  const string traceFile = ":memory:";
435  simulator.forceTraceDBFileName(traceFile);
436  if (!useCompiledSimulation)
437  simulator.setRFAccessTracing(tracing);
438  simulator.setUtilizationDataSaving(tracing);
439  simulator.setExecutionTracing(tracing);
440 
441  simulator.loadMachine(machine);
442  simulator.loadProgram(program);
443  // run the 'setup.sh' in the test application directory
444  testApplication.setupSimulation();
445  // if there is 'simulate.ttasim' file in the application dir we use that
446  if (testApplication.hasSimulateTTASim()) {
447  std::string command = "";
448  std::istream* input = testApplication.simulateTTASim();
449  BaseLineReader reader(*input, *oStream_);
450  reader.initialize();
451  reader.setPromptPrinting(false);
452  SimulatorInterpreterContext interpreterContext(simulator);
453  SimulatorInterpreter interpreter(0, NULL, interpreterContext, reader);
454  while (!interpreter.isQuitCommandGiven()) {
455  try {
456  command = reader.readLine();
457  } catch (const EndOfFile&) {
458  interpreter.interpret(SIM_INTERP_QUIT_COMMAND);
459  if (interpreter.result().size() > 0) {
460  *oStream_ << interpreter.result() << std::endl;
461  }
462  break;
463  }
464  command = StringTools::trim(command);
465  if (command == "") {
466  continue;
467  }
468  interpreter.interpret(command);
469  if (interpreter.result().size() > 0) {
470  *oStream_ << interpreter.result() << std::endl;
471  }
472  }
473  delete input;
474  input = NULL;
475  } else {
476  // no 'simulate.ttasim' file
477  BaseLineReader reader(std::cin, *oStream_);
478  reader.initialize();
479  SimulatorInterpreterContext interpreterContext(simulator);
480  SimulatorInterpreter interpreter(0, NULL, interpreterContext, reader);
481  simulator.run();
482  if (interpreter.result().size() > 0) {
483  *oStream_ << interpreter.result() << std::endl;
484  }
485  }
486 
487  runnedCycles = simulator.cycleCount();
488 
489  int instructionCount = program.instructionVector().size();
490  if (executionCounts) {
491  executionCounts->resize(instructionCount, 0);
492  for (int i=0; i<instructionCount; ++i) {
493  (*executionCounts)[i] = simulator.executableInstructionAt(i)
494  .executionCount();
495  }
496  }
497 
498  // Flush data collected during simulation to the trace file.
499  const ExecutionTrace* db = NULL;
500  if (tracing) {
501  db = simulator.lastTraceDB();
502  }
503 
504  simulator.killSimulation();
505 
506  return db;
507 }

References SimulatorFrontend::cycleCount(), SimulatorFrontend::executableInstructionAt(), ExecutableInstruction::executionCount(), SimulatorFrontend::forceTraceDBFileName(), TestApplication::hasSimulateTTASim(), BaseLineReader::initialize(), TclInterpreter::interpret(), SimulatorInterpreter::isQuitCommandGiven(), SimulatorFrontend::killSimulation(), SimulatorFrontend::lastTraceDB(), SimulatorFrontend::loadMachine(), SimulatorFrontend::loadProgram(), machine, 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().

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.

◆ 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.

◆ oStream_

std::ostringstream* DesignSpaceExplorer::oStream_
private

Output stream.

Definition at line 137 of file DesignSpaceExplorer.hh.

◆ pluginTool_

PluginTools DesignSpaceExplorer::pluginTool_
staticprivate

The plugin tool.

Definition at line 133 of file DesignSpaceExplorer.hh.


The documentation for this class was generated from the following files:
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
ComponentImplementationSelector::selectComponents
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)
Definition: ComponentImplementationSelector.cc:645
DSDBManager::addCycleCount
void addCycleCount(RowID application, RowID architecture, ClockCycleCount count)
Definition: DSDBManager.cc:583
TTAProgram::Program
Definition: Program.hh:63
TestApplication::simulateTTASim
std::istream * simulateTTASim() const
Definition: TestApplication.cc:186
TestApplication::setupSimulation
void setupSimulation() const
Definition: TestApplication.cc:168
CostEstimator::Estimator::totalArea
AreaInGates totalArea(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation)
area estimation functions
Definition: Estimator.cc:84
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
DSDBManager::addEnergyEstimate
void addEnergyEstimate(RowID application, RowID implementation, double energyEstimate)
Definition: DSDBManager.cc:477
CostEstimates::setLongestPathDelay
void setLongestPathDelay(double delay)
Definition: CostEstimates.cc:69
CostEstimates::setEnergy
void setEnergy(const TTAProgram::Program &program, double energy)
Definition: CostEstimates.cc:83
SimulatorFrontend::SIM_COMPILED
@ SIM_COMPILED
Compiled, faster simulation.
Definition: SimulatorFrontend.hh:103
DesignSpaceExplorer::db
virtual DSDBManager & db()
Definition: DesignSpaceExplorer.cc:300
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
DSDBManager::MachineConfiguration::hasImplementation
bool hasImplementation
Definition: DSDBManager.hh:80
Application::runShellCommandAndGetOutput
static int runShellCommandAndGetOutput(const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)
Definition: Application.cc:338
CostEstimator::Estimator::totalEnergy
EnergyInMilliJoules totalEnergy(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation, const TTAProgram::Program &program, const ExecutionTrace &traceDB)
energy estimation functions
Definition: Estimator.cc:433
DesignSpaceExplorer::addConfToDSDB
RowID addConfToDSDB(const DSDBManager::MachineConfiguration &conf)
Definition: DesignSpaceExplorer.cc:755
OperationGlobals::setOutputStream
static void setOutputStream(std::ostream &newOutputStream)
Definition: OperationGlobals.cc:59
CostEstimator::Estimator::longestPath
DelayInNanoSeconds longestPath(const TTAMachine::Machine &machine, const IDF::MachineImplementation &machineImplementation)
delay estimation functions
Definition: Estimator.cc:915
DSDBManager::setLongestPathDelayEstimate
void setLongestPathDelayEstimate(RowID implementation, double delay)
Definition: DSDBManager.cc:617
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
Application::verboseLevel
static int verboseLevel()
Definition: Application.hh:176
CostEstimator::AreaInGates
double AreaInGates
type for area values in equivalent gates
Definition: CostEstimatorTypes.hh:35
FileSystem::findFromDirectory
static bool findFromDirectory(const std::string &regex, const std::string &directory, STLCONT &found)
TestApplication::hasSimulateTTASim
bool hasSimulateTTASim() const
Definition: TestApplication.cc:259
BaseLineReader
Definition: BaseLineReader.hh:47
Environment::tceCompiler
static std::string tceCompiler()
Definition: Environment.cc:928
DesignSpaceExplorer::createEstimateData
void createEstimateData(const TTAMachine::Machine &mach, const IDF::MachineImplementation &idf, CostEstimator::AreaInGates &area, CostEstimator::DelayInNanoSeconds &longestPathDelay)
Definition: DesignSpaceExplorer.cc:735
DesignSpaceExplorer::estimator_
CostEstimator::Estimator estimator_
The estimator frontend.
Definition: DesignSpaceExplorer.hh:135
CostEstimator::EnergyInMilliJoules
double EnergyInMilliJoules
type for consumed energy in milli joules
Definition: CostEstimatorTypes.hh:37
DesignSpaceExplorer::selectComponents
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
Definition: DesignSpaceExplorer.cc:698
DesignSpaceExplorer::schedule
TTAProgram::Program * schedule(const std::string applicationFile, TTAMachine::Machine &machine, TCEString paramOptions="-O3")
Definition: DesignSpaceExplorer.cc:315
DSDBManager::MachineConfiguration::implementationID
RowID implementationID
Definition: DSDBManager.hh:81
SimulatorInterpreter
Definition: SimulatorInterpreter.hh:49
SIM_INTERP_QUIT_COMMAND
#define SIM_INTERP_QUIT_COMMAND
The command used to quit the command line interface.
Definition: SimulatorConstants.hh:45
ExplorerCmdLineOptions
Definition: ExplorerCmdLineOptions.hh:45
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
InvalidData
Definition: Exception.hh:149
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
DSDBManager::setAreaEstimate
void setAreaEstimate(RowID implementation, CostEstimator::AreaInGates area)
Definition: DSDBManager.cc:641
DSDBManager::isUnschedulable
bool isUnschedulable(RowID application, RowID architecture) const
Definition: DSDBManager.cc:550
ExecutionTrace
Definition: ExecutionTrace.hh:56
ADFSerializer
Definition: ADFSerializer.hh:49
Application::cmdLineOptions
static CmdLineOptions * cmdLineOptions()
Definition: Application.cc:397
XMLSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition: XMLSerializer.cc:142
__func__
#define __func__
Definition: Application.hh:67
PluginTools::registerModule
void registerModule(const std::string &module)
Definition: PluginTools.cc:138
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
SerializerException
Definition: Exception.hh:675
DesignSpaceExplorer::pluginTool_
static PluginTools pluginTool_
The plugin tool.
Definition: DesignSpaceExplorer.hh:133
Exception
Definition: Exception.hh:54
DesignSpaceExplorer::loadExplorerPlugin
static DesignSpaceExplorerPlugin * loadExplorerPlugin(const std::string &pluginName, DSDBManager *dsdb=NULL)
Definition: DesignSpaceExplorer.cc:527
DesignSpaceExplorer::simulate
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)
Definition: DesignSpaceExplorer.cc:416
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
DSDBManager::addConfiguration
RowID addConfiguration(const MachineConfiguration &conf)
Definition: DSDBManager.cc:299
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
ComponentImplementationSelector
Definition: ComponentImplementationSelector.hh:74
CostEstimator::DelayInNanoSeconds
double DelayInNanoSeconds
type for propagation delays in nano seconds
Definition: CostEstimatorTypes.hh:39
StringTools::trim
static std::string trim(const std::string &source)
Definition: StringTools.cc:55
DSDBManager::hasCycleCount
bool hasCycleCount(RowID application, RowID architecture) const
Definition: DSDBManager.cc:1228
DesignSpaceExplorer::setDSDB
virtual void setDSDB(DSDBManager &dsdb)
Definition: DesignSpaceExplorer.cc:107
CostEstimates::setArea
void setArea(double area)
Definition: CostEstimates.cc:58
PluginTools::addSearchPath
void addSearchPath(const std::string &searchPath)
Definition: PluginTools.cc:95
FileSystem::fileExists
static bool fileExists(const std::string fileName)
DSDBManager::setUnschedulable
void setUnschedulable(RowID application, RowID architecture)
Definition: DSDBManager.cc:515
TCEString
Definition: TCEString.hh:53
DesignSpaceExplorer::oStream_
std::ostringstream * oStream_
Output stream.
Definition: DesignSpaceExplorer.hh:137
DesignSpaceExplorer::dsdb_
DSDBManager * dsdb_
Design space database where results are stored.
Definition: DesignSpaceExplorer.hh:131
ADFSerializer::writeMachine
void writeMachine(const TTAMachine::Machine &machine)
Definition: ADFSerializer.cc:259
DSDBManager::implementation
IDF::MachineImplementation * implementation(RowID id) const
Definition: DSDBManager.cc:887
TTAProgram::Program::loadFromTPEF
static Program * loadFromTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition: Program.cc:1112
Environment::explorerPluginPaths
static std::vector< std::string > explorerPluginPaths()
Definition: Environment.cc:809
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
DSDBManager::applicationPath
std::string applicationPath(RowID id) const
Definition: DSDBManager.cc:947
IOException
Definition: Exception.hh:130
EndOfFile
Definition: Exception.hh:189
DS
#define DS
Definition: LLVMBackend.cc:124
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
debugLog
#define debugLog(text)
Definition: Application.hh:95
FileSystem::fileNameBody
static std::string fileNameBody(const std::string &fileName)
Definition: FileSystem.cc:291
DSDBManager::MachineConfiguration::architectureID
RowID architectureID
Definition: DSDBManager.hh:79
TestApplication
Definition: TestApplication.hh:46
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
FileSystem::createTempDirectory
static std::string createTempDirectory(const std::string &path="/tmp", const std::string &tempDirPrefix="tmp_tce_")
Definition: FileSystem.cc:441
DSDBManager::addImplementation
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
Definition: DSDBManager.cc:252
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
DSDBManager::applicationIDs
std::set< RowID > applicationIDs() const
Definition: DSDBManager.cc:1381
TTAMachine::Machine
Definition: Machine.hh:73
SimulatorFrontend::SIM_NORMAL
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).
Definition: SimulatorFrontend.hh:102