arrayJson #56

Merged
Alexander_KS merged 6 commits from arrayJson into master 2025-05-18 15:32:13 +00:00
6 changed files with 144 additions and 102 deletions

View File

@@ -9,6 +9,7 @@
#include "DvmhDirectiveBase.h" #include "DvmhDirectiveBase.h"
#include "../Utils/utils.h" #include "../Utils/utils.h"
#include "../Utils/errors.h" #include "../Utils/errors.h"
#include "../Utils/json.hpp"
class Symbol; class Symbol;
class Expression; class Expression;
@@ -20,6 +21,7 @@ struct FuncInfo;
#define MAP std::map #define MAP std::map
#define SET std::set #define SET std::set
#define TO_STR std::to_string #define TO_STR std::to_string
#define JSON nlohmann::json
#if __SPF #if __SPF
extern int sharedMemoryParallelization; extern int sharedMemoryParallelization;
@@ -104,7 +106,7 @@ namespace Distribution
MAP<STRING, SET<int>> usagePlaces; MAP<STRING, SET<int>> usagePlaces;
VECTOR<bool> mappedDims; VECTOR<bool> mappedDims;
VECTOR<bool> depracateToDistribute; VECTOR<bool> deprecateToDistribute;
bool ompThreadPrivate; bool ompThreadPrivate;
bool privateInLoop; bool privateInLoop;
@@ -169,7 +171,7 @@ namespace Distribution
sizes.resize(dimSize); sizes.resize(dimSize);
sizesExpr.resize(dimSize); sizesExpr.resize(dimSize);
mappedDims.resize(dimSize); mappedDims.resize(dimSize);
depracateToDistribute.resize(dimSize); deprecateToDistribute.resize(dimSize);
for (int z = 0; z < dimSize; ++z) for (int z = 0; z < dimSize; ++z)
{ {
@@ -177,7 +179,7 @@ namespace Distribution
PAIR<int, int> initVal = std::make_pair(0, 0); PAIR<int, int> initVal = std::make_pair(0, 0);
sizesExpr[z] = std::make_pair(std::make_pair((Expression*)NULL, initVal), std::make_pair((Expression*)NULL, initVal)); sizesExpr[z] = std::make_pair(std::make_pair((Expression*)NULL, initVal), std::make_pair((Expression*)NULL, initVal));
mappedDims[z] = false; mappedDims[z] = false;
depracateToDistribute[z] = false; deprecateToDistribute[z] = false;
} }
GenUniqKey(); GenUniqKey();
@@ -212,7 +214,7 @@ namespace Distribution
uniqKey = copy.uniqKey; uniqKey = copy.uniqKey;
containsInRegions = copy.containsInRegions; containsInRegions = copy.containsInRegions;
mappedDims = copy.mappedDims; mappedDims = copy.mappedDims;
depracateToDistribute = copy.depracateToDistribute; deprecateToDistribute = copy.deprecateToDistribute;
ompThreadPrivate = copy.ompThreadPrivate; ompThreadPrivate = copy.ompThreadPrivate;
privateInLoop = copy.privateInLoop; privateInLoop = copy.privateInLoop;
inEquivalence = copy.inEquivalence; inEquivalence = copy.inEquivalence;
@@ -224,7 +226,7 @@ namespace Distribution
int countToRem = 0; int countToRem = 0;
for (int z = 0; z < dimSize; ++z) for (int z = 0; z < dimSize; ++z)
{ {
if (!mappedDims[z] || depracateToDistribute[z]) if (!mappedDims[z] || deprecateToDistribute[z])
{ {
needToRemove = true; needToRemove = true;
countToRem++; countToRem++;
@@ -244,19 +246,19 @@ namespace Distribution
for (int z = 0; z < dimSize; ++z) for (int z = 0; z < dimSize; ++z)
{ {
if (mappedDims[z] && !depracateToDistribute[z]) if (mappedDims[z] && !deprecateToDistribute[z])
{ {
newSizes.push_back(sizes[z]); newSizes.push_back(sizes[z]);
newSizesExpr.push_back(sizesExpr[z]); newSizesExpr.push_back(sizesExpr[z]);
newMappedDims.push_back(mappedDims[z]); newMappedDims.push_back(mappedDims[z]);
newDepr.push_back(depracateToDistribute[z]); newDepr.push_back(deprecateToDistribute[z]);
} }
} }
sizes = newSizes; sizes = newSizes;
sizesExpr = newSizesExpr; sizesExpr = newSizesExpr;
mappedDims = newMappedDims; mappedDims = newMappedDims;
depracateToDistribute = newDepr; deprecateToDistribute = newDepr;
dimSize = (int)sizes.size(); dimSize = (int)sizes.size();
return false; return false;
@@ -424,48 +426,64 @@ namespace Distribution
void ClearShadowSpecs() { allShadowSpecs.clear(); } void ClearShadowSpecs() { allShadowSpecs.clear(); }
STRING toString() JSON toJson()
{ {
STRING retVal = ""; JSON retVal;
retVal += TO_STR(id);
retVal += "#" + name;
retVal += "#" + shortName;
retVal += "#" + TO_STR(dimSize);
retVal += "#" + TO_STR(typeSize);
retVal += "#" + TO_STR(isNonDistribute);
retVal += "#" + TO_STR(locationPos.first);
retVal += "#" + locationPos.second;
retVal += "#" + TO_STR(sizes.size()); retVal["id"] = (int64_t)id;
for (int i = 0; i < sizes.size(); ++i) retVal["name"] = name;
retVal += "#" + TO_STR(sizes[i].first) + "#" + TO_STR(sizes[i].second); retVal["shortName"] = shortName;
retVal["packedAddress"] = std::to_string((long long)this);
retVal += "#" + TO_STR(depracateToDistribute.size()); retVal["dimSize"] = dimSize;
for (int i = 0; i < depracateToDistribute.size(); ++i) retVal["typeSize"] = typeSize;
retVal += "#" + TO_STR((int)depracateToDistribute[i]); retVal["state"] = (int)isNonDistribute;
retVal["location"] = (int)locationPos.first;
retVal["locName"] = locationPos.second;
retVal += "#" + TO_STR(mappedDims.size()); retVal["isTemplFlag"] = (int)isTemplFlag;
retVal["isLoopArrayFlag"] = (int)isLoopArrayFlag;
JSON deprToDist = nlohmann::json::array();
for (int i = 0; i < deprecateToDistribute.size(); ++i)
deprToDist.push_back((int)deprecateToDistribute[i]);
retVal["deprecateToDist"] = deprToDist;
JSON mappedDimsJ = nlohmann::json::array();
for (int i = 0; i < mappedDims.size(); ++i) 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()); JSON sizesJ = nlohmann::json::array();
for (auto it = templateInfo.begin(); it != templateInfo.end(); ++it) for (int i = 0; i < sizes.size(); ++i)
retVal += "#" + TO_STR(it->first) + it->second->toString(); {
JSON pair;
retVal += "#" + TO_STR((int)isTemplFlag); pair["key"] = sizes[i].first;
retVal += "|" + TO_STR((int)isLoopArrayFlag); pair["value"] = sizes[i].second;
retVal += "|" + TO_STR(declPlaces.size()); sizesJ.push_back(pair);
}
retVal["sizes"] = sizesJ;
for (auto &place : declPlaces) JSON regions = nlohmann::json::array();
retVal += "|" + place.first + "|" + TO_STR(place.second); for (auto& reg : containsInRegions)
regions.push_back(reg);
retVal["regions"] = regions;
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;
retVal += "|" + TO_STR(containsInRegions.size());
for (auto &reg : containsInRegions)
retVal += "|" + reg;
return retVal; return retVal;
} }
Array* GetTemplateArray(const uint64_t regionId, bool withCheck = true) Array* GetTemplateArray(const uint64_t regionId, bool withCheck = true)
{ {
TemplateLink *currLink = getTemlateInfo(regionId, withCheck); TemplateLink *currLink = getTemlateInfo(regionId, withCheck);
@@ -587,13 +605,13 @@ namespace Distribution
{ {
if (dim >= dimSize) if (dim >= dimSize)
return; return;
depracateToDistribute[dim] = value; deprecateToDistribute[dim] = value;
} }
void DeprecateAllDims() void DeprecateAllDims()
{ {
for (int dim = 0; dim < dimSize; ++dim) for (int dim = 0; dim < dimSize; ++dim)
depracateToDistribute[dim] = true; deprecateToDistribute[dim] = true;
} }
bool IsDimDepracated(const int dim) const bool IsDimDepracated(const int dim) const
@@ -603,9 +621,9 @@ namespace Distribution
else else
{ {
if (templateDimsOrder.size() == 0) if (templateDimsOrder.size() == 0)
return depracateToDistribute[dim]; return deprecateToDistribute[dim];
else else
return depracateToDistribute[templateDimsOrder[dim]]; return deprecateToDistribute[templateDimsOrder[dim]];
} }
} }
@@ -613,11 +631,11 @@ namespace Distribution
{ {
bool ret = true; bool ret = true;
for (int z = 0; z < dimSize; ++z) for (int z = 0; z < dimSize; ++z)
ret = ret && depracateToDistribute[z]; ret = ret && deprecateToDistribute[z];
return ret; return ret;
} }
const VECTOR<bool>& GetDeprecetedDims() const { return depracateToDistribute; } const VECTOR<bool>& GetDeprecetedDims() const { return deprecateToDistribute; }
int GetTypeSize() const { return typeSize; } int GetTypeSize() const { return typeSize; }

View File

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

View File

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

View File

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

View File

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

View File

@@ -766,15 +766,17 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho
else else
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
string resVal = ""; json regions = json::array();
resVal += to_string(parallelRegions.size()); for (auto& reg : parallelRegions)
for (int i = 0; i < parallelRegions.size(); ++i) {
resVal += parallelRegions[i]->toString(); json currReg = reg->toJson();
regions.push_back(currReg);
}
//__spf_print(1, "==============\n"); json allRegions;
//__spf_print(1, "%s\n", resVal.c_str()); allRegions["allRegions"] = regions;
//__spf_print(1, "==============\n");
string resVal = allRegions.dump();
copyStringToShort(result, resVal); copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1; retSize = (int)resVal.size() + 1;
} }
@@ -1419,14 +1421,17 @@ int SPF_GetAllDeclaratedArrays(void*& context, int winHandler, short *options, s
{ {
runPassesForVisualizer(projName, { GET_ALL_ARRAY_DECL }); runPassesForVisualizer(projName, { GET_ALL_ARRAY_DECL });
string resVal = ""; json arrays = json::array();
for (auto f = declaredArrays.begin(); f != declaredArrays.end(); ++f) for (const auto& [_, array] : declaredArrays)
{ {
if (f != declaredArrays.begin()) json jArray = array.first->toJson();
resVal += "@"; arrays.push_back(jArray);
resVal += f->second.first->toString();
} }
json allArrays;
allArrays["allArrays"] = arrays;
string resVal = allArrays.dump();
copyStringToShort(result, resVal); copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1; retSize = (int)resVal.size() + 1;
} }