added json for SPF_CreateParallelVariant pass

This commit is contained in:
ALEXks
2025-05-20 16:20:27 +03:00
parent 4bcf83f551
commit b1eeac0b10
3 changed files with 30 additions and 60 deletions

View File

@@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include "dvm.h" #include "dvm.h"
#include "../GraphCall/graph_calls.h" #include "../GraphCall/graph_calls.h"
#include "../Utils/json.hpp"
class ParallelStats class ParallelStats
{ {
@@ -11,10 +12,10 @@ public:
RemoteCount = ShadowCount = ReductionCount = AcrossCount = 0; RemoteCount = ShadowCount = ReductionCount = AcrossCount = 0;
} }
int RemoteCount; int RemoteCount = 0;
int ShadowCount; int ShadowCount = 0;
int ReductionCount; int ReductionCount = 0;
int AcrossCount; int AcrossCount = 0;
}; };
class PredictorStats class PredictorStats
@@ -27,28 +28,32 @@ public:
} }
ParallelStats ParallelStat; ParallelStats ParallelStat;
int ParallelCount; int ParallelCount = 0;
int RemoteCount; int RemoteCount = 0;
int RedistributeCount; int RedistributeCount = 0;
int IntervalCount; int IntervalCount = 0;
int TotalScoreComm; int TotalScoreComm = 0;
int TotalScorePar; int TotalScorePar = 0;
int TotalScoreDist; int TotalScoreDist = 0;
std::string to_string() nlohmann::json toJson()
{ {
std::string res = ""; nlohmann::json stat;
res += std::to_string(ParallelCount) + "|";
res += std::to_string(RemoteCount) + "|";
res += std::to_string(RedistributeCount) + "|";
res += std::to_string(IntervalCount) + "|";
res += std::to_string(ParallelStat.RemoteCount) + "|"; stat["ParallelCount"] = ParallelCount;
res += std::to_string(ParallelStat.ShadowCount) + "|"; stat["RemoteCount"] = RemoteCount;
res += std::to_string(ParallelStat.ReductionCount) + "|"; stat["RedistributeCount"] = RedistributeCount;
res += std::to_string(ParallelStat.AcrossCount); stat["IntervalCount"] = IntervalCount;
return res; stat["PS_RemoteCount"] = ParallelStat.RemoteCount;
stat["PS_ShadowCount"] = ParallelStat.ShadowCount;
stat["PS_ReductionCount"] = ParallelStat.ReductionCount;
stat["PS_AcrossCount"] = ParallelStat.AcrossCount;
//TODO: need to improve
// (summed.TotalScoreComm != 0 ? 1.0 / summed.TotalScoreComm : 0.0) + (double)summed.TotalScorePar * 1000 + (countOfDist == 0 ? -5000 : countOfDist);
stat["TotalScore"] = -1 * (ParallelStat.RemoteCount + ParallelStat.ShadowCount + ParallelStat.ReductionCount + ParallelStat.AcrossCount);
return stat;
} }
}; };

View File

@@ -2221,8 +2221,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
runPass(GROUP_ACTUAL_AND_REMOTE, proj_name, folderName); runPass(GROUP_ACTUAL_AND_REMOTE, proj_name, folderName);
runAnalysis(*project, CALCULATE_STATS_SCHEME, false); runAnalysis(*project, CALCULATE_STATS_SCHEME, false);
for (auto& elem : allPredictorStats)
__spf_print(1, " stat for file %s: %s\n", elem.first.c_str(), elem.second.to_string().c_str());
//TODO: need to rewrite this to new algo //TODO: need to rewrite this to new algo
/*if (!folderName && !consoleMode || predictOn) /*if (!folderName && !consoleMode || predictOn)
runAnalysis(*project, PREDICT_SCHEME, false); */ runAnalysis(*project, PREDICT_SCHEME, false); */

View File

@@ -1065,7 +1065,6 @@ int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, sh
printf("SAPFOR: set all info done\n"); printf("SAPFOR: set all info done\n");
runPassesForVisualizer(projName, { INSERT_PARALLEL_DIRS }, folderName); runPassesForVisualizer(projName, { INSERT_PARALLEL_DIRS }, folderName);
string predictRes = "";
PredictorStats summed; PredictorStats summed;
for (auto &predFile : allPredictorStats) for (auto &predFile : allPredictorStats)
{ {
@@ -1081,44 +1080,11 @@ int SPF_CreateParallelVariant(void*& context, int winHandler, short *options, sh
summed.TotalScoreComm += predFile.second.TotalScoreComm; summed.TotalScoreComm += predFile.second.TotalScoreComm;
summed.TotalScoreDist += predFile.second.TotalScoreDist; summed.TotalScoreDist += predFile.second.TotalScoreDist;
summed.TotalScorePar += predFile.second.TotalScorePar; summed.TotalScorePar += predFile.second.TotalScorePar;
}
predictRes += summed.to_string();
//predictRes += "|" + to_string((summed.TotalScoreComm != 0 ? 1.0 / summed.TotalScoreComm : 0.0 )+ (double)summed.TotalScorePar * 1000 + (countOfDist == 0 ? -5000 : countOfDist));
if (countOfDist == 0)
predictRes += "|x";
else
predictRes += "|" + to_string(-1 * (summed.ParallelStat.AcrossCount + summed.ParallelStat.RemoteCount + summed.RedistributeCount + summed.RemoteCount));
//predictRes += "|0";
//TODO: need to rewrite to new algo
/*if (folderName == NULL)
{
SpfInterval *mainIterval = getMainInterval(project, intervals);
const int idxBest = mainIterval->getBestTimeIdx();
double speedUpBest = 1;
int procCount = 1;
string topo = "";
if (idxBest != -1 && mainIterval->exec_time != 0)
{
speedUpBest = mainIterval->exec_time / mainIterval->predictedTimes[idxBest];
topo += "[";
for (int z = 0; z < topologies[idxBest].size(); ++z)
{
topo += to_string(topologies[idxBest][z]);
procCount *= topologies[idxBest][z];
if (z != topologies[idxBest].size() - 1)
topo += "x";
}
topo += "]";
}
char buf[256];
sprintf(buf, "%.2f", speedUpBest / procCount * 100.0);
predictRes += "|" + string(buf) + topo;
} }
else
predictRes += "|0";*/
string predictRes = summed.toJson().dump();
copyStringToShort(predictorStats, predictRes); copyStringToShort(predictorStats, predictRes);
__spf_print(1, " statistic to send: %s\n", predictRes.c_str()); __spf_print(1, " statistic to send: %s\n", predictRes.c_str());
retSize = (int)predictRes.size(); retSize = (int)predictRes.size();
} }