@@ -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+
8692const 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