Skip to content

Commit c19bf12

Browse files
Add parsing of min (>=) constraints for mapspace.
1 parent 002b743 commit c19bf12

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

include/mapping/constraints.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Constraints
5252
// The constraints.
5353
std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>> factors_;
5454
std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>> max_factors_;
55+
std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>> min_factors_;
5556
std::map<unsigned, std::pair<std::vector<problem::Shape::FlattenedDimensionID>,
5657
std::vector<problem::Shape::FlattenedDimensionID>>> permutations_;
5758
std::map<unsigned, std::uint32_t> spatial_splits_;
@@ -73,6 +74,7 @@ class Constraints
7374

7475
const std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>>& Factors() const;
7576
const std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>>& MaxFactors() const;
77+
const std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>>& MinFactors() const;
7678
const std::map<unsigned, std::pair<std::vector<problem::Shape::FlattenedDimensionID>,
7779
std::vector<problem::Shape::FlattenedDimensionID>>>& Permutations() const;
7880
const std::map<unsigned, std::uint32_t>& SpatialSplits() const;
@@ -113,6 +115,7 @@ class Constraints
113115
// Parsers.
114116
std::map<problem::Shape::FlattenedDimensionID, int> ParseFactors(config::CompoundConfigNode constraint);
115117
std::map<problem::Shape::FlattenedDimensionID, int> ParseMaxFactors(config::CompoundConfigNode constraint);
118+
std::map<problem::Shape::FlattenedDimensionID, int> ParseMinFactors(config::CompoundConfigNode constraint);
116119
std::pair<std::vector<problem::Shape::FlattenedDimensionID>,
117120
std::vector<problem::Shape::FlattenedDimensionID>> ParsePermutations(config::CompoundConfigNode constraint);
118121
void ParseDatatypeBypassSettings(config::CompoundConfigNode constraint, unsigned level);

src/mapping/constraints.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ const std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>>&
8383
return max_factors_;
8484
}
8585

86+
const std::map<unsigned, std::map<problem::Shape::FlattenedDimensionID, int>>&
87+
Constraints::MinFactors() const
88+
{
89+
return min_factors_;
90+
}
91+
8692
const std::map<unsigned, std::uint32_t>&
8793
Constraints::MaxRemainders() const
8894
{
@@ -623,6 +629,21 @@ void Constraints::ParseSingleConstraint(
623629
max_factors_[level_id][max_factor.first] = max_factor.second;
624630
}
625631

632+
auto level_min_factors = ParseMinFactors(attributes);
633+
for (auto& min_factor: level_min_factors)
634+
{
635+
if (min_factors_[level_id].find(min_factor.first) != min_factors_[level_id].end())
636+
{
637+
std::cerr << "ERROR: re-specification of min factor for dimension "
638+
<< problem::GetShape()->FlattenedDimensionIDToName.at(min_factor.first)
639+
<< " at level " << arch_props_.TilingLevelName(level_id)
640+
<< ". This may imply a conflict between architecture and "
641+
<< "mapspace constraints." << std::endl;
642+
exit(1);
643+
}
644+
min_factors_[level_id][min_factor.first] = min_factor.second;
645+
}
646+
626647
auto level_permutations = ParsePermutations(attributes);
627648
if (level_permutations.first.size() > 0 || level_permutations.second.size() > 0)
628649
{
@@ -1021,6 +1042,65 @@ Constraints::ParseMaxFactors(config::CompoundConfigNode constraint)
10211042
return retval;
10221043
}
10231044

1045+
//
1046+
// Parse user min factors.
1047+
//
1048+
std::map<problem::Shape::FlattenedDimensionID, int>
1049+
Constraints::ParseMinFactors(config::CompoundConfigNode constraint)
1050+
{
1051+
std::map<problem::Shape::FlattenedDimensionID, int> retval;
1052+
1053+
std::string buffer;
1054+
if (constraint.lookupValue("factors", buffer))
1055+
{
1056+
buffer = buffer.substr(0, buffer.find("#"));
1057+
1058+
std::regex re("([A-Za-z]+)[[:space:]]*>=[[:space:]]*([0-9]+)", std::regex::extended);
1059+
std::smatch sm;
1060+
std::string str = std::string(buffer);
1061+
1062+
while (std::regex_search(str, sm, re))
1063+
{
1064+
std::string dimension_name = sm[1];
1065+
problem::Shape::FlattenedDimensionID dimension;
1066+
try
1067+
{
1068+
dimension = problem::GetShape()->FlattenedDimensionNameToID.at(dimension_name);
1069+
}
1070+
catch (const std::out_of_range& oor)
1071+
{
1072+
std::cerr << "ERROR: parsing factors: " << buffer << ": dimension " << dimension_name
1073+
<< " not found in problem shape." << std::endl;
1074+
exit(1);
1075+
}
1076+
1077+
int min = std::stoi(sm[2]);
1078+
if (min <= 0)
1079+
{
1080+
std::cerr << "ERROR: min factor must be positive in constraint: " << buffer << std::endl;
1081+
exit(1);
1082+
}
1083+
1084+
// Found all the information we need to setup a factor!
1085+
retval[dimension] = min;
1086+
1087+
str = sm.suffix().str();
1088+
}
1089+
}
1090+
if (constraint.lookupValue("default_min_factor", buffer))
1091+
{
1092+
int min = std::stoi(buffer);
1093+
for(auto& it : problem::GetShape()->FlattenedDimensionNameToID)
1094+
{
1095+
if(retval.find(it.second) == retval.end())
1096+
{
1097+
retval[it.second] = min;
1098+
}
1099+
}
1100+
}
1101+
return retval;
1102+
}
1103+
10241104
//
10251105
// Parse user permutations.
10261106
//

0 commit comments

Comments
 (0)