From 1a1705d2e4e72eb13950b2c16e8cce115a128a69 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Mon, 7 Oct 2024 14:50:37 +0300 Subject: [PATCH] added statistics --- .../_src/Predictor/PredictScheme.cpp | 130 ++++++++++++++++-- .../_src/Predictor/PredictScheme.h | 3 +- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 5 +- 3 files changed, 125 insertions(+), 13 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp index 5844fad..7679029 100644 --- a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.cpp @@ -16,6 +16,8 @@ #include "../DynamicAnalysis/gcov_info.h" #include "PredictScheme.h" #include "../Utils/SgUtils.h" +#include "../DirectiveProcessing/directive_parser.h" +#include "../Distribution/DvmhDirective.h" using std::map; using std::string; @@ -125,7 +127,7 @@ void processFileToPredict(SgFile *file, PredictorStats &predictorCounts) predictorCounts.TotalScorePar += predictorCounts.ParallelCount; } -static void calculate_for_parallel_loop(SgStatement* loop, const map& gcov, +static void calculateForParallelLoop(SgStatement* loop, const map& 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(); @@ -150,39 +152,42 @@ static void calculate_for_parallel_loop(SgStatement* loop, const map>& allFuncInfo, - const map>& gCovInfo) { +void calculateStatsForPredictor(const map>& allFuncInfo, + const map>& gCovInfo) { uint64_t total_exec_count = 0; uint64_t parallel_exec_count = 0; uint64_t count_of_parallel_lines = 0; - for (auto& byFile : allFuncInfo) { + 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()) { + 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) { + 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) { + 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); + calculateForParallelLoop(loop, gcov, paralle_exec, lines_count); st = loop->lastNodeOfStmt(); parallel_exec_count += paralle_exec; @@ -207,8 +212,8 @@ void calculate_stats_for_predictor(const map>& allFunc continue; auto& info = it->second; - - if (info.getNumLine() != line) { + if (info.getNumLine() != line) + { __spf_print(1, "bad gcov info\n"); printInternalError(convertFileName(__FILE__).c_str(), __LINE__); } @@ -225,4 +230,107 @@ void calculate_stats_for_predictor(const map>& allFunc stats << "average_parallel_exec;" << parallel_exec_count / (double)count_of_parallel_lines << std::endl; stats << "parallel_rate;" << parallel_exec_count / (double)total_exec_count << std::endl; stats.close(); +} + +void parseDvmDirForPredictor(const map>& allFuncInfo, + const map>& gCovInfo) +{ + ofstream dirs("dirs.csv"); + + 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()) + { + SgExpression* list; + SgExpression* dup; + auto line = 0; + + switch (st->variant()) + { + case DVM_PARALLEL_ON_DIR: + { + auto stat = st; + while (isDVM_stat(stat)) + stat = stat->lexPrev(); + line = stat->lineNumber(); // XXX + + list = st->expr(1); + auto it = gcov.find(line); + auto& info = it->second; + if (info.getNumLine() != line) + { + __spf_print(1, "bad gcov info\n"); + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + dirs << info.getExecutedCount() << ";" << "PARALLEL;" << st->expr(2)->unparse() << ";" << st->expr(0)->unparse() << ";"; + while (list) + { + dirs << list->lhs()->unparse() << ";"; + list = list->rhs(); + } + + dirs << std::endl; + } + break; + case DVM_VAR_DECL: // TODO + dup = st->expr(2)->lhs()->copyPtr(); + dup->setLhs(NULL); + dirs << "1;" << dup->unparse() << ";" << st->expr(2)->lhs()->lhs()->unparse() << ";" << st->expr(0)->unparse() << ";\n"; + break; + case DVM_DISTRIBUTE_DIR: + dirs << "1;" << "DISTRIBUTE;" << st->expr(1)->unparse() << ";" << st->expr(0)->unparse() << ";\n"; + break; + case DVM_ALIGN_DIR: + dirs << "1;" << "ALIGN;" << st->expr(0)->unparse() << "(" << st->expr(1)->unparse() << ");" << st->expr(2)->unparse() << ";\n"; + break; + case DVM_SHADOW_DIR: + dirs << "1;" << "SHADOW;" << st->expr(0)->unparse() << "(" << st->expr(1)->unparse() << ");\n"; + break; + case DVM_REMOTE_ACCESS_DIR: + { + line = st->lexNext()->lineNumber(); + auto it = gcov.find(line); + auto& info = it->second; + if (info.getNumLine() != line) + { + __spf_print(1, "bad gcov info\n"); + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + } + + dirs << info.getExecutedCount() << ";" << "REMOTE_ACCESS;"; + list = st->expr(0); + while (list) + { + dirs << list->lhs()->unparse() << ";"; + list = list->rhs(); + } + dirs << "\n"; + break; + } + default: + //printf("var = %d line %d\n", st->variant(), st->lineNumber()); + break; + } + } + } + } + + dirs.close(); } \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h index d333fb7..a29c73a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h +++ b/sapfor/experts/Sapfor_2017/_src/Predictor/PredictScheme.h @@ -54,4 +54,5 @@ public: void processFileToPredict(SgFile *file, PredictorStats &predictorCounts); -void calculate_stats_for_predictor(const std::map>& allFuncInfo, const std::map>& gCovInfo); \ No newline at end of file +void calculateStatsForPredictor(const std::map>& allFuncInfo, const std::map>& gCovInfo); +void parseDvmDirForPredictor(const std::map>& allFuncInfo, const std::map>& gCovInfo); \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index ca5a72d..98bea28 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -1894,7 +1894,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne 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); else if (curr_regime == GET_STATS_FOR_PREDICTOR) - calculate_stats_for_predictor(allFuncInfo, gCovInfo); + { + calculateStatsForPredictor(allFuncInfo, gCovInfo); + parseDvmDirForPredictor(allFuncInfo, gCovInfo); + } const float elapsed = duration_cast(high_resolution_clock::now() - timeForPass).count() / 1000.; const float elapsedGlobal = duration_cast(high_resolution_clock::now() - globalTime).count() / 1000.;