From 719e3723aea64353ba62e54cef777a407e36da8f Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sun, 11 May 2025 08:33:50 +0300 Subject: [PATCH 1/6] added json for SPF_GetAllDeclaratedArrays pass --- src/Distribution/Array.h | 60 +++++++++++++++++++++++++ src/VisualizerCalls/get_information.cpp | 13 +++--- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/Distribution/Array.h b/src/Distribution/Array.h index 4d56db1..dd9f615 100644 --- a/src/Distribution/Array.h +++ b/src/Distribution/Array.h @@ -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,6 +426,7 @@ namespace Distribution void ClearShadowSpecs() { allShadowSpecs.clear(); } + //TODO: to remove STRING toString() { STRING retVal = ""; @@ -466,6 +469,63 @@ namespace Distribution return retVal; } + JSON toJson() + { + JSON retVal; + + retVal["id"] = (int64_t)id; + retVal["name"] = name; + retVal["shortName"] = shortName; + + 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) + deprToDist.push_back((int)depracateToDistribute[i]); + retVal["depracateToDist"] = deprToDist; + + JSON mappedDimsJ = nlohmann::json::array(); + for (int i = 0; i < mappedDims.size(); ++i) + mappedDimsJ.push_back((int)mappedDims[i]); + retVal["mappedDims"] = mappedDimsJ; + + 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; + + JSON regions = nlohmann::json::array(); + 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; + + return retVal; + } + Array* GetTemplateArray(const uint64_t regionId, bool withCheck = true) { TemplateLink *currLink = getTemlateInfo(regionId, withCheck); diff --git a/src/VisualizerCalls/get_information.cpp b/src/VisualizerCalls/get_information.cpp index eb945f3..c8a11a7 100644 --- a/src/VisualizerCalls/get_information.cpp +++ b/src/VisualizerCalls/get_information.cpp @@ -1419,14 +1419,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; } -- 2.49.1 From bcecd5460b9dcabbae604209ace457e7b1839c11 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sat, 17 May 2025 18:49:46 +0300 Subject: [PATCH 2/6] added json for SPF_GetArrayDistribution pass --- src/Distribution/Array.h | 43 ------------------- src/Distribution/DvmhDirectiveBase.cpp | 46 ++++++++++++--------- src/Distribution/DvmhDirectiveBase.h | 4 +- src/ParallelizationRegions/ParRegions.h | 55 ++++++++++++++----------- src/VisualizerCalls/get_information.cpp | 16 +++---- 5 files changed, 70 insertions(+), 94 deletions(-) diff --git a/src/Distribution/Array.h b/src/Distribution/Array.h index dd9f615..a6cfc77 100644 --- a/src/Distribution/Array.h +++ b/src/Distribution/Array.h @@ -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 ® : containsInRegions) - retVal += "|" + reg; - return retVal; - } - JSON toJson() { JSON retVal; diff --git a/src/Distribution/DvmhDirectiveBase.cpp b/src/Distribution/DvmhDirectiveBase.cpp index 55b6586..996a105 100644 --- a/src/Distribution/DvmhDirectiveBase.cpp +++ b/src/Distribution/DvmhDirectiveBase.cpp @@ -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 static void uniteSets(const set &first, const set &second, set &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; } diff --git a/src/Distribution/DvmhDirectiveBase.h b/src/Distribution/DvmhDirectiveBase.h index 5d0ac07..d3c98a7 100644 --- a/src/Distribution/DvmhDirectiveBase.h +++ b/src/Distribution/DvmhDirectiveBase.h @@ -3,6 +3,8 @@ #include #include +#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> attrType; @@ -48,7 +50,7 @@ public: public: std::string GenRuleBase() const; - std::string toString(); + nlohmann::json toJson(); public: DIST::Array *alignArray; diff --git a/src/ParallelizationRegions/ParRegions.h b/src/ParallelizationRegions/ParRegions.h index 97a4a50..fc72c3d 100644 --- a/src/ParallelizationRegions/ParRegions.h +++ b/src/ParallelizationRegions/ParRegions.h @@ -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 &arrays = allArrays.GetArrays(); - retVal += "#" + std::to_string(arrays.size()); - - //create map - 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; } diff --git a/src/VisualizerCalls/get_information.cpp b/src/VisualizerCalls/get_information.cpp index c8a11a7..fcab5f8 100644 --- a/src/VisualizerCalls/get_information.cpp +++ b/src/VisualizerCalls/get_information.cpp @@ -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; } -- 2.49.1 From 4614e166b4ce2e4b47fc2a21b42d8c7b82d6f147 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sat, 17 May 2025 18:51:35 +0300 Subject: [PATCH 3/6] version updated --- src/Utils/version.h | 2 +- src/VisualizerCalls/get_information.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Utils/version.h b/src/Utils/version.h index 2fc9463..e5e1b0e 100644 --- a/src/Utils/version.h +++ b/src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2419" +#define VERSION_SPF "2420" diff --git a/src/VisualizerCalls/get_information.cpp b/src/VisualizerCalls/get_information.cpp index fcab5f8..9d73c1b 100644 --- a/src/VisualizerCalls/get_information.cpp +++ b/src/VisualizerCalls/get_information.cpp @@ -766,15 +766,15 @@ int SPF_GetArrayDistribution(void*& context, int winHandler, short *options, sho else printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - json allRegionsV = json::array(); + json regions = json::array(); for (auto& reg : parallelRegions) { json currReg = reg->toJson(); - allRegionsV.push_back(currReg); + regions.push_back(currReg); } json allRegions; - allRegions["allRegions"] = allRegionsV; + allRegions["allRegions"] = regions; string resVal = allRegions.dump(); copyStringToShort(result, resVal); -- 2.49.1 From 81725651b19c0b51d7776b4c59d8ba6303775e62 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sun, 18 May 2025 14:51:37 +0300 Subject: [PATCH 4/6] fixed Array::toJson() --- src/Distribution/Array.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Distribution/Array.h b/src/Distribution/Array.h index a6cfc77..67ac43b 100644 --- a/src/Distribution/Array.h +++ b/src/Distribution/Array.h @@ -433,6 +433,7 @@ namespace Distribution retVal["id"] = (int64_t)id; retVal["name"] = name; retVal["shortName"] = shortName; + retVal["packedAddress"] = std::to_string((long long)this); retVal["dimSize"] = dimSize; retVal["typeSize"] = typeSize; -- 2.49.1 From 0fe97ceb24726f3df38c41a7a176b71edd750dc4 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sun, 18 May 2025 15:12:59 +0300 Subject: [PATCH 5/6] fixed AlignRuleBase::toJson() --- src/Distribution/DvmhDirectiveBase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Distribution/DvmhDirectiveBase.cpp b/src/Distribution/DvmhDirectiveBase.cpp index 996a105..28576a8 100644 --- a/src/Distribution/DvmhDirectiveBase.cpp +++ b/src/Distribution/DvmhDirectiveBase.cpp @@ -760,6 +760,8 @@ json AlignRuleBase::toJson() tuple["dimNum"] = dimNum; tuple["a"] = AB.first; tuple["b"] = AB.second; + + alignRuleWithJ.push_back(tuple); } retVal["alignRuleWith"] = alignRuleWithJ; return retVal; -- 2.49.1 From 718b1738a11d3fe2559d95e8bbbd51fa2ce6035e Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sun, 18 May 2025 16:42:38 +0300 Subject: [PATCH 6/6] fixed typo --- src/Distribution/Array.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Distribution/Array.h b/src/Distribution/Array.h index 67ac43b..8f77faf 100644 --- a/src/Distribution/Array.h +++ b/src/Distribution/Array.h @@ -106,7 +106,7 @@ namespace Distribution MAP> usagePlaces; VECTOR mappedDims; - VECTOR depracateToDistribute; + VECTOR deprecateToDistribute; bool ompThreadPrivate; bool privateInLoop; @@ -171,7 +171,7 @@ namespace Distribution sizes.resize(dimSize); sizesExpr.resize(dimSize); mappedDims.resize(dimSize); - depracateToDistribute.resize(dimSize); + deprecateToDistribute.resize(dimSize); for (int z = 0; z < dimSize; ++z) { @@ -179,7 +179,7 @@ namespace Distribution PAIR initVal = std::make_pair(0, 0); sizesExpr[z] = std::make_pair(std::make_pair((Expression*)NULL, initVal), std::make_pair((Expression*)NULL, initVal)); mappedDims[z] = false; - depracateToDistribute[z] = false; + deprecateToDistribute[z] = false; } GenUniqKey(); @@ -214,7 +214,7 @@ namespace Distribution uniqKey = copy.uniqKey; containsInRegions = copy.containsInRegions; mappedDims = copy.mappedDims; - depracateToDistribute = copy.depracateToDistribute; + deprecateToDistribute = copy.deprecateToDistribute; ompThreadPrivate = copy.ompThreadPrivate; privateInLoop = copy.privateInLoop; inEquivalence = copy.inEquivalence; @@ -226,7 +226,7 @@ namespace Distribution int countToRem = 0; for (int z = 0; z < dimSize; ++z) { - if (!mappedDims[z] || depracateToDistribute[z]) + if (!mappedDims[z] || deprecateToDistribute[z]) { needToRemove = true; countToRem++; @@ -246,19 +246,19 @@ namespace Distribution for (int z = 0; z < dimSize; ++z) { - if (mappedDims[z] && !depracateToDistribute[z]) + if (mappedDims[z] && !deprecateToDistribute[z]) { newSizes.push_back(sizes[z]); newSizesExpr.push_back(sizesExpr[z]); newMappedDims.push_back(mappedDims[z]); - newDepr.push_back(depracateToDistribute[z]); + newDepr.push_back(deprecateToDistribute[z]); } } sizes = newSizes; sizesExpr = newSizesExpr; mappedDims = newMappedDims; - depracateToDistribute = newDepr; + deprecateToDistribute = newDepr; dimSize = (int)sizes.size(); return false; @@ -445,9 +445,9 @@ namespace Distribution retVal["isLoopArrayFlag"] = (int)isLoopArrayFlag; JSON deprToDist = nlohmann::json::array(); - for (int i = 0; i < depracateToDistribute.size(); ++i) - deprToDist.push_back((int)depracateToDistribute[i]); - retVal["depracateToDist"] = deprToDist; + 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) @@ -605,13 +605,13 @@ namespace Distribution { if (dim >= dimSize) return; - depracateToDistribute[dim] = value; + deprecateToDistribute[dim] = value; } void DeprecateAllDims() { for (int dim = 0; dim < dimSize; ++dim) - depracateToDistribute[dim] = true; + deprecateToDistribute[dim] = true; } bool IsDimDepracated(const int dim) const @@ -621,9 +621,9 @@ namespace Distribution else { if (templateDimsOrder.size() == 0) - return depracateToDistribute[dim]; + return deprecateToDistribute[dim]; else - return depracateToDistribute[templateDimsOrder[dim]]; + return deprecateToDistribute[templateDimsOrder[dim]]; } } @@ -631,11 +631,11 @@ namespace Distribution { bool ret = true; for (int z = 0; z < dimSize; ++z) - ret = ret && depracateToDistribute[z]; + ret = ret && deprecateToDistribute[z]; return ret; } - const VECTOR& GetDeprecetedDims() const { return depracateToDistribute; } + const VECTOR& GetDeprecetedDims() const { return deprecateToDistribute; } int GetTypeSize() const { return typeSize; } -- 2.49.1