arrayJson #56

Merged
Alexander_KS merged 6 commits from arrayJson into master 2025-05-18 15:32:13 +00:00
5 changed files with 70 additions and 94 deletions
Showing only changes of commit bcecd5460b - Show all commits

View File

@@ -426,49 +426,6 @@ namespace Distribution
void ClearShadowSpecs() { allShadowSpecs.clear(); }
//TODO: to remove
STRING toString()
{
STRING 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());
for (int i = 0; i < sizes.size(); ++i)
retVal += "#" + TO_STR(sizes[i].first) + "#" + TO_STR(sizes[i].second);
retVal += "#" + TO_STR(depracateToDistribute.size());
for (int i = 0; i < depracateToDistribute.size(); ++i)
retVal += "#" + TO_STR((int)depracateToDistribute[i]);
retVal += "#" + TO_STR(mappedDims.size());
for (int i = 0; i < mappedDims.size(); ++i)
retVal += "#" + TO_STR((int)mappedDims[i]);
retVal += "#" + TO_STR(templateInfo.size());
for (auto it = templateInfo.begin(); it != templateInfo.end(); ++it)
retVal += "#" + TO_STR(it->first) + it->second->toString();
retVal += "#" + TO_STR((int)isTemplFlag);
retVal += "|" + TO_STR((int)isLoopArrayFlag);
retVal += "|" + TO_STR(declPlaces.size());
for (auto &place : declPlaces)
retVal += "|" + place.first + "|" + TO_STR(place.second);
retVal += "|" + TO_STR(containsInRegions.size());
for (auto &reg : containsInRegions)
retVal += "|" + reg;
return retVal;
}
JSON toJson()
{
JSON 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,32 @@ 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";
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 alignRules = json::array();
for (auto& rule : alignRule)
{
json pair;
pair["key"] = rule.first;
pair["value"] = rule.second;
alignRules.push_back(pair);
}
retVal["alignRule"] = alignRules;
json alignRuleWithJ = json::array();
for (auto& [dimNum, AB] : alignRuleWith)
{
json tuple;
tuple["dimNum"] = dimNum;
tuple["a"] = AB.first;
tuple["b"] = AB.second;
}
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;
linesInfo.push_back(linesRegs);
}
retVal["regionsLines"] = linesInfo;
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();
}
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

@@ -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 allRegionsV = json::array();
for (auto& reg : parallelRegions)
{
json currReg = reg->toJson();
allRegionsV.push_back(currReg);
}
//__spf_print(1, "==============\n");
//__spf_print(1, "%s\n", resVal.c_str());
//__spf_print(1, "==============\n");
json allRegions;
allRegions["allRegions"] = allRegionsV;
string resVal = allRegions.dump();
copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1;
}