fixed and improved SAPFOR and FDVM

This commit is contained in:
ALEXks
2023-12-27 12:57:00 +03:00
parent 752e9206db
commit 34f0214404
15 changed files with 109 additions and 35 deletions

View File

@@ -12668,6 +12668,7 @@ int DistrArrayAssign(SgStatement *stmt)
return(1);
left_whole = !le->lhs();
right_whole = !re->lhs();
CANCEL_RTS2_MODE; // switch to basic RTS interface
ChangeDistArrayRef(le->lhs()); //replacing dvm-array references in subscript list
ChangeDistArrayRef(re->lhs());
LINE_NUMBER_BEFORE(stmt,stmt);
@@ -12709,13 +12710,15 @@ int DistrArrayAssign(SgStatement *stmt)
doAssignStmtAfter(ArrayCopy(headr, from_init, from_init+rr, from_init+2*rr, headl, to_init, to_init+rl, to_init+2*rl, 0));
if(dvm_ind)
doCallAfter(DeleteObject_H(DVM000(dvm_ind)));
SET_DVM(to_init);
SET_DVM(to_init);
RESUMPTION_RTS2_MODE; // return to RTS2 interface
return(1);
}
// assignment statement of kind: <dvm_array_section> = <scalar_expression>
if(only_debug)
return(1);
CANCEL_RTS2_MODE; // switch to basic RTS interface
if(INTERFACE_RTS2 && !isWholeArray(stmt->expr(0)))
err("Illegal array statement in -Opl2 mode", 642, stmt);
@@ -12735,6 +12738,7 @@ int DistrArrayAssign(SgStatement *stmt)
else
doAssignStmtAfter(ArrayCopy(headr, to_init, to_init, to_init, headl, to_init, to_init+rl, to_init+2*rl, -1));
SET_DVM(to_init);
RESUMPTION_RTS2_MODE; // return to RTS2 interface
return(1);
}
@@ -12753,6 +12757,7 @@ int AssignDistrArray(SgStatement *stmt)
// assignment statement of kind: <array_section> = <dvm_array_section>
if(only_debug)
return(1);
CANCEL_RTS2_MODE; // switch to basic RTS interface
left_whole = !le->lhs();
right_whole = !re->lhs();
@@ -12781,8 +12786,10 @@ int AssignDistrArray(SgStatement *stmt)
typer = ar->type()->baseType();
rr = Rank(ar);
headr = HeaderRef(ar);
if(!headr) // if there is error of dvm-array specification, header is not created
if(!headr) { // if there is error of dvm-array specification, header is not created
RESUMPTION_RTS2_MODE; // return to RTS2 interface
return(0);
}
if(!CompareTypes(typel,typer))
err("Different types of left and right side",620,stmt);
@@ -12801,6 +12808,7 @@ int AssignDistrArray(SgStatement *stmt)
doCallAfter(DeleteObject_H(DVM000(dvm_ind)));
SET_DVM(dvm_ind ? dvm_ind : to_init) ; //SET_DVM(to_init);
RESUMPTION_RTS2_MODE; // return to RTS2 interface
return(1);
}

View File

@@ -415,6 +415,8 @@ const int Logical_8 = 12;
#define HEDR(A) ((A)->thesymb->entry.Template.func_hedr)
#define FILE_LAST_STATEMENT(ST) ((SgStatement **)(ST)->attributeValue(0,LAST_STATEMENT))
#define CALLED_FUNCTIONS(ST) ((symb_list **)(ST)->attributeValue(0,RTC_CALLS))
#define INTERFACE_RTS2 (parloop_by_handler == 2)
#define CANCEL_RTS2_MODE if(parloop_by_handler == 2) parloop_by_handler = -1
#define RESUMPTION_RTS2_MODE if(parloop_by_handler == -1) parloop_by_handler = 2
#define HEADER_FOR_HANDLER(A) ( (SgSymbol **)(A)->attributeValue(0,HANDLER_HEADER) )
#define USE_STATEMENTS_ARE_REQUIRED ( (int *) first_do_par->attributeValue(0,MODULE_USE) )

View File

@@ -382,7 +382,17 @@ ArraySet DvmhRegionInserter::excludeRemotes(const ArraySet& block, SgStatement*
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
SgStatement* next = remoteDir->lexNext();
const string leftS = next->variant() == ASSIGN_STAT ? OriginalSymbol(next->expr(0)->symbol())->identifier() : "";
const string leftS = "";
//TODO: record ref!
if (next->variant() == ASSIGN_STAT)
{
auto ex = next->expr(0);
if (ex->variant() == ARRAY_REF)
OriginalSymbol(ex->symbol())->identifier();
else if (ex->variant() == RECORD_REF && ex->rhs()->variant() == ARRAY_REF)
OriginalSymbol(ex->rhs()->symbol())->identifier();
}
set<DIST::Array*> raArrays;

View File

@@ -2666,7 +2666,7 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p
const vector<string> &inRegion,
const set<string> &funcParNames,
map<SgStatement*, set<string>>& ompThreadPrivate,
const map<string, int>& keyValueFromGUI,
const map<string, int>& distrStateFromGUI,
const bool saveAllLocals,
map<string, vector<Messages>>& currMessages,
int& errorCount)
@@ -2852,8 +2852,8 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
else
{
auto it = keyValueFromGUI.find(itNew->second.first->GetIndepUniqName());
if (it != keyValueFromGUI.end())
auto it = distrStateFromGUI.find(itNew->second.first->GetIndepUniqName());
if (it != distrStateFromGUI.end())
{
if (it->second != oldVal)
{
@@ -2910,7 +2910,7 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p
//assume all arguments of function as OUT, except for inctrinsics
bool isWriteN = intr ? false : true;
//need to correct W/R usage with GraphCall map later
findArrayRefs(funcExp->arg(z), st, fName, z, isWriteN, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO, isExecutable, currFunctionName, inRegion, funcParNames, ompThreadPrivate, keyValueFromGUI, saveAllLocals, currMessages, errorCount);
findArrayRefs(funcExp->arg(z), st, fName, z, isWriteN, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO, isExecutable, currFunctionName, inRegion, funcParNames, ompThreadPrivate, distrStateFromGUI, saveAllLocals, currMessages, errorCount);
}
}
else
@@ -2920,8 +2920,8 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p
queue.push(findInfo("", ex->lhs(), -1, isWriteN));
if (ex->rhs())
queue.push(findInfo("", ex->rhs(), -1, isWriteN));
//findArrayRefs(ex->lhs(), st, "", -1, isWriteN, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO, isExecutable, currFunctionName, inRegion, funcParNames, ompThreadPrivate, keyValueFromGUI, saveAllLocals, currMessages, errorCount);
//findArrayRefs(ex->rhs(), st, "", -1, isWriteN, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO, isExecutable, currFunctionName, inRegion, funcParNames, ompThreadPrivate, keyValueFromGUI, saveAllLocals, currMessages, errorCount);
//findArrayRefs(ex->lhs(), st, "", -1, isWriteN, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO, isExecutable, currFunctionName, inRegion, funcParNames, ompThreadPrivate, distrStateFromGUI, saveAllLocals, currMessages, errorCount);
//findArrayRefs(ex->rhs(), st, "", -1, isWriteN, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO, isExecutable, currFunctionName, inRegion, funcParNames, ompThreadPrivate, distrStateFromGUI, saveAllLocals, currMessages, errorCount);
}
}
}
@@ -3036,7 +3036,7 @@ static void addPrivates(SgStatement *st, set<string>& privates, map<string, set<
int getAllDeclaredArrays(SgFile *file, map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>> &declaredArrays,
map<SgStatement*, set<tuple<int, string, string>>> &declaratedArraysSt, map<string, vector<Messages>> &currMessages,
const vector<ParallelRegion*> &regions, const map<string, int>& keyValueFromGUI)
const vector<ParallelRegion*> &regions, const map<string, int>& distrStateFromGUI)
{
int countErrors = 0;
@@ -3243,7 +3243,7 @@ int getAllDeclaredArrays(SgFile *file, map<tuple<int, string, string>, pair<DIST
findArrayRefs(funcExp->arg(z), st, fName, z, true,
commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO,
isSgExecutableStatement(st) ? true : false, currFunctionName,
regNames, funcParNames, ompThreadPrivate, keyValueFromGUI, saveAllLocals,
regNames, funcParNames, ompThreadPrivate, distrStateFromGUI, saveAllLocals,
currMessages, countErrors);
}
}
@@ -3253,7 +3253,7 @@ int getAllDeclaredArrays(SgFile *file, map<tuple<int, string, string>, pair<DIST
findArrayRefs(st->expr(i), st, "", -1, (st->variant() == ASSIGN_STAT && i == 0) ? true : false,
commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO,
isSgExecutableStatement(st) ? true : false, currFunctionName,
regNames, funcParNames, ompThreadPrivate, keyValueFromGUI, saveAllLocals,
regNames, funcParNames, ompThreadPrivate, distrStateFromGUI, saveAllLocals,
currMessages, countErrors);
}
}
@@ -3290,7 +3290,7 @@ int getAllDeclaredArrays(SgFile *file, map<tuple<int, string, string>, pair<DIST
for (int i = 0; i < 3; ++i)
findArrayRefs(st->expr(i), st, "", -1, false, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO,
false, "NULL", regNames, funcParNames, ompThreadPrivate, keyValueFromGUI, false,
false, "NULL", regNames, funcParNames, ompThreadPrivate, distrStateFromGUI, false,
currMessages, countErrors);
}
st = st->lexNext();
@@ -3328,7 +3328,7 @@ int getAllDeclaredArrays(SgFile *file, map<tuple<int, string, string>, pair<DIST
for (int i = 0; i < 3; ++i)
findArrayRefs(curr->expr(i), curr, "", -1, false, commonBlocks, declaredArrays, declaratedArraysSt, privates, deprecatedByIO,
false, blockName, regNames, funcParNames, ompThreadPrivate, keyValueFromGUI, false,
false, blockName, regNames, funcParNames, ompThreadPrivate, distrStateFromGUI, false,
currMessages, countErrors);
curr = curr->lexNext();
}

View File

@@ -48,7 +48,7 @@ std::string getShortName(const std::tuple<int, std::string, std::string> &uniqKe
int getAllDeclaredArrays(SgFile *file, std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> &declaredArrays,
std::map<SgStatement*, std::set<std::tuple<int, std::string, std::string>>> &declaratedArraysSt, std::map<std::string, std::vector<Messages>> &currMessages,
const std::vector<ParallelRegion*> &regions, const std::map<std::string, int>& keyValueFromGUI);
const std::vector<ParallelRegion*> &regions, const std::map<std::string, int>& distrStateFromGUI);
void insertSpfAnalysisBeforeParalleLoops(const std::vector<LoopGraph*> &loops);
void recalculateArraySizes(std::set<DIST::Array*> &arraysDone, const std::set<DIST::Array*> &allArrays, const std::map<DIST::Array*, std::set<DIST::Array*>> &arrayLinksByFuncCalls, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
int getSizeOfType(SgType* t);

View File

@@ -943,7 +943,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
}
else if (curr_regime == GET_ALL_ARRAY_DECL)
{
int err = getAllDeclaredArrays(file, declaredArrays, declaratedArraysSt, SPF_messages, subs_parallelRegions, keyValueFromGUI);
int err = getAllDeclaredArrays(file, declaredArrays, declaratedArraysSt, SPF_messages, subs_parallelRegions, distrStateFromGUI);
if (err != 0)
internalExit = -1;
}
@@ -1167,6 +1167,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
getMaxMinBlockDistribution(file, min_max_block);
else if (curr_regime == CONVERT_TO_C)
covertToC(file);
else if (curr_regime == INSERT_NO_DISTR_FLAGS_FROM_GUI)
addPrivatesToArraysFromGUI(file, declaredArrays, distrStateFromGUI);
else if (curr_regime == TEST_PASS)
{
//test pass
@@ -2485,6 +2487,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case PURE_INTENT_INSERT:
case REMOVE_OMP_DIRS_TRANSFORM:
case REMOVE_COMMENTS:
case INSERT_NO_DISTR_FLAGS_FROM_GUI:
runAnalysis(*project, curr_regime, true, "", folderName);
break;
case PRIVATE_REMOVING:

View File

@@ -172,6 +172,7 @@ enum passes {
REMOVE_COMMENTS,
GET_MIN_MAX_BLOCK_DIST,
CONVERT_TO_C,
INSERT_NO_DISTR_FLAGS_FROM_GUI,
TEST_PASS,
EMPTY_PASS
@@ -349,6 +350,7 @@ static void setPassValues()
passNames[REMOVE_COMMENTS] = "REMOVE_COMMENTS";
passNames[GET_MIN_MAX_BLOCK_DIST] = "GET_MIN_MAX_BLOCK_DIST";
passNames[CONVERT_TO_C] = "CONVERT_TO_C";
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
passNames[TEST_PASS] = "TEST_PASS";
}

View File

@@ -158,7 +158,7 @@ std::pair<std::string, int> inOnlyForloopOnPlace;
//
//cache for declaration arrays state switching
std::map<std::string, int> keyValueFromGUI;
std::map<std::string, int> distrStateFromGUI;
//
//for PROCESS_IO

View File

@@ -38,7 +38,7 @@ static SgType* createArrayCharType(int len, int dim)
}
static void findDecls(SgExpression* ex, vector<SgExpression*>& local, const map<string, SgStatement*>& localParams,
set<string>& added, set<string>& IntentInParams)
set<string>& added, set<string>& intentInParams)
{
if (ex)
{
@@ -48,7 +48,7 @@ static void findDecls(SgExpression* ex, vector<SgExpression*>& local, const map<
localParams.find(ex->symbol()->identifier()) == localParams.end())
{
if (added.find(ex->symbol()->identifier()) == added.end() &&
IntentInadded.find(ex->symbol()->identifier()) == IntentInadded.end())
intentInParams.find(ex->symbol()->identifier()) == intentInParams.end())
{
added.insert(ex->symbol()->identifier());
local.push_back(ex);
@@ -60,15 +60,15 @@ static void findDecls(SgExpression* ex, vector<SgExpression*>& local, const map<
{
if (ex->symbol()->variant() == VARIABLE_NAME &&
added.find(ex->symbol()->identifier()) == added.end() &&
IntentInadded.find(ex->symbol()->identifier()) == IntentInadded.end())
intentInParams.find(ex->symbol()->identifier()) == intentInParams.end())
{
added.insert(ex->symbol()->identifier());
local.push_back(new SgArrayRefExp(*ex->symbol()));
}
}
findDecls(ex->lhs(), local, localParams, added, IntentInParams);
findDecls(ex->rhs(), local, localParams, added, IntentInParams);
findDecls(ex->lhs(), local, localParams, added, intentInParams);
findDecls(ex->rhs(), local, localParams, added, intentInParams);
}
}
@@ -90,10 +90,10 @@ static void findLocalData(SgStatement* func, SgStatement* end, vector<SgExpressi
SgStatement* start = func->lexNext();
FuncInfo* funcI = findFileInfoByName(func, allFuncInfo);
set<string> IntentInParams;
set<string> intentInParams;
for (int i = 0; i < funcI->funcParams.countOfPars; ++i)
if (funcI->funcParams.isArgIn(i) && !funcI->funcParams.isArgOut(i))
IntentInParams.insert(funcI->funcParams.identificators[i]);
intentInParams.insert(funcI->funcParams.identificators[i]);
for (SgStatement* st = start; st != end; st = st->lexNext())
{
@@ -114,7 +114,7 @@ static void findLocalData(SgStatement* func, SgStatement* end, vector<SgExpressi
{
//printf("line %d %s Var %s\n", st->lineNumber(), st->fileName(), tag[st->variant()]);
if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90)
findDecls(st->expr(0), local, localParams, added, IntentInParams);
findDecls(st->expr(0), local, localParams, added, intentInParams);
}
}

View File

@@ -216,7 +216,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
Pass(RESTORE_LOOP_FROM_ASSIGN) <= list({ SUBST_EXPR_AND_UNPARSE, SUBST_EXPR_RD_AND_UNPARSE });
Pass(GET_ALL_ARRAY_DECL) <= Pass(CALL_GRAPH_IR);
Pass(GET_ALL_ARRAY_DECL) <= list({ CALL_GRAPH_IR, INSERT_NO_DISTR_FLAGS_FROM_GUI });
Pass(LOOP_GRAPH) <= Pass(PRIVATE_CALL_GRAPH_STAGE3) <= list(FIND_FUNC_TO_INCLUDE, PRIVATE_ANALYSIS_IR) <= list({ LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH, LOOP_ANALYZER_ALIGNS });

View File

@@ -4396,6 +4396,7 @@ void removeSpecialCommentsFromProject(SgFile* file)
}
}
//TODO: for gen_block and other variations, and redistributions dirs
void getMaxMinBlockDistribution(SgFile* file, pair<int, int>& min_max)
{
SgStatement* st = file->firstStatement();
@@ -4445,3 +4446,40 @@ void getMaxMinBlockDistribution(SgFile* file, pair<int, int>& min_max)
st = st->lexNext();
}
}
void addPrivatesToArraysFromGUI(SgFile* file, const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays,
const map<string, int>& distrStateFromGUI)
{
map<SgStatement*, set<string>> added;
for (auto& arrayPair : declaredArrays)
{
DIST::Array* array = arrayPair.second.first;
string key = array->GetIndepUniqName();
auto it = distrStateFromGUI.find(key);
if (it == distrStateFromGUI.end())
continue;
if (it->second != DIST::NO_DISTR)
continue;
for (auto& decl : array->GetDeclInfoWithSymb())
{
auto& place = decl.first;
const auto& symb = decl.second->GetOriginal();
if (place.first != file->filename())
continue;
SgStatement* declSt = SgStatement::getStatementByFileAndLine(place.first, place.second);
checkNull(declSt, convertFileName(__FILE__).c_str(), __LINE__);
string toAdd = "!$SPF ANALYSIS(PRIVATE(" + string(symb->identifier()) + "))\n";
added[declSt].insert(toAdd);
}
}
for (auto& toInsert : added)
for (auto& elem : toInsert.second)
toInsert.first->addComment(elem.c_str());
}

View File

@@ -109,4 +109,6 @@ std::set<std::string> getAllFilesInProject();
void LogIftoIfThen(SgStatement* stmt);
void removeSpecialCommentsFromProject(SgFile* file);
void getMaxMinBlockDistribution(SgFile* file, std::pair<int, int>& min_max);
void getMaxMinBlockDistribution(SgFile* file, std::pair<int, int>& min_max);
void addPrivatesToArraysFromGUI(SgFile* file, const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays, const std::map<std::string, int>& distrStateFromGUI);

View File

@@ -1404,7 +1404,6 @@ pair<vector<string>, vector<string>> splitCommandLineForParse(char** argv, int a
for (int z = 0; z < argc; ++z)
{
string arg = argv[z];
string ext = OnlyExt(arg.c_str());
convertToLower(ext);
if (arg.find("*") != string::npos || checkFormat(ext, ""))
@@ -1423,11 +1422,11 @@ pair<vector<string>, vector<string>> splitCommandLineForParse(char** argv, int a
{
auto cmp_ext = file.extension().string();
convertToLower(cmp_ext);
if (cmp_ext.size() && cmp_ext[0] == '.')
cmp_ext.erase(cmp_ext.begin());
if (checkFormat(cmp_ext, arg))
if (checkFormat(cmp_ext, ext))
files.insert(file.filename().string());
else
printf(" skip file %s\n", arg.c_str());
}
#endif
}

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2258"
#define VERSION_SPF "2262"

View File

@@ -1560,7 +1560,7 @@ int SPF_GetFileLineInfo(void*& context, int winHandler, short *options, short *p
return retSize;
}
extern map<string, int> keyValueFromGUI;
extern map<string, int> distrStateFromGUI;
int SPF_SetDistributionFlagToArray(void*& context, char *key, int flag)
{
MessageManager::clearCache();
@@ -1589,7 +1589,7 @@ int SPF_SetDistributionFlagToArray(void*& context, char *key, int flag)
}
}
else
keyValueFromGUI[keyStr] = flag;
distrStateFromGUI[keyStr] = flag;
}
catch (...)
{
@@ -1654,7 +1654,7 @@ int SPF_SetDistributionFlagToArrays(void*& context, const char* keys, const char
int flagI = -1;
if (sscanf(flagsS[z].c_str(), "%d", &flagI) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
keyValueFromGUI[keysS[z]] = flagI;
distrStateFromGUI[keysS[z]] = flagI;
}
}
}
@@ -1887,6 +1887,14 @@ int SPF_SharedMemoryParallelization(void*& context, int winHandler, short* optio
return simpleTransformPass(INSERT_PARALLEL_DIRS_NODIST, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
}
int SPF_InsertPrivateFromGUI(void*& context, int winHandler, short* options, short* projName, short* folderName, short*& output,
int*& outputSize, short*& outputMessage, int*& outputMessageSize)
{
MessageManager::clearCache();
MessageManager::setWinHandler(winHandler);
return simpleTransformPass(INSERT_NO_DISTR_FLAGS_FROM_GUI, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
}
static inline void convertBackSlash(char *str, int strL)
{
for (int z = 0; z < strL; ++z)
@@ -2597,6 +2605,8 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
retCode = SPF_ResolveCommonBlockConflicts(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_SharedMemoryParallelization")
retCode = SPF_SharedMemoryParallelization(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_InsertPrivateFromGUI")
retCode = SPF_InsertPrivateFromGUI(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else
{
if (showDebug)