2 Commits

Author SHA1 Message Date
ALEXks
a241d1ec45 added json for SPF_GetArrayDistribution pass 2025-05-17 18:49:46 +03:00
ALEXks
d06f360cf6 added json for SPF_GetAllDeclaratedArrays pass 2025-05-11 08:33:50 +03:00
6 changed files with 127 additions and 88 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;
@@ -424,48 +426,63 @@ 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 += "#" + TO_STR(depracateToDistribute.size()); retVal["dimSize"] = dimSize;
retVal["typeSize"] = typeSize;
retVal["state"] = (int)isNonDistribute;
retVal["location"] = (int)locationPos.first;
retVal["locName"] = locationPos.second;
retVal["isTemplFlag"] = (int)isTemplFlag;
retVal["isLoopArrayFlag"] = (int)isLoopArrayFlag;
JSON deprToDist = nlohmann::json::array();
for (int i = 0; i < depracateToDistribute.size(); ++i) 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) 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);

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,32 @@ 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;
retVal += "#" + std::to_string(alignRule.size()); pair["value"] = rule.second;
for (int i = 0; i < alignRule.size(); ++i) alignRules.push_back(pair);
retVal += "#" + std::to_string(alignRule[i].first) + "#" + std::to_string(alignRule[i].second); }
retVal["alignRule"] = alignRules;
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;
}
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 "2416" #define VERSION_SPF "2417"

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 allRegionsV = 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();
allRegionsV.push_back(currReg);
}
//__spf_print(1, "==============\n"); json allRegions;
//__spf_print(1, "%s\n", resVal.c_str()); allRegions["allRegions"] = allRegionsV;
//__spf_print(1, "==============\n");
string resVal = allRegions.dump();
copyStringToShort(result, resVal); copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1; retSize = (int)resVal.size() + 1;
} }
@@ -1416,14 +1418,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;
} }