|
|
|
|
@@ -17,10 +17,10 @@
|
|
|
|
|
#include "../Utils/utils.h"
|
|
|
|
|
|
|
|
|
|
using std::map;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::pair;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::tuple;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
|
map<size_t, size_t> createTemplateIdMapping(const vector<ParallelRegion*>& parallelRegions)
|
|
|
|
|
{
|
|
|
|
|
@@ -68,14 +68,184 @@ map<size_t, size_t> createTemplateIdMapping(const vector<ParallelRegion*> ¶l
|
|
|
|
|
return templateIdMapping;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: вычислять директивы разово заранее
|
|
|
|
|
double runLibpredictCalc(SgProject &project,
|
|
|
|
|
const vector<size_t>& topology,
|
|
|
|
|
const string& clusterConfStr,
|
|
|
|
|
PrecomputedLibpredictParams precomputeLibpredictParams(
|
|
|
|
|
SgProject& project,
|
|
|
|
|
const vector<ParallelRegion*>& parallelRegions,
|
|
|
|
|
map<string, vector<LoopGraph*>>& loopGraph,
|
|
|
|
|
map<string, vector<Messages>> &SPF_messages,
|
|
|
|
|
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;
|
|
|
|
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1) {
|
|
|
|
|
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// distribute
|
|
|
|
|
for (const auto& distrRule : currentVar) {
|
|
|
|
|
DIST::Array* array = distrRule.first;
|
|
|
|
|
const DistrVariant* variant = distrRule.second;
|
|
|
|
|
|
|
|
|
|
if (array && variant && !array->IsNotDistribute()) {
|
|
|
|
|
PrecomputedDistributeParams params;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
const auto& arraySizes = array->GetSizes();
|
|
|
|
|
for (int dim = 0; dim < array->GetDimSize(); ++dim) {
|
|
|
|
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
|
|
|
|
|
|
|
|
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
|
|
|
|
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::BLOCK);
|
|
|
|
|
} else {
|
|
|
|
|
params.axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::NONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto& shadowSpec = array->GetShadowSpec();
|
|
|
|
|
for (int dim = 0; dim < shadowSpec.size() && dim < array->GetDimSize(); ++dim) {
|
|
|
|
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
|
|
|
|
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.distributeParams.push_back(params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// align
|
|
|
|
|
for (const auto& alignRule : dataDirectives.alignRules) {
|
|
|
|
|
DIST::Array* alignArray = alignRule.alignArray;
|
|
|
|
|
DIST::Array* alignWithArray = alignRule.alignWith;
|
|
|
|
|
|
|
|
|
|
if (alignArray && alignWithArray && !alignArray->IsNotDistribute()) {
|
|
|
|
|
PrecomputedAlignParams params;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
for (int dim = 0; dim < alignArray->GetDimSize(); ++dim) {
|
|
|
|
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
|
|
|
|
params.dimensions.push_back(dimSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int dim = 0; dim < alignWithArray->GetDimSize(); ++dim) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (int i = 0; i < alignRule.alignRuleWith.size(); ++i) {
|
|
|
|
|
const auto& ruleWith = alignRule.alignRuleWith[i];
|
|
|
|
|
if (ruleWith.first == dim) {
|
|
|
|
|
const auto& rule = ruleWith.second;
|
|
|
|
|
if (rule.first == 0) {
|
|
|
|
|
// constant
|
|
|
|
|
params.distributionExpressions.emplace_back(rule.second);
|
|
|
|
|
} else {
|
|
|
|
|
// linear expression a * I + b
|
|
|
|
|
params.distributionExpressions.emplace_back(i, rule.first, rule.second);
|
|
|
|
|
}
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
// There is no rule for this measurement
|
|
|
|
|
params.distributionExpressions.emplace_back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto& shadowSpec = alignArray->GetShadowSpec();
|
|
|
|
|
for (int dim = 0; dim < shadowSpec.size() && dim < alignArray->GetDimSize(); ++dim) {
|
|
|
|
|
params.shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.alignParams.push_back(params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// shadow_renew
|
|
|
|
|
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
|
|
|
|
for (int i = project.numberOfFiles() - 1; i >= 0; --i) {
|
|
|
|
|
SgFile* file = &(project.file(i));
|
|
|
|
|
auto fountInfo = findAllDirectives(
|
|
|
|
|
file,
|
|
|
|
|
getObjectForFileFromMap(file->filename(), const_cast<map<string, vector<LoopGraph*>>&>(loopGraph)),
|
|
|
|
|
parallelRegions[z]->GetId());
|
|
|
|
|
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& dirPair : parallelDirs) {
|
|
|
|
|
LoopGraph* loopPtr = dirPair.first;
|
|
|
|
|
ParallelDirective* directive = dirPair.second;
|
|
|
|
|
|
|
|
|
|
if (directive && !directive->shadowRenew.empty()) {
|
|
|
|
|
for (size_t shadowIdx = 0; shadowIdx < directive->shadowRenew.size(); ++shadowIdx) {
|
|
|
|
|
const auto& shadowRenewItem = directive->shadowRenew[shadowIdx];
|
|
|
|
|
const string& arrayName = shadowRenewItem.first.second; // uniqName
|
|
|
|
|
const vector<pair<int, int>>& bounds = shadowRenewItem.second;
|
|
|
|
|
|
|
|
|
|
DIST::Array* shadowArray = allArrays.GetArrayByName(arrayName);
|
|
|
|
|
if (shadowArray == NULL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shadowArray && !shadowArray->IsNotDistribute()) {
|
|
|
|
|
PrecomputedShadowRenewParams params;
|
|
|
|
|
|
|
|
|
|
params.arrayId = shadowArray->GetId();
|
|
|
|
|
params.shadowArray = shadowArray;
|
|
|
|
|
|
|
|
|
|
for (const auto& bound : bounds) {
|
|
|
|
|
params.shadow_renew.emplace_back(static_cast<size_t>(bound.first),
|
|
|
|
|
static_cast<size_t>(bound.second));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
params.corner = directive->shadowRenewCorner[shadowIdx];
|
|
|
|
|
params.number_loop_iterations = loopPtr ? static_cast<size_t>(loopPtr->countOfIters) : 1;
|
|
|
|
|
|
|
|
|
|
result.shadowRenewParams.push_back(params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
|
|
@@ -91,195 +261,57 @@ double runLibpredictCalc(SgProject &project,
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// distribute and align from parallelRegions
|
|
|
|
|
for (int z = 0; z < parallelRegions.size(); ++z) {
|
|
|
|
|
const DataDirective &dataDirectives = parallelRegions[z]->GetDataDir();
|
|
|
|
|
const vector<int> ¤tVariant = parallelRegions[z]->GetCurrentVariant();
|
|
|
|
|
const DIST::Arrays<int> &allArrays = parallelRegions[z]->GetAllArrays();
|
|
|
|
|
|
|
|
|
|
auto &tmp = dataDirectives.distrRules;
|
|
|
|
|
vector<pair<DIST::Array*, const DistrVariant*>> currentVar;
|
|
|
|
|
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
|
|
|
|
|
currentVar.push_back(std::make_pair(tmp[z1].first, &tmp[z1].second[currentVariant[z1]]));
|
|
|
|
|
|
|
|
|
|
// distribute
|
|
|
|
|
for (const auto& distrRule : currentVar) {
|
|
|
|
|
DIST::Array* array = distrRule.first;
|
|
|
|
|
const DistrVariant* variant = distrRule.second;
|
|
|
|
|
|
|
|
|
|
if (array && variant && !array->IsNotDistribute()) {
|
|
|
|
|
size_t originalId = array->GetId();
|
|
|
|
|
size_t arrayId = originalId;
|
|
|
|
|
|
|
|
|
|
if (array->IsTemplate()) {
|
|
|
|
|
auto it = templateIdMapping.find(originalId);
|
|
|
|
|
if (it != templateIdMapping.end()) {
|
|
|
|
|
arrayId = it->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t elemSize = array->GetTypeSize();
|
|
|
|
|
|
|
|
|
|
vector<libpredict::DistributeAxisRule> axisDistributions;
|
|
|
|
|
const auto& arraySizes = array->GetSizes();
|
|
|
|
|
for (int dim = 0; dim < array->GetDimSize(); ++dim) {
|
|
|
|
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
|
|
|
|
|
|
|
|
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
|
|
|
|
axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::BLOCK);
|
|
|
|
|
} else {
|
|
|
|
|
axisDistributions.emplace_back(dimSize, libpredict::TypeDistribute::NONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<pair<size_t, size_t>> shadowEdges;
|
|
|
|
|
const auto& shadowSpec = array->GetShadowSpec();
|
|
|
|
|
for (int dim = 0; dim < shadowSpec.size() && dim < array->GetDimSize(); ++dim) {
|
|
|
|
|
if (dim < variant->distRule.size() && variant->distRule[dim] == dist::BLOCK) {
|
|
|
|
|
shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libpredict::RetDistribute retDistribute = libpredict::Distribute(arrayId, elemSize, axisDistributions, shadowEdges);
|
|
|
|
|
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",
|
|
|
|
|
array->GetShortName().c_str(), arrayId, (int)retDistribute);
|
|
|
|
|
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(array->GetShortName()).c_str(), (int)retDistribute);
|
|
|
|
|
to_wstring(params.array->GetShortName()).c_str(), (int)retDistribute);
|
|
|
|
|
__spf_printToLongBuf(messageR, R208);
|
|
|
|
|
getObjectForFileFromMap(array->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(
|
|
|
|
|
Messages(ERROR, array->GetDeclInfo().begin()->second, messageR, messageE, 1065));
|
|
|
|
|
}
|
|
|
|
|
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& alignRule : dataDirectives.alignRules) {
|
|
|
|
|
DIST::Array* alignArray = alignRule.alignArray;
|
|
|
|
|
DIST::Array* alignWithArray = alignRule.alignWith;
|
|
|
|
|
|
|
|
|
|
if (alignArray && alignWithArray && !alignArray->IsNotDistribute()) {
|
|
|
|
|
size_t arrayId = alignArray->GetId();
|
|
|
|
|
size_t originalDistributedArrayId = alignWithArray->GetId();
|
|
|
|
|
size_t distributedArrayId = originalDistributedArrayId;
|
|
|
|
|
|
|
|
|
|
if (alignWithArray->IsTemplate()) {
|
|
|
|
|
auto it = templateIdMapping.find(originalDistributedArrayId);
|
|
|
|
|
if (it != templateIdMapping.end()) {
|
|
|
|
|
distributedArrayId = it->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t elemSize = alignArray->GetTypeSize();
|
|
|
|
|
|
|
|
|
|
const auto& arraySizes = alignArray->GetSizes();
|
|
|
|
|
vector<size_t> dimensions;
|
|
|
|
|
for (int dim = 0; dim < alignArray->GetDimSize(); ++dim) {
|
|
|
|
|
size_t dimSize = arraySizes[dim].second - arraySizes[dim].first + 1;
|
|
|
|
|
dimensions.push_back(dimSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<libpredict::AlignDisplay> distributionExpressions;
|
|
|
|
|
for (int dim = 0; dim < alignWithArray->GetDimSize(); ++dim) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (int i = 0; i < alignRule.alignRuleWith.size(); ++i) {
|
|
|
|
|
const auto& ruleWith = alignRule.alignRuleWith[i];
|
|
|
|
|
if (ruleWith.first == dim) {
|
|
|
|
|
const auto& rule = ruleWith.second;
|
|
|
|
|
if (rule.first == 0) {
|
|
|
|
|
// Константа
|
|
|
|
|
distributionExpressions.emplace_back(rule.second);
|
|
|
|
|
} else {
|
|
|
|
|
// Линейное выражение a * I + b
|
|
|
|
|
distributionExpressions.emplace_back(i, rule.first, rule.second);
|
|
|
|
|
}
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
// Нет правила для этого измерения
|
|
|
|
|
distributionExpressions.emplace_back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<pair<size_t, size_t>> shadowEdges;
|
|
|
|
|
const auto& shadowSpec = alignArray->GetShadowSpec();
|
|
|
|
|
for (int dim = 0; dim < shadowSpec.size() && dim < alignArray->GetDimSize(); ++dim) {
|
|
|
|
|
shadowEdges.emplace_back(shadowSpec[dim].first, shadowSpec[dim].second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libpredict::RetAlign retAlign = libpredict::Align(arrayId, distributedArrayId, elemSize, dimensions, distributionExpressions, shadowEdges);
|
|
|
|
|
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",
|
|
|
|
|
alignArray->GetShortName().c_str(), arrayId,
|
|
|
|
|
alignWithArray->GetShortName().c_str(), distributedArrayId, (int)retAlign);
|
|
|
|
|
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(alignArray->GetShortName()).c_str(),
|
|
|
|
|
to_wstring(alignWithArray->GetShortName()).c_str(), (int)retAlign);
|
|
|
|
|
to_wstring(params.alignArray->GetShortName()).c_str(),
|
|
|
|
|
to_wstring(params.alignWithArray->GetShortName()).c_str(), (int)retAlign);
|
|
|
|
|
__spf_printToLongBuf(messageR, R209);
|
|
|
|
|
getObjectForFileFromMap(alignArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(
|
|
|
|
|
Messages(ERROR, alignArray->GetDeclInfo().begin()->second, messageR, messageE, 1066));
|
|
|
|
|
}
|
|
|
|
|
getObjectForFileFromMap(params.alignArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.alignArray->GetDeclInfo().begin()->second, messageR, messageE, 1066));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// shadow_renew
|
|
|
|
|
map<LoopGraph*, ParallelDirective*> parallelDirs;
|
|
|
|
|
for (int i = project.numberOfFiles() - 1; i >= 0; --i) {
|
|
|
|
|
SgFile *file = &(project.file(i));
|
|
|
|
|
auto fountInfo = findAllDirectives(file, getObjectForFileFromMap(file->filename(), loopGraph), parallelRegions[z]->GetId());
|
|
|
|
|
parallelDirs.insert(fountInfo.begin(), fountInfo.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& dirPair : parallelDirs) {
|
|
|
|
|
LoopGraph* loopPtr = dirPair.first;
|
|
|
|
|
ParallelDirective* directive = dirPair.second;
|
|
|
|
|
|
|
|
|
|
if (directive && !directive->shadowRenew.empty()) {
|
|
|
|
|
for (size_t shadowIdx = 0; shadowIdx < directive->shadowRenew.size(); ++shadowIdx) {
|
|
|
|
|
const auto& shadowRenewItem = directive->shadowRenew[shadowIdx];
|
|
|
|
|
const string& arrayName = shadowRenewItem.first.second; // uniqName
|
|
|
|
|
const vector<pair<int, int>>& bounds = shadowRenewItem.second;
|
|
|
|
|
|
|
|
|
|
DIST::Array* shadowArray = allArrays.GetArrayByName(arrayName);
|
|
|
|
|
if (shadowArray == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (shadowArray && !shadowArray->IsNotDistribute()) {
|
|
|
|
|
size_t arrayId = shadowArray->GetId();
|
|
|
|
|
|
|
|
|
|
vector<pair<size_t, size_t>> shadow_renew;
|
|
|
|
|
for (const auto& bound : bounds) {
|
|
|
|
|
shadow_renew.emplace_back(static_cast<size_t>(bound.first),
|
|
|
|
|
static_cast<size_t>(bound.second));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool corner = directive->shadowRenewCorner[shadowIdx];
|
|
|
|
|
size_t number_loop_iterations = loopPtr ? static_cast<size_t>(loopPtr->countOfIters) : 1;
|
|
|
|
|
|
|
|
|
|
libpredict::RetShadowRenew retShadowRenew = libpredict::ShadowRenew(arrayId, shadow_renew, corner, number_loop_iterations);
|
|
|
|
|
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) {
|
|
|
|
|
__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;
|
|
|
|
|
__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, R210);
|
|
|
|
|
getObjectForFileFromMap(shadowArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(
|
|
|
|
|
Messages(ERROR, shadowArray->GetDeclInfo().begin()->second, messageR, messageE, 1067));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getObjectForFileFromMap(params.shadowArray->GetDeclInfo().begin()->first.c_str(), SPF_messages).push_back(Messages(ERROR, params.shadowArray->GetDeclInfo().begin()->second, messageR, messageE, 1067));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -300,14 +332,17 @@ void runPredictScheme(SgProject &project,
|
|
|
|
|
|
|
|
|
|
auto& tmp = dataDirectives.distrRules;
|
|
|
|
|
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]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto var : currentVar) {
|
|
|
|
|
int countBlock = 0;
|
|
|
|
|
for (int z = 0; z < var->distRule.size(); ++z)
|
|
|
|
|
if (var->distRule[z] == dist::BLOCK)
|
|
|
|
|
for (int z = 0; z < var->distRule.size(); ++z) {
|
|
|
|
|
if (var->distRule[z] == dist::BLOCK) {
|
|
|
|
|
++countBlock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
maxSizeDist = std::max(maxSizeDist, countBlock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -324,11 +359,16 @@ void runPredictScheme(SgProject &project,
|
|
|
|
|
// 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
|
|
|
|
|
topologies = vector<vector<size_t>>();
|
|
|
|
|
if (maxSizeDist) {
|
|
|
|
|
|
|
|
|
|
if (maxSizeDist > 4) maxSizeDist = 4;
|
|
|
|
|
if (maxSizeDist > 4) {
|
|
|
|
|
maxSizeDist = 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize cluster
|
|
|
|
|
int procCount = 0;
|
|
|
|
|
@@ -347,13 +387,19 @@ void runPredictScheme(SgProject &project,
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
if (n4 != 1 && maxSizeDist < 4 || n4 == 1 && maxSizeDist == 4) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topologies.push_back(vector<size_t>{n1, n2, n3, n4});
|
|
|
|
|
}
|
|
|
|
|
@@ -364,15 +410,17 @@ void runPredictScheme(SgProject &project,
|
|
|
|
|
vector<size_t> best;
|
|
|
|
|
double bestTime = std::numeric_limits<double>::max();
|
|
|
|
|
for (auto& topology : topologies) {
|
|
|
|
|
double currTime = runLibpredictCalc(project, topology, clusterConfStr, parallelRegions, loopGraph, SPF_messages, templateIdMapping);
|
|
|
|
|
double currTime = runLibpredictCalc(topology, clusterConfStr, precomputedParams, SPF_messages);
|
|
|
|
|
|
|
|
|
|
string outStr = "";
|
|
|
|
|
for (const auto &elem : topology)
|
|
|
|
|
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)
|
|
|
|
|
if (currTime == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currTime < bestTime) {
|
|
|
|
|
bestTime = currTime;
|
|
|
|
|
@@ -380,8 +428,9 @@ void runPredictScheme(SgProject &project,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string outStr;
|
|
|
|
|
for (const auto &elem : best)
|
|
|
|
|
for (const auto& elem : best) {
|
|
|
|
|
outStr += std::to_string(elem) + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__spf_print(1, "best topology %s with time %f\n", outStr.c_str(), bestTime);
|
|
|
|
|
} else {
|
|
|
|
|
|