libpredict_integration: add iteration by processes_per_processor

This commit is contained in:
2026-02-21 21:31:40 +03:00
parent 2caaf1ce07
commit 611cd8014c
5 changed files with 63 additions and 39 deletions

View File

@@ -319,7 +319,6 @@ double runLibpredictCalc(const vector<size_t>& topology,
} }
void runPredictScheme(SgProject& project, void runPredictScheme(SgProject& project,
vector<vector<size_t>>& topologies,
const vector<ParallelRegion*>& parallelRegions, const vector<ParallelRegion*>& parallelRegions,
map<string, vector<LoopGraph*>>& loopGraph, map<string, vector<LoopGraph*>>& loopGraph,
map<string, vector<Messages>>& SPF_messages) map<string, vector<Messages>>& SPF_messages)
@@ -363,16 +362,14 @@ void runPredictScheme(SgProject& project,
PrecomputedLibpredictParams precomputedParams = precomputeLibpredictParams( PrecomputedLibpredictParams precomputedParams = precomputeLibpredictParams(
project, parallelRegions, loopGraph, templateIdMapping); project, parallelRegions, loopGraph, templateIdMapping);
// iterating through topologies to find most optimal one // iterating through topologies and processes_per_processor to find most optimal one
topologies = vector<vector<size_t>>();
if (maxSizeDist) { if (maxSizeDist) {
if (maxSizeDist > 4) { if (maxSizeDist > 4) {
maxSizeDist = 4; maxSizeDist = 4;
} }
// Initialize cluster // Initialize cluster
int procCount = 0; libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr);
libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr, procCount);
if (retInitCluster != libpredict::INIT_CLUSTER_SUCCESS) { if (retInitCluster != libpredict::INIT_CLUSTER_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict cluster with config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInitCluster); __spf_print(1, "ERROR: Failed to initialize libpredict cluster with config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInitCluster);
@@ -385,6 +382,31 @@ void runPredictScheme(SgProject& project,
return; return;
} }
vector<size_t> best;
double bestTime = std::numeric_limits<double>::max();
for (size_t processes_per_processor = 1; processes_per_processor <= 16; ++processes_per_processor) {
int procCount = 0;
libpredict::RetInitMapping retInitMapping = libpredict::InitMapping(processes_per_processor, procCount);
if (retInitMapping != libpredict::INIT_MAPPING_SUCCESS) {
__spf_print(1, "ERROR: Failed to initialize libpredict mapping with processes_per_processor: %zu, return code: %d\n",
processes_per_processor, (int)retInitMapping);
std::wstring messageR, messageE;
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict mapping with processes_per_processor: %zu, return code: %d",
processes_per_processor, (int)retInitMapping);
__spf_printToLongBuf(messageR, R211);
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1068));
continue;
}
if (procCount == 0) {
break; // No more processors available
}
__spf_print(1, "Calculate with processes_per_processor=%zu, procCount=%d\n", processes_per_processor, procCount);
for (size_t n1 = 2; n1 <= procCount; ++n1) { for (size_t n1 = 2; n1 <= procCount; ++n1) {
for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) { for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) {
if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) { if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) {
@@ -401,15 +423,7 @@ void runPredictScheme(SgProject& project,
continue; continue;
} }
topologies.push_back(vector<size_t>{n1, n2, n3, n4}); vector<size_t> topology = {n1, n2, n3, n4};
}
}
}
}
vector<size_t> best;
double bestTime = std::numeric_limits<double>::max();
for (auto& topology : topologies) {
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages); double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
string outStr = ""; string outStr = "";
@@ -419,7 +433,7 @@ void runPredictScheme(SgProject& project,
__spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime); __spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
if (currTime == -1) { if (currTime == -1) {
return; continue;
} }
if (currTime < bestTime) { if (currTime < bestTime) {
@@ -427,12 +441,19 @@ void runPredictScheme(SgProject& project,
best = topology; best = topology;
} }
} }
}
}
}
}
if (!best.empty()) {
string outStr; string outStr;
for (const auto& elem : best) { for (const auto& elem : best) {
outStr += std::to_string(elem) + " "; outStr += std::to_string(elem) + " ";
} }
__spf_print(1, "best topology %s with time %f\n", outStr.c_str(), bestTime); __spf_print(1, "best topology %s with time %f\n", outStr.c_str(), bestTime);
}
} else { } else {
__spf_print(1, "impossible to calculate best topology: project does not contain distribution directives\n"); __spf_print(1, "impossible to calculate best topology: project does not contain distribution directives\n");
} }

View File

@@ -46,7 +46,6 @@ PrecomputedLibpredictParams precomputeLibpredictParams(
const std::map<size_t, size_t>& templateIdMapping); const std::map<size_t, size_t>& templateIdMapping);
void runPredictScheme(SgProject& project, void runPredictScheme(SgProject& project,
std::vector<std::vector<size_t>>& topologies,
const std::vector<ParallelRegion*>& parallelRegions, const std::vector<ParallelRegion*>& parallelRegions,
std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
std::map<std::string, std::vector<Messages>>& SPF_messages); std::map<std::string, std::vector<Messages>>& SPF_messages);

View File

@@ -1733,7 +1733,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
} }
} }
else if (curr_regime == PREDICT_SCHEME) else if (curr_regime == PREDICT_SCHEME)
runPredictScheme(project, topologies, parallelRegions, loopGraph, SPF_messages); runPredictScheme(project, parallelRegions, loopGraph, SPF_messages);
else if (curr_regime == CREATE_INTER_TREE) else if (curr_regime == CREATE_INTER_TREE)
{ {
if (keepFiles) if (keepFiles)

View File

@@ -519,6 +519,8 @@ static const wchar_t* R208 = L"R208:";
static const wchar_t* R209 = L"R209:"; static const wchar_t* R209 = L"R209:";
//1067 //1067
static const wchar_t* R210 = L"R210:"; static const wchar_t* R210 = L"R210:";
//1068
static const wchar_t* R211 = L"R211:";
//2001 //2001
static const wchar_t *R94 = L"R94:"; static const wchar_t *R94 = L"R94:";

View File

@@ -196,6 +196,8 @@ R208 = "Ошибка распределения массива '%s' с помо
R209 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d" R209 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d"
//1067 //1067
R210 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d" R210 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d"
//1068
R211 = "Ошибка инициализации отображения libpredict с processes_per_processor: %zu, код возврата: %d"
//2001 //2001
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу" R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"