Skip to content

Commit 51c6c86

Browse files
author
Pekka Jääskeläinen
committed
functions_of_interest to the DSE
An application descriptor file that can be used to set the functions of interest in the simulated program. If given, only the time spent in the chosen functions is included in the execution time that guides the design space exploration. This is useful for cases where the main() contains printouts and verification code which then launches the actual function to optimize for.
1 parent 284b602 commit 51c6c86

5 files changed

Lines changed: 129 additions & 47 deletions

File tree

openasip/doc/man/OpenASIP/OpenASIP.tex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9052,17 +9052,20 @@ \section{Automatic Design Space Explorer (explore)}
90529052
90539053
\textbf{Output}: ExpResDB (Section~\ref{sec:expresdb})
90549054
9055-
\subsection{Explorer Application format}
9055+
\subsection{Explorer Application Directory}
90569056
9057-
Applications are given as directories that contain the application specific
9058-
files to the Explorer. Below is a description of all the possible files inside
9059-
the application directory.
9057+
Software applications that drive the design space exploration are given as folders
9058+
that contain the application specific files to the Explorer. Below is a description
9059+
of all the possible files inside the application directory.
90609060
90619061
\begin{tabular}{p{0.25\textwidth}p{0.60\textwidth}}
90629062
\textbf{file name} &\textbf{Description} \\
90639063
\hline
90649064
program.bc & The program byte code (produced using ``\verb|oacc --emit-llvm|'').\\
90659065
description.txt & The application description.\\
9066+
functions\_of\_interest & Comma separated list of functions in the program
9067+
that should be (exclusively) included in the execution time measurement. This
9068+
file is optional. If not given, the whole application's execution time is used. \\
90669069
simulate.ttasim & TTASIM simulation script piped to the TTASIM to produce
90679070
ttasim.out file. If no such file is given the simulation is started with
90689071
"until 0" command.\\

openasip/src/applibs/Explorer/DesignSpaceExplorer.cc

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,39 @@
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

6669
using std::set;
6770
using 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

openasip/src/applibs/dsdb/TestApplication.cc

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ const string TestApplication::DESCRIPTION_FILE_NAME_ = "description.txt";
4545
const string TestApplication::APPLICATION_BASE_FILE_NAME_ = "program";
4646
const string TestApplication::SETUP_FILE_NAME_ = "setup.sh";
4747
const string TestApplication::SIMULATE_TTASIM_FILE_NAME_ = "simulate.ttasim";
48-
const string
49-
TestApplication::CORRECT_OUTPUT_FILE_NAME_ = "correct_simulation_output";
48+
const string TestApplication::CORRECT_OUTPUT_FILE_NAME_ =
49+
"correct_simulation_output";
5050
const string TestApplication::VERIFY_FILE_NAME_ = "verify.sh";
5151
const string TestApplication::CLEANUP_FILE_NAME_ = "cleanup.sh";
52+
const string TestApplication::FUNCTIONS_OF_INTEREST_FILE_NAME_ =
53+
"functions_of_interest";
5254
const string TestApplication::MAX_RUNTIME_ = "max_runtime";
5355
const int TestApplication::MAX_LINE_LENGTH_ = 512;
5456

@@ -76,6 +78,16 @@ TestApplication::TestApplication(const string& testApplicationPath)
7678
}
7779
fclose(file);
7880
}
81+
82+
if (hasFunctionsOfInterest()) {
83+
std::ifstream f(
84+
testApplicationPath_ + FileSystem::DIRECTORY_SEPARATOR +
85+
FUNCTIONS_OF_INTEREST_FILE_NAME_);
86+
std::string str(
87+
(std::istreambuf_iterator<char>(f)),
88+
std::istreambuf_iterator<char>());
89+
functionsOfInterest_ = TCEString(str).split(",");
90+
}
7991
}
8092

8193
/**
@@ -301,9 +313,20 @@ TestApplication::hasCleanupSimulation() const {
301313
return FileSystem::fileExists(cleanupFile);
302314
}
303315

316+
/**
317+
* @return true if 'functions_of_interest' file is found in the application
318+
* directory.
319+
*/
320+
bool
321+
TestApplication::hasFunctionsOfInterest() const {
322+
return FileSystem::fileIsReadable(
323+
testApplicationPath_ + FileSystem::DIRECTORY_SEPARATOR +
324+
FUNCTIONS_OF_INTEREST_FILE_NAME_);
325+
}
326+
304327
/**
305328
* Returns the application path in the test application directory.
306-
*
329+
*
307330
* If the file 'sequential_program' does not exists returns an empty string.
308331
*
309332
* @return The path of the 'sequential_program' file.

openasip/src/applibs/dsdb/TestApplication.hh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@
2727
* Declaration of TestApplication class.
2828
*
2929
* @author Jari Mäntyneva 2007 (jari.mantyneva-no.spam-tut.fi)
30-
* @author Pekka Jääskeläinen 2012
30+
* @author Pekka Jääskeläinen 2012, 2025
3131
* @note rating: red
3232
*/
3333

3434
#ifndef TTA_TEST_APPLICATION_HH
3535
#define TTA_TEST_APPLICATION_HH
3636

37+
#include <sstream>
3738
#include <string>
3839
#include <vector>
39-
#include <sstream>
40-
#include "Exception.hh"
4140

41+
#include "Exception.hh"
42+
#include "TCEString.hh"
4243

4344
/**
44-
* Class for handling files in test application directory.
45+
* Class for handling files in test application directory.
4546
*/
4647
class TestApplication {
4748
public:
@@ -59,6 +60,7 @@ public:
5960
bool hasCorrectOutput() const;
6061
bool hasVerifySimulation() const;
6162
bool hasCleanupSimulation() const;
63+
bool hasFunctionsOfInterest() const;
6264
bool isValid() const {
6365
return hasApplication() &&
6466
(hasCorrectOutput() || hasVerifySimulation());
@@ -72,12 +74,18 @@ public:
7274
void cleanupSimulation() const;
7375
ClockCycles cycleCount() const;
7476
Runtime maxRuntime() const;
77+
const std::vector<TCEString>&
78+
functionsOfInterest() const {
79+
return functionsOfInterest_;
80+
}
7581

7682
private:
7783
/// Path of the test application directory.
7884
const std::string testApplicationPath_;
7985
/// Maximum runtime of the test appication in nano seconds
8086
Runtime maxRuntime_;
87+
/// The names of the functions of interest (in terms of cycle count).
88+
std::vector<TCEString> functionsOfInterest_;
8189

8290
/// File name of the description text for the application.
8391
static const std::string DESCRIPTION_FILE_NAME_;
@@ -96,6 +104,11 @@ private:
96104
static const std::string VERIFY_FILE_NAME_;
97105
/// Name of the clean up file.
98106
static const std::string CLEANUP_FILE_NAME_;
107+
/// Name of the file that has a comma separated list of functions of
108+
/// interest for the cycle count measurements in the given app.
109+
/// The exclusive profile of these functions will be used as the
110+
/// cycle count in evaluation.
111+
static const std::string FUNCTIONS_OF_INTEREST_FILE_NAME_;
99112
/// Name of the file that contains maximum runtime.
100113
static const std::string MAX_RUNTIME_;
101114
/// Maximum line length in a file.

openasip/src/applibs/mach/MachineConnectivityCheck.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,9 @@ bool MachineConnectivityCheck::raConnected(const TTAMachine::Machine& machine) {
968968
static bool spammed = false;
969969
// check connection from RA to jump for fn return.
970970
ControlUnit& cu = *machine.controlUnit();
971+
972+
if (cu.returnAddressPort() == nullptr) return true;
973+
971974
SpecialRegisterPort& ra = *cu.returnAddressPort();
972975
if (cu.hasOperation("jump")) {
973976
auto jumpOp = cu.operation("jump");
@@ -2097,4 +2100,4 @@ bool MachineConnectivityCheck::canBypassOpToDst(
20972100
sourcePorts, destinationPorts,
20982101
(move.isUnconditional()) ?
20992102
nullptr : &move.guard().guard());
2100-
}
2103+
}

0 commit comments

Comments
 (0)