Compare commits
5 Commits
1bb0334fa2
...
libpredict
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d0fee77c7 | |||
| 6fceaaf704 | |||
| f623eaeb5b | |||
| c26cc261c4 | |||
| d1a9113072 |
@@ -163,9 +163,6 @@ set(PARALLEL_REG src/ParallelizationRegions/ParRegions.cpp
|
|||||||
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
|
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
|
||||||
src/ParallelizationRegions/resolve_par_reg_conflicts.h)
|
src/ParallelizationRegions/resolve_par_reg_conflicts.h)
|
||||||
|
|
||||||
set(MERGE_COPY_ARRAYS src/ParallelizationRegions/parse_merge_dirs.cpp
|
|
||||||
src/ParallelizationRegions/parse_merge_dirs.h)
|
|
||||||
|
|
||||||
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
|
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
|
||||||
src/Transformations/DeadCodeRemoving/dead_code.h)
|
src/Transformations/DeadCodeRemoving/dead_code.h)
|
||||||
set(TR_CP src/Transformations/CheckPoints/checkpoints.cpp
|
set(TR_CP src/Transformations/CheckPoints/checkpoints.cpp
|
||||||
@@ -334,7 +331,9 @@ set(MAIN src/Sapfor.cpp
|
|||||||
src/Utils/PassManager.h)
|
src/Utils/PassManager.h)
|
||||||
|
|
||||||
set(PREDICTOR src/Predictor/PredictScheme.cpp
|
set(PREDICTOR src/Predictor/PredictScheme.cpp
|
||||||
src/Predictor/PredictScheme.h)
|
src/Predictor/PredictScheme.h
|
||||||
|
src/Predictor/PredictSchemeWithLibrary.cpp
|
||||||
|
src/Predictor/PredictSchemeWithLibrary.h)
|
||||||
|
|
||||||
set(LIBPREDICTOR ${libpred_sources}/cluster.cpp
|
set(LIBPREDICTOR ${libpred_sources}/cluster.cpp
|
||||||
${libpred_sources}/predictor.cpp
|
${libpred_sources}/predictor.cpp
|
||||||
@@ -422,7 +421,6 @@ set(SOURCE_EXE
|
|||||||
${LOOP_ANALYZER}
|
${LOOP_ANALYZER}
|
||||||
${TRANSFORMS}
|
${TRANSFORMS}
|
||||||
${PARALLEL_REG}
|
${PARALLEL_REG}
|
||||||
${MERGE_COPY_ARRAYS}
|
|
||||||
${PRIV}
|
${PRIV}
|
||||||
${FDVM}
|
${FDVM}
|
||||||
${OMEGA}
|
${OMEGA}
|
||||||
@@ -474,7 +472,6 @@ source_group (GraphCall FILES ${GR_CALL})
|
|||||||
source_group (GraphLoop FILES ${GR_LOOP})
|
source_group (GraphLoop FILES ${GR_LOOP})
|
||||||
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
|
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
|
||||||
source_group (ParallelizationRegions FILES ${PARALLEL_REG})
|
source_group (ParallelizationRegions FILES ${PARALLEL_REG})
|
||||||
source_group (MergeCopyArrays FILES ${MERGE_COPY_ARRAYS})
|
|
||||||
source_group (PrivateAnalyzer FILES ${PRIV})
|
source_group (PrivateAnalyzer FILES ${PRIV})
|
||||||
source_group (FDVM_Compiler FILES ${FDVM})
|
source_group (FDVM_Compiler FILES ${FDVM})
|
||||||
source_group (SageExtension FILES ${OMEGA})
|
source_group (SageExtension FILES ${OMEGA})
|
||||||
|
|||||||
Submodule projects/dvm updated: 4d4041a081...4b7ef11871
Submodule projects/libpredictor updated: d0772cdb57...e6e805a390
@@ -122,6 +122,7 @@ static LoopGraph* createDirectiveForLoop(LoopGraph *currentLoop, MapToArray &mai
|
|||||||
if (found == false)
|
if (found == false)
|
||||||
{
|
{
|
||||||
directive->shadowRenew.push_back(make_pair(key, vector<pair<int, int>>()));
|
directive->shadowRenew.push_back(make_pair(key, vector<pair<int, int>>()));
|
||||||
|
directive->shadowRenewCorner.push_back(false);
|
||||||
|
|
||||||
const DIST::Array *arrayRef = read;
|
const DIST::Array *arrayRef = read;
|
||||||
for (int i = 0; i < arrayRef->GetDimSize(); ++i)
|
for (int i = 0; i < arrayRef->GetDimSize(); ++i)
|
||||||
|
|||||||
@@ -857,6 +857,11 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
|
|||||||
shadowRenewShifts[i].resize(shadowRenew[i].second.size());
|
shadowRenewShifts[i].resize(shadowRenew[i].second.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shadowRenewCorner.size() == 0)
|
||||||
|
{
|
||||||
|
shadowRenewCorner.resize(shadowRenew.size(), false);
|
||||||
|
}
|
||||||
|
|
||||||
string shadowAdd = ", SHADOW_RENEW(";
|
string shadowAdd = ", SHADOW_RENEW(";
|
||||||
int inserted = 0;
|
int inserted = 0;
|
||||||
|
|
||||||
@@ -899,7 +904,10 @@ ParallelDirective::genDirective(File* file, const vector<pair<DIST::Array*, cons
|
|||||||
for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1]))
|
for (auto& elem : genSubscripts(shadowRenew[i1].second, shadowRenewShifts[i1]))
|
||||||
newArrayRef->addSubscript(*elem);
|
newArrayRef->addSubscript(*elem);
|
||||||
|
|
||||||
if (shadowRenew[i1].second.size() > 1 && needCorner(shadowArray, shiftsByAccess, loop))
|
bool needCornerFlag = shadowRenew[i1].second.size() > 1 && needCorner(shadowArray, shiftsByAccess, loop);
|
||||||
|
shadowRenewCorner[i1] = needCornerFlag;
|
||||||
|
|
||||||
|
if (needCornerFlag)
|
||||||
{
|
{
|
||||||
SgExpression* tmp = new SgExpression(ARRAY_OP, newArrayRef, NULL, NULL);
|
SgExpression* tmp = new SgExpression(ARRAY_OP, newArrayRef, NULL, NULL);
|
||||||
p->setLhs(*tmp);
|
p->setLhs(*tmp);
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ public:
|
|||||||
// origin_Name uniqName bounds
|
// origin_Name uniqName bounds
|
||||||
std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> shadowRenew;
|
std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> shadowRenew;
|
||||||
std::vector<std::vector<std::pair<int, int>>> shadowRenewShifts;
|
std::vector<std::vector<std::pair<int, int>>> shadowRenewShifts;
|
||||||
|
std::vector<bool> shadowRenewCorner;
|
||||||
|
|
||||||
// origin_Name uniqName bounds
|
// origin_Name uniqName bounds
|
||||||
std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> across;
|
std::vector<std::pair<std::pair<std::string, std::string>, std::vector<std::pair<int, int>>>> across;
|
||||||
@@ -125,6 +126,7 @@ public:
|
|||||||
privates = copyFrom.privates;
|
privates = copyFrom.privates;
|
||||||
shadowRenew = copyFrom.shadowRenew;
|
shadowRenew = copyFrom.shadowRenew;
|
||||||
shadowRenewShifts = copyFrom.shadowRenewShifts;
|
shadowRenewShifts = copyFrom.shadowRenewShifts;
|
||||||
|
shadowRenewCorner = copyFrom.shadowRenewCorner;
|
||||||
across = copyFrom.across;
|
across = copyFrom.across;
|
||||||
acrossShifts = copyFrom.acrossShifts;
|
acrossShifts = copyFrom.acrossShifts;
|
||||||
remoteAccess = copyFrom.remoteAccess;
|
remoteAccess = copyFrom.remoteAccess;
|
||||||
@@ -151,6 +153,7 @@ public:
|
|||||||
on.clear();
|
on.clear();
|
||||||
privates.clear();
|
privates.clear();
|
||||||
shadowRenew.clear();
|
shadowRenew.clear();
|
||||||
|
shadowRenewCorner.clear();
|
||||||
across.clear();
|
across.clear();
|
||||||
acrossShifts.clear();
|
acrossShifts.clear();
|
||||||
reduction.clear();
|
reduction.clear();
|
||||||
|
|||||||
@@ -1,567 +0,0 @@
|
|||||||
#include "parse_merge_dirs.h"
|
|
||||||
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
using std::map;
|
|
||||||
using std::pair;
|
|
||||||
using std::string;
|
|
||||||
using std::unordered_map;
|
|
||||||
using std::unordered_set;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
static void parseMergeDirective(const char *comment,
|
|
||||||
vector<pair<string, string>> &parsed_mapping)
|
|
||||||
{
|
|
||||||
while (comment)
|
|
||||||
{
|
|
||||||
auto *line_end = strchr(comment, '\n');
|
|
||||||
|
|
||||||
static const char prefix[] = "!!SPF TRANSFORM(MERGE_ARRAYS(";
|
|
||||||
static const auto compare_chars = sizeof(prefix) - 1;
|
|
||||||
|
|
||||||
if (strncasecmp(comment, prefix, compare_chars) == 0)
|
|
||||||
{
|
|
||||||
auto *pair_start = comment + compare_chars;
|
|
||||||
auto *comma = strchr(pair_start, ',');
|
|
||||||
if (comma)
|
|
||||||
{
|
|
||||||
auto *close_br = strchr(comma + 1, ')');
|
|
||||||
if (close_br)
|
|
||||||
{
|
|
||||||
parsed_mapping.emplace_back(
|
|
||||||
string(pair_start, comma - pair_start),
|
|
||||||
string(comma + 1, close_br - comma - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
comment = line_end;
|
|
||||||
|
|
||||||
if (comment)
|
|
||||||
comment++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static string getNonDefaultRegion(DIST::Array *a)
|
|
||||||
{
|
|
||||||
string result;
|
|
||||||
|
|
||||||
if (!a)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
for (const auto ®_name : a->GetRegionsName())
|
|
||||||
{
|
|
||||||
if (reg_name != "default")
|
|
||||||
{
|
|
||||||
if (!result.empty())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
result = reg_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasSameSizes(DIST::Array *a, DIST::Array *b)
|
|
||||||
{
|
|
||||||
for (auto *array : {a, b})
|
|
||||||
{
|
|
||||||
for (const auto &p : array->GetSizes())
|
|
||||||
{
|
|
||||||
if (p.first < 0 || p.second < 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return a->GetSizes() == b->GetSizes() && a->GetTypeSize() == b->GetTypeSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkSimilarTemplates(vector<ParallelRegion *> ®ions,
|
|
||||||
const unordered_map<string, string> &new_region_mapping)
|
|
||||||
{
|
|
||||||
// new region -> old regions
|
|
||||||
unordered_map<string, unordered_set<string>> new_region_inverse_mapping;
|
|
||||||
for (const auto &p : new_region_mapping)
|
|
||||||
new_region_inverse_mapping[p.second].insert(p.first);
|
|
||||||
|
|
||||||
for (const auto &new_reg : new_region_inverse_mapping)
|
|
||||||
{
|
|
||||||
DIST::Array *template_array = nullptr;
|
|
||||||
string first_reg_name;
|
|
||||||
|
|
||||||
for (const auto &old_region_name : new_reg.second)
|
|
||||||
{
|
|
||||||
auto *old_reg = getRegionByName(regions, old_region_name);
|
|
||||||
|
|
||||||
if (!old_reg)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
const auto &distr_rules = old_reg->GetDataDir().GetDistrRules();
|
|
||||||
if (distr_rules.size() != 1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto *current_template = distr_rules.front().first;
|
|
||||||
|
|
||||||
if (template_array)
|
|
||||||
{
|
|
||||||
if (!hasSameSizes(template_array, current_template))
|
|
||||||
{
|
|
||||||
__spf_print(1, "Templates of %s and %s has different sizes\n",
|
|
||||||
first_reg_name.c_str(),
|
|
||||||
old_region_name.c_str());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// else everything OK
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
template_array = current_template;
|
|
||||||
first_reg_name = old_region_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasSameAlignment(const std::unordered_set<const AlignRule *> &align_a,
|
|
||||||
const std::unordered_set<const AlignRule *> &align_b)
|
|
||||||
{
|
|
||||||
if (align_a.size() != 1 || align_b.size() != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto *rule_a = *align_a.begin();
|
|
||||||
const auto *rule_b = *align_b.begin();
|
|
||||||
|
|
||||||
if (rule_a->alignRule != rule_b->alignRule)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void printExpr(SgExpression *e, string pad)
|
|
||||||
{
|
|
||||||
if (!e)
|
|
||||||
return;
|
|
||||||
|
|
||||||
__spf_print(1, "%s%d: %s\n", pad.c_str(), e->variant(), e->unparse());
|
|
||||||
|
|
||||||
printExpr(e->lhs(), pad + " ");
|
|
||||||
printExpr(e->rhs(), pad + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
static pair<vector<SgStatement *>, SgSymbol *> generateDeclaration(const string &array_name, const string &common_block_name,
|
|
||||||
const vector<pair<int, int>> &sizes, SgType *type, SgStatement *scope)
|
|
||||||
{
|
|
||||||
auto *array_symbol = new SgSymbol(VARIABLE_NAME, array_name.c_str(), new SgType(T_ARRAY), scope);
|
|
||||||
|
|
||||||
auto *decl = new SgDeclarationStatement(VAR_DECL);
|
|
||||||
|
|
||||||
decl->setExpression(1, new SgTypeExp(*type));
|
|
||||||
|
|
||||||
SgExpression *subs = new SgExprListExp();
|
|
||||||
|
|
||||||
auto *array_ref = new SgArrayRefExp(*array_symbol, *subs);
|
|
||||||
|
|
||||||
for (int i = 0; i < sizes.size(); i++)
|
|
||||||
{
|
|
||||||
const auto &p = sizes[i];
|
|
||||||
auto *d = new SgExpression(DDOT, new SgValueExp(p.first), new SgValueExp(p.second));
|
|
||||||
subs->setLhs(d);
|
|
||||||
|
|
||||||
if (i + 1 < sizes.size())
|
|
||||||
{
|
|
||||||
subs->setRhs(new SgExprListExp());
|
|
||||||
subs = subs->rhs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
decl->setExpression(0, array_ref);
|
|
||||||
|
|
||||||
auto comm = new SgStatement(COMM_STAT);
|
|
||||||
|
|
||||||
comm->setExpression(0, new SgExpression(COMM_LIST,
|
|
||||||
new SgVarRefExp(array_symbol),
|
|
||||||
NULL,
|
|
||||||
new SgSymbol(COMMON_NAME, common_block_name.c_str())));
|
|
||||||
|
|
||||||
return {{decl, comm}, array_symbol};
|
|
||||||
}
|
|
||||||
|
|
||||||
SgSymbol *insertDeclIfNeeded(const string &array_name,
|
|
||||||
const string &common_block_name,
|
|
||||||
DIST::Array *example_array,
|
|
||||||
FuncInfo *dest,
|
|
||||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
|
||||||
{
|
|
||||||
if (SgFile::switchToFile(dest->fileName) == -1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto &by_func = inserted_arrays[dest];
|
|
||||||
auto it = by_func.find(array_name);
|
|
||||||
|
|
||||||
if (it != by_func.end())
|
|
||||||
return it->second;
|
|
||||||
|
|
||||||
SgStatement *st = dest->funcPointer;
|
|
||||||
|
|
||||||
auto *end = st->lastNodeOfStmt();
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st != end && !isSgExecutableStatement(st))
|
|
||||||
{
|
|
||||||
st = st->lexNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto generated = generateDeclaration(array_name, common_block_name,
|
|
||||||
example_array->GetSizes(),
|
|
||||||
SgTypeInt(), dest->funcPointer);
|
|
||||||
for (auto *new_stmt : generated.first)
|
|
||||||
st->insertStmtBefore(*new_stmt, *dest->funcPointer);
|
|
||||||
|
|
||||||
by_func[array_name] = generated.second;
|
|
||||||
|
|
||||||
return generated.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
static pair<string, string> createNewArray(DIST::Array *example_array, const string &base_name,
|
|
||||||
const map<string, vector<FuncInfo *>> &allFuncInfo,
|
|
||||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
|
||||||
{
|
|
||||||
auto common_block_name = base_name + "_merge_cb";
|
|
||||||
auto array_name = base_name;
|
|
||||||
|
|
||||||
for (const auto &by_file : allFuncInfo)
|
|
||||||
{
|
|
||||||
for (auto *func_info : by_file.second)
|
|
||||||
{
|
|
||||||
if (func_info->isMain)
|
|
||||||
{
|
|
||||||
insertDeclIfNeeded(
|
|
||||||
array_name,
|
|
||||||
common_block_name,
|
|
||||||
example_array,
|
|
||||||
func_info,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_pair(array_name, common_block_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void replaceArrayRec(SgExpression *e,
|
|
||||||
const unordered_set<string> &arrays_to_replace,
|
|
||||||
SgSymbol **func_symbol_hint,
|
|
||||||
const pair<string, string> &replace_by,
|
|
||||||
DIST::Array *example_array,
|
|
||||||
FuncInfo *func,
|
|
||||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
|
||||||
{
|
|
||||||
if (!e)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (isArrayRef(e) && arrays_to_replace.find(e->symbol()->identifier()) != arrays_to_replace.end())
|
|
||||||
{
|
|
||||||
if (!(*func_symbol_hint))
|
|
||||||
{
|
|
||||||
*func_symbol_hint = insertDeclIfNeeded(
|
|
||||||
replace_by.first, replace_by.second,
|
|
||||||
example_array,
|
|
||||||
func,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
e->setSymbol(*func_symbol_hint);
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceArrayRec(
|
|
||||||
e->lhs(),
|
|
||||||
arrays_to_replace,
|
|
||||||
func_symbol_hint,
|
|
||||||
replace_by,
|
|
||||||
example_array,
|
|
||||||
func,
|
|
||||||
inserted_arrays);
|
|
||||||
|
|
||||||
replaceArrayRec(
|
|
||||||
e->rhs(),
|
|
||||||
arrays_to_replace,
|
|
||||||
func_symbol_hint,
|
|
||||||
replace_by,
|
|
||||||
example_array,
|
|
||||||
func,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void replaceRegion(SgStatement* st, const unordered_map<string, string> &new_region_mapping)
|
|
||||||
{
|
|
||||||
if (!st)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(isSPF_stat(st) && st->variant() == SPF_PARALLEL_REG_DIR)
|
|
||||||
{
|
|
||||||
auto it = new_region_mapping.find(st->symbol()->identifier());
|
|
||||||
|
|
||||||
if (it != new_region_mapping.end())
|
|
||||||
st->setSymbol(*(new SgSymbol(CONST_NAME, it->second.c_str())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void mergeCopyArrays(vector<ParallelRegion *> ®ions, const map<string, vector<FuncInfo *>> &allFuncInfo)
|
|
||||||
{
|
|
||||||
for (const auto *region : regions)
|
|
||||||
{
|
|
||||||
__spf_print(1, "region %s\n", region->GetName().c_str());
|
|
||||||
|
|
||||||
const auto &dirs = region->GetDataDir();
|
|
||||||
|
|
||||||
__spf_print(1, " distr rules: %d\n", dirs.distrRules.size());
|
|
||||||
|
|
||||||
const auto ¤tVariant = region->GetCurrentVariant();
|
|
||||||
|
|
||||||
int distr_idx = 0;
|
|
||||||
for (const auto &distr : dirs.distrRules)
|
|
||||||
{
|
|
||||||
const auto &dist_rule = distr.second.back().distRule;
|
|
||||||
|
|
||||||
string sizes;
|
|
||||||
for (const auto &p : distr.first->GetSizes())
|
|
||||||
{
|
|
||||||
if (!sizes.empty())
|
|
||||||
sizes.push_back(',');
|
|
||||||
|
|
||||||
sizes += std::to_string(p.first) + ":" + std::to_string(p.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, " DIST %s(%s)", distr.first->GetName().c_str(), sizes.c_str());
|
|
||||||
for (const auto &dim : dist_rule)
|
|
||||||
__spf_print(1, " %c", dim == dist::BLOCK ? 'B' : '*');
|
|
||||||
|
|
||||||
__spf_print(1, "\n");
|
|
||||||
distr_idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, " align rules: %d\n", dirs.alignRules.size());
|
|
||||||
|
|
||||||
for (const auto &align : dirs.alignRules)
|
|
||||||
{
|
|
||||||
string sub_a, sub_b;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (const auto coefs : align.alignRule)
|
|
||||||
{
|
|
||||||
if (!sub_a.empty())
|
|
||||||
sub_a.push_back(',');
|
|
||||||
|
|
||||||
sub_a += std::to_string(coefs.first) + "*i" +
|
|
||||||
std::to_string(i) + "+" + std::to_string(coefs.second);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto coefs : align.alignRuleWith)
|
|
||||||
{
|
|
||||||
if (!sub_b.empty())
|
|
||||||
sub_b.push_back(',');
|
|
||||||
|
|
||||||
sub_b += std::to_string(coefs.second.first) + "*i" +
|
|
||||||
std::to_string(coefs.first) + "+" + std::to_string(coefs.second.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, " ALIGN %s(%s) WITH %s(%s)\n",
|
|
||||||
align.alignArray->GetName().c_str(), sub_a.c_str(),
|
|
||||||
align.alignWith->GetName().c_str(), sub_b.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse directives
|
|
||||||
|
|
||||||
// new array name -> current arrays
|
|
||||||
unordered_map<string, unordered_set<DIST::Array *>> arrays_to_merge;
|
|
||||||
unordered_map<DIST::Array *, unordered_set<const AlignRule *>> array_alignment;
|
|
||||||
|
|
||||||
for (const auto &by_file : allFuncInfo)
|
|
||||||
{
|
|
||||||
const auto current_file_name = by_file.first;
|
|
||||||
|
|
||||||
if (SgFile::switchToFile(current_file_name) == -1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
for (auto *func_info : by_file.second)
|
|
||||||
{
|
|
||||||
SgStatement *curr_stmt = func_info->funcPointer;
|
|
||||||
if (!curr_stmt)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto *stmt_end = curr_stmt->lastDeclaration();
|
|
||||||
if (!stmt_end)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
stmt_end = stmt_end->lexNext();
|
|
||||||
|
|
||||||
for (; curr_stmt && curr_stmt != stmt_end; curr_stmt = curr_stmt->lexNext())
|
|
||||||
{
|
|
||||||
if (curr_stmt->comments())
|
|
||||||
{
|
|
||||||
vector<pair<string, string>> parsed_mapping;
|
|
||||||
parseMergeDirective(curr_stmt->comments(), parsed_mapping);
|
|
||||||
|
|
||||||
for (const auto &p : parsed_mapping)
|
|
||||||
{
|
|
||||||
auto *found_array = getArrayFromDeclarated(curr_stmt, p.first);
|
|
||||||
if (found_array)
|
|
||||||
{
|
|
||||||
arrays_to_merge[p.second].insert(found_array);
|
|
||||||
array_alignment[found_array] = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// find alignment rules for array
|
|
||||||
|
|
||||||
for (const auto *region : regions)
|
|
||||||
{
|
|
||||||
const auto &dirs = region->GetDataDir();
|
|
||||||
|
|
||||||
for (const auto &align : dirs.alignRules)
|
|
||||||
{
|
|
||||||
auto it = array_alignment.find(align.alignArray);
|
|
||||||
|
|
||||||
if (it != array_alignment.end())
|
|
||||||
it->second.insert(&align);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// old region -> new region
|
|
||||||
unordered_map<string, string> new_region_mapping;
|
|
||||||
|
|
||||||
// new array -> new region
|
|
||||||
unordered_map<string, string> arrays_new_region_mapping;
|
|
||||||
vector<string> created_region_names;
|
|
||||||
|
|
||||||
for (const auto &by_new_array : arrays_to_merge)
|
|
||||||
{
|
|
||||||
string new_region_name;
|
|
||||||
for (auto *current_array : by_new_array.second)
|
|
||||||
{
|
|
||||||
auto current_array_region = getNonDefaultRegion(current_array);
|
|
||||||
auto it = new_region_mapping.find(current_array_region);
|
|
||||||
if (it != new_region_mapping.end())
|
|
||||||
{
|
|
||||||
if (new_region_name.empty())
|
|
||||||
new_region_name = it->second;
|
|
||||||
else if (new_region_name != it->second)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_region_name.empty())
|
|
||||||
{
|
|
||||||
new_region_name = "merged_reg_" + std::to_string(created_region_names.size());
|
|
||||||
created_region_names.push_back(new_region_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto *current_array : by_new_array.second)
|
|
||||||
{
|
|
||||||
auto current_array_region = getNonDefaultRegion(current_array);
|
|
||||||
new_region_mapping[current_array_region] = new_region_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
arrays_new_region_mapping[by_new_array.first] = new_region_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!checkSimilarTemplates(regions, new_region_mapping))
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> inserted_arrays;
|
|
||||||
|
|
||||||
for (const auto &by_dest_array : arrays_to_merge)
|
|
||||||
{
|
|
||||||
const auto ©_arrays = by_dest_array.second;
|
|
||||||
|
|
||||||
if (copy_arrays.empty())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
auto *first_element = *copy_arrays.begin();
|
|
||||||
auto first_elem_rules_it = array_alignment.find(first_element);
|
|
||||||
|
|
||||||
if (first_elem_rules_it == array_alignment.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const auto &first_elem_rules = first_elem_rules_it->second;
|
|
||||||
|
|
||||||
for (auto *array_to_merge : copy_arrays)
|
|
||||||
{
|
|
||||||
auto array_rules_it = array_alignment.find(array_to_merge);
|
|
||||||
|
|
||||||
if (array_rules_it == array_alignment.end())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
const auto &array_rules = array_rules_it->second;
|
|
||||||
|
|
||||||
if (!hasSameSizes(array_to_merge, first_element) || !hasSameAlignment(first_elem_rules, array_rules))
|
|
||||||
{
|
|
||||||
__spf_print(1, "Arrays %s and %s has different sizes or align rules\n",
|
|
||||||
array_to_merge->GetName().c_str(),
|
|
||||||
first_element->GetName().c_str());
|
|
||||||
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__spf_print(1, "merge into %s (%s):\n", by_dest_array.first.c_str(), arrays_new_region_mapping[by_dest_array.first].c_str());
|
|
||||||
for (auto *array_to_merge : copy_arrays)
|
|
||||||
__spf_print(1, "%s\n", array_to_merge->GetName().c_str());
|
|
||||||
|
|
||||||
auto created_array_info = createNewArray(first_element, by_dest_array.first, allFuncInfo, inserted_arrays);
|
|
||||||
|
|
||||||
unordered_set<string> arrays_to_replace;
|
|
||||||
for (auto *array_to_merge : copy_arrays)
|
|
||||||
arrays_to_replace.insert(array_to_merge->GetShortName());
|
|
||||||
|
|
||||||
for (const auto &by_file : allFuncInfo)
|
|
||||||
{
|
|
||||||
if (SgFile::switchToFile(by_file.first) == -1)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
for (auto *func_info : by_file.second)
|
|
||||||
{
|
|
||||||
SgSymbol *func_symbol_hint = nullptr;
|
|
||||||
SgStatement *st = func_info->funcPointer;
|
|
||||||
|
|
||||||
auto *func_end = st->lastNodeOfStmt();
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st && !isSgExecutableStatement(st) && st != func_end)
|
|
||||||
st = st->lexNext();
|
|
||||||
|
|
||||||
while (st && st != func_end)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
replaceArrayRec(
|
|
||||||
st->expr(i),
|
|
||||||
arrays_to_replace,
|
|
||||||
&func_symbol_hint,
|
|
||||||
created_array_info,
|
|
||||||
first_element,
|
|
||||||
func_info,
|
|
||||||
inserted_arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceRegion(st, new_region_mapping);
|
|
||||||
|
|
||||||
st = st->lexNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include "../GraphCall/graph_calls.h"
|
|
||||||
#include "ParRegions.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
void mergeCopyArrays(std::vector<ParallelRegion*> ®ions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
|
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "expr_transform.h"
|
#include "expr_transform.h"
|
||||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "CFGraph/CFGraph.h"
|
||||||
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
@@ -36,6 +37,109 @@ using std::tuple;
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
void runPredictSchemeOld(SgProject &project,
|
||||||
|
vector<vector<size_t>> &topologies,
|
||||||
|
vector<ParallelRegion*> ¶llelRegions,
|
||||||
|
map<string, vector<LoopGraph*>> &loopGraph,
|
||||||
|
map<string, vector<SpfInterval*>> &intervals,
|
||||||
|
map<string, vector<Messages>> &SPF_messages)
|
||||||
|
{
|
||||||
|
int maxSizeDist = 0;
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||||
|
{
|
||||||
|
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
||||||
|
|
||||||
|
auto &tmp = dataDirectives.distrRules;
|
||||||
|
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
||||||
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
||||||
|
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
||||||
|
|
||||||
|
for (auto &elem : currentVar)
|
||||||
|
{
|
||||||
|
DIST::Array *array = elem.first;
|
||||||
|
const DistrVariant *var = elem.second;
|
||||||
|
|
||||||
|
int countBlock = 0;
|
||||||
|
for (int z = 0; z < var->distRule.size(); ++z)
|
||||||
|
if (var->distRule[z] == dist::BLOCK)
|
||||||
|
++countBlock;
|
||||||
|
maxSizeDist = std::max(maxSizeDist, countBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SpfInterval *mainIterval = getMainInterval(&project, intervals, SPF_messages);
|
||||||
|
topologies.clear();
|
||||||
|
if (maxSizeDist)
|
||||||
|
{
|
||||||
|
const int procNum = 8;
|
||||||
|
//TODO:
|
||||||
|
//topologies = getTopologies(procNum, maxSizeDist);
|
||||||
|
throw -10;
|
||||||
|
|
||||||
|
const int countOfTop = topologies.size();
|
||||||
|
if (countOfTop < 0)
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
for (auto &inter : intervals)
|
||||||
|
initTimeForIntervalTree(countOfTop, inter.second);
|
||||||
|
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z)
|
||||||
|
{
|
||||||
|
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
||||||
|
DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArraysToModify();
|
||||||
|
|
||||||
|
auto &tmp = dataDirectives.distrRules;
|
||||||
|
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
||||||
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
||||||
|
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
||||||
|
|
||||||
|
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
||||||
|
vector<std::tuple<DIST::Array*, vector<long>, pair<string, int>>> allSingleRemotes;
|
||||||
|
for (int i = project.numberOfFiles() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
SgFile *file = &(project.file(i));
|
||||||
|
auto fountInfo = findAllDirectives(file, getObjectForFileFromMap(file->filename(), loopGraph), parallelRegions[z]->GetId());
|
||||||
|
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
||||||
|
|
||||||
|
auto fountRem = findAllSingleRemotes(file, parallelRegions[z]->GetId(), parallelRegions);
|
||||||
|
allSingleRemotes.insert(allSingleRemotes.end(), fountRem.begin(), fountRem.end());
|
||||||
|
}
|
||||||
|
//TODO!
|
||||||
|
//int err = predictScheme(parallelRegions[z], currentVar, allArrays.GetArrays(), parallelDirs, intervals, SPF_messages, allSingleRemotes, maxSizeDist, procNum);
|
||||||
|
/*if (err != 0)
|
||||||
|
internalExit = err;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<SpfInterval*> tmp = { mainIterval };
|
||||||
|
aggregatePredictedTimes(tmp);
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
int best = -1;
|
||||||
|
double bestSpeedUp = 0;
|
||||||
|
for (auto &top : topologies)
|
||||||
|
{
|
||||||
|
string outStr = "";
|
||||||
|
for (auto &elem : top)
|
||||||
|
outStr += std::to_string(elem) + " ";
|
||||||
|
double currS = mainIterval->exec_time / mainIterval->predictedTimes[idx];
|
||||||
|
__spf_print(1, "%d: speed up %f for top. %s\n", idx, currS, outStr.c_str());
|
||||||
|
|
||||||
|
if (best == -1 || bestSpeedUp < currS)
|
||||||
|
{
|
||||||
|
bestSpeedUp = currS;
|
||||||
|
best = idx;
|
||||||
|
}
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
__spf_print(1, "best topology %d with speed up %f\n", best, bestSpeedUp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (auto &inter : intervals)
|
||||||
|
initTimeForIntervalTree(0, inter.second);
|
||||||
|
}
|
||||||
|
|
||||||
static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm)
|
static void fillParallel(SgExpression *exp, ParallelStats &parStats, int &totalScoreComm)
|
||||||
{
|
{
|
||||||
if (exp)
|
if (exp)
|
||||||
|
|||||||
@@ -60,4 +60,6 @@ public:
|
|||||||
void processFileToPredict(SgFile *file, PredictorStats &predictorCounts);
|
void processFileToPredict(SgFile *file, PredictorStats &predictorCounts);
|
||||||
|
|
||||||
void calculateStatsForPredictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
|
void calculateStatsForPredictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
|
||||||
void parseDvmDirForPredictor(const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays, const std::map<std::string, CommonBlock*>& commonBlocks, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
|
void parseDvmDirForPredictor(const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays, const std::map<std::string, CommonBlock*>& commonBlocks, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
|
||||||
|
|
||||||
|
void runPredictSchemeOld(SgProject &project, std::vector<std::vector<size_t>> &topologies, std::vector<ParallelRegion*> ¶llelRegions, std::map<std::string, std::vector<LoopGraph*>> &loopGraph, std::map<std::string, std::vector<SpfInterval*>> &intervals, std::map<std::string, std::vector<Messages>> &SPF_messages);
|
||||||
|
|||||||
439
src/Predictor/PredictSchemeWithLibrary.cpp
Normal file
439
src/Predictor/PredictSchemeWithLibrary.cpp
Normal file
@@ -0,0 +1,439 @@
|
|||||||
|
#include "leak_detector.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#include "dvm.h"
|
||||||
|
#include "PredictSchemeWithLibrary.h"
|
||||||
|
#include "../../projects/libpredictor/include/libpredict/predictor.h"
|
||||||
|
#include "../DirectiveProcessing/directive_parser.h"
|
||||||
|
#include "../Distribution/DvmhDirective.h"
|
||||||
|
#include "../ParallelizationRegions/ParRegions.h"
|
||||||
|
#include "../GraphLoop/graph_loops_func.h"
|
||||||
|
#include "../Utils/errors.h"
|
||||||
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
|
using std::map;
|
||||||
|
using std::pair;
|
||||||
|
using std::string;
|
||||||
|
using std::tuple;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
|
map<size_t, size_t> createTemplateIdMapping(const vector<ParallelRegion*>& parallelRegions)
|
||||||
|
{
|
||||||
|
size_t maxArrayId = 0;
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
|
||||||
|
for (const auto& distrRule : dataDirectives.distrRules) {
|
||||||
|
if (distrRule.first && !distrRule.first->IsTemplate()) {
|
||||||
|
maxArrayId = std::max(maxArrayId, (size_t)distrRule.first->GetId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& alignRule : dataDirectives.alignRules) {
|
||||||
|
if (alignRule.alignArray && !alignRule.alignArray->IsTemplate()) {
|
||||||
|
maxArrayId = std::max(maxArrayId, (size_t)alignRule.alignArray->GetId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
map<size_t, size_t> templateIdMapping;
|
||||||
|
size_t nextTemplateId = maxArrayId + 1;
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
|
||||||
|
for (const auto& distrRule : dataDirectives.distrRules) {
|
||||||
|
if (distrRule.first && distrRule.first->IsTemplate()) {
|
||||||
|
size_t originalId = distrRule.first->GetId();
|
||||||
|
if (templateIdMapping.find(originalId) == templateIdMapping.end()) {
|
||||||
|
templateIdMapping[originalId] = nextTemplateId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& alignRule : dataDirectives.alignRules) {
|
||||||
|
if (alignRule.alignWith && alignRule.alignWith->IsTemplate()) {
|
||||||
|
size_t originalId = alignRule.alignWith->GetId();
|
||||||
|
if (templateIdMapping.find(originalId) == templateIdMapping.end()) {
|
||||||
|
templateIdMapping[originalId] = nextTemplateId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return templateIdMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrecomputedLibpredictParams precomputeLibpredictParams(
|
||||||
|
SgProject& project,
|
||||||
|
const vector<ParallelRegion*>& parallelRegions,
|
||||||
|
const map<string, vector<LoopGraph*>>& loopGraph,
|
||||||
|
const map<size_t, size_t>& templateIdMapping)
|
||||||
|
{
|
||||||
|
PrecomputedLibpredictParams result;
|
||||||
|
|
||||||
|
// distribute and align from parallelRegions
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
|
||||||
|
const DIST::Arrays<int>& allArrays = parallelRegions[z]->GetAllArrays();
|
||||||
|
|
||||||
|
auto& tmp = dataDirectives.distrRules;
|
||||||
|
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
||||||
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
|
||||||
|
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// distribute
|
||||||
|
for (const auto& distrRule : currentVar) {
|
||||||
|
DIST::Array* array = distrRule.first;
|
||||||
|
const DistrVariant* variant = distrRule.second;
|
||||||
|
|
||||||
|
if (array && variant && !array->IsNotDistribute()) {
|
||||||
|
PrecomputedDistributeParams params;
|
||||||
|
|
||||||
|
size_t originalId = array->GetId();
|
||||||
|
params.arrayId = originalId;
|
||||||
|
|
||||||
|
if (array->IsTemplate()) {
|
||||||
|
auto it = templateIdMapping.find(originalId);
|
||||||
|
if (it != templateIdMapping.end()) {
|
||||||
|
params.arrayId = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params.elemSize = array->GetTypeSize();
|
||||||
|
params.array = array;
|
||||||
|
|
||||||
|
const auto& arraySizes = array->GetSizes();
|
||||||
|
for (int dim = 0; dim < array->GetDimSize(); ++dim) {
|
||||||
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
||||||
|
|
||||||
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
||||||
|
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::BLOCK);
|
||||||
|
} else {
|
||||||
|
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::NONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& shadowSpec = array->GetShadowSpec();
|
||||||
|
for (int dim = 0; dim < shadowSpec.size() && dim < array->GetDimSize(); ++dim) {
|
||||||
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
||||||
|
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.distributeParams.push_back(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// align
|
||||||
|
for (const auto& alignRule : dataDirectives.alignRules) {
|
||||||
|
DIST::Array* alignArray = alignRule.alignArray;
|
||||||
|
DIST::Array* alignWithArray = alignRule.alignWith;
|
||||||
|
|
||||||
|
if (alignArray && alignWithArray && !alignArray->IsNotDistribute()) {
|
||||||
|
PrecomputedAlignParams params;
|
||||||
|
|
||||||
|
params.arrayId = alignArray->GetId();
|
||||||
|
size_t originalDistributedArrayId = alignWithArray->GetId();
|
||||||
|
params.distributedArrayId = originalDistributedArrayId;
|
||||||
|
|
||||||
|
if (alignWithArray->IsTemplate()) {
|
||||||
|
auto it = templateIdMapping.find(originalDistributedArrayId);
|
||||||
|
if (it != templateIdMapping.end()) {
|
||||||
|
params.distributedArrayId = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params.elemSize = alignArray->GetTypeSize();
|
||||||
|
params.alignArray = alignArray;
|
||||||
|
params.alignWithArray = alignWithArray;
|
||||||
|
|
||||||
|
const auto& arraySizes = alignArray->GetSizes();
|
||||||
|
for (int dim = 0; dim < alignArray->GetDimSize(); ++dim) {
|
||||||
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
||||||
|
params.dimensions.push_back(dimSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int dim = 0; dim < alignWithArray->GetDimSize(); ++dim) {
|
||||||
|
bool found = false;
|
||||||
|
for (int i = 0; i < alignRule.alignRuleWith.size(); ++i) {
|
||||||
|
const auto& ruleWith = alignRule.alignRuleWith[i];
|
||||||
|
if (ruleWith.first == dim) {
|
||||||
|
const auto& rule = ruleWith.second;
|
||||||
|
if (rule.first == 0) {
|
||||||
|
// constant
|
||||||
|
params.distributionExpressions.emplace_back(rule.second);
|
||||||
|
} else {
|
||||||
|
// linear expression a * I + b
|
||||||
|
params.distributionExpressions.emplace_back(i, rule.first, rule.second);
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
// There is no rule for this measurement
|
||||||
|
params.distributionExpressions.emplace_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& shadowSpec = alignArray->GetShadowSpec();
|
||||||
|
for (int dim = 0; dim < shadowSpec.size() && dim < alignArray->GetDimSize(); ++dim) {
|
||||||
|
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.alignParams.push_back(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow_renew
|
||||||
|
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
||||||
|
for (int i = project.numberOfFiles() - 1; i >= 0; --i) {
|
||||||
|
SgFile* file = &(project.file(i));
|
||||||
|
auto fountInfo = findAllDirectives(
|
||||||
|
file,
|
||||||
|
getObjectForFileFromMap(file->filename(), const_cast<map<string, vector<LoopGraph*>>&>(loopGraph)),
|
||||||
|
parallelRegions[z]->GetId());
|
||||||
|
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& dirPair : parallelDirs) {
|
||||||
|
LoopGraph* loopPtr = dirPair.first;
|
||||||
|
ParallelDirective* directive = dirPair.second;
|
||||||
|
|
||||||
|
if (directive && !directive->shadowRenew.empty()) {
|
||||||
|
for (size_t shadowIdx = 0; shadowIdx < directive->shadowRenew.size(); ++shadowIdx) {
|
||||||
|
const auto& shadowRenewItem = directive->shadowRenew[shadowIdx];
|
||||||
|
const string& arrayName = shadowRenewItem.first.second; // uniqName
|
||||||
|
const vector<pair<int, int>>& bounds = shadowRenewItem.second;
|
||||||
|
|
||||||
|
DIST::Array* shadowArray = allArrays.GetArrayByName(arrayName);
|
||||||
|
if (shadowArray == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shadowArray && !shadowArray->IsNotDistribute()) {
|
||||||
|
PrecomputedShadowRenewParams params;
|
||||||
|
|
||||||
|
params.arrayId = shadowArray->GetId();
|
||||||
|
params.shadowArray = shadowArray;
|
||||||
|
|
||||||
|
for (const auto& bound : bounds) {
|
||||||
|
params.shadow_renew.emplace_back(static_cast<size_t>(bound.first),
|
||||||
|
static_cast<size_t>(bound.second));
|
||||||
|
}
|
||||||
|
|
||||||
|
params.corner = directive->shadowRenewCorner[shadowIdx];
|
||||||
|
params.number_loop_iterations = loopPtr ? static_cast<size_t>(loopPtr->countOfIters) : 1;
|
||||||
|
|
||||||
|
result.shadowRenewParams.push_back(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
double runLibpredictCalc(const vector<size_t>& topology,
|
||||||
|
const string& clusterConfStr,
|
||||||
|
const PrecomputedLibpredictParams& precomputedParams,
|
||||||
|
map<string, vector<Messages>>& SPF_messages)
|
||||||
|
{
|
||||||
|
libpredict::RetInitGrid retInitGrid = libpredict::InitGrid(topology[0], topology[1], topology[2], topology[3]);
|
||||||
|
|
||||||
|
if (retInitGrid != libpredict::INIT_GRID_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to initialize libpredict grid with topology: %zu %zu %zu %zu, return code: %d\n",
|
||||||
|
topology[0], topology[1], topology[2], topology[3], (int)retInitGrid);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict grid with topology: %zu %zu %zu %zu, return code: %d",
|
||||||
|
topology[0], topology[1], topology[2], topology[3], (int)retInitGrid);
|
||||||
|
__spf_printToLongBuf(messageR, R207);
|
||||||
|
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1064));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// distribute
|
||||||
|
for (const auto& params : precomputedParams.distributeParams) {
|
||||||
|
libpredict::RetDistribute retDistribute = libpredict::Distribute(
|
||||||
|
params.arrayId, params.elemSize, params.axisDistributions, params.shadowEdges);
|
||||||
|
|
||||||
|
if (retDistribute != libpredict::DISTRIBUTE_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to distribute array '%s' (id=%zu) with libpredict, return code: %d\n",
|
||||||
|
params.array->GetShortName().c_str(), params.arrayId, (int)retDistribute);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to distribute array '%s' with libpredict, return code: %d",
|
||||||
|
to_wstring(params.array->GetShortName()).c_str(), (int)retDistribute);
|
||||||
|
__spf_printToLongBuf(messageR, R208);
|
||||||
|
getObjectForFileFromMap(params.array->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.array->GetDeclInfo().begin()->second, messageR, messageE, 1065));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// align
|
||||||
|
for (const auto& params : precomputedParams.alignParams) {
|
||||||
|
libpredict::RetAlign retAlign = libpredict::Align(
|
||||||
|
params.arrayId, params.distributedArrayId, params.elemSize,
|
||||||
|
params.dimensions, params.distributionExpressions, params.shadowEdges);
|
||||||
|
|
||||||
|
if (retAlign != libpredict::ALIGN_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to align array '%s' (id=%zu) with array '%s' (id=%zu), return code: %d\n",
|
||||||
|
params.alignArray->GetShortName().c_str(), params.arrayId,
|
||||||
|
params.alignWithArray->GetShortName().c_str(), params.distributedArrayId, (int)retAlign);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to align array '%s' with array '%s' using libpredict, return code: %d",
|
||||||
|
to_wstring(params.alignArray->GetShortName()).c_str(),
|
||||||
|
to_wstring(params.alignWithArray->GetShortName()).c_str(), (int)retAlign);
|
||||||
|
__spf_printToLongBuf(messageR, R209);
|
||||||
|
getObjectForFileFromMap(params.alignArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.alignArray->GetDeclInfo().begin()->second, messageR, messageE, 1066));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow_renew
|
||||||
|
for (const auto& params : precomputedParams.shadowRenewParams) {
|
||||||
|
libpredict::RetShadowRenew retShadowRenew = libpredict::ShadowRenew(
|
||||||
|
params.arrayId, params.shadow_renew, params.corner, params.number_loop_iterations);
|
||||||
|
|
||||||
|
if (retShadowRenew != libpredict::SHADOW_RENEW_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to process shadow_renew for array '%s' (id=%zu), return code: %d\n",
|
||||||
|
params.shadowArray->GetShortName().c_str(), params.arrayId, (int)retShadowRenew);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to process shadow_renew for array '%s' with libpredict, return code: %d",
|
||||||
|
to_wstring(params.shadowArray->GetShortName()).c_str(), (int)retShadowRenew);
|
||||||
|
__spf_printToLongBuf(messageR, R210);
|
||||||
|
getObjectForFileFromMap(params.shadowArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.shadowArray->GetDeclInfo().begin()->second, messageR, messageE, 1067));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return libpredict::GetTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void runPredictScheme(SgProject& project,
|
||||||
|
vector<vector<size_t>>& topologies,
|
||||||
|
const vector<ParallelRegion*>& parallelRegions,
|
||||||
|
map<string, vector<LoopGraph*>>& loopGraph,
|
||||||
|
map<string, vector<Messages>>& SPF_messages)
|
||||||
|
{
|
||||||
|
// calculating maximum dimension of distribution
|
||||||
|
int maxSizeDist = 0;
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
|
||||||
|
|
||||||
|
auto& tmp = dataDirectives.distrRules;
|
||||||
|
vector<const DistrVariant*> currentVar;
|
||||||
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
|
||||||
|
currentVar.push_back(&tmp[z1].second[currentVariant[z1]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto var : currentVar) {
|
||||||
|
int countBlock = 0;
|
||||||
|
for (int z = 0; z < var->distRule.size(); ++z) {
|
||||||
|
if (var->distRule[z] == dist::BLOCK) {
|
||||||
|
++countBlock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxSizeDist = std::max(maxSizeDist, countBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculating name of a cluster configuration file
|
||||||
|
string clusterConfStr;
|
||||||
|
if (project.numberOfFiles() > 0) {
|
||||||
|
string firstFilePath = project.fileName(0);
|
||||||
|
|
||||||
|
size_t lastSlash = firstFilePath.find_last_of("/\\");
|
||||||
|
clusterConfStr = firstFilePath.substr(0, lastSlash + 1) + "cluster.conf";
|
||||||
|
}
|
||||||
|
|
||||||
|
// creating template ID display to avoid conflicts
|
||||||
|
map<size_t, size_t> templateIdMapping = createTemplateIdMapping(parallelRegions);
|
||||||
|
|
||||||
|
// Precomputing parameters of directive functions from libpredict
|
||||||
|
PrecomputedLibpredictParams precomputedParams = precomputeLibpredictParams(
|
||||||
|
project, parallelRegions, loopGraph, templateIdMapping);
|
||||||
|
|
||||||
|
// iterating through topologies to find most optimal one
|
||||||
|
topologies = vector<vector<size_t>>();
|
||||||
|
if (maxSizeDist) {
|
||||||
|
if (maxSizeDist > 4) {
|
||||||
|
maxSizeDist = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize cluster
|
||||||
|
int procCount = 0;
|
||||||
|
libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr, procCount);
|
||||||
|
|
||||||
|
if (retInitCluster != libpredict::INIT_CLUSTER_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to initialize libpredict cluster with config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInitCluster);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict cluster with config: %s, return code: %d",
|
||||||
|
to_wstring(clusterConfStr).c_str(), (int)retInitCluster);
|
||||||
|
__spf_printToLongBuf(messageR, R206);
|
||||||
|
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1063));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t n1 = 2; n1 <= procCount; ++n1) {
|
||||||
|
for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) {
|
||||||
|
if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t n3 = 1; n3 <= n2 && n1 * n2 * n3 <= procCount; ++n3) {
|
||||||
|
if (n3 != 1 && maxSizeDist < 3 || n3 == 1 && maxSizeDist == 3) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t n4 = 1; n4 <= n3 && n1 * n2 * n3 * n4 <= procCount; ++n4) {
|
||||||
|
if (n4 != 1 && maxSizeDist < 4 || n4 == 1 && maxSizeDist == 4) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
topologies.push_back(vector<size_t>{n1, n2, n3, n4});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<size_t> best;
|
||||||
|
double bestTime = std::numeric_limits<double>::max();
|
||||||
|
for (auto& topology : topologies) {
|
||||||
|
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
|
||||||
|
|
||||||
|
string outStr = "";
|
||||||
|
for (const auto& elem : topology) {
|
||||||
|
outStr += std::to_string(elem) + " ";
|
||||||
|
}
|
||||||
|
__spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
|
||||||
|
|
||||||
|
if (currTime == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currTime < bestTime) {
|
||||||
|
bestTime = currTime;
|
||||||
|
best = topology;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string outStr;
|
||||||
|
for (const auto& elem : best) {
|
||||||
|
outStr += std::to_string(elem) + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
__spf_print(1, "best topology %s with time %f\n", outStr.c_str(), bestTime);
|
||||||
|
} else {
|
||||||
|
__spf_print(1, "impossible to calculate best topology: project does not contain distribution directives\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
57
src/Predictor/PredictSchemeWithLibrary.h
Normal file
57
src/Predictor/PredictSchemeWithLibrary.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include "dvm.h"
|
||||||
|
#include "graph_calls.h"
|
||||||
|
#include "../../projects/libpredictor/include/libpredict/predictor.h"
|
||||||
|
|
||||||
|
struct PrecomputedDistributeParams {
|
||||||
|
size_t arrayId;
|
||||||
|
size_t elemSize;
|
||||||
|
std::vector<libpredict::DistributeAxisRule> axisDistributions;
|
||||||
|
std::vector<std::pair<size_t, size_t>> shadowEdges;
|
||||||
|
DIST::Array* array;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrecomputedAlignParams {
|
||||||
|
size_t arrayId;
|
||||||
|
size_t distributedArrayId;
|
||||||
|
size_t elemSize;
|
||||||
|
std::vector<size_t> dimensions;
|
||||||
|
std::vector<libpredict::AlignDisplay> distributionExpressions;
|
||||||
|
std::vector<std::pair<size_t, size_t>> shadowEdges;
|
||||||
|
DIST::Array* alignArray;
|
||||||
|
DIST::Array* alignWithArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrecomputedShadowRenewParams {
|
||||||
|
size_t arrayId;
|
||||||
|
std::vector<std::pair<size_t, size_t>> shadow_renew;
|
||||||
|
bool corner;
|
||||||
|
size_t number_loop_iterations;
|
||||||
|
DIST::Array* shadowArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrecomputedLibpredictParams {
|
||||||
|
std::vector<PrecomputedDistributeParams> distributeParams;
|
||||||
|
std::vector<PrecomputedAlignParams> alignParams;
|
||||||
|
std::vector<PrecomputedShadowRenewParams> shadowRenewParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
PrecomputedLibpredictParams precomputeLibpredictParams(
|
||||||
|
SgProject& project,
|
||||||
|
const std::vector<ParallelRegion*>& parallelRegions,
|
||||||
|
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
|
||||||
|
const std::map<size_t, size_t>& templateIdMapping);
|
||||||
|
|
||||||
|
void runPredictScheme(SgProject& project,
|
||||||
|
std::vector<std::vector<size_t>>& topologies,
|
||||||
|
const std::vector<ParallelRegion*>& parallelRegions,
|
||||||
|
std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
|
||||||
|
std::map<std::string, std::vector<Messages>>& SPF_messages);
|
||||||
|
|
||||||
|
double runLibpredictCalc(const std::vector<size_t>& topology,
|
||||||
|
const std::string& clusterConfStr,
|
||||||
|
const PrecomputedLibpredictParams& precomputedParams,
|
||||||
|
std::map<std::string, std::vector<Messages>>& SPF_messages);
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
#include "SgUtils.h"
|
#include "SgUtils.h"
|
||||||
#include "graph_loops.h"
|
#include "graph_loops.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "CFGraph/CFGraph.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -122,95 +121,21 @@ static void SolveDataFlow(Region* DFG)
|
|||||||
Collapse(DFG);
|
Collapse(DFG);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long CalculateLength(const AccessingSet& array)
|
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
{
|
{
|
||||||
if (array.GetElements().empty())
|
map<LoopGraph*, ArrayAccessingIndexes> result;
|
||||||
return 0;
|
for (const auto& [loopName, loops] : loopGraph)
|
||||||
unsigned long long result = 1;
|
|
||||||
for (const auto& range : array.GetElements())
|
|
||||||
{
|
{
|
||||||
for (const auto& dim : range)
|
for (const auto& loop : loops)
|
||||||
{
|
{
|
||||||
result *= (dim.step * dim.tripCount);
|
for (const auto& [funcInfo, blocks]: FullIR)
|
||||||
|
{
|
||||||
|
Region* loopRegion = new Region(loop, blocks);
|
||||||
|
SolveDataFlow(loopRegion);
|
||||||
|
result[loop] = loopRegion->array_priv;
|
||||||
|
delete(loopRegion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
|
|
||||||
{
|
|
||||||
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
|
||||||
spfStat->setlineNumber(loop->loop->lineNumber());
|
|
||||||
spfStat->setFileName(loop->loop->fileName());
|
|
||||||
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
|
|
||||||
set<SgSymbol*> arraysToInsert;
|
|
||||||
for (const auto& [_, accessingSet] : privates)
|
|
||||||
{
|
|
||||||
for (const auto& arrayElement : accessingSet.GetElements())
|
|
||||||
{
|
|
||||||
if (arrayElement.empty())
|
|
||||||
continue;
|
|
||||||
arraysToInsert.insert(arrayElement[0].array->symbol());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spfStat->setExpression(0, *toAdd);
|
|
||||||
toAdd = toAdd->lhs();
|
|
||||||
bool first = true;
|
|
||||||
for (auto& elem : arraysToInsert)
|
|
||||||
{
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
toAdd->setLhs(new SgExpression(EXPR_LIST));
|
|
||||||
toAdd = toAdd->lhs();
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
toAdd->setRhs(new SgExpression(EXPR_LIST));
|
|
||||||
toAdd = toAdd->rhs();
|
|
||||||
}
|
|
||||||
toAdd->setLhs(new SgVarRefExp(elem));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arraysToInsert.size() == 0)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
loop->loop->insertStmtBefore(*spfStat, *loop->loop->controlParent());
|
|
||||||
insertedPrivates.insert(spfStat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR, set<SgStatement*> &insertedPrivates)
|
|
||||||
{
|
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
|
||||||
for (const auto& [fileName, loops] : loopGraph)
|
|
||||||
{
|
|
||||||
SgFile::switchToFile(fileName);
|
|
||||||
for (const auto& loop : loops)
|
|
||||||
{
|
|
||||||
SgStatement* search_func = loop->loop->GetOriginal();
|
|
||||||
|
|
||||||
while (search_func && (!isSgProgHedrStmt(search_func)))
|
|
||||||
search_func = search_func->controlParent();
|
|
||||||
|
|
||||||
for (const auto& [funcInfo, blocks]: FullIR)
|
|
||||||
{
|
|
||||||
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
|
||||||
{
|
|
||||||
Region* loopRegion = new Region(loop, blocks);
|
|
||||||
if (loopRegion->getBasickBlocks().size() <= 1)
|
|
||||||
{
|
|
||||||
delete(loopRegion);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SolveDataFlow(loopRegion);
|
|
||||||
result[loop] = loopRegion->array_priv;
|
|
||||||
delete(loopRegion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.find(loop) != result.end() && !result[loop].empty())
|
|
||||||
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "range_structures.h"
|
#include "range_structures.h"
|
||||||
#include "graph_loops.h"
|
#include "graph_loops.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "CFGraph/CFGraph.h"
|
||||||
|
|
||||||
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates);
|
std::map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
|
||||||
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);
|
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
|
|||||||
|
|
||||||
uint64_t start3 = dim1.start + x0 * dim1.step;
|
uint64_t start3 = dim1.start + x0 * dim1.step;
|
||||||
uint64_t step3 = c * dim1.step;
|
uint64_t step3 = c * dim1.step;
|
||||||
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 , dim1.array};
|
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
|||||||
vector<ArrayDimension> result;
|
vector<ArrayDimension> result;
|
||||||
/* add the part before intersection */
|
/* add the part before intersection */
|
||||||
if (dim1.start < intersection->start)
|
if (dim1.start < intersection->start)
|
||||||
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step, dim1.array});
|
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step });
|
||||||
|
|
||||||
/* add the parts between intersection steps */
|
/* add the parts between intersection steps */
|
||||||
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
||||||
@@ -73,7 +73,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
|||||||
{
|
{
|
||||||
if (i - start > 1)
|
if (i - start > 1)
|
||||||
{
|
{
|
||||||
result.push_back({ dim1.start + (start + 1) * dim1.step, dim1.step, i - start - 1, dim1.array });
|
result.push_back({ dim1.start + (start + 1) * dim1.step, dim1.step, i - start - 1 });
|
||||||
start = i;
|
start = i;
|
||||||
}
|
}
|
||||||
interValue += intersection->step;
|
interValue += intersection->step;
|
||||||
@@ -85,7 +85,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
|||||||
/* first value after intersection */
|
/* first value after intersection */
|
||||||
uint64_t right_start = intersection->start + intersection->step * (intersection->tripCount - 1) + dim1.step;
|
uint64_t right_start = intersection->start + intersection->step * (intersection->tripCount - 1) + dim1.step;
|
||||||
uint64_t tripCount = (dim1.start + dim1.step * dim1.tripCount - right_start) / dim1.step;
|
uint64_t tripCount = (dim1.start + dim1.step * dim1.tripCount - right_start) / dim1.step;
|
||||||
result.push_back({ right_start, dim1.step, tripCount, dim1.array });
|
result.push_back({ right_start, dim1.step, tripCount });
|
||||||
}
|
}
|
||||||
delete(intersection);
|
delete(intersection);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -6,12 +6,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "SgUtils.h"
|
|
||||||
|
|
||||||
struct ArrayDimension
|
struct ArrayDimension
|
||||||
{
|
{
|
||||||
uint64_t start, step, tripCount;
|
uint64_t start, step, tripCount;
|
||||||
SgArrayRefExp* array;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AccessingSet {
|
class AccessingSet {
|
||||||
|
|||||||
@@ -139,16 +139,17 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fillCount = 0;
|
if(coefsForDims.empty())
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
while (!index_vars.empty() && !refPos.empty() && !coefsForDims.empty())
|
while (!index_vars.empty())
|
||||||
{
|
{
|
||||||
auto var = index_vars.back();
|
auto var = index_vars.back();
|
||||||
int currentVarPos = refPos.back();
|
int currentVarPos = refPos.back();
|
||||||
pair<int, int> currentCoefs = coefsForDims.back();
|
pair<int, int> currentCoefs = coefsForDims.back();
|
||||||
ArrayDimension current_dim;
|
ArrayDimension current_dim;
|
||||||
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
||||||
current_dim = { stoul(var->getValue()), 1, 1, ref};
|
current_dim = { stoul(var->getValue()), 1, 1 };
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string name, full_name = var->getValue();
|
string name, full_name = var->getValue();
|
||||||
@@ -176,23 +177,19 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
|
|
||||||
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
||||||
uint64_t step = currentCoefs.first;
|
uint64_t step = currentCoefs.first;
|
||||||
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters, ref };
|
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters };
|
||||||
}
|
}
|
||||||
|
|
||||||
accessPoint[n - index_vars.size()] = current_dim;
|
accessPoint[n - index_vars.size()] = current_dim;
|
||||||
fillCount++;
|
|
||||||
index_vars.pop_back();
|
index_vars.pop_back();
|
||||||
refPos.pop_back();
|
refPos.pop_back();
|
||||||
coefsForDims.pop_back();
|
coefsForDims.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fillCount == accessPoint.size())
|
if (operation == SAPFOR::CFG_OP::STORE)
|
||||||
{
|
def[array_name].Insert(accessPoint);
|
||||||
if (operation == SAPFOR::CFG_OP::STORE)
|
else
|
||||||
def[array_name].Insert(accessPoint);
|
use[array_name].Insert(accessPoint);
|
||||||
else
|
|
||||||
use[array_name].Insert(accessPoint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
118
src/Sapfor.cpp
118
src/Sapfor.cpp
@@ -23,7 +23,6 @@
|
|||||||
#include "ParallelizationRegions/ParRegions_func.h"
|
#include "ParallelizationRegions/ParRegions_func.h"
|
||||||
#include "ParallelizationRegions/resolve_par_reg_conflicts.h"
|
#include "ParallelizationRegions/resolve_par_reg_conflicts.h"
|
||||||
#include "ParallelizationRegions/expand_extract_reg.h"
|
#include "ParallelizationRegions/expand_extract_reg.h"
|
||||||
#include "ParallelizationRegions/parse_merge_dirs.h"
|
|
||||||
|
|
||||||
#include "Distribution/Distribution.h"
|
#include "Distribution/Distribution.h"
|
||||||
#include "Distribution/GraphCSR.h"
|
#include "Distribution/GraphCSR.h"
|
||||||
@@ -58,6 +57,7 @@
|
|||||||
#include "expr_transform.h"
|
#include "expr_transform.h"
|
||||||
|
|
||||||
#include "Predictor/PredictScheme.h"
|
#include "Predictor/PredictScheme.h"
|
||||||
|
#include "Predictor/PredictSchemeWithLibrary.h"
|
||||||
#include "Predictor/PredictorModel.h"
|
#include "Predictor/PredictorModel.h"
|
||||||
#include "SageAnalysisTool/depInterfaceExt.h"
|
#include "SageAnalysisTool/depInterfaceExt.h"
|
||||||
#include "DvmhRegions/DvmhRegionInserter.h"
|
#include "DvmhRegions/DvmhRegionInserter.h"
|
||||||
@@ -280,7 +280,6 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
|
|||||||
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
|
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
|
||||||
if (isSPF_stat(st)) // except sapfor parallel regions and if attributes dont move
|
if (isSPF_stat(st)) // except sapfor parallel regions and if attributes dont move
|
||||||
if (st->variant() != SPF_PARALLEL_REG_DIR && st->variant() != SPF_END_PARALLEL_REG_DIR)
|
if (st->variant() != SPF_PARALLEL_REG_DIR && st->variant() != SPF_END_PARALLEL_REG_DIR)
|
||||||
if (insertedPrivates.find(st) == insertedPrivates.end())
|
|
||||||
toDel.push_back(st);
|
toDel.push_back(st);
|
||||||
|
|
||||||
for (auto& elem : toDel)
|
for (auto& elem : toDel)
|
||||||
@@ -1021,6 +1020,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
if(func->funcPointer->variant() != ENTRY_STAT)
|
if(func->funcPointer->variant() != ENTRY_STAT)
|
||||||
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
||||||
}
|
}
|
||||||
|
else if (curr_regime == FIND_PRIVATE_ARRAYS)
|
||||||
|
FindPrivateArrays(loopGraph, fullIR);
|
||||||
else if (curr_regime == TEST_PASS)
|
else if (curr_regime == TEST_PASS)
|
||||||
{
|
{
|
||||||
//test pass
|
//test pass
|
||||||
@@ -1728,103 +1729,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (curr_regime == PREDICT_SCHEME)
|
else if (curr_regime == PREDICT_SCHEME)
|
||||||
{
|
runPredictScheme(project, topologies, parallelRegions, loopGraph, SPF_messages);
|
||||||
int maxSizeDist = 0;
|
|
||||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
|
||||||
{
|
|
||||||
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
|
||||||
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
|
||||||
|
|
||||||
auto &tmp = dataDirectives.distrRules;
|
|
||||||
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
|
||||||
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
|
||||||
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
|
||||||
|
|
||||||
for (auto &elem : currentVar)
|
|
||||||
{
|
|
||||||
DIST::Array *array = elem.first;
|
|
||||||
const DistrVariant *var = elem.second;
|
|
||||||
|
|
||||||
int countBlock = 0;
|
|
||||||
for (int z = 0; z < var->distRule.size(); ++z)
|
|
||||||
if (var->distRule[z] == dist::BLOCK)
|
|
||||||
++countBlock;
|
|
||||||
maxSizeDist = std::max(maxSizeDist, countBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SpfInterval *mainIterval = getMainInterval(&project, intervals, SPF_messages);
|
|
||||||
topologies.clear();
|
|
||||||
if (maxSizeDist)
|
|
||||||
{
|
|
||||||
const int procNum = 8;
|
|
||||||
//TODO:
|
|
||||||
//topologies = getTopologies(procNum, maxSizeDist);
|
|
||||||
throw -10;
|
|
||||||
|
|
||||||
const int countOfTop = topologies.size();
|
|
||||||
if (countOfTop < 0)
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
for (auto &inter : intervals)
|
|
||||||
initTimeForIntervalTree(countOfTop, inter.second);
|
|
||||||
|
|
||||||
for (int z = 0; z < parallelRegions.size(); ++z)
|
|
||||||
{
|
|
||||||
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
|
||||||
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
|
||||||
DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArraysToModify();
|
|
||||||
|
|
||||||
auto &tmp = dataDirectives.distrRules;
|
|
||||||
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
|
||||||
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
|
||||||
currentVar.push_back(make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
|
||||||
|
|
||||||
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
|
||||||
vector<std::tuple<DIST::Array*, vector<long>, pair<string, int>>> allSingleRemotes;
|
|
||||||
for (int i = n - 1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
SgFile *file = &(project.file(i));
|
|
||||||
auto fountInfo = findAllDirectives(file, getObjectForFileFromMap(file->filename(), loopGraph), parallelRegions[z]->GetId());
|
|
||||||
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
|
||||||
|
|
||||||
auto fountRem = findAllSingleRemotes(file, parallelRegions[z]->GetId(), parallelRegions);
|
|
||||||
allSingleRemotes.insert(allSingleRemotes.end(), fountRem.begin(), fountRem.end());
|
|
||||||
}
|
|
||||||
//TODO!
|
|
||||||
//int err = predictScheme(parallelRegions[z], currentVar, allArrays.GetArrays(), parallelDirs, intervals, SPF_messages, allSingleRemotes, maxSizeDist, procNum);
|
|
||||||
/*if (err != 0)
|
|
||||||
internalExit = err;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<SpfInterval*> tmp = { mainIterval };
|
|
||||||
aggregatePredictedTimes(tmp);
|
|
||||||
|
|
||||||
int idx = 0;
|
|
||||||
int best = -1;
|
|
||||||
double bestSpeedUp = 0;
|
|
||||||
for (auto &top : topologies)
|
|
||||||
{
|
|
||||||
string outStr = "";
|
|
||||||
for (auto &elem : top)
|
|
||||||
outStr += std::to_string(elem) + " ";
|
|
||||||
double currS = mainIterval->exec_time / mainIterval->predictedTimes[idx];
|
|
||||||
__spf_print(1, "%d: speed up %f for top. %s\n", idx, currS, outStr.c_str());
|
|
||||||
|
|
||||||
if (best == -1 || bestSpeedUp < currS)
|
|
||||||
{
|
|
||||||
bestSpeedUp = currS;
|
|
||||||
best = idx;
|
|
||||||
}
|
|
||||||
++idx;
|
|
||||||
}
|
|
||||||
__spf_print(1, "best topology %d with speed up %f\n", best, bestSpeedUp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (auto &inter : intervals)
|
|
||||||
initTimeForIntervalTree(0, inter.second);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (curr_regime == CREATE_INTER_TREE)
|
else if (curr_regime == CREATE_INTER_TREE)
|
||||||
{
|
{
|
||||||
if (keepFiles)
|
if (keepFiles)
|
||||||
@@ -1916,12 +1821,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
}
|
}
|
||||||
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
||||||
transformAssumedSizeParameters(allFuncInfo);
|
transformAssumedSizeParameters(allFuncInfo);
|
||||||
else if (curr_regime == FIND_PRIVATE_ARRAYS_ANALYSIS)
|
|
||||||
FindPrivateArrays(loopGraph, fullIR, insertedPrivates);
|
|
||||||
else if (curr_regime == MERGE_COPY_ARRAYS)
|
|
||||||
{
|
|
||||||
mergeCopyArrays(parallelRegions, allFuncInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.;
|
||||||
@@ -2226,9 +2125,8 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
|||||||
|
|
||||||
runAnalysis(*project, CALCULATE_STATS_SCHEME, false);
|
runAnalysis(*project, CALCULATE_STATS_SCHEME, false);
|
||||||
|
|
||||||
//TODO: need to rewrite this to new algo
|
if (!folderName && !consoleMode || predictOn)
|
||||||
/*if (!folderName && !consoleMode || predictOn)
|
runAnalysis(*project, PREDICT_SCHEME, false);
|
||||||
runAnalysis(*project, PREDICT_SCHEME, false); */
|
|
||||||
|
|
||||||
runAnalysis(*project, REMOVE_COPIES, false);
|
runAnalysis(*project, REMOVE_COPIES, false);
|
||||||
runAnalysis(*project, SWAP_LOOPS, false);
|
runAnalysis(*project, SWAP_LOOPS, false);
|
||||||
@@ -2375,12 +2273,10 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
|||||||
case FIX_COMMON_BLOCKS:
|
case FIX_COMMON_BLOCKS:
|
||||||
case TEST_PASS:
|
case TEST_PASS:
|
||||||
case SET_IMPLICIT_NONE:
|
case SET_IMPLICIT_NONE:
|
||||||
case MERGE_COPY_ARRAYS:
|
|
||||||
runAnalysis(*project, curr_regime, false);
|
runAnalysis(*project, curr_regime, false);
|
||||||
case SUBST_EXPR_RD_AND_UNPARSE:
|
case SUBST_EXPR_RD_AND_UNPARSE:
|
||||||
case SUBST_EXPR_AND_UNPARSE:
|
case SUBST_EXPR_AND_UNPARSE:
|
||||||
case REMOVE_DEAD_CODE_AND_UNPARSE:
|
case REMOVE_DEAD_CODE_AND_UNPARSE:
|
||||||
case FIND_PRIVATE_ARRAYS:
|
|
||||||
if (folderName)
|
if (folderName)
|
||||||
runAnalysis(*project, UNPARSE_FILE, true, "", folderName);
|
runAnalysis(*project, UNPARSE_FILE, true, "", folderName);
|
||||||
else
|
else
|
||||||
@@ -2642,7 +2538,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST || curr_regime == FIND_PRIVATE_ARRAYS)
|
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST)
|
||||||
{
|
{
|
||||||
ignoreArrayDistributeState = true;
|
ignoreArrayDistributeState = true;
|
||||||
sharedMemoryParallelization = 1;
|
sharedMemoryParallelization = 1;
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ enum passes {
|
|||||||
REMOVE_DVM_INTERVALS,
|
REMOVE_DVM_INTERVALS,
|
||||||
VERIFY_DVM_DIRS,
|
VERIFY_DVM_DIRS,
|
||||||
|
|
||||||
MERGE_COPY_ARRAYS,
|
|
||||||
|
|
||||||
REMOVE_DIST_ARRAYS_FROM_IO,
|
REMOVE_DIST_ARRAYS_FROM_IO,
|
||||||
|
|
||||||
SUBST_EXPR,
|
SUBST_EXPR,
|
||||||
@@ -185,7 +183,6 @@ enum passes {
|
|||||||
SET_IMPLICIT_NONE,
|
SET_IMPLICIT_NONE,
|
||||||
RENAME_INLCUDES,
|
RENAME_INLCUDES,
|
||||||
|
|
||||||
FIND_PRIVATE_ARRAYS_ANALYSIS,
|
|
||||||
FIND_PRIVATE_ARRAYS,
|
FIND_PRIVATE_ARRAYS,
|
||||||
|
|
||||||
TRANSFORM_ASSUMED_SIZE_PARAMETERS,
|
TRANSFORM_ASSUMED_SIZE_PARAMETERS,
|
||||||
@@ -272,7 +269,6 @@ static void setPassValues()
|
|||||||
passNames[VERIFY_DVM_DIRS] = "VERIFY_DVM_DIRS";
|
passNames[VERIFY_DVM_DIRS] = "VERIFY_DVM_DIRS";
|
||||||
passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS";
|
passNames[REMOVE_DVM_DIRS_TO_COMMENTS] = "REMOVE_DVM_DIRS_TO_COMMENTS";
|
||||||
passNames[REMOVE_SPF_DIRS] = "REMOVE_SPF_DIRS";
|
passNames[REMOVE_SPF_DIRS] = "REMOVE_SPF_DIRS";
|
||||||
passNames[MERGE_COPY_ARRAYS] = "MERGE_COPY_ARRAYS";
|
|
||||||
passNames[REMOVE_DIST_ARRAYS_FROM_IO] = "REMOVE_DIST_ARRAYS_FROM_IO";
|
passNames[REMOVE_DIST_ARRAYS_FROM_IO] = "REMOVE_DIST_ARRAYS_FROM_IO";
|
||||||
passNames[SUBST_EXPR] = "SUBST_EXPR";
|
passNames[SUBST_EXPR] = "SUBST_EXPR";
|
||||||
passNames[SUBST_EXPR_RD] = "SUBST_EXPR_RD";
|
passNames[SUBST_EXPR_RD] = "SUBST_EXPR_RD";
|
||||||
@@ -375,7 +371,6 @@ static void setPassValues()
|
|||||||
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
||||||
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
||||||
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
||||||
passNames[FIND_PRIVATE_ARRAYS_ANALYSIS] = "FIND_PRIVATE_ARRAYS_ANALYSIS";
|
|
||||||
passNames[FIND_PRIVATE_ARRAYS] = "FIND_PRIVATE_ARRAYS";
|
passNames[FIND_PRIVATE_ARRAYS] = "FIND_PRIVATE_ARRAYS";
|
||||||
|
|
||||||
passNames[TRANSFORM_ASSUMED_SIZE_PARAMETERS] = "TRANSFORM_ASSUMED_SIZE_PARAMETERS";
|
passNames[TRANSFORM_ASSUMED_SIZE_PARAMETERS] = "TRANSFORM_ASSUMED_SIZE_PARAMETERS";
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ std::map<std::string, PredictorStats> allPredictorStats;
|
|||||||
|
|
||||||
//for DVM INTERVALS
|
//for DVM INTERVALS
|
||||||
std::map<std::string, std::vector<SpfInterval*>> intervals; // file -> intervals
|
std::map<std::string, std::vector<SpfInterval*>> intervals; // file -> intervals
|
||||||
std::vector<std::vector<long>> topologies; // current topologies
|
std::vector<std::vector<size_t>> topologies; // current topologies
|
||||||
//
|
//
|
||||||
|
|
||||||
//for GCOV_PARSER
|
//for GCOV_PARSER
|
||||||
@@ -175,11 +175,6 @@ std::set<std::tuple<std::string, int, std::string>> parametersOfProject; // [fil
|
|||||||
//for GET_MIN_MAX_BLOCK_DIST
|
//for GET_MIN_MAX_BLOCK_DIST
|
||||||
std::pair<int, int> min_max_block = std::make_pair(-1, -1);
|
std::pair<int, int> min_max_block = std::make_pair(-1, -1);
|
||||||
//
|
//
|
||||||
|
|
||||||
//for FIND_PRIVATE_ARRAYS
|
|
||||||
std::set<SgStatement*> insertedPrivates;
|
|
||||||
//
|
|
||||||
|
|
||||||
const char* passNames[EMPTY_PASS + 1];
|
const char* passNames[EMPTY_PASS + 1];
|
||||||
const char* optionNames[EMPTY_OPTION + 1];
|
const char* optionNames[EMPTY_OPTION + 1];
|
||||||
bool passNamesWasInit = false;
|
bool passNamesWasInit = false;
|
||||||
|
|||||||
@@ -316,10 +316,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
||||||
|
|
||||||
list({ CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS_ANALYSIS);
|
list({ CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS);
|
||||||
list({ FIND_PRIVATE_ARRAYS_ANALYSIS, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN, REVERT_SUBST_EXPR_RD }) <= Pass(FIND_PRIVATE_ARRAYS);
|
|
||||||
|
|
||||||
Pass(CREATE_TEMPLATE_LINKS) <= Pass(MERGE_COPY_ARRAYS);
|
|
||||||
|
|
||||||
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
||||||
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
||||||
|
|||||||
@@ -78,7 +78,12 @@ enum typeMessage { WARR, ERROR, NOTE };
|
|||||||
// 60 "Format misplaced"
|
// 60 "Format misplaced"
|
||||||
// 61 "Array has declaration area conflict"
|
// 61 "Array has declaration area conflict"
|
||||||
// 62 "need to move common declaration to main for DECLATE"
|
// 62 "need to move common declaration to main for DECLATE"
|
||||||
//
|
// 63 "Failed to initialize libpredict cluster"
|
||||||
|
// 64 "Failed to initialize libpredict grid"
|
||||||
|
// 65 "Failed to distribute array with libpredict"
|
||||||
|
// 66 "Failed to align array with libpredict"
|
||||||
|
// 67 "Failed to process shadow_renew with libpredict"
|
||||||
|
//
|
||||||
// 20xx TRANSFORM GROUP
|
// 20xx TRANSFORM GROUP
|
||||||
// 01 "can not convert array assign to loop"
|
// 01 "can not convert array assign to loop"
|
||||||
// 02 "converted arithmetic IF to simple IF"
|
// 02 "converted arithmetic IF to simple IF"
|
||||||
@@ -305,7 +310,7 @@ static void printStackTrace() { };
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Свободный - R206
|
// Свободный - R210
|
||||||
// Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор.
|
// Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор.
|
||||||
// В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле
|
// В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле
|
||||||
// russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен
|
// russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен
|
||||||
@@ -504,6 +509,16 @@ static const wchar_t *R183 = L"R183:";
|
|||||||
static const wchar_t *R184 = L"R184:%s";
|
static const wchar_t *R184 = L"R184:%s";
|
||||||
//1062
|
//1062
|
||||||
static const wchar_t* R205 = L"R205:%s#%s";
|
static const wchar_t* R205 = L"R205:%s#%s";
|
||||||
|
//1063
|
||||||
|
static const wchar_t* R206 = L"R206:";
|
||||||
|
//1064
|
||||||
|
static const wchar_t* R207 = L"R207:";
|
||||||
|
//1065
|
||||||
|
static const wchar_t* R208 = L"R208:";
|
||||||
|
//1066
|
||||||
|
static const wchar_t* R209 = L"R209:";
|
||||||
|
//1067
|
||||||
|
static const wchar_t* R210 = L"R210:";
|
||||||
|
|
||||||
//2001
|
//2001
|
||||||
static const wchar_t *R94 = L"R94:";
|
static const wchar_t *R94 = L"R94:";
|
||||||
|
|||||||
@@ -184,8 +184,18 @@ R182 = "Редукционная операция по элементу масс
|
|||||||
R183 = "Расположение операторов FORMAT не поддерживается, попробуйте применить проход Коррекция стиля кода".
|
R183 = "Расположение операторов FORMAT не поддерживается, попробуйте применить проход Коррекция стиля кода".
|
||||||
//1061
|
//1061
|
||||||
R184 = "Область объявления массива '%s' конфликтует с предыдущей областью. Возможно, это вызвано использованием include-файлов. Попробуйте применить проход 'Подстановка заголовочных файлов'".
|
R184 = "Область объявления массива '%s' конфликтует с предыдущей областью. Возможно, это вызвано использованием include-файлов. Попробуйте применить проход 'Подстановка заголовочных файлов'".
|
||||||
//1042
|
//1062
|
||||||
R205 = "Массив '%s' состоящий в common блоке '%s' должен иметь описание в главной программной единице для объявления в директиве DECLARE"
|
R205 = "Массив '%s' состоящий в common блоке '%s' должен иметь описание в главной программной единице для объявления в директиве DECLARE"
|
||||||
|
//1063
|
||||||
|
R206 = "Ошибка инициализации библиотеки libpredict с конфигурацией кластера: %s, код возврата: %d"
|
||||||
|
//1064
|
||||||
|
R207 = "Ошибка инициализации сетки libpredict с топологией: %zu %zu %zu %zu, код возврата: %d"
|
||||||
|
//1065
|
||||||
|
R208 = "Ошибка распределения массива '%s' с помощью libpredict, код возврата: %d"
|
||||||
|
//1066
|
||||||
|
R209 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d"
|
||||||
|
//1067
|
||||||
|
R210 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d"
|
||||||
|
|
||||||
//2001
|
//2001
|
||||||
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"
|
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERSION_SPF "2448"
|
#define VERSION_SPF "2446"
|
||||||
|
|||||||
@@ -950,7 +950,7 @@ int SPF_ModifyArrayDistribution(void*& context, int winHandler, short *options,
|
|||||||
|
|
||||||
extern map<string, PredictorStats> allPredictorStats;
|
extern map<string, PredictorStats> allPredictorStats;
|
||||||
extern map<string, vector<SpfInterval*>> intervals;
|
extern map<string, vector<SpfInterval*>> intervals;
|
||||||
extern vector<vector<long>> topologies;
|
extern vector<vector<size_t>> topologies;
|
||||||
|
|
||||||
int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, short *projName, short *folderName, int64_t *variants, int *varLen,
|
int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, short *projName, short *folderName, int64_t *variants, int *varLen,
|
||||||
string &output, string &outputMessage, string &predictorStats)
|
string &output, string &outputMessage, string &predictorStats)
|
||||||
@@ -1793,15 +1793,6 @@ int SPF_RenameIncludes(void*& context, int winHandler, short* options, short* pr
|
|||||||
return simpleTransformPass(RENAME_INLCUDES, options, projName, folderName, output, outputMessage);
|
return simpleTransformPass(RENAME_INLCUDES, options, projName, folderName, output, outputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SPF_InsertPrivateArrayDirectives(void*& context, int winHandler, short* options, short* projName, short* folderName, string& output, string& outputMessage)
|
|
||||||
{
|
|
||||||
MessageManager::clearCache();
|
|
||||||
MessageManager::setWinHandler(winHandler);
|
|
||||||
ignoreArrayDistributeState = true;
|
|
||||||
sharedMemoryParallelization = 1;
|
|
||||||
return simpleTransformPass(FIND_PRIVATE_ARRAYS, options, projName, folderName, output, outputMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void convertBackSlash(char *str, int strL)
|
static inline void convertBackSlash(char *str, int strL)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < strL; ++z)
|
for (int z = 0; z < strL; ++z)
|
||||||
@@ -1816,7 +1807,7 @@ static int inline runModificationPass(passes passName, short* projName, short* f
|
|||||||
runPassesForVisualizer(projName, { passName }, folderName);
|
runPassesForVisualizer(projName, { passName }, folderName);
|
||||||
|
|
||||||
//fill data
|
//fill data
|
||||||
// newFiles: <èìåíà ôàéëîâ äëÿ ìîä, ñîäåðæèìîå ôàéëà>
|
// newFiles: <<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>>
|
||||||
string newFile;
|
string newFile;
|
||||||
|
|
||||||
if (SgFile::switchToFile(outFileName.c_str()) == -1)
|
if (SgFile::switchToFile(outFileName.c_str()) == -1)
|
||||||
@@ -2385,7 +2376,7 @@ const wstring Sapfor_RunAnalysis(const char* analysisName_c, const char* options
|
|||||||
retCode = SPF_GetArrayLinks(context, winHandler, optSh, projSh, result, output, outputMessage);
|
retCode = SPF_GetArrayLinks(context, winHandler, optSh, projSh, result, output, outputMessage);
|
||||||
else if (whichRun == "SPF_GetMaxMinBlockDistribution")
|
else if (whichRun == "SPF_GetMaxMinBlockDistribution")
|
||||||
retCode = SPF_GetMaxMinBlockDistribution(context, winHandler, optSh, projSh, result, output, outputMessage);
|
retCode = SPF_GetMaxMinBlockDistribution(context, winHandler, optSh, projSh, result, output, outputMessage);
|
||||||
else if (whichRun == "SPF_ÑhangeDirectory") // russian C
|
else if (whichRun == "SPF_<EFBFBD>hangeDirectory") // russian C
|
||||||
{
|
{
|
||||||
if (options_c == NULL)
|
if (options_c == NULL)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
@@ -2508,8 +2499,6 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
|
|||||||
retCode = SPF_InsertImplicitNone(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
retCode = SPF_InsertImplicitNone(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
||||||
else if (whichRun == "SPF_RenameIncludes")
|
else if (whichRun == "SPF_RenameIncludes")
|
||||||
retCode = SPF_RenameIncludes(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
retCode = SPF_RenameIncludes(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
||||||
else if (whichRun == "SPF_InsertPrivateArrayDirectives")
|
|
||||||
retCode = SPF_InsertPrivateArrayDirectives(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
|
||||||
else if (whichRun == "SPF_CreateParallelVariant")
|
else if (whichRun == "SPF_CreateParallelVariant")
|
||||||
{
|
{
|
||||||
vector<string> splited;
|
vector<string> splited;
|
||||||
|
|||||||
Reference in New Issue
Block a user