refactor shared memory parallelization (wip)

This commit is contained in:
2024-06-23 11:44:17 +03:00
parent 4a0ac0ff17
commit 455d0e4a3c

View File

@@ -387,7 +387,8 @@ vector<int> matchSubscriptToLoopSymbols(const vector<SgForStmt*> &parentLoops, S
return allPositions; return allPositions;
} }
static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops, SgExpression *currExp, const int side, static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops, vector<set<string>>& privatesVarsForLoop,
SgExpression *currExp, const int side,
map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, const int currLine, map<SgForStmt*, map<SgSymbol*, ArrayInfo>> &loopInfo, const int currLine,
map<int, LoopGraph*> &sortedLoopGraph, const ParallelRegion *reg, const double currentW, map<int, LoopGraph*> &sortedLoopGraph, const ParallelRegion *reg, const double currentW,
const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls) const map<DIST::Array*, set<DIST::Array*>> &arrayLinksByFuncCalls)
@@ -440,7 +441,9 @@ static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
vector<int> canNotMapToLoop; vector<int> canNotMapToLoop;
for (int i = 0; i < wasFoundForLoop.size(); ++i) for (int i = 0; i < wasFoundForLoop.size(); ++i)
{ {
if (wasFoundForLoop[i] != 1) if (wasFoundForLoop[i] != 1 &&
// always true for distributed data case
privatesVarsForLoop[i].find(string(arrayRef->symbol()->identifier())) == privatesVarsForLoop[i].end())
{ {
auto itLoop = sortedLoopGraph.find(parentLoops[i]->lineNumber()); auto itLoop = sortedLoopGraph.find(parentLoops[i]->lineNumber());
if (itLoop == sortedLoopGraph.end()) if (itLoop == sortedLoopGraph.end())
@@ -517,7 +520,8 @@ static vector<int> matchArrayToLoopSymbols(const vector<SgForStmt*> &parentLoops
} }
static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp, static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp,
const vector<SgForStmt*>& parentLoops, const int side, const int lineNum, const vector<SgForStmt*>& parentLoops, vector<set<string>>& privatesVarsForLoop,
const int side, const int lineNum,
map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo, map<SgForStmt*, map<SgSymbol*, ArrayInfo>>& loopInfo,
map<int, LoopGraph*> &sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays, map<int, LoopGraph*> &sortedLoopGraph, map<string, pair<SgSymbol*, SgStatement*>>& notMappedDistributedArrays,
set<string>& mappedDistrbutedArrays, set<string>& mappedDistrbutedArrays,
@@ -533,7 +537,7 @@ static void mapArrayRef(SgStatement* currentSt, SgExpression* currExp,
__spf_print(PRINT_ARRAY_ARCS, "%s to array <%s> on line %d: ", printSide, OriginalSymbol(currExp->symbol())->identifier(), lineNum); __spf_print(PRINT_ARRAY_ARCS, "%s to array <%s> on line %d: ", printSide, OriginalSymbol(currExp->symbol())->identifier(), lineNum);
bool wasMapped = false; bool wasMapped = false;
vector<int> matched = matchArrayToLoopSymbols(parentLoops, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls); vector<int> matched = matchArrayToLoopSymbols(parentLoops, privatesVarsForLoop, currExp, side, loopInfo, lineNum, sortedLoopGraph, reg, currentW, arrayLinksByFuncCalls);
for (int z = 0; z < matched.size(); ++z) for (int z = 0; z < matched.size(); ++z)
wasMapped |= (matched[z] != 0); wasMapped |= (matched[z] != 0);
@@ -570,7 +574,8 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
if (isArrayRef(currExp)) if (isArrayRef(currExp))
{ {
//... and current array is not in private list //... and current array is not in private list
if (privatesVars.find(string(OriginalSymbol(currExp->symbol())->identifier())) == privatesVars.end()) if (sharedMemoryParallelization ||
privatesVars.find(string(OriginalSymbol(currExp->symbol())->identifier())) == privatesVars.end())
{ {
if (wasDistributedArrayRef) if (wasDistributedArrayRef)
{ {
@@ -582,23 +587,23 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
if (itLoop->second->perfectLoop != depth) if (itLoop->second->perfectLoop != depth)
break; break;
if (!(sharedMemoryParallelization && side == RIGHT))
itLoop->second->hasIndirectAccess = true; itLoop->second->hasIndirectAccess = true;
if (sharedMemoryParallelization && side == RIGHT)
itLoop->second->hasIndirectAccess = false;
} }
mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, sortedLoopGraph, mapArrayRef(currentSt, currExp, parentLoops, privatesVarsForLoop, side, lineNum, loopInfo, sortedLoopGraph,
notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls); notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls);
} }
else else
{ {
wasDistributedArrayRef = true; wasDistributedArrayRef = true;
mapArrayRef(currentSt, currExp, parentLoops, side, lineNum, loopInfo, sortedLoopGraph, mapArrayRef(currentSt, currExp, parentLoops, privatesVarsForLoop, side, lineNum, loopInfo, sortedLoopGraph,
notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls); notMappedDistributedArrays, mappedDistrbutedArrays, reg, currentW, arrayLinksByFuncCalls);
} }
} }
else else
{ {
if ((currRegime == DATA_DISTR || currRegime == SHARED_MEMORY_PAR) && side == LEFT) if (currRegime == DATA_DISTR && side == LEFT)
{ {
auto symb = OriginalSymbol(currExp->symbol()); auto symb = OriginalSymbol(currExp->symbol());
SgStatement *decl = declaratedInStmt(symb); SgStatement *decl = declaratedInStmt(symb);
@@ -653,8 +658,6 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
const string key = string(OriginalSymbol(currExp->symbol())->identifier()); const string key = string(OriginalSymbol(currExp->symbol())->identifier());
if (loopsPrivates.find(key) == loopsPrivates.end()) if (loopsPrivates.find(key) == loopsPrivates.end())
{
if (sharedMemoryParallelization == 0)
{ {
for (auto& loop : parentLoops) for (auto& loop : parentLoops)
{ {
@@ -670,7 +673,6 @@ static void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *cu
sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true; sortedLoopGraph[loop->lineNumber()]->hasWritesToNonDistribute = true;
} }
} }
}
//TODO: this case looks strange //TODO: this case looks strange
/*else if (loopsRedUnited.find(key) == loopsRedUnited.end()) /*else if (loopsRedUnited.find(key) == loopsRedUnited.end())
{ {
@@ -1384,7 +1386,7 @@ static void convertOneLoop(LoopGraph *currLoop, map<LoopGraph*, map<DIST::Array*
SgStatement *decl = declaratedInStmt(currentArray); SgStatement *decl = declaratedInStmt(currentArray);
const char *symbIdent = currentArray->identifier(); const char *symbIdent = currentArray->identifier();
if (privateArrays.find(symbIdent) == privateArrays.end()) if (privateArrays.find(symbIdent) == privateArrays.end() || sharedMemoryParallelization)
{ {
const tuple<int, string, string> uniqKey = getUniqName(commonBlocks, decl, currentArray); const tuple<int, string, string> uniqKey = getUniqName(commonBlocks, decl, currentArray);
@@ -1401,7 +1403,7 @@ static void convertOneLoop(LoopGraph *currLoop, map<LoopGraph*, map<DIST::Array*
else else
arrayToAdd = itFound->second; arrayToAdd = itFound->second;
if (arrayToAdd->IsNotDistribute() == true) if (!sharedMemoryParallelization && arrayToAdd->IsNotDistribute() == true)
continue; continue;
set<DIST::Array*> links; set<DIST::Array*> links;
@@ -2094,14 +2096,18 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
} }
if(!sharedMemoryParallelization)
for (auto it = itF->second.begin(); it != itF->second.end(); ++it) for (auto it = itF->second.begin(); it != itF->second.end(); ++it)
privatesVars.insert(*it); privatesVars.insert(*it);
} }
} }
else else
{
if(!sharedMemoryParallelization)
{ {
tryToFindPrivateInAttributes(st, privatesVars); tryToFindPrivateInAttributes(st, privatesVars);
fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars); fillNonDistrArraysAsPrivate(st, declaredArrays, declaratedArraysSt, privatesVars);
}
if (isDVM_stat(st) == false && isSgExecutableStatement(st)) if (isDVM_stat(st) == false && isSgExecutableStatement(st))
{ {
@@ -2195,6 +2201,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
} }
} }
if(!sharedMemoryParallelization)
addToDistributionGraph(convertedLoopInfo, arrayLinksByFuncCalls); addToDistributionGraph(convertedLoopInfo, arrayLinksByFuncCalls);
for (auto &toDel : tmpLoops) for (auto &toDel : tmpLoops)
@@ -2203,7 +2210,6 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
if (!skipDeps) if (!skipDeps)
{ {
for (auto &loopLine : loopWithOutArrays) for (auto &loopLine : loopWithOutArrays)
{ {
if (loopLine > 0) if (loopLine > 0)
@@ -2311,6 +2317,9 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> &regions, map<tuple<int,
selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile); selectFreeLoopsForParallelization(loopsForFunction, funcName, (regime == DATA_DISTR), regions, messagesForFile);
} }
if(regime == SHARED_MEMORY_PAR)
createParallelDirectives(convertedLoopInfo, regions, arrayLinksByFuncCalls, messagesForFile);
__spf_print(PRINT_PROF_INFO, "Function ended\n"); __spf_print(PRINT_PROF_INFO, "Function ended\n");
} }
} }