improved and fixed FDVM, added ISNERT_INCLUDES pass

This commit is contained in:
ALEXks
2023-12-16 17:42:11 +03:00
parent 110970caa6
commit 1f3d9944b8
10 changed files with 613 additions and 775 deletions

View File

@@ -2532,7 +2532,10 @@ void ACC_ParallelLoopEnd(SgStatement *pardo)
}
if (options.isOn(LOOP_ANALYSIS))
{
delete currentLoop;
currentLoop = NULL;
}
}
if (options.isOn(RTC))

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,12 @@
#include "dvm.h"
#include "aks_structs.h"
#include <vector>
#include <map>
#include <string>
using std::vector;
using std::string;
using std::map;
#define DEBUG_LV1 true
#if 1
@@ -16,9 +23,7 @@ SgExpression* findDirect(SgExpression *inExpr, int DIR)
if (inExpr)
{
if (inExpr->variant() == DIR)
{
return inExpr;
}
else
{
if (inExpr->lhs())
@@ -31,7 +36,7 @@ SgExpression* findDirect(SgExpression *inExpr, int DIR)
return temp;
}
static SgSymbol** fillDataOfArray(SgExpression* on, int& dimInPar)
static vector<SgSymbol*> fillDataOfArray(SgExpression* on, int& dimInPar)
{
dimInPar = 0;
SgExpression* temp = on;
@@ -40,7 +45,8 @@ static SgSymbol** fillDataOfArray(SgExpression* on, int& dimInPar)
dimInPar++;
temp = temp->rhs();
}
SgSymbol** symbInPar = new SgSymbol * [dimInPar];
vector<SgSymbol*> symbInPar(dimInPar);
temp = on;
for (int i = 0; i < dimInPar; ++i)
{
@@ -50,20 +56,20 @@ static SgSymbol** fillDataOfArray(SgExpression* on, int& dimInPar)
return symbInPar;
}
SageArrayIdxs* GetIdxInParDir(const std::map<std::string, SgExpression*>& on, SgExpression *across, bool tie = false)
static void printError()
{
SageArrayIdxs *ret = new SageArrayIdxs();
SageArrayIdxs *act = ret;
int allDim = 0;
int dimInPar = 0;
SgSymbol** symbInPar = NULL;
ret->next = NULL;
ret->array_expr = NULL;
ret->read_write = -1;
ret->dim = 0;
ret->symb = NULL;
err("internal error in across", 424, first_do_par);
exit(-1);
}
static vector<SageArrayIdxs> GetIdxInParDir(const map<string, SgExpression*>& on, SgExpression *across, bool tie = false)
{
vector<SageArrayIdxs> ret;
int dimInPar = 0;
vector<SgSymbol*> symbInPar;
vector<SgExpression*> toAnalyze;
std::vector<SgExpression*> toAnalyze;
if (across->lhs()->variant() == EXPR_LIST)
toAnalyze.push_back(across->lhs());
else
@@ -80,13 +86,10 @@ SageArrayIdxs* GetIdxInParDir(const std::map<std::string, SgExpression*>& on, Sg
across = toAnalyze[i];
while (across)
{
if (symbInPar == NULL)
if (symbInPar.size() == 0)
{
if (on.size() == 0)
{
fprintf(stderr, "internal error in across convertion for GPU\n");
exit(-1);
}
printError();
else if (on.size() == 1)
symbInPar = fillDataOfArray(on.begin()->second, dimInPar);
}
@@ -99,20 +102,14 @@ SageArrayIdxs* GetIdxInParDir(const std::map<std::string, SgExpression*>& on, Sg
if (t->variant() == ARRAY_REF)
{
if (on.find(t->symbol()->identifier()) == on.end())
{
fprintf(stderr, "internal error in across convertion for GPU\n");
exit(-1);
}
printError();
else
symbInPar = fillDataOfArray(on.find(t->symbol()->identifier())->second, dimInPar);
}
else if (t->variant() == ARRAY_OP)
{
if (on.find(t->lhs()->symbol()->identifier()) == on.end())
{
fprintf(stderr, "internal error in across convertion for GPU\n");
exit(-1);
}
printError();
else
symbInPar = fillDataOfArray(on.find(t->lhs()->symbol()->identifier())->second, dimInPar);
}
@@ -134,37 +131,35 @@ SageArrayIdxs* GetIdxInParDir(const std::map<std::string, SgExpression*>& on, Sg
dim++;
tmp = tmp->rhs();
}
act->next = new SageArrayIdxs();
act = act->next;
act->next = NULL;
act->symb = new SageSymbols*[dim];
act->dim = dim;
SageArrayIdxs act;
act.symb.resize(dim);
act.dim = dim;
for (int i = 0; i < dim; ++i)
{
act->symb[i] = new SageSymbols();
act->symb[i]->across_left = t->lhs()->lhs()->valueInteger();
act->symb[i]->across_right = t->lhs()->rhs()->valueInteger();
if (act->symb[i]->across_left != 0 || act->symb[i]->across_right != 0)
act->symb[i]->symb = symbInPar[i];
act.symb[i].across_left = t->lhs()->lhs()->valueInteger();
act.symb[i].across_right = t->lhs()->rhs()->valueInteger();
if (act.symb[i].across_left != 0 || act.symb[i].across_right != 0)
act.symb[i].symb = symbInPar[i];
else if (i < dimInPar)
act->symb[i]->symb = symbInPar[i];
act.symb[i].symb = symbInPar[i];
else
act->symb[i]->symb = NULL;
act->symb[i]->next = NULL;
act.symb[i].symb = NULL;
t = t->rhs();
}
allDim++;
ret.push_back(act);
across = across->rhs();
}
}
ret->dim = allDim;
return ret;
}
SageAcrossInfo* GetLoopsWithParAndAcrDir()
SageAcrossInfo GetLoopsWithParAndAcrDir()
{
SageAcrossInfo *q = NULL;
SageAcrossInfo retVal;
SgStatement *temp = dvm_parallel_dir;
if (temp->variant() == DVM_PARALLEL_ON_DIR)
@@ -172,14 +167,13 @@ SageAcrossInfo* GetLoopsWithParAndAcrDir()
SgExpression *t = findDirect(temp->expr(1), ACROSS_OP);
SgExpression *tie = findDirect(temp->expr(1), ACC_TIE_OP);
std::map<std::string, SgExpression*> arrays;
map<string, SgExpression*> arrays;
if (t != NULL)
{
q = new SageAcrossInfo();
if (temp->expr(0) && temp->expr(0)->lhs())
{
arrays[temp->expr(0)->symbol()->identifier()] = temp->expr(0)->lhs();
q->idx = GetIdxInParDir(arrays, t);
retVal.idxs = GetIdxInParDir(arrays, t);
}
else if (tie)
{
@@ -189,34 +183,24 @@ SageAcrossInfo* GetLoopsWithParAndAcrDir()
arrays[list->lhs()->symbol()->identifier()] = list->lhs()->lhs();
list = list->rhs();
}
q->idx = GetIdxInParDir(arrays, t, true);
retVal.idxs = GetIdxInParDir(arrays, t, true);
}
else
{
fprintf(stderr, "internal error in across convertion for GPU\n");
exit(-1);
}
q->next = NULL;
printError();
}
}
return q;
return retVal;
}
SageSymbols *GetSymbInParalell(int *n, SgExpression *first)
vector<SageSymbols> GetSymbInParalell(SgExpression *first)
{
SageSymbols *retval;
SageSymbols *p_t = new SageSymbols();
retval = p_t;
vector<SageSymbols> retval;
while(first)
{
SageSymbols *q = new SageSymbols();
q->len = -1;
q->next = NULL;
q->symb = first->lhs()->symbol();
p_t->next = q;
p_t = q;
n[0]++;
SageSymbols q(first->lhs()->symbol(), -1, 0, 0);
retval.push_back(q);
first = first->rhs();
}
return retval->next;
return retval;
}

View File

@@ -4757,7 +4757,7 @@ void RedistributeArray(SgSymbol *das, int idisars, SgExpression *distr_rule_list
if_st = doIfThenConstrForRedis(headref_flag,stdis,iamv); /*08.05.17*/
where = end_if = if_st->lexNext()->lexNext(); // reffer to ENDIF statement
i1 = ndvm;
if(ACC_program) /*ACC*/
if(ACC_program || parloop_by_handler) /*ACC*/
where->insertStmtBefore(*Redistribute_H(headref,sign),*where->controlParent());
amvref = (ia & TEMPLATE_BIT) ? headref : GetAMView( headref);
//inserting after ELSE
@@ -4838,7 +4838,7 @@ void RedistributeArray(SgSymbol *das, int idisars, SgExpression *distr_rule_list
else {
SgExpression *amvref;
if(ACC_program) /*ACC*/
if(ACC_program || parloop_by_handler) /*ACC*/
where->insertStmtBefore(*Redistribute_H(headref,sign),*where->controlParent());
amvref = (ia & TEMPLATE_BIT) ? headref : GetAMView( headref);
@@ -5108,7 +5108,7 @@ void RealignArray(SgSymbol *als, SgSymbol *tgs, int iaxis, int nr, SgExpression
return;
}
iamv = ndvm;
if(ACC_program ) /*ACC*/
if(ACC_program || parloop_by_handler) /*ACC*/
{ if( !(ia & POSTPONE_BIT) )
doCallAfter(Realign_H(HeaderRef(als),new_sign));
else {

View File

@@ -2668,7 +2668,7 @@ SgStatement *RTL_GPU_Init()
SgCallStmt *call = new SgCallStmt(*fdvm[DVMH_INIT]);
fmask[DVMH_INIT] = 2;
call -> addArg(*DVM000(ndvm));
if(!only_debug && ACC_program)
if(!only_debug && (ACC_program || parloop_by_handler))
call -> addComment(OpenMpComment_InitFlags(ndvm));
int flag = 1;

View File

@@ -282,7 +282,7 @@ void EndOfParallelLoopNest(SgStatement *stmt, SgStatement *end_stmt, SgStatement
ConsistentArraysStart(cons_list);
if(iconsg) {//there is synchronous CONSISTENT clause in PARALLEL
if(IN_COMPUTE_REGION || parloop_by_handler) /*ACC*/
if(IN_COMPUTE_REGION) /*ACC*/
// generating call statement:
// call dvmh_handle_consistent(ConsistGroupRef)
doCallAfter(HandleConsistent(consgref));
@@ -2227,6 +2227,8 @@ SgExpression *MappingList(SgStatement *stmt, SgExpression *aref)
(el = new SgExprListExp(*e))->setRhs(arglist);
arglist = el;
}
(el = new SgExprListExp(*ConstRef(nt)))->setRhs(arglist); // add rank to axis list
arglist = el;
return arglist;
}

View File

@@ -1,64 +1,49 @@
#pragma once
#include "acc_data.h"
struct SageStOp
{
SgForStmt *loop_op;
SgStatement *comment_op;
SageStOp *inner_loops;
SageStOp *next;
int count_inner_loops;
int line_code;
int numChList1;
int numChList2;
int depth;
int LoopNest;
};
struct SageSymbols
{
SageSymbols()
{
across_left = across_right = 0;
len = -1;
symb = NULL;
}
SageSymbols(SgSymbol* symb, int len, int across_left, int across_right) :
symb(symb), len(len), across_left(across_left), across_right(across_right)
{ }
SgSymbol *symb;
int len;
SageSymbols *next;
int across_left;
int across_right;
};
struct SageArrayIdxs
{
SageSymbols **symb;
std::vector<SageSymbols> symb;
int dim;
int read_write;
SgExpression *array_expr;
SageArrayIdxs *next;
};
struct Templates
{
SageSymbols *first;
int count;
int read_write;
int count_write_read;
Templates *next;
};
struct SageAcrossInfo
{
SageStOp *Op;
SageArrayIdxs *idx;
SageAcrossInfo *next;
std::vector<SageArrayIdxs> idxs;
};
struct ArgsForKernel
{
SgStatement *st_header;
std::list<SageSymbols*> symb;
std::list<SageSymbols*> nSymb;
std::list<SgSymbol*> sizeVars;
std::list<SgSymbol*> acrossS;
std::list<SgSymbol*> notAcrS;
std::list<SgSymbol*> idxAcross;
std::list<SgSymbol*> idxNotAcross;
std::vector<SageSymbols> symb;
std::vector<SageSymbols> nSymb;
std::vector<SgSymbol*> sizeVars;
std::vector<SgSymbol*> acrossS;
std::vector<SgSymbol*> notAcrossS;
std::vector<SgSymbol*> idxAcross;
std::vector<SgSymbol*> idxNotAcross;
std::vector<SgSymbol*> otherVars;
std::vector<char*> arrayNames;
std::vector<SgSymbol*> otherVarsForOneTh;
@@ -96,8 +81,8 @@ struct ParamsForAllVariants
int loopV;
int acrossV;
int allDims;
SageSymbols **loopSymb;
SageSymbols **loopAcrossSymb;
std::vector<SageSymbols> loopSymb;
std::vector<SageSymbols> loopAcrossSymb;
char *nameOfNewSAdapter;
char *nameOfNewKernelSymb;
int type;
@@ -217,7 +202,6 @@ struct AnalyzeReturnGpuO1
// functions
SgExpression* findDirect(SgExpression*, int);
//SageArrayIdxs* GetIdxInParDir(SgExpression*, SgExpression*);
SageAcrossInfo* GetLoopsWithParAndAcrDir();
SageSymbols *GetSymbInParalell(int*, SgExpression*);
SageAcrossInfo GetLoopsWithParAndAcrDir();
std::vector<SageSymbols> GetSymbInParalell(SgExpression*);
int GetIdxPlaceInParDir(SageSymbols*, SgSymbol*);

View File

@@ -321,7 +321,8 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
//TODO: add freeForm for each file
if (curr_regime == INSERT_INCLUDES && filesToInclude.find(file_name) != filesToInclude.end())
{
unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile, moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString, true); //,
unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile,
moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString, true);
auto itI = filesToInclude.find(file_name);
for (auto& incl : itI->second)
if (allIncludeFiles.find(incl) != allIncludeFiles.end())
@@ -329,7 +330,8 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
}
else
{
unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile, moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString);
unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile,
moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString);
// copy includes that have not changed
if (folderName != NULL)
@@ -995,6 +997,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
fileIt->second.insert(first->fileName());
}
}
if (inlcudeAllFiles)
if (fileIt->second.size())
filesToInclude[file_name] = fileIt->second;
}
else if (curr_regime == REMOVE_AND_CALC_SHADOW)
{
@@ -2825,6 +2831,8 @@ int main(int argc, char **argv)
debSh = 1;
else if (string(curr_arg) == "-noLogo")
noLogo = true;
else if (string(curr_arg) == "-includeAll")
inlcudeAllFiles = true;
break;
default:
break;

View File

@@ -46,6 +46,7 @@ bool ignoreArrayDistributeState = false;
bool fullDepGraph = false;
bool noLogo = false;
bool withTemplateInfo = false;
bool inlcudeAllFiles = false; // for pass INSERT_INLCUDES
uint64_t currentAvailMemory = 0;
int QUALITY; // quality of conflicts search in graph
@@ -82,7 +83,7 @@ std::map<std::string, std::map<int, std::set<std::string>>> commentsToInclude;
//
//for INSERT_INCLUDES
std::map<std::string, std::set<std::string>> filesToInclude;
std::map<std::string, std::set<std::string>> filesToInclude; // file -> includes
//
//for PASSES DEPENDENSIES

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2256"
#define VERSION_SPF "2257"