From 517f5d2b6c3beafc8874d87ae7c3ab11e2359c21 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Thu, 18 Jul 2024 12:35:14 +0300 Subject: [PATCH 1/2] remove select_dim_conf pass --- sapfor/experts/Sapfor_2017/CMakeLists.txt | 4 +- .../_src/GraphCall/select_array_conf.cpp | 303 ------------------ .../_src/GraphCall/select_array_conf.h | 16 - .../_src/GraphLoop/graph_loops.cpp | 7 - sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 4 - sapfor/experts/Sapfor_2017/_src/Sapfor.h | 2 - .../Sapfor_2017/_src/Utils/PassManager.h | 2 +- .../_src/VisualizerCalls/get_information.cpp | 2 +- 8 files changed, 3 insertions(+), 337 deletions(-) delete mode 100644 sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp delete mode 100644 sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h diff --git a/sapfor/experts/Sapfor_2017/CMakeLists.txt b/sapfor/experts/Sapfor_2017/CMakeLists.txt index 6c70baf..f13bc4e 100644 --- a/sapfor/experts/Sapfor_2017/CMakeLists.txt +++ b/sapfor/experts/Sapfor_2017/CMakeLists.txt @@ -299,9 +299,7 @@ set(EXPR_TRANSFORM _src/ExpressionTransform/control_flow_graph_part.cpp set(GR_CALL _src/GraphCall/graph_calls.cpp _src/GraphCall/graph_calls.h _src/GraphCall/graph_calls_base.cpp - _src/GraphCall/graph_calls_func.h - _src/GraphCall/select_array_conf.cpp - _src/GraphCall/select_array_conf.h) + _src/GraphCall/graph_calls_func.h) set(GR_LOOP _src/GraphLoop/graph_loops_base.cpp _src/GraphLoop/graph_loops.cpp diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp deleted file mode 100644 index 9f9a9a2..0000000 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.cpp +++ /dev/null @@ -1,303 +0,0 @@ -#include "select_array_conf.h" -#include "../Utils/utils.h" - -using std::map; -using std::string; -using std::vector; -using std::set; -using std::pair; -using std::wstring; - -using std::inserter; -using std::copy; -using std::to_string; - -bool IsSetsIntersect(const set& lhs, const set& rhs) -{ - if (lhs.empty() || rhs.empty()) - return false; - - if (lhs.size() * 100 < rhs.size()) - { - for (const auto& x : lhs) - if (rhs.find(x) != rhs.end()) - return true; - return false; - } - - if (rhs.size() * 100 < lhs.size()) - { - for (const auto& x : rhs) - if (lhs.find(x) != lhs.end()) - return true; - return false; - } - - auto l_it = lhs.begin(), l_end = lhs.end(); - auto r_it = rhs.begin(), r_end = rhs.end(); - - while (l_it != l_end && r_it != r_end) - { - if (*l_it < *r_it) - { - l_it = lhs.lower_bound(*r_it); - continue; - } - if (*r_it < *l_it) - { - r_it = rhs.lower_bound(*l_it); - continue; - } - - return true; - } - - return false; -} - -static void findUsedArraysInParallelLoops(LoopGraph* loop, set& res) -{ - if(loop->directive) - copy(loop->usedArraysAll.begin(), loop->usedArraysAll.end(), inserter(res, res.end())); - else - for(LoopGraph* child : loop->children) - findUsedArraysInParallelLoops(child, res); -} - -static void preventLoopsFromParallelizations(LoopGraph* loop, const set& prevent, - vector& messagesForFile) -{ - if (loop->directive) - { - if (IsSetsIntersect(prevent, loop->usedArraysAll)) - { - // prevent this loop - delete loop->directive; - loop->directive = NULL; - - vector conflict_arrays; // = prevent \intersection loop->usedArraysAll - - set_intersection(prevent.begin(), prevent.end(), - loop->usedArraysAll.begin(), loop->usedArraysAll.end(), - back_inserter(conflict_arrays)); - - for(auto& conflict_array : conflict_arrays) - { - // constructing string with array and it's sizes - string array_bounds; - const auto& array_sizes = conflict_array->GetSizes(); - for(int i = 0; i < array_sizes.size(); i++) - { - if(i != 0) - array_bounds += ","; - array_bounds += "*"; - } - - string array_ref = conflict_array->GetShortName() + "(" + array_bounds + ")"; - - // add conflict message - std::wstring bufE, bufR; - __spf_printToLongBuf(bufE, L"Array reference '%s' has a different size from the original array", to_wstring(array_ref).c_str()); - __spf_printToLongBuf(bufR, R202, to_wstring(array_ref).c_str()); - - messagesForFile.push_back(Messages(WARR, loop->lineNum, bufR, bufE, 3023)); - loop->hasAccessToSubArray = true; - } - - if(!conflict_arrays.empty()) - messagesForFile.push_back(Messages(NOTE, loop->lineNum, R204, L"Array's memory intersections prevents this loop from parallelization", 3024)); - } - } - - for (LoopGraph* child : loop->children) - preventLoopsFromParallelizations(child, prevent, messagesForFile); -} - -struct DimConf -{ - vector> dims; - - DimConf(DIST::Array* a) : dims(a->GetSizes()) { } - - friend bool operator<(const DimConf& l, const DimConf& r) { return l.dims < r.dims; } -}; - -static map>>::const_iterator -pickBest(const map>>& arrs) -{ - const int undefined = -1; - int max_elems = undefined; - auto best_it = arrs.begin(); - - for (auto it = arrs.begin(); it != arrs.end(); it++) - { - int elems = 1; - for (const auto& p : it->first.dims) - { - if(p.first >= 0 && p.second >= p.first) - { - elems *= p.second - p.first; - } - else - { - elems = undefined; - break; - } - } - - if (elems > max_elems) - { - max_elems = elems; - best_it = it; - } - } - - return best_it; -} - -void SelectArrayConfForParallelization(SgProject* proj, map>& funcByFile, - const map>& loopGraph, - map>& allMessages, - const map>& arrayLinksByFuncCalls) -{ - map funcByName; - for (const auto& byFile : funcByFile) - for(const auto& byFunc : byFile.second) - funcByName[byFunc->funcName] = byFunc; - - // array(real ref) dims func array in func - map>>> usedArrays; - - for (const auto& byFile : loopGraph) - { - SgFile::switchToFile(byFile.first); - - auto& loops = byFile.second; - - auto file_funcs_it = funcByFile.find(byFile.first); - - if(file_funcs_it == funcByFile.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile - - map> usedInLoops; - - for (const auto& loop : loops) - { - SgStatement* search_func = loop->loop->GetOriginal(); - - while (search_func && (!isSgProgHedrStmt(search_func))) - search_func = search_func->controlParent(); - - if (!search_func) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //loop statement outside any function statement - - bool loop_analyzed = false; - for (const auto& byFunc : file_funcs_it->second) - { - if (byFunc->funcPointer->GetOriginal() == search_func) - { - if(!loop->usedArraysAll.empty()) - findUsedArraysInParallelLoops(loop, usedInLoops[byFunc]); - - loop_analyzed = true; - break; - } - } - - if (!loop_analyzed) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop - } - - for (const auto& byFunc : usedInLoops) - { - for (DIST::Array* arr : byFunc.second) - { - set realRefs; - getRealArrayRefs(arr, arr, realRefs, arrayLinksByFuncCalls); - - bool fullUnknownSizes = true; - for (auto& dim : arr->GetSizes()) - { - if (dim.first == dim.second && dim.first != -1) - fullUnknownSizes = false; - } - - if (fullUnknownSizes && realRefs.find(arr) != realRefs.end()) - continue; - - for(DIST::Array* ref : realRefs) - usedArrays[ref][DimConf(arr)][byFunc.first].insert(arr); - } - } - } - - map> preventFromParallelization; - - for (const auto& byRealRef : usedArrays) - { - DIST::Array* realRef = byRealRef.first; - auto& refferedDims = byRealRef.second; - - // prevent from parallelization all configurations except best one - - auto best_conf_it = pickBest(refferedDims); - - for (auto by_worse_dim_conf_it = refferedDims.begin(); by_worse_dim_conf_it != refferedDims.end(); by_worse_dim_conf_it++) - { - if(by_worse_dim_conf_it != best_conf_it) - { - for (const auto& byFunc : by_worse_dim_conf_it->second) - { - FuncInfo* f = byFunc.first; - auto& to_prevent = byFunc.second; - - auto& destSet = preventFromParallelization[f]; - copy(to_prevent.begin(), to_prevent.end(), inserter(destSet, destSet.end())); - } - } - } - } - - for (const auto& byFile : loopGraph) - { - vector& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages); - SgFile::switchToFile(byFile.first); - - auto& loops = byFile.second; - - auto file_funcs_it = funcByFile.find(byFile.first); - - if (file_funcs_it == funcByFile.end()) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // no such file in funcByFile - - map> usedInLoops; - - for (const auto& loop : loops) - { - SgStatement* search_func = loop->loop->GetOriginal(); - - while (search_func && (!isSgProgHedrStmt(search_func))) - search_func = search_func->controlParent(); - - if (!search_func) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //loop statement outside any function statement - - bool loop_analyzed = false; - for (const auto& byFunc : file_funcs_it->second) - { - if (byFunc->funcPointer->GetOriginal() == search_func) - { - auto prevent_it = preventFromParallelization.find(byFunc); - if (prevent_it != preventFromParallelization.end()) - preventLoopsFromParallelizations(loop, prevent_it->second, fileM); - - loop_analyzed = true; - break; - } - } - - if (!loop_analyzed) - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); //no func found for loop - } - } -} \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h b/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h deleted file mode 100644 index 4d2e392..0000000 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/select_array_conf.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "../Distribution/Distribution.h" -#include "../GraphLoop/graph_loops.h" -#include "../ParallelizationRegions/ParRegions.h" - - -void SelectArrayConfForParallelization(SgProject* proj, std::map>& funcByFile, - const std::map>& loopGraph, - std::map>& allMessages, - const std::map>& arrayLinksByFuncCalls); \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp index 4b22dc3..3205757 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp @@ -918,13 +918,6 @@ static void printToBuffer(const LoopGraph *currLoop, const int childSize, char b else loopState = 1; } - else if (PASSES_DONE[SELECT_ARRAY_DIM_CONF]) - { - if (currLoop->hasLimitsToParallel()) - loopState = 2; - else - loopState = 1; - } else { if (currLoop->hasLimitsToParallel()) diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 834bd12..fabdc4b 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -40,7 +40,6 @@ #include "LoopAnalyzer/loop_analyzer.h" #include "GraphCall/graph_calls_func.h" -#include "GraphCall/select_array_conf.h" #include "GraphLoop/graph_loops_func.h" #include "DynamicAnalysis/gCov_parser_func.h" #include "DynamicAnalysis/createParallelRegions.h" @@ -1880,9 +1879,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne runPrivateVariableAnalysis(loopGraph, fullIR, commonBlocks, SPF_messages); else if (curr_regime == FIX_COMMON_BLOCKS) fixCommonBlocks(allFuncInfo, commonBlocks, &project); - else if (curr_regime == SELECT_ARRAY_DIM_CONF) { - ;// SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, SPF_messages, arrayLinksByFuncCalls); - } 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); diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.h b/sapfor/experts/Sapfor_2017/_src/Sapfor.h index e9d8bf9..26ee059 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.h +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.h @@ -67,7 +67,6 @@ enum passes { CHECK_ARGS_DECL, FIND_FUNC_TO_INCLUDE, - SELECT_ARRAY_DIM_CONF, ONLY_ARRAY_GRAPH, PRIVATE_ANALYSIS_SPF, @@ -238,7 +237,6 @@ static void setPassValues() passNames[VERIFY_COMMON] = "VERIFY_COMMON"; passNames[VERIFY_OPERATORS] = "VERIFY_OPERATORS"; passNames[FIND_FUNC_TO_INCLUDE] = "FIND_FUNC_TO_INCLUDE"; - passNames[SELECT_ARRAY_DIM_CONF] = "SELECT_ARRAY_DIM_CONF"; passNames[CREATE_DISTR_DIRS] = "CREATE_DISTR_DIRS"; passNames[CREATE_PARALLEL_DIRS] = "CREATE_PARALLEL_DIRS"; passNames[INSERT_PARALLEL_DIRS] = "INSERT_PARALLEL_DIRS"; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h index 50f571b..82cb2cf 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/PassManager.h @@ -233,7 +233,7 @@ void InitPassesDependencies(map> &passDepsIn, set list({ GET_ALL_ARRAY_DECL, CALL_GRAPH2, CODE_CHECKER_PASSES, SUBST_EXPR_RD, ARRAY_ACCESS_ANALYSIS_FOR_CORNER }) <= list({ LOOP_ANALYZER_NODIST, LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH }); - list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(SELECT_ARRAY_DIM_CONF) <= Pass(INSERT_PARALLEL_DIRS_NODIST); + list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(INSERT_PARALLEL_DIRS_NODIST); Pass(CHECK_ARGS_DECL) <= Pass(CREATE_TEMPLATE_LINKS); diff --git a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp index 28be54d..1285cdf 100644 --- a/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VisualizerCalls/get_information.cpp @@ -820,7 +820,7 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho else if (regime == 1) { if (sharedMemoryParallelization) - runPassesForVisualizer(projName, { SELECT_ARRAY_DIM_CONF }); + runPassesForVisualizer(projName, { LOOP_ANALYZER_NODIST }); else runPassesForVisualizer(projName, { LOOP_ANALYZER_DATA_DIST_S1 }); } -- 2.49.1 From bb4c9a8606cb1d576d1fd8260047ac9ad2fac279 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Thu, 18 Jul 2024 18:02:01 +0300 Subject: [PATCH 2/2] save prev logic --- sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp | 3 ++- sapfor/experts/Sapfor_2017/_src/Utils/version.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp index 3205757..8660aca 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphLoop/graph_loops.cpp @@ -911,7 +911,8 @@ extern int PASSES_DONE[EMPTY_PASS]; static void printToBuffer(const LoopGraph *currLoop, const int childSize, char buf[512]) { int loopState = 0; // 0 - unknown, 1 - good, 2 - bad - if (PASSES_DONE[CREATE_TEMPLATE_LINKS]) + if (PASSES_DONE[CREATE_TEMPLATE_LINKS] || + PASSES_DONE[LOOP_ANALYZER_NODIST]) { if (currLoop->hasLimitsToParallel()) loopState = 2; diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 170b9c5..93f5303 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2351" +#define VERSION_SPF "2352" -- 2.49.1