added new pass for statistics, updated dvm

This commit is contained in:
ALEXks
2024-08-30 12:17:35 +03:00
parent 861ce8262e
commit 7b34de49a8
12 changed files with 114 additions and 14 deletions

View File

@@ -170,7 +170,7 @@ static char* getNestCond()
static char* getNewCycleVar(const char *oldVar) static char* getNewCycleVar(const char *oldVar)
{ {
char *str = new char[strlen(oldVar) + 2]; char *str = new char[strlen(oldVar) + 3];
str[0] = '\0'; str[0] = '\0';
strcat(str, "__"); strcat(str, "__");
strcat(str, oldVar); strcat(str, oldVar);
@@ -3468,7 +3468,7 @@ SgSymbol *hasSameNameAsSource(SgSymbol *symb)
int sameVariableName(SgSymbol *symb1, SgSymbol *symb2) int sameVariableName(SgSymbol *symb1, SgSymbol *symb2)
{ {
if (!symb1 || !symb2 || (symb1->variant() != VARIABLE_NAME && symb1->variant() != CONST_NAME) || symb2->variant() != VARIABLE_NAME && symb2->variant() != CONST_NAME) if (!symb1 || !symb2 || (symb1->variant() != VARIABLE_NAME && symb1->variant() != CONST_NAME && symb1->variant() != FUNCTION_NAME) || symb2->variant() != VARIABLE_NAME && symb2->variant() != CONST_NAME && symb2->variant() != FUNCTION_NAME)
return 0; return 0;
if (!strcmp (symb1->identifier(), symb2->identifier())) if (!strcmp (symb1->identifier(), symb2->identifier()))
return 1; return 1;

View File

@@ -661,7 +661,7 @@ void ReadWritePrint_Statement(SgStatement *stmt, int error_msg)
//if(IN_COMPUTE_REGION && !in_checksection) //if(IN_COMPUTE_REGION && !in_checksection)
// ChangeDistArrayRef(iol); // ChangeDistArrayRef(iol);
} }
if(inparloop && (send || IN_COMPUTE_REGION) && error_msg) if(inparloop && (send || IN_COMPUTE_REGION || parloop_by_handler) && error_msg)
err("Illegal I/O statement in the range of parallel loop/region", 184,stmt); err("Illegal I/O statement in the range of parallel loop/region", 184,stmt);
} }

View File

@@ -458,7 +458,7 @@ int WhatInterface(SgStatement *stmt)
case SHADOW_COMP_OP: case SHADOW_COMP_OP:
case ACROSS_OP: case ACROSS_OP:
case ACC_TIE_OP: case ACC_TIE_OP:
case CONSISTENT_OP: case CONSISTENT_OP:
case STAGE_OP: case STAGE_OP:
case REMOTE_ACCESS_OP: case REMOTE_ACCESS_OP:
if(e->symbol()) // asynchronous REMOTE_ACCESS if(e->symbol()) // asynchronous REMOTE_ACCESS
@@ -2297,8 +2297,10 @@ void Interface_2(SgStatement *stmt,SgExpression *clause[],SgExpression *init[],S
} }
if (clause[CONSISTENT_]) //there is CONSISTENT clause if (clause[CONSISTENT_]) //there is CONSISTENT clause
for (SgExpression *el = clause[CONSISTENT_]->lhs(); el; el=el->rhs()) for (SgExpression *el = clause[CONSISTENT_]->lhs(); el; el=el->rhs())
InsertNewStatementAfter(Consistent_H(ilh, HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0), MappingList(stmt, el->lhs())), cur_st, cur_st->controlParent()); {
SgExpression *head = HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0);
InsertNewStatementAfter(Consistent_H(ilh, head, MappingList(stmt, el->lhs())), cur_st, cur_st->controlParent());
}
if (clause[REMOTE_ACCESS_]) //there is REMOTE_ACCESS clause if (clause[REMOTE_ACCESS_]) //there is REMOTE_ACCESS clause
{ int nbuf=1; { int nbuf=1;
//adding new element to remote_access directive/clause list //adding new element to remote_access directive/clause list
@@ -2306,7 +2308,10 @@ void Interface_2(SgStatement *stmt,SgExpression *clause[],SgExpression *init[],S
RemoteVariableList(clause[REMOTE_ACCESS_]->symbol(), clause[REMOTE_ACCESS_]->lhs(), stmt); RemoteVariableList(clause[REMOTE_ACCESS_]->symbol(), clause[REMOTE_ACCESS_]->lhs(), stmt);
for (SgExpression *el=clause[REMOTE_ACCESS_]->lhs(); el; el=el->rhs(),nbuf++) for (SgExpression *el=clause[REMOTE_ACCESS_]->lhs(); el; el=el->rhs(),nbuf++)
InsertNewStatementAfter(LoopRemoteAccess_H(ilh, HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0), el->lhs()->symbol(), MappingList(stmt, ArrayRefAddition(el->lhs()))), cur_st, cur_st->controlParent()); {
SgExpression *head = HeaderForArrayInParallelDir(el->lhs()->symbol(), stmt, 0);
InsertNewStatementAfter(LoopRemoteAccess_H(ilh, head, el->lhs()->symbol(), MappingList(stmt, ArrayRefAddition(el->lhs()))), cur_st, cur_st->controlParent());
}
} }
if (clause[SHADOW_COMPUTE_]) //there is SHADOW_COMPUTE clause if (clause[SHADOW_COMPUTE_]) //there is SHADOW_COMPUTE clause

View File

@@ -45,4 +45,4 @@ int Perform::getPercent() { return percent; }
void Perform::setNumber(int a) { number = a; } void Perform::setNumber(int a) { number = a; }
void Perform::setPercent(int a) { percent = a; } void Perform::setPercent(int a) { percent = a; }
void Perform::gcov_print() { __spf_print(1, "%d - %d\n", number, percent); } void Perform::gcov_print() { __spf_print(1, "%d - %d\n", number, percent); }
ostream &operator<<(ostream &out, const Perform &a) { out << "number= " << a.number << "\npercent= " << a.percent << endl; return out; } ostream &operator<<(ostream &out, const Perform &a) { out << "number= " << a.number << ": percent= " << a.percent << endl; return out; }

View File

@@ -1019,6 +1019,10 @@ static void insert(SgStatement* callSt, SgStatement* tempHedr, SgStatement* begi
st->setlineNumber(getNextNegativeLineNumber()); st->setlineNumber(getNextNegativeLineNumber());
} }
next = prev->lexNext();
next->setlineNumber(callSt->lineNumber());
next->setFileName(callSt->fileName());
last->extractStmt(); last->extractStmt();
if (callSt->variant() == PROC_STAT) if (callSt->variant() == PROC_STAT)

View File

@@ -4,6 +4,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdint> #include <cstdint>
#include <fstream>
#include <map> #include <map>
#include <vector> #include <vector>
@@ -12,9 +13,16 @@
#include <queue> #include <queue>
#include "dvm.h" #include "dvm.h"
#include "../DynamicAnalysis/gcov_info.h"
#include "PredictScheme.h" #include "PredictScheme.h"
#include "../Utils/SgUtils.h" #include "../Utils/SgUtils.h"
using std::map;
using std::string;
using std::vector;
using std::set;
using std::ofstream;
static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm) static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm)
{ {
if (exp) if (exp)
@@ -116,3 +124,77 @@ void processFileToPredict(SgFile *file, PredictorStats &predictorCounts)
predictorCounts.TotalScorePar += predictorCounts.ParallelCount; predictorCounts.TotalScorePar += predictorCounts.ParallelCount;
} }
static void calculate_for_parallel_loop(SgStatement* loop, const map<int, Gcov_info>& gcov,
uint64_t& paralle_exec_count, uint64_t& count_of_parallel_lines) {
for (auto st = loop; st != loop->lastNodeOfStmt(); st = st->lexNext()) {
int line = st->lineNumber();
if (line <= 0)
continue;
auto it = gcov.find(line);
if (it == gcov.end()) {
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
auto& info = it->second;
if (info.getNumLine() != line) {
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
count_of_parallel_lines++;
paralle_exec_count += info.getExecutedCount();
}
}
void calculate_stats_for_predictor(const map<string, vector<FuncInfo*>>& allFuncInfo,
const map<string, map<int, Gcov_info>>& gCovInfo) {
uint64_t paralle_exec_count = 0;
uint64_t count_of_parallel_lines = 0;
for (auto& byFile : allFuncInfo) {
int ok = SgFile::switchToFile(byFile.first);
if (ok == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto it = gCovInfo.find(byFile.first);
if (it == gCovInfo.end()) {
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
auto& gcov = it->second;
for (auto& func : byFile.second) {
SgStatement* stat = func->funcPointer->GetOriginal();
for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext()) {
uint64_t paralle_exec = 0;
uint64_t lines_count = 0;
if (st->variant() == DVM_PARALLEL_ON_DIR) {
auto loop = st->lexNext();
checkNull(loop, convertFileName(__FILE__).c_str(), __LINE__);
if (loop->variant() != FOR_NODE)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
calculate_for_parallel_loop(loop, gcov, paralle_exec, lines_count);
st = loop->lastNodeOfStmt();
paralle_exec_count += paralle_exec;
count_of_parallel_lines += lines_count;
__spf_print(1, " PAR LOOP [%d %s] total exec %llu, total exec lines %llu, avg %.16e\n",
loop->lineNumber(), byFile.first.c_str(), paralle_exec, lines_count, paralle_exec / (double)lines_count);
}
}
}
}
__spf_print(1, " coverage_average %.16e\n", paralle_exec_count / (double)count_of_parallel_lines);
ofstream stats("stats.csv");
stats << "coverage_average;" << paralle_exec_count / (double)count_of_parallel_lines << std::endl;
stats.close();
}

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include "dvm.h" #include "dvm.h"
#include "../GraphCall/graph_calls.h"
class ParallelStats class ParallelStats
{ {
@@ -51,4 +52,6 @@ public:
} }
}; };
void processFileToPredict(SgFile *file, PredictorStats &predictorCounts); void processFileToPredict(SgFile *file, PredictorStats &predictorCounts);
void calculate_stats_for_predictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);

View File

@@ -1892,9 +1892,9 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == FIX_COMMON_BLOCKS) else if (curr_regime == FIX_COMMON_BLOCKS)
fixCommonBlocks(allFuncInfo, commonBlocks, &project); fixCommonBlocks(allFuncInfo, commonBlocks, &project);
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST) else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
{
__spf_print(1, "GET_MIN_MAX_BLOCK_DIST: %d %d\n", min_max_block.first, min_max_block.second); __spf_print(1, "GET_MIN_MAX_BLOCK_DIST: %d %d\n", min_max_block.first, min_max_block.second);
} else if (curr_regime == GET_STATS_FOR_PREDICTOR)
calculate_stats_for_predictor(allFuncInfo, gCovInfo);
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.; const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.; const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;

View File

@@ -109,6 +109,7 @@ enum passes {
FILL_COMMON_BLOCKS, FILL_COMMON_BLOCKS,
PREDICT_SCHEME, PREDICT_SCHEME,
CALCULATE_STATS_SCHEME, CALCULATE_STATS_SCHEME,
GET_STATS_FOR_PREDICTOR,
DEF_USE_STAGE1, DEF_USE_STAGE1,
DEF_USE_STAGE2, DEF_USE_STAGE2,
@@ -288,6 +289,7 @@ static void setPassValues()
passNames[ARRAY_ACCESS_ANALYSIS_FOR_CORNER] = "ARRAY_ACCESS_ANALYSIS_FOR_CORNER"; passNames[ARRAY_ACCESS_ANALYSIS_FOR_CORNER] = "ARRAY_ACCESS_ANALYSIS_FOR_CORNER";
passNames[FILL_COMMON_BLOCKS] = "FILL_COMMON_BLOCKS"; passNames[FILL_COMMON_BLOCKS] = "FILL_COMMON_BLOCKS";
passNames[PREDICT_SCHEME] = "PREDICT_SCHEME"; passNames[PREDICT_SCHEME] = "PREDICT_SCHEME";
passNames[GET_STATS_FOR_PREDICTOR] = "GET_STATS_FOR_PREDICTOR";
passNames[DEF_USE_STAGE1] = "DEF_USE_STAGE1"; passNames[DEF_USE_STAGE1] = "DEF_USE_STAGE1";
passNames[DEF_USE_STAGE2] = "DEF_USE_STAGE2"; passNames[DEF_USE_STAGE2] = "DEF_USE_STAGE2";
passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS"; passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS";

View File

@@ -265,7 +265,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ LOOP_ANALYZER_COMP_DIST, REMOVE_OMP_DIRS }) <= list({ CREATE_DISTR_DIRS, CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS }); list({ LOOP_ANALYZER_COMP_DIST, REMOVE_OMP_DIRS }) <= list({ CREATE_DISTR_DIRS, CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS });
Pass(CALL_GRAPH2) <= list({ ONLY_ARRAY_GRAPH, CREATE_NESTED_LOOPS, FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE, FIND_PARAMETERS }); Pass(CALL_GRAPH2) <= list({ ONLY_ARRAY_GRAPH, CREATE_NESTED_LOOPS, FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE, FIND_PARAMETERS, GET_STATS_FOR_PREDICTOR });
Pass(CALL_GRAPH2) <= list({ PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT }); Pass(CALL_GRAPH2) <= list({ PURE_SAVE_TO_PARAMS, PURE_MODULE_TO_PARAMS, PURE_COMMON_TO_PARAMS, PURE_INTENT_INSERT });

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2359" #define VERSION_SPF "2362"

View File

@@ -554,11 +554,15 @@ bool OperatorChecker(SgFile* file, map<string, vector<Messages>>& currMessages)
SgStatement* st = file->firstStatement(); SgStatement* st = file->firstStatement();
string currF = file->filename(); string currF = file->filename();
while (st) while (st)
{ {
int line = st->lineNumber(); int line = st->lineNumber();
if (line > 0 && st->fileName() == currF) if (line > 0 && st->variant() == PROG_HEDR && st->symbol()->identifier() == string("_MAIN"))
; // skip
else if (line > 0 && st->fileName() == currF)
{ {
;
int var = st->controlParent()->variant(); int var = st->controlParent()->variant();
bool cpWasAdded = (var == ARITHIF_NODE || var == LOGIF_NODE || var == GOTO_NODE || var == IF_NODE) && (usedLines.find(line) != usedLines.end()); bool cpWasAdded = (var == ARITHIF_NODE || var == LOGIF_NODE || var == GOTO_NODE || var == IF_NODE) && (usedLines.find(line) != usedLines.end());