Compare commits
3 Commits
c26cc261c4
...
libpredict
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d0fee77c7 | |||
| 6fceaaf704 | |||
| f623eaeb5b |
Submodule projects/libpredictor updated: d0772cdb57...e6e805a390
@@ -17,42 +17,76 @@
|
|||||||
#include "../Utils/utils.h"
|
#include "../Utils/utils.h"
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
using std::string;
|
||||||
using std::tuple;
|
using std::tuple;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
// МОЖЕТ КАК-ТО ВЫЧИСЛЯТЬ ДИРЕКТИВЫ, А ПОТОМ ДЕЛАТЬ ПРОГОНЫ?
|
map<size_t, size_t> createTemplateIdMapping(const vector<ParallelRegion*>& parallelRegions)
|
||||||
double runLibpredictCalc(SgProject &project,
|
|
||||||
const vector<size_t> &topology,
|
|
||||||
const string &clusterConfStr,
|
|
||||||
const vector<ParallelRegion*> ¶llelRegions,
|
|
||||||
map<string, vector<LoopGraph*>> &loopGraph,
|
|
||||||
map<string, vector<Messages>> &SPF_messages)
|
|
||||||
{
|
{
|
||||||
libpredict::RetInit retInit = libpredict::Init(clusterConfStr, topology[0], topology[1], topology[2], topology[3]);
|
size_t maxArrayId = 0;
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
|
||||||
if (retInit != libpredict::INIT_SUCCESS) {
|
for (const auto& distrRule : dataDirectives.distrRules) {
|
||||||
__spf_print(1, "ERROR: Failed to initialize libpredict with cluster config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInit);
|
if (distrRule.first && !distrRule.first->IsTemplate()) {
|
||||||
|
maxArrayId = std::max(maxArrayId, (size_t)distrRule.first->GetId());
|
||||||
std::wstring messageR, messageE;
|
}
|
||||||
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict library with cluster config: %s, return code: %d",
|
|
||||||
to_wstring(clusterConfStr).c_str(), (int)retInit);
|
|
||||||
__spf_printToLongBuf(messageR, R206);
|
|
||||||
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1063));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// distribute и align из parallelRegions
|
for (const auto& alignRule : dataDirectives.alignRules) {
|
||||||
for (int z = 0; z < parallelRegions.size(); ++z) {
|
if (alignRule.alignArray && !alignRule.alignArray->IsTemplate()) {
|
||||||
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
maxArrayId = std::max(maxArrayId, (size_t)alignRule.alignArray->GetId());
|
||||||
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
}
|
||||||
const DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArrays();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto &tmp = dataDirectives.distrRules;
|
map<size_t, size_t> templateIdMapping;
|
||||||
|
size_t nextTemplateId = maxArrayId + 1;
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
|
||||||
|
for (const auto& distrRule : dataDirectives.distrRules) {
|
||||||
|
if (distrRule.first && distrRule.first->IsTemplate()) {
|
||||||
|
size_t originalId = distrRule.first->GetId();
|
||||||
|
if (templateIdMapping.find(originalId) == templateIdMapping.end()) {
|
||||||
|
templateIdMapping[originalId] = nextTemplateId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& alignRule : dataDirectives.alignRules) {
|
||||||
|
if (alignRule.alignWith && alignRule.alignWith->IsTemplate()) {
|
||||||
|
size_t originalId = alignRule.alignWith->GetId();
|
||||||
|
if (templateIdMapping.find(originalId) == templateIdMapping.end()) {
|
||||||
|
templateIdMapping[originalId] = nextTemplateId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return templateIdMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrecomputedLibpredictParams precomputeLibpredictParams(
|
||||||
|
SgProject& project,
|
||||||
|
const vector<ParallelRegion*>& parallelRegions,
|
||||||
|
const map<string, vector<LoopGraph*>>& loopGraph,
|
||||||
|
const map<size_t, size_t>& templateIdMapping)
|
||||||
|
{
|
||||||
|
PrecomputedLibpredictParams result;
|
||||||
|
|
||||||
|
// distribute and align from parallelRegions
|
||||||
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
|
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
|
||||||
|
const DIST::Arrays<int>& allArrays = parallelRegions[z]->GetAllArrays();
|
||||||
|
|
||||||
|
auto& tmp = dataDirectives.distrRules;
|
||||||
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
||||||
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
|
||||||
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
||||||
|
}
|
||||||
|
|
||||||
// distribute
|
// distribute
|
||||||
for (const auto& distrRule : currentVar) {
|
for (const auto& distrRule : currentVar) {
|
||||||
@@ -60,42 +94,40 @@ double runLibpredictCalc(SgProject &project,
|
|||||||
const DistrVariant* variant = distrRule.second;
|
const DistrVariant* variant = distrRule.second;
|
||||||
|
|
||||||
if (array && variant && !array->IsNotDistribute()) {
|
if (array && variant && !array->IsNotDistribute()) {
|
||||||
size_t arrayId = array->GetId();
|
PrecomputedDistributeParams params;
|
||||||
size_t elemSize = array->GetTypeSize();
|
|
||||||
|
size_t originalId = array->GetId();
|
||||||
|
params.arrayId = originalId;
|
||||||
|
|
||||||
|
if (array->IsTemplate()) {
|
||||||
|
auto it = templateIdMapping.find(originalId);
|
||||||
|
if (it != templateIdMapping.end()) {
|
||||||
|
params.arrayId = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params.elemSize = array->GetTypeSize();
|
||||||
|
params.array = array;
|
||||||
|
|
||||||
vector<libpredict::DistributeAxisRule> axisDistributions;
|
|
||||||
const auto& arraySizes = array->GetSizes();
|
const auto& arraySizes = array->GetSizes();
|
||||||
for (int dim = 0; dim < array->GetDimSize(); ++dim) {
|
for (int dim = 0; dim < array->GetDimSize(); ++dim) {
|
||||||
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
||||||
|
|
||||||
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
||||||
axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::BLOCK);
|
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::BLOCK);
|
||||||
} else {
|
} else {
|
||||||
axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::NONE);
|
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<size_t, size_t>> shadowEdges;
|
|
||||||
const auto& shadowSpec = array->GetShadowSpec();
|
const auto& shadowSpec = array->GetShadowSpec();
|
||||||
for (int dim = 0; dim < shadowSpec.size() && dim < array->GetDimSize(); ++dim) {
|
for (int dim = 0; dim < shadowSpec.size() && dim < array->GetDimSize(); ++dim) {
|
||||||
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
||||||
shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libpredict::RetDistribute retDistribute = libpredict::Distribute(arrayId, elemSize, axisDistributions, shadowEdges);
|
result.distributeParams.push_back(params);
|
||||||
|
|
||||||
if (retDistribute != libpredict::DISTRIBUTE_SUCCESS) {
|
|
||||||
__spf_print(1, "ERROR: Failed to distribute array '%s' (id=%zu) with libpredict, return code: %d\n",
|
|
||||||
array->GetShortName().c_str(), arrayId, (int)retDistribute);
|
|
||||||
|
|
||||||
std::wstring messageR, messageE;
|
|
||||||
__spf_printToLongBuf(messageE, L"Failed to distribute array '%s' with libpredict, return code: %d",
|
|
||||||
to_wstring(array->GetShortName()).c_str(), (int)retDistribute);
|
|
||||||
__spf_printToLongBuf(messageR, R207);
|
|
||||||
getObjectForFileFromMap(array->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(
|
|
||||||
Messages(ERROR, array->GetDeclInfo().begin()->second, messageR, messageE, 1064));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,16 +137,29 @@ double runLibpredictCalc(SgProject &project,
|
|||||||
DIST::Array* alignWithArray = alignRule.alignWith;
|
DIST::Array* alignWithArray = alignRule.alignWith;
|
||||||
|
|
||||||
if (alignArray && alignWithArray && !alignArray->IsNotDistribute()) {
|
if (alignArray && alignWithArray && !alignArray->IsNotDistribute()) {
|
||||||
size_t arrayId = alignArray->GetId();
|
PrecomputedAlignParams params;
|
||||||
size_t distributedArrayId = alignWithArray->GetId();
|
|
||||||
size_t elemSize = alignArray->GetTypeSize();
|
params.arrayId = alignArray->GetId();
|
||||||
|
size_t originalDistributedArrayId = alignWithArray->GetId();
|
||||||
|
params.distributedArrayId = originalDistributedArrayId;
|
||||||
|
|
||||||
|
if (alignWithArray->IsTemplate()) {
|
||||||
|
auto it = templateIdMapping.find(originalDistributedArrayId);
|
||||||
|
if (it != templateIdMapping.end()) {
|
||||||
|
params.distributedArrayId = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params.elemSize = alignArray->GetTypeSize();
|
||||||
|
params.alignArray = alignArray;
|
||||||
|
params.alignWithArray = alignWithArray;
|
||||||
|
|
||||||
const auto& arraySizes = alignArray->GetSizes();
|
const auto& arraySizes = alignArray->GetSizes();
|
||||||
vector<size_t> dimensions;
|
for (int dim = 0; dim < alignArray->GetDimSize(); ++dim) {
|
||||||
for (int dim = 0; dim < alignArray->GetDimSize(); ++dim)
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
||||||
dimensions.push_back(arraySizes[dim].second - arraySizes[dim].first + 1);
|
params.dimensions.push_back(dimSize);
|
||||||
|
}
|
||||||
|
|
||||||
vector<libpredict::AlignDisplay> distributionExpressions;
|
|
||||||
for (int dim = 0; dim < alignWithArray->GetDimSize(); ++dim) {
|
for (int dim = 0; dim < alignWithArray->GetDimSize(); ++dim) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < alignRule.alignRuleWith.size(); ++i) {
|
for (int i = 0; i < alignRule.alignRuleWith.size(); ++i) {
|
||||||
@@ -122,51 +167,39 @@ double runLibpredictCalc(SgProject &project,
|
|||||||
if (ruleWith.first == dim) {
|
if (ruleWith.first == dim) {
|
||||||
const auto& rule = ruleWith.second;
|
const auto& rule = ruleWith.second;
|
||||||
if (rule.first == 0) {
|
if (rule.first == 0) {
|
||||||
// Константа
|
// constant
|
||||||
distributionExpressions.emplace_back(rule.second);
|
params.distributionExpressions.emplace_back(rule.second);
|
||||||
} else {
|
} else {
|
||||||
// Линейное выражение a * I + b
|
// linear expression a * I + b
|
||||||
distributionExpressions.emplace_back(i, rule.first, rule.second);
|
params.distributionExpressions.emplace_back(i, rule.first, rule.second);
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
// Нет правила для этого измерения
|
// There is no rule for this measurement
|
||||||
distributionExpressions.emplace_back();
|
params.distributionExpressions.emplace_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<size_t, size_t>> shadowEdges;
|
|
||||||
const auto& shadowSpec = alignArray->GetShadowSpec();
|
const auto& shadowSpec = alignArray->GetShadowSpec();
|
||||||
for (int dim = 0; dim < shadowSpec.size() && dim < alignArray->GetDimSize(); ++dim) {
|
for (int dim = 0; dim < shadowSpec.size() && dim < alignArray->GetDimSize(); ++dim) {
|
||||||
shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
||||||
}
|
}
|
||||||
|
|
||||||
libpredict::RetAlign retAlign = libpredict::Align(arrayId, distributedArrayId, elemSize, dimensions, distributionExpressions, shadowEdges);
|
result.alignParams.push_back(params);
|
||||||
|
|
||||||
if (retAlign != libpredict::ALIGN_SUCCESS) {
|
|
||||||
__spf_print(1, "ERROR: Failed to align array '%s' (id=%zu) with array '%s' (id=%zu), return code: %d\n",
|
|
||||||
alignArray->GetShortName().c_str(), arrayId,
|
|
||||||
alignWithArray->GetShortName().c_str(), distributedArrayId, (int)retAlign);
|
|
||||||
|
|
||||||
std::wstring messageR, messageE;
|
|
||||||
__spf_printToLongBuf(messageE, L"Failed to align array '%s' with array '%s' using libpredict, return code: %d",
|
|
||||||
to_wstring(alignArray->GetShortName()).c_str(),
|
|
||||||
to_wstring(alignWithArray->GetShortName()).c_str(), (int)retAlign);
|
|
||||||
__spf_printToLongBuf(messageR, R208);
|
|
||||||
getObjectForFileFromMap(alignArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(
|
|
||||||
Messages(ERROR, alignArray->GetDeclInfo().begin()->second, messageR, messageE, 1065));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shadow_renew
|
// shadow_renew
|
||||||
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
||||||
for (int i = project.numberOfFiles() - 1; i >= 0; --i) {
|
for (int i = project.numberOfFiles() - 1; i >= 0; --i) {
|
||||||
SgFile *file = &(project.file(i));
|
SgFile* file = &(project.file(i));
|
||||||
auto fountInfo = findAllDirectives(file, getObjectForFileFromMap(file->filename(), loopGraph), parallelRegions[z]->GetId());
|
auto fountInfo = findAllDirectives(
|
||||||
|
file,
|
||||||
|
getObjectForFileFromMap(file->filename(), const_cast<map<string, vector<LoopGraph*>>&>(loopGraph)),
|
||||||
|
parallelRegions[z]->GetId());
|
||||||
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,66 +214,135 @@ double runLibpredictCalc(SgProject &project,
|
|||||||
const vector<pair<int, int>>& bounds = shadowRenewItem.second;
|
const vector<pair<int, int>>& bounds = shadowRenewItem.second;
|
||||||
|
|
||||||
DIST::Array* shadowArray = allArrays.GetArrayByName(arrayName);
|
DIST::Array* shadowArray = allArrays.GetArrayByName(arrayName);
|
||||||
if (shadowArray == NULL)
|
if (shadowArray == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (shadowArray && !shadowArray->IsNotDistribute()) {
|
if (shadowArray && !shadowArray->IsNotDistribute()) {
|
||||||
size_t arrayId = shadowArray->GetId();
|
PrecomputedShadowRenewParams params;
|
||||||
|
|
||||||
|
params.arrayId = shadowArray->GetId();
|
||||||
|
params.shadowArray = shadowArray;
|
||||||
|
|
||||||
vector<pair<size_t, size_t>> shadow_renew;
|
|
||||||
for (const auto& bound : bounds) {
|
for (const auto& bound : bounds) {
|
||||||
shadow_renew.emplace_back(static_cast<size_t>(bound.first),
|
params.shadow_renew.emplace_back(static_cast<size_t>(bound.first),
|
||||||
static_cast<size_t>(bound.second));
|
static_cast<size_t>(bound.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool corner = directive->shadowRenewCorner[shadowIdx];
|
params.corner = directive->shadowRenewCorner[shadowIdx];
|
||||||
|
params.number_loop_iterations = loopPtr ? static_cast<size_t>(loopPtr->countOfIters) : 1;
|
||||||
|
|
||||||
size_t number_loop_iterations = loopPtr ? static_cast<size_t>(loopPtr->countOfIters) : 1;
|
result.shadowRenewParams.push_back(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
libpredict::RetShadowRenew retShadowRenew = libpredict::ShadowRenew(arrayId, shadow_renew, corner, number_loop_iterations);
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
double runLibpredictCalc(const vector<size_t>& topology,
|
||||||
|
const string& clusterConfStr,
|
||||||
|
const PrecomputedLibpredictParams& precomputedParams,
|
||||||
|
map<string, vector<Messages>>& SPF_messages)
|
||||||
|
{
|
||||||
|
libpredict::RetInitGrid retInitGrid = libpredict::InitGrid(topology[0], topology[1], topology[2], topology[3]);
|
||||||
|
|
||||||
|
if (retInitGrid != libpredict::INIT_GRID_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to initialize libpredict grid with topology: %zu %zu %zu %zu, return code: %d\n",
|
||||||
|
topology[0], topology[1], topology[2], topology[3], (int)retInitGrid);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict grid with topology: %zu %zu %zu %zu, return code: %d",
|
||||||
|
topology[0], topology[1], topology[2], topology[3], (int)retInitGrid);
|
||||||
|
__spf_printToLongBuf(messageR, R207);
|
||||||
|
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1064));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// distribute
|
||||||
|
for (const auto& params : precomputedParams.distributeParams) {
|
||||||
|
libpredict::RetDistribute retDistribute = libpredict::Distribute(
|
||||||
|
params.arrayId, params.elemSize, params.axisDistributions, params.shadowEdges);
|
||||||
|
|
||||||
|
if (retDistribute != libpredict::DISTRIBUTE_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to distribute array '%s' (id=%zu) with libpredict, return code: %d\n",
|
||||||
|
params.array->GetShortName().c_str(), params.arrayId, (int)retDistribute);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to distribute array '%s' with libpredict, return code: %d",
|
||||||
|
to_wstring(params.array->GetShortName()).c_str(), (int)retDistribute);
|
||||||
|
__spf_printToLongBuf(messageR, R208);
|
||||||
|
getObjectForFileFromMap(params.array->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.array->GetDeclInfo().begin()->second, messageR, messageE, 1065));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// align
|
||||||
|
for (const auto& params : precomputedParams.alignParams) {
|
||||||
|
libpredict::RetAlign retAlign = libpredict::Align(
|
||||||
|
params.arrayId, params.distributedArrayId, params.elemSize,
|
||||||
|
params.dimensions, params.distributionExpressions, params.shadowEdges);
|
||||||
|
|
||||||
|
if (retAlign != libpredict::ALIGN_SUCCESS) {
|
||||||
|
__spf_print(1, "ERROR: Failed to align array '%s' (id=%zu) with array '%s' (id=%zu), return code: %d\n",
|
||||||
|
params.alignArray->GetShortName().c_str(), params.arrayId,
|
||||||
|
params.alignWithArray->GetShortName().c_str(), params.distributedArrayId, (int)retAlign);
|
||||||
|
|
||||||
|
std::wstring messageR, messageE;
|
||||||
|
__spf_printToLongBuf(messageE, L"Failed to align array '%s' with array '%s' using libpredict, return code: %d",
|
||||||
|
to_wstring(params.alignArray->GetShortName()).c_str(),
|
||||||
|
to_wstring(params.alignWithArray->GetShortName()).c_str(), (int)retAlign);
|
||||||
|
__spf_printToLongBuf(messageR, R209);
|
||||||
|
getObjectForFileFromMap(params.alignArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.alignArray->GetDeclInfo().begin()->second, messageR, messageE, 1066));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow_renew
|
||||||
|
for (const auto& params : precomputedParams.shadowRenewParams) {
|
||||||
|
libpredict::RetShadowRenew retShadowRenew = libpredict::ShadowRenew(
|
||||||
|
params.arrayId, params.shadow_renew, params.corner, params.number_loop_iterations);
|
||||||
|
|
||||||
if (retShadowRenew != libpredict::SHADOW_RENEW_SUCCESS) {
|
if (retShadowRenew != libpredict::SHADOW_RENEW_SUCCESS) {
|
||||||
__spf_print(1, "ERROR: Failed to process shadow_renew for array '%s' (id=%zu), return code: %d\n",
|
__spf_print(1, "ERROR: Failed to process shadow_renew for array '%s' (id=%zu), return code: %d\n",
|
||||||
shadowArray->GetShortName().c_str(), arrayId, (int)retShadowRenew);
|
params.shadowArray->GetShortName().c_str(), params.arrayId, (int)retShadowRenew);
|
||||||
|
|
||||||
std::wstring messageR, messageE;
|
std::wstring messageR, messageE;
|
||||||
__spf_printToLongBuf(messageE, L"Failed to process shadow_renew for array '%s' with libpredict, return code: %d",
|
__spf_printToLongBuf(messageE, L"Failed to process shadow_renew for array '%s' with libpredict, return code: %d",
|
||||||
to_wstring(shadowArray->GetShortName()).c_str(), (int)retShadowRenew);
|
to_wstring(params.shadowArray->GetShortName()).c_str(), (int)retShadowRenew);
|
||||||
__spf_printToLongBuf(messageR, R209);
|
__spf_printToLongBuf(messageR, R210);
|
||||||
getObjectForFileFromMap(shadowArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(
|
getObjectForFileFromMap(params.shadowArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.shadowArray->GetDeclInfo().begin()->second, messageR, messageE, 1067));
|
||||||
Messages(ERROR, shadowArray->GetDeclInfo().begin()->second, messageR, messageE, 1066));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return libpredict::GetTime();
|
return libpredict::GetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runPredictScheme(SgProject &project,
|
void runPredictScheme(SgProject& project,
|
||||||
vector<vector<size_t>> &topologies,
|
vector<vector<size_t>>& topologies,
|
||||||
const vector<ParallelRegion*> ¶llelRegions,
|
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)
|
||||||
{
|
{
|
||||||
// calculating maximum dimension of distribution
|
// calculating maximum dimension of distribution
|
||||||
int maxSizeDist = 0;
|
int maxSizeDist = 0;
|
||||||
for (int z = 0; z < parallelRegions.size(); ++z) {
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
||||||
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
|
||||||
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
|
||||||
|
|
||||||
auto &tmp = dataDirectives.distrRules;
|
auto& tmp = dataDirectives.distrRules;
|
||||||
vector<const DistrVariant*> currentVar;
|
vector<const DistrVariant*> currentVar;
|
||||||
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
|
||||||
currentVar.push_back(&tmp[z1].second[currentVariant[z1]]);
|
currentVar.push_back(&tmp[z1].second[currentVariant[z1]]);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto var : currentVar) {
|
for (auto var : currentVar) {
|
||||||
int countBlock = 0;
|
int countBlock = 0;
|
||||||
for (int z = 0; z < var->distRule.size(); ++z)
|
for (int z = 0; z < var->distRule.size(); ++z) {
|
||||||
if (var->distRule[z] == dist::BLOCK)
|
if (var->distRule[z] == dist::BLOCK) {
|
||||||
++countBlock;
|
++countBlock;
|
||||||
|
}
|
||||||
|
}
|
||||||
maxSizeDist = std::max(maxSizeDist, countBlock);
|
maxSizeDist = std::max(maxSizeDist, countBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,22 +356,51 @@ void runPredictScheme(SgProject &project,
|
|||||||
clusterConfStr = firstFilePath.substr(0, lastSlash + 1) + "cluster.conf";
|
clusterConfStr = firstFilePath.substr(0, lastSlash + 1) + "cluster.conf";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// creating template ID display to avoid conflicts
|
||||||
|
map<size_t, size_t> templateIdMapping = createTemplateIdMapping(parallelRegions);
|
||||||
|
|
||||||
|
// Precomputing parameters of directive functions from libpredict
|
||||||
|
PrecomputedLibpredictParams precomputedParams = precomputeLibpredictParams(
|
||||||
|
project, parallelRegions, loopGraph, templateIdMapping);
|
||||||
|
|
||||||
// iterating through topologies to find most optimal one
|
// iterating through topologies to find most optimal one
|
||||||
topologies = vector<vector<size_t>>();
|
topologies = vector<vector<size_t>>();
|
||||||
if (maxSizeDist) {
|
if (maxSizeDist) {
|
||||||
|
if (maxSizeDist > 4) {
|
||||||
|
maxSizeDist = 4;
|
||||||
|
}
|
||||||
|
|
||||||
if (maxSizeDist > 4) maxSizeDist = 4;
|
// Initialize cluster
|
||||||
|
int procCount = 0;
|
||||||
|
libpredict::RetInitCluster retInitCluster = libpredict::InitCluster(clusterConfStr, procCount);
|
||||||
|
|
||||||
// TODO: look at cluster configuration
|
if (retInitCluster != libpredict::INIT_CLUSTER_SUCCESS) {
|
||||||
size_t n1max = 10;
|
__spf_print(1, "ERROR: Failed to initialize libpredict cluster with config: %s, return code: %d\n", clusterConfStr.c_str(), (int)retInitCluster);
|
||||||
size_t n2max = (maxSizeDist >= 2) ? 10 : 1;
|
|
||||||
size_t n3max = (maxSizeDist >= 3) ? 10 : 1;
|
std::wstring messageR, messageE;
|
||||||
size_t n4max = (maxSizeDist >= 4) ? 10 : 1;
|
__spf_printToLongBuf(messageE, L"Failed to initialize libpredict cluster with config: %s, return code: %d",
|
||||||
|
to_wstring(clusterConfStr).c_str(), (int)retInitCluster);
|
||||||
|
__spf_printToLongBuf(messageR, R206);
|
||||||
|
getObjectForFileFromMap(clusterConfStr.c_str(), SPF_messages).push_back(Messages(ERROR, 1, messageR, messageE, 1063));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t n1 = 2; n1 <= procCount; ++n1) {
|
||||||
|
for (size_t n2 = 1; n2 <= n1 && n1 * n2 <= procCount; ++n2) {
|
||||||
|
if (n2 != 1 && maxSizeDist < 2 || n2 == 1 && maxSizeDist == 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t n3 = 1; n3 <= n2 && n1 * n2 * n3 <= procCount; ++n3) {
|
||||||
|
if (n3 != 1 && maxSizeDist < 3 || n3 == 1 && maxSizeDist == 3) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t n4 = 1; n4 <= n3 && n1 * n2 * n3 * n4 <= procCount; ++n4) {
|
||||||
|
if (n4 != 1 && maxSizeDist < 4 || n4 == 1 && maxSizeDist == 4) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t n1 = 1; n1 <= n1max; ++n1) {
|
|
||||||
for (size_t n2 = 1; n2 <= n2max; ++n2) {
|
|
||||||
for (size_t n3 = 1; n3 <= n3max; ++n3) {
|
|
||||||
for (size_t n4 = 1; n4 <= n4max; ++n4) {
|
|
||||||
topologies.push_back(vector<size_t>{n1, n2, n3, n4});
|
topologies.push_back(vector<size_t>{n1, n2, n3, n4});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,17 +409,18 @@ void runPredictScheme(SgProject &project,
|
|||||||
|
|
||||||
vector<size_t> best;
|
vector<size_t> best;
|
||||||
double bestTime = std::numeric_limits<double>::max();
|
double bestTime = std::numeric_limits<double>::max();
|
||||||
for (auto &topology : topologies) {
|
for (auto& topology : topologies) {
|
||||||
// if (DEBUG) {
|
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
|
||||||
// string outStr = "";
|
|
||||||
// for (const auto &elem : top)
|
|
||||||
// outStr += std::to_string(elem) + " ";
|
|
||||||
// __spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
|
|
||||||
// }
|
|
||||||
double currTime = runLibpredictCalc(project, topology, clusterConfStr, parallelRegions, loopGraph, SPF_messages);
|
|
||||||
|
|
||||||
if (currTime == -1)
|
string outStr = "";
|
||||||
|
for (const auto& elem : topology) {
|
||||||
|
outStr += std::to_string(elem) + " ";
|
||||||
|
}
|
||||||
|
__spf_print(1, "topology %s has time %f\n", outStr.c_str(), currTime);
|
||||||
|
|
||||||
|
if (currTime == -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (currTime < bestTime) {
|
if (currTime < bestTime) {
|
||||||
bestTime = currTime;
|
bestTime = currTime;
|
||||||
@@ -296,8 +428,9 @@ void runPredictScheme(SgProject &project,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 {
|
||||||
|
|||||||
@@ -4,16 +4,54 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "dvm.h"
|
#include "dvm.h"
|
||||||
#include "graph_calls.h"
|
#include "graph_calls.h"
|
||||||
|
#include "../../projects/libpredictor/include/libpredict/predictor.h"
|
||||||
|
|
||||||
void runPredictScheme(SgProject &project,
|
struct PrecomputedDistributeParams {
|
||||||
std::vector<std::vector<size_t>> &topologies,
|
size_t arrayId;
|
||||||
const std::vector<ParallelRegion*> ¶llelRegions,
|
size_t elemSize;
|
||||||
std::map<std::string, std::vector<LoopGraph*>> &loopGraph,
|
std::vector<libpredict::DistributeAxisRule> axisDistributions;
|
||||||
std::map<std::string, std::vector<Messages>> &SPF_messages);
|
std::vector<std::pair<size_t, size_t>> shadowEdges;
|
||||||
|
DIST::Array* array;
|
||||||
|
};
|
||||||
|
|
||||||
double runLibpredictCalc(SgProject &project,
|
struct PrecomputedAlignParams {
|
||||||
const std::vector<size_t> &topology,
|
size_t arrayId;
|
||||||
const std::string &clusterConfStr,
|
size_t distributedArrayId;
|
||||||
const std::vector<ParallelRegion*> ¶llelRegions,
|
size_t elemSize;
|
||||||
std::map<std::string, std::vector<LoopGraph*>> &loopGraph,
|
std::vector<size_t> dimensions;
|
||||||
std::map<std::string, std::vector<Messages>> &SPF_messages);
|
std::vector<libpredict::AlignDisplay> distributionExpressions;
|
||||||
|
std::vector<std::pair<size_t, size_t>> shadowEdges;
|
||||||
|
DIST::Array* alignArray;
|
||||||
|
DIST::Array* alignWithArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrecomputedShadowRenewParams {
|
||||||
|
size_t arrayId;
|
||||||
|
std::vector<std::pair<size_t, size_t>> shadow_renew;
|
||||||
|
bool corner;
|
||||||
|
size_t number_loop_iterations;
|
||||||
|
DIST::Array* shadowArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrecomputedLibpredictParams {
|
||||||
|
std::vector<PrecomputedDistributeParams> distributeParams;
|
||||||
|
std::vector<PrecomputedAlignParams> alignParams;
|
||||||
|
std::vector<PrecomputedShadowRenewParams> shadowRenewParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
PrecomputedLibpredictParams precomputeLibpredictParams(
|
||||||
|
SgProject& project,
|
||||||
|
const std::vector<ParallelRegion*>& parallelRegions,
|
||||||
|
const std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
|
||||||
|
const std::map<size_t, size_t>& templateIdMapping);
|
||||||
|
|
||||||
|
void runPredictScheme(SgProject& project,
|
||||||
|
std::vector<std::vector<size_t>>& topologies,
|
||||||
|
const std::vector<ParallelRegion*>& parallelRegions,
|
||||||
|
std::map<std::string, std::vector<LoopGraph*>>& loopGraph,
|
||||||
|
std::map<std::string, std::vector<Messages>>& SPF_messages);
|
||||||
|
|
||||||
|
double runLibpredictCalc(const std::vector<size_t>& topology,
|
||||||
|
const std::string& clusterConfStr,
|
||||||
|
const PrecomputedLibpredictParams& precomputedParams,
|
||||||
|
std::map<std::string, std::vector<Messages>>& SPF_messages);
|
||||||
|
|||||||
@@ -78,10 +78,11 @@ enum typeMessage { WARR, ERROR, NOTE };
|
|||||||
// 60 "Format misplaced"
|
// 60 "Format misplaced"
|
||||||
// 61 "Array has declaration area conflict"
|
// 61 "Array has declaration area conflict"
|
||||||
// 62 "need to move common declaration to main for DECLATE"
|
// 62 "need to move common declaration to main for DECLATE"
|
||||||
// 63 "Failed to initialize libpredict library"
|
// 63 "Failed to initialize libpredict cluster"
|
||||||
// 64 "Failed to distribute array with libpredict"
|
// 64 "Failed to initialize libpredict grid"
|
||||||
// 65 "Failed to align array with libpredict"
|
// 65 "Failed to distribute array with libpredict"
|
||||||
// 66 "Failed to process shadow_renew with libpredict"
|
// 66 "Failed to align array with libpredict"
|
||||||
|
// 67 "Failed to process shadow_renew with libpredict"
|
||||||
//
|
//
|
||||||
// 20xx TRANSFORM GROUP
|
// 20xx TRANSFORM GROUP
|
||||||
// 01 "can not convert array assign to loop"
|
// 01 "can not convert array assign to loop"
|
||||||
@@ -309,7 +310,7 @@ static void printStackTrace() { };
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Свободный - R209
|
// Свободный - R210
|
||||||
// Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор.
|
// Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор.
|
||||||
// В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле
|
// В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле
|
||||||
// russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен
|
// russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен
|
||||||
@@ -516,6 +517,8 @@ static const wchar_t* R207 = L"R207:";
|
|||||||
static const wchar_t* R208 = L"R208:";
|
static const wchar_t* R208 = L"R208:";
|
||||||
//1066
|
//1066
|
||||||
static const wchar_t* R209 = L"R209:";
|
static const wchar_t* R209 = L"R209:";
|
||||||
|
//1067
|
||||||
|
static const wchar_t* R210 = L"R210:";
|
||||||
|
|
||||||
//2001
|
//2001
|
||||||
static const wchar_t *R94 = L"R94:";
|
static const wchar_t *R94 = L"R94:";
|
||||||
|
|||||||
@@ -189,11 +189,13 @@ R205 = "Массив '%s' состоящий в common блоке '%s' долж
|
|||||||
//1063
|
//1063
|
||||||
R206 = "Ошибка инициализации библиотеки libpredict с конфигурацией кластера: %s, код возврата: %d"
|
R206 = "Ошибка инициализации библиотеки libpredict с конфигурацией кластера: %s, код возврата: %d"
|
||||||
//1064
|
//1064
|
||||||
R207 = "Ошибка распределения массива '%s' с помощью libpredict, код возврата: %d"
|
R207 = "Ошибка инициализации сетки libpredict с топологией: %zu %zu %zu %zu, код возврата: %d"
|
||||||
//1065
|
//1065
|
||||||
R208 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d"
|
R208 = "Ошибка распределения массива '%s' с помощью libpredict, код возврата: %d"
|
||||||
//1066
|
//1066
|
||||||
R209 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d"
|
R209 = "Ошибка выравнивания массива '%s' с массивом '%s' с помощью libpredict, код возврата: %d"
|
||||||
|
//1067
|
||||||
|
R210 = "Ошибка обработки shadow_renew для массива '%s' с помощью libpredict, код возврата: %d"
|
||||||
|
|
||||||
//2001
|
//2001
|
||||||
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"
|
R94 = "Невозможно автоматически преобразовать данное присваивание к циклу"
|
||||||
|
|||||||
Reference in New Issue
Block a user