7 Commits

Author SHA1 Message Date
ALEXks
0fe97ceb24 fixed AlignRuleBase::toJson() 2025-05-18 16:41:14 +03:00
ALEXks
81725651b1 fixed Array::toJson() 2025-05-18 16:41:14 +03:00
ALEXks
4614e166b4 version updated 2025-05-18 16:41:10 +03:00
ALEXks
bcecd5460b added json for SPF_GetArrayDistribution pass 2025-05-18 16:40:31 +03:00
ALEXks
719e3723ae added json for SPF_GetAllDeclaratedArrays pass 2025-05-18 16:40:31 +03:00
ALEXks
12d3c2c8e5 fixed NULL error in matchParallelAndDist function 2025-05-18 15:42:38 +03:00
ALEXks
a719dea05f fixed BUILD_INCLUDE_DEPENDENCIES pass 2025-05-18 15:38:26 +03:00
9 changed files with 158 additions and 110 deletions

View File

@@ -1601,7 +1601,7 @@ static bool matchParallelAndDist(const pair<DIST::Array*, const DistrVariant*>&
parallelOn = NULL;
for (auto& refOn : realRefs)
{
linkWithTempl = parallelOn->GetLinksWithTemplate(regionId);
linkWithTempl = refOn->GetLinksWithTemplate(regionId);
int z = 0;
for (int k = 0; k < linkWithTempl.size(); ++k)
if (linkWithTempl[k] != -1)

View File

@@ -9,6 +9,7 @@
#include "DvmhDirectiveBase.h"
#include "../Utils/utils.h"
#include "../Utils/errors.h"
#include "../Utils/json.hpp"
class Symbol;
class Expression;
@@ -20,6 +21,7 @@ struct FuncInfo;
#define MAP std::map
#define SET std::set
#define TO_STR std::to_string
#define JSON nlohmann::json
#if __SPF
extern int sharedMemoryParallelization;
@@ -424,45 +426,61 @@ namespace Distribution
void ClearShadowSpecs() { allShadowSpecs.clear(); }
STRING toString()
JSON toJson()
{
STRING retVal = "";
retVal += TO_STR(id);
retVal += "#" + name;
retVal += "#" + shortName;
retVal += "#" + TO_STR(dimSize);
retVal += "#" + TO_STR(typeSize);
retVal += "#" + TO_STR(isNonDistribute);
JSON retVal;
retVal += "#" + TO_STR(locationPos.first);
retVal += "#" + locationPos.second;
retVal["id"] = (int64_t)id;
retVal["name"] = name;
retVal["shortName"] = shortName;
retVal["packedAddress"] = std::to_string((long long)this);
retVal += "#" + TO_STR(sizes.size());
for (int i = 0; i < sizes.size(); ++i)
retVal += "#" + TO_STR(sizes[i].first) + "#" + TO_STR(sizes[i].second);
retVal["dimSize"] = dimSize;
retVal["typeSize"] = typeSize;
retVal["state"] = (int)isNonDistribute;
retVal["location"] = (int)locationPos.first;
retVal["locName"] = locationPos.second;
retVal += "#" + TO_STR(depracateToDistribute.size());
retVal["isTemplFlag"] = (int)isTemplFlag;
retVal["isLoopArrayFlag"] = (int)isLoopArrayFlag;
JSON deprToDist = nlohmann::json::array();
for (int i = 0; i < depracateToDistribute.size(); ++i)
retVal += "#" + TO_STR((int)depracateToDistribute[i]);
deprToDist.push_back((int)depracateToDistribute[i]);
retVal["depracateToDist"] = deprToDist;
retVal += "#" + TO_STR(mappedDims.size());
JSON mappedDimsJ = nlohmann::json::array();
for (int i = 0; i < mappedDims.size(); ++i)
retVal += "#" + TO_STR((int)mappedDims[i]);
mappedDimsJ.push_back((int)mappedDims[i]);
retVal["mappedDims"] = mappedDimsJ;
retVal += "#" + TO_STR(templateInfo.size());
for (auto it = templateInfo.begin(); it != templateInfo.end(); ++it)
retVal += "#" + TO_STR(it->first) + it->second->toString();
JSON sizesJ = nlohmann::json::array();
for (int i = 0; i < sizes.size(); ++i)
{
JSON pair;
pair["key"] = sizes[i].first;
pair["value"] = sizes[i].second;
sizesJ.push_back(pair);
}
retVal["sizes"] = sizesJ;
retVal += "#" + TO_STR((int)isTemplFlag);
retVal += "|" + TO_STR((int)isLoopArrayFlag);
retVal += "|" + TO_STR(declPlaces.size());
JSON regions = nlohmann::json::array();
for (auto& reg : containsInRegions)
regions.push_back(reg);
retVal["regions"] = regions;
for (auto &place : declPlaces)
retVal += "|" + place.first + "|" + TO_STR(place.second);
retVal += "|" + TO_STR(containsInRegions.size());
for (auto &reg : containsInRegions)
retVal += "|" + reg;
JSON declPlacesJ = nlohmann::json::array();
for (auto& place : declPlaces)
{
JSON elem;
elem["file"] = place.first;
elem["line"] = place.second;
declPlacesJ.push_back(elem);
}
retVal["declPlaces"] = declPlacesJ;
return retVal;
}

View File

@@ -12,6 +12,8 @@
#include "../Distribution/GraphCSR.h"
#include "../Utils/errors.h"
#include "../Utils/utils.h"
#include "../Utils/json.hpp"
#include "../GraphCall/graph_calls_func.h"
using std::vector;
@@ -27,6 +29,8 @@ using std::make_pair;
using std::min;
using std::max;
using nlohmann::json;
template<typename setT>
static void uniteSets(const set<setT> &first, const set<setT> &second, set<setT> &result)
{
@@ -732,30 +736,34 @@ string AlignRuleBase::GenRuleBase() const
return retVal;
}
string AlignRuleBase::toString()
json AlignRuleBase::toJson()
{
string retVal = "";
json retVal;
if (alignArray)
retVal += "#" + std::to_string((long long)alignArray);
else
retVal += "#-1";
retVal["packedAlignArrayAddress"] = alignArray ? std::to_string((long long)alignArray) : std::to_string((long long)-1);
retVal["packedAlignWithAddress"] = alignWith ? std::to_string((long long)alignWith) : std::to_string((long long)-1);
if (alignWith)
retVal += "#" + std::to_string((long long)alignWith);
else
retVal += "#-1";
json alignRules = json::array();
for (auto& rule : alignRule)
{
json pair;
pair["key"] = rule.first;
pair["value"] = rule.second;
alignRules.push_back(pair);
}
retVal["alignRule"] = alignRules;
retVal += "#" + std::to_string(alignRule.size());
for (int i = 0; i < alignRule.size(); ++i)
retVal += "#" + std::to_string(alignRule[i].first) + "#" + std::to_string(alignRule[i].second);
retVal += "#" + std::to_string(alignRuleWith.size());
for (int i = 0; i < alignRuleWith.size(); ++i)
retVal += "#" + std::to_string(alignRuleWith[i].first)
+ "#" + std::to_string(alignRuleWith[i].second.first)
+ "#" + std::to_string(alignRuleWith[i].second.second);
json alignRuleWithJ = json::array();
for (auto& [dimNum, AB] : alignRuleWith)
{
json tuple;
tuple["dimNum"] = dimNum;
tuple["a"] = AB.first;
tuple["b"] = AB.second;
alignRuleWithJ.push_back(tuple);
}
retVal["alignRuleWith"] = alignRuleWithJ;
return retVal;
}

View File

@@ -3,6 +3,8 @@
#include <vector>
#include <string>
#include "../Utils/json.hpp"
typedef enum lang : int { LANG_C, LANG_F } language;
typedef enum dist : int { BLOCK, NONE } distType;
typedef std::pair<std::pair<int, int>, std::pair<int, int>> attrType;
@@ -48,7 +50,7 @@ public:
public:
std::string GenRuleBase() const;
std::string toString();
nlohmann::json toJson();
public:
DIST::Array *alignArray;

View File

@@ -11,6 +11,8 @@
#include "../Distribution/Distribution.h"
#include "../Utils/AstWrapper.h"
#include "../Utils/json.hpp"
#if __SPF
#include "../Utils/SgUtils.h"
#endif
@@ -235,35 +237,42 @@ public:
return retVal;
}
std::string toString()
nlohmann::json toJson()
{
std::string retVal = "";
nlohmann::json retVal;
retVal += "#" + std::to_string(regionId);
retVal += "#" + originalName;
retVal += "#" + std::to_string(lines.size());
retVal["packedRegionId"] = std::to_string(regionId);
retVal["originalName"] = originalName;
for (auto it = lines.begin(); it != lines.end(); ++it)
nlohmann::json arrays = nlohmann::json::array();
for (auto& array : allArrays.GetArrays())
arrays.push_back(array->toJson());
retVal["packedArrays"] = arrays;
nlohmann::json linesInfo = nlohmann::json::array();
for (auto& [file, linesByFile] : lines)
{
retVal += "|" + it->first + "|";
retVal += std::to_string(it->second.size());
for (int i = 0; i < it->second.size(); ++i)
retVal += "#" + std::to_string(it->second[i].lines.first) + "#" + std::to_string(it->second[i].lines.second);
nlohmann::json linesRegs;
nlohmann::json lines = nlohmann::json::array();
for (auto& elem : linesByFile)
{
JSON pair;
pair["key"] = elem.lines.first;
pair["value"] = elem.lines.second;
lines.push_back(pair);
}
linesRegs["file"] = file;
linesRegs["lines"] = lines;
const std::set<DIST::Array*> &arrays = allArrays.GetArrays();
retVal += "#" + std::to_string(arrays.size());
//create map<array_address, DIST::Array_toString()>
for (auto it = arrays.begin(); it != arrays.end(); ++it)
{
retVal += "#" + std::to_string((long long)(*it));
retVal += "#" + (*it)->toString();
linesInfo.push_back(linesRegs);
}
retVal["regionsLines"] = linesInfo;
retVal += "#" + std::to_string(dataDirectives.alignRules.size());
for (int i = 0; i < dataDirectives.alignRules.size(); ++i)
retVal += dataDirectives.alignRules[i].toString();
nlohmann::json alignRules = nlohmann::json::array();
for (auto& rule : dataDirectives.alignRules)
alignRules.push_back(rule.toJson());
retVal["alignRules"] = alignRules;
return retVal;
}

View File

@@ -331,7 +331,8 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
unparseToBuf = removeIncludeStatsAndUnparse(file, file_name, fout_name.c_str(), allIncludeFiles, out_free_form == 1, moduleUsesByFile,
moduleDecls, getObjectForFileFromMap(file_name, exctactedModuleStats), toString, false, true);
auto itI = filesToInclude.find(file_name);
for (auto& [_, incl] : itI->second)
for (auto& [_, incls] : itI->second)
for (auto& incl : incls)
if (allIncludeFiles.find(incl) != allIncludeFiles.end())
allIncludeFiles.erase(incl);
}
@@ -827,7 +828,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
{
auto fileIt = includeDependencies.find(file_name);
if (fileIt == includeDependencies.end())
fileIt = includeDependencies.insert(fileIt, make_pair(file_name, vector<pair<int, string>>()));
fileIt = includeDependencies.insert(fileIt, make_pair(file_name, map<int, set<string>>()));
set<string> modFiles;
for (auto& elem : moduleDecls)
@@ -844,7 +845,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
{
if (lastFromFile == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
fileIt->second.push_back(make_pair(lastFromFile->lineNumber(), st->fileName()));
fileIt->second[lastFromFile->lineNumber()].insert(st->fileName());
}
else
lastFromFile = st;
@@ -1603,14 +1604,17 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
set<string> includedToThisFile;
if (itDep != includeDependencies.end())
{
for (auto& [_, incl] : itDep->second)
for (auto& [_, incls] : itDep->second)
{
for (auto& incl : incls)
{
auto comm = commentsToInclude.find(incl);
if (comm != commentsToInclude.end())
for (auto &allComm : comm->second)
for (auto& allComm : comm->second)
includedToThisFile.insert(allComm.second.begin(), allComm.second.end());
}
}
}
for (int z = 0; z < parallelRegions.size(); ++z)
{

View File

@@ -85,7 +85,7 @@ std::map<std::string, std::map<int, std::set<std::string>>> commentsToInclude;
//
//for INSERT_INCLUDES
std::map<std::string, std::vector<std::pair<int, std::string>>> filesToInclude; // file -> includes [nearest line, include]
std::map<std::string, std::map<int, std::set<std::string>>> filesToInclude; // file -> includes [nearest line, include]
//
//for PASSES DEPENDENSIES
@@ -96,7 +96,7 @@ std::set<passes> passesIgnoreStateDone;
//for files info
std::map<std::string, int> lineInfo; // file -> lines count
std::map<std::string, std::pair<std::set<int>, std::set<int>>> dirsInfo; // file -> dirs <lines SPF, lines DVM> count
std::map<std::string, std::vector<std::pair<int, std::string>>> includeDependencies; // file -> includes [nearest line, include]
std::map<std::string, std::map<int, std::set<std::string>>> includeDependencies; // file -> includes [nearest line, include]
std::vector<std::string> filesCompilationOrder; // order of files for unite to one file
std::map<std::string, std::map<SgStatement*, std::vector<SgStatement*>>> exctactedModuleStats; // file -> hided excluded modules
//

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2417"
#define VERSION_SPF "2420"

View File

@@ -766,15 +766,17 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho
else
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
string resVal = "";
resVal += to_string(parallelRegions.size());
for (int i = 0; i < parallelRegions.size(); ++i)
resVal += parallelRegions[i]->toString();
json regions = json::array();
for (auto& reg : parallelRegions)
{
json currReg = reg->toJson();
regions.push_back(currReg);
}
//__spf_print(1, "==============\n");
//__spf_print(1, "%s\n", resVal.c_str());
//__spf_print(1, "==============\n");
json allRegions;
allRegions["allRegions"] = regions;
string resVal = allRegions.dump();
copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1;
}
@@ -1308,7 +1310,7 @@ int SPF_GetIntrinsics(void*& context, short *&result)
return (int)resVal.size() + 1;
}
extern map<string, vector<pair<int, string>>> includeDependencies;
extern map<string, map<int, set<string>>> includeDependencies;
int SPF_GetIncludeDependencies(void*& context, int winHandler, short *options, short *projName, short *&result, short*& output, int*& outputSize,
short*& outputMessage, int*& outputMessageSize)
{
@@ -1328,13 +1330,16 @@ int SPF_GetIncludeDependencies(void*& context, int winHandler, short *options, s
includes["file"] = deps.first;
json array = json::array();
for (const auto& [line, incl] : deps.second)
for (const auto& [line, incls] : deps.second)
{
for (auto& incl : incls)
{
json elem;
elem["line"] = line;
elem["dependencyFileName"] = incl;
array.push_back(elem);
}
}
includes["includes"] = array;
inc_array.push_back(includes);
}
@@ -1416,14 +1421,17 @@ int SPF_GetAllDeclaratedArrays(void*& context, int winHandler, short *options, s
{
runPassesForVisualizer(projName, { GET_ALL_ARRAY_DECL });
string resVal = "";
for (auto f = declaredArrays.begin(); f != declaredArrays.end(); ++f)
json arrays = json::array();
for (const auto& [_, array] : declaredArrays)
{
if (f != declaredArrays.begin())
resVal += "@";
resVal += f->second.first->toString();
json jArray = array.first->toJson();
arrays.push_back(jArray);
}
json allArrays;
allArrays["allArrays"] = arrays;
string resVal = allArrays.dump();
copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1;
}
@@ -2189,7 +2197,7 @@ int SPF_InlineProcedures(void*& context, int winHandler, short* options, short*
}
extern map<string, vector<pair<int, string>>> filesToInclude;
extern map<string, map<int, set<string>>> filesToInclude;
int SPF_InsertIncludesPass(void*& context, int winHandler, short *options, short *projName, short *folderName, char *visFilesToInclude,
short *&output, int *&outputSize, short *&outputMessage, int *&outputMessageSize)
{
@@ -2222,9 +2230,8 @@ int SPF_InsertIncludesPass(void*& context, int winHandler, short *options, short
if (sscanf(splited[k].c_str(), "%d", &line) == -1)
return -5;
auto pair = make_pair(line, splited[k + 1]);
filesToInclude[file].push_back(pair);
__spf_print(1, " include = [%d %s]\n", pair.first, pair.second.c_str());
filesToInclude[file][line].insert(splited[k + 1]);
__spf_print(1, " include = [%d %s]\n", line, splited[k + 1].c_str());
}
i += 2 * num;
}