3232 * @note rating: red
3333 */
3434
35- #include < sstream >
36- # include < fstream >
35+ #include " DesignSpaceExplorer.hh "
36+
3737#include < algorithm>
38+ #include < fstream>
3839#include < set>
39- #include < vector >
40+ #include < sstream >
4041#include < string>
42+ #include < vector>
4143
42- #include " DesignSpaceExplorer.hh"
4344#include " ADFSerializer.hh"
44- #include " ExplorerCmdLineOptions .hh"
45- #include " DesignSpaceExplorerPlugin .hh"
45+ #include " Application .hh"
46+ #include " ComponentImplementationSelector .hh"
4647#include " CostEstimates.hh"
47- #include " ExecutionTrace .hh"
48+ #include " CostEstimatorTypes .hh"
4849#include " DSDBManager.hh"
50+ #include " DesignSpaceExplorerPlugin.hh"
51+ #include " Exception.hh"
52+ #include " ExecutableInstruction.hh"
53+ #include " ExecutionTrace.hh"
54+ #include " ExplorerCmdLineOptions.hh"
55+ #include " Instruction.hh"
4956#include " Machine.hh"
50- #include " Program.hh"
5157#include " MachineImplementation.hh"
52- #include " PluginTools.hh"
53- #include " CostEstimatorTypes.hh"
54- #include " UniversalMachine.hh"
55- #include " StringTools.hh"
5658#include " OperationBehavior.hh"
57- #include " SimulatorToolbox.hh"
59+ #include " OperationGlobals.hh"
60+ #include " PluginTools.hh"
61+ #include " Procedure.hh"
62+ #include " Program.hh"
5863#include " SimulatorFrontend.hh"
5964#include " SimulatorInterpreter.hh"
60- #include " ExecutableInstruction.hh"
61- #include " OperationGlobals.hh"
62- #include " Application.hh"
63- #include " ComponentImplementationSelector.hh"
64- #include " Exception.hh"
65+ #include " SimulatorToolbox.hh"
66+ #include " StringTools.hh"
67+ #include " UniversalMachine.hh"
6568
6669using std::set;
6770using std::vector;
@@ -211,24 +214,33 @@ DesignSpaceExplorer::evaluate(
211214 return false ;
212215 }
213216
217+ bool hasFunctionsOfInterest =
218+ testApplication.hasFunctionsOfInterest ();
219+ std::vector<ClockCycleCount> instructionExecutionCounts;
220+
214221 // simulate the scheduled program
215- ClockCycleCount runnedCycles ;
222+ ClockCycleCount totalCycleCount ;
216223 const ExecutionTrace* traceDB = NULL ;
217224 if (configuration.hasImplementation && estimate) {
218225 traceDB = simulate (
219- *scheduledProgram, *adf, testApplication, 0 , runnedCycles,
220- true );
226+ *scheduledProgram, *adf, testApplication, 0 ,
227+ totalCycleCount, true , false ,
228+ hasFunctionsOfInterest ? &instructionExecutionCounts
229+ : nullptr );
221230 } else {
222231 simulate (
223- *scheduledProgram, *adf, testApplication, 0 , runnedCycles,
224- false );
232+ *scheduledProgram, *adf, testApplication, 0 ,
233+ totalCycleCount, false , false ,
234+ hasFunctionsOfInterest ? &instructionExecutionCounts
235+ : nullptr );
225236 }
226237
227238 // std::cerr << "DEBUG: simulated" << std::endl;
228239 // verify the simulation
229240 if (testApplication.hasCorrectOutput ()) {
230- string correctResult = testApplication.correctOutput ();
231- string resultString = oStream_->str ();
241+ string correctResult =
242+ StringTools::trim (testApplication.correctOutput ());
243+ string resultString = StringTools::trim (oStream_->str ());
232244 if (resultString != correctResult) {
233245 std::cerr << " Simulation FAILED, possible bug in scheduler!"
234246 << std::endl;
@@ -250,17 +262,45 @@ DesignSpaceExplorer::evaluate(
250262 adf = NULL ;
251263 return false ;
252264 }
253- // std::cerr << "DEBUG: simulation OK" << std::endl;
265+ // std::cerr << "DEBUG: simulation OK" << std::endl;
254266 // reset the stream pointer in to the beginning and empty the
255267 // stream
256268 oStream_->str (" " );
257269 oStream_->seekp (0 );
258270 }
259271
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 (auto & procName : interestingProcedures) {
283+ if (!scheduledProgram->hasProcedure (procName)) continue ;
284+ TTAProgram::Procedure& proc =
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+ }
291+ if (Application::increasedVerbose ()) {
292+ Application::logStream ()
293+ << " [Procedure: " << procName
294+ << " , size: " << proc.instructionCount ()
295+ << " cc: " << procCycles << " ] " << std::endl;
296+ }
297+ cycleCountOfInterest += procCycles;
298+ }
299+ }
300+
260301 // add simulated cycle count to dsdb
261302 dsdb_->addCycleCount (
262- (*i), configuration.architectureID ,
263- runnedCycles);
303+ (*i), configuration.architectureID , cycleCountOfInterest);
264304
265305 if (configuration.hasImplementation && estimate) {
266306 // energy estimate the simulated program
@@ -417,7 +457,7 @@ DesignSpaceExplorer::simulate(
417457 const TestApplication& testApplication, const ClockCycleCount&,
418458 ClockCycleCount& runnedCycles, const bool tracing,
419459 const bool useCompiledSimulation,
420- std::vector<ClockCycleCount>* executionCounts ) {
460+ std::vector<ClockCycleCount>* instructionExecutionCounts ) {
421461 // initialize the simulator
422462 SimulatorFrontend simulator (
423463 useCompiledSimulation ?
@@ -484,13 +524,13 @@ DesignSpaceExplorer::simulate(
484524 }
485525
486526 runnedCycles = simulator.cycleCount ();
487-
527+
488528 int instructionCount = program.instructionVector ().size ();
489- if (executionCounts ) {
490- executionCounts ->resize (instructionCount, 0 );
491- for (int i= 0 ; i< instructionCount; ++i) {
492- (*executionCounts )[i] = simulator. executableInstructionAt (i)
493- .executionCount ();
529+ if (instructionExecutionCounts != nullptr ) {
530+ instructionExecutionCounts ->resize (instructionCount, 0 );
531+ for (int i = 0 ; i < instructionCount; ++i) {
532+ (*instructionExecutionCounts )[i] =
533+ simulator. executableInstructionAt (i) .executionCount ();
494534 }
495535 }
496536
0 commit comments