Skip to content

Commit 6b41058

Browse files
Mapspaces now accommodate min factors.
1 parent f1daa2e commit 6b41058

File tree

6 files changed

+100
-5
lines changed

6 files changed

+100
-5
lines changed

include/mapspaces/subspaces.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class IndexFactorizationSpace
5656
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> prefactors =
5757
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>>(),
5858
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors =
59+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>>(),
60+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> minfactors =
5961
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>>());
6062

6163
unsigned long GetFactor(uint128_t nest_id, problem::Shape::FlattenedDimensionID dim, unsigned level);
@@ -80,6 +82,7 @@ class ResidualIndexFactorizationSpace
8082
std::map<problem::Shape::FlattenedDimensionID, std::uint64_t> cofactors_order,
8183
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> prefactors,
8284
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors,
85+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> minfactors,
8386
std::vector<unsigned long int> remainders = {},
8487
std::vector<unsigned long int> remainders_ix = {}
8588
);

include/util/numeric.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Factors
6565
Factors(const unsigned long n, const int order, std::map<unsigned, unsigned long> given);
6666

6767
void PruneMax(std::map<unsigned, unsigned long>& max);
68+
void PruneMin(std::map<unsigned, unsigned long>& min);
6869

6970
std::vector<unsigned long>& operator[](int index);
7071

@@ -119,6 +120,7 @@ class ResidualFactors
119120

120121

121122
void PruneMax();
123+
void PruneMin();
122124

123125
std::vector<std::vector<unsigned long>> operator[](int index);
124126

src/mapspaces/ruby.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void Ruby::InitIndexFactorizationSpace()
119119
{
120120
auto user_factors = constraints_.Factors();
121121
auto user_max_factors = constraints_.MaxFactors();
122+
auto user_min_factors = constraints_.MinFactors();
122123
auto user_max_remainders = constraints_.MaxRemainders();
123124

124125
assert(user_factors.size() <= arch_props_.TilingLevels());
@@ -141,6 +142,7 @@ void Ruby::InitIndexFactorizationSpace()
141142

142143
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> prefactors;
143144
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors;
145+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> minfactors;
144146
std::vector<bool> exhausted_um_loops(int(problem::GetShape()->NumFlattenedDimensions), false);
145147

146148
// Find user-specified fixed factors.
@@ -183,7 +185,23 @@ void Ruby::InitIndexFactorizationSpace()
183185
}
184186
}
185187

186-
//Find spatial levels and their fanouts
188+
// Find user-specified min factors.
189+
for (unsigned level = 0; level < arch_props_.TilingLevels(); level++)
190+
{
191+
auto it = user_min_factors.find(level);
192+
if (it != user_min_factors.end())
193+
{
194+
// Some min factors exist for this level.
195+
for (auto& factor : it->second)
196+
{
197+
auto& dimension = factor.first;
198+
auto& min = factor.second;
199+
minfactors[dimension][level] = min;
200+
}
201+
}
202+
}
203+
204+
// Find spatial levels and their fanouts
187205
std::vector<unsigned long int> remainders;
188206
std::vector<unsigned long int> remainders_ix;
189207
for (uint64_t level = arch_props_.TilingLevels(); level >= 1; level--)
@@ -198,8 +216,8 @@ void Ruby::InitIndexFactorizationSpace()
198216
}
199217
}
200218

201-
// We're now ready to initialize the object.
202-
index_factorization_space_.Init(workload_, cofactors_order, prefactors, maxfactors, remainders, remainders_ix);
219+
// We're now ready to initialize the object.
220+
index_factorization_space_.Init(workload_, cofactors_order, prefactors, maxfactors, minfactors, remainders, remainders_ix);
203221

204222
// Update the size of the mapspace.
205223
size_[int(mapspace::Dimension::IndexFactorization)] = index_factorization_space_.Size();

src/mapspaces/subspaces.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ IndexFactorizationSpace::IndexFactorizationSpace() :
4444
void IndexFactorizationSpace::Init(const problem::Workload &workload,
4545
std::map<problem::Shape::FlattenedDimensionID, std::uint64_t> cofactors_order,
4646
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> prefactors,
47-
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors)
47+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors,
48+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> minfactors)
4849
{
4950
// Sanity check on input pre-factors.
5051
for (auto& prefactor_set: prefactors)
@@ -92,6 +93,9 @@ void IndexFactorizationSpace::Init(const problem::Workload &workload,
9293
if (maxfactors.find(dim) != maxfactors.end())
9394
dimension_factors_[idim].PruneMax(maxfactors[dim]);
9495

96+
if (minfactors.find(dim) != minfactors.end())
97+
dimension_factors_[idim].PruneMin(minfactors[dim]);
98+
9599
counter_base[idim] = dimension_factors_[idim].size();
96100
}
97101

@@ -131,6 +135,7 @@ void ResidualIndexFactorizationSpace::Init(const problem::Workload &workload,
131135
std::map<problem::Shape::FlattenedDimensionID, std::uint64_t> cofactors_order,
132136
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> prefactors,
133137
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors,
138+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> minfactors,
134139
std::vector<unsigned long int> remainders,
135140
std::vector<unsigned long int> remainders_ix)
136141
{
@@ -170,6 +175,9 @@ void ResidualIndexFactorizationSpace::Init(const problem::Workload &workload,
170175
if (maxfactors.find(dim) != maxfactors.end())
171176
dimension_factors_[idim].PruneMax();
172177

178+
if (minfactors.find(dim) != minfactors.end())
179+
dimension_factors_[idim].PruneMin();
180+
173181
counter_base[idim] = dimension_factors_[idim].size();
174182

175183
}

src/mapspaces/uber.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void Uber::InitIndexFactorizationSpace()
119119
{
120120
auto user_factors = constraints_.Factors();
121121
auto user_max_factors = constraints_.MaxFactors();
122+
auto user_min_factors = constraints_.MinFactors();
122123

123124
assert(user_factors.size() <= arch_props_.TilingLevels());
124125

@@ -140,6 +141,7 @@ void Uber::InitIndexFactorizationSpace()
140141

141142
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> prefactors;
142143
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> maxfactors;
144+
std::map<problem::Shape::FlattenedDimensionID, std::map<unsigned, unsigned long>> minfactors;
143145
std::vector<bool> exhausted_um_loops(int(problem::GetShape()->NumFlattenedDimensions), false);
144146

145147
// Find user-specified fixed factors.
@@ -182,8 +184,24 @@ void Uber::InitIndexFactorizationSpace()
182184
}
183185
}
184186

187+
// Find user-specified min factors.
188+
for (unsigned level = 0; level < arch_props_.TilingLevels(); level++)
189+
{
190+
auto it = user_min_factors.find(level);
191+
if (it != user_min_factors.end())
192+
{
193+
// Some min factors exist for this level.
194+
for (auto& factor : it->second)
195+
{
196+
auto& dimension = factor.first;
197+
auto& min = factor.second;
198+
minfactors[dimension][level] = min;
199+
}
200+
}
201+
}
202+
185203
// We're now ready to initialize the object.
186-
index_factorization_space_.Init(workload_, cofactors_order, prefactors, maxfactors);
204+
index_factorization_space_.Init(workload_, cofactors_order, prefactors, maxfactors, minfactors);
187205

188206
// Update the size of the mapspace.
189207
size_[int(mapspace::Dimension::IndexFactorization)] = index_factorization_space_.Size();

src/util/numeric.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,40 @@ void Factors::PruneMax(std::map<unsigned, unsigned long>& max)
231231
}
232232
}
233233

234+
void Factors::PruneMin(std::map<unsigned, unsigned long>& min)
235+
{
236+
// Prune the vector of cofactor sets by removing those sets that have factors
237+
// outside user-specified min/max range. We should really have done this during
238+
// MultiplicativeSplitRecursive. However, the "given" map complicates things
239+
// because given factors may be scattered, and we'll need a map table to
240+
// find the original rank from the "compressed" rank seen by
241+
// MultiplicativeSplitRecursive. Doing it now is slower but cleaner and less
242+
// bug-prone.
243+
244+
auto cofactors_it = cofactors_.begin();
245+
while (cofactors_it != cofactors_.end())
246+
{
247+
bool illegal = false;
248+
for (auto& min_factor : min)
249+
{
250+
auto index = min_factor.first;
251+
auto min = min_factor.second;
252+
assert(index <= cofactors_it->size());
253+
auto value = cofactors_it->at(index);
254+
if (value < min)
255+
{
256+
illegal = true;
257+
break;
258+
}
259+
}
260+
261+
if (illegal)
262+
cofactors_it = cofactors_.erase(cofactors_it);
263+
else
264+
cofactors_it++;
265+
}
266+
}
267+
234268
std::vector<unsigned long>& Factors::operator[](int index)
235269
{
236270
return cofactors_[index];
@@ -530,6 +564,18 @@ void ResidualFactors::PruneMax()
530564

531565
}
532566

567+
void ResidualFactors::PruneMin()
568+
{
569+
// Prune the vector of cofactor sets by removing those sets that have factors
570+
// outside user-specified min/max range. We should really have done this during
571+
// MultiplicativeSplitRecursive. However, the "given" map complicates things
572+
// because given factors may be scattered, and we'll need a map table to
573+
// find the original rank from the "compressed" rank seen by
574+
// MultiplicativeSplitRecursive. Doing it now is slower but cleaner and less
575+
// bug-prone.
576+
577+
}
578+
533579
ResidualFactors::ResidualFactors() : n_(0) {}
534580

535581
/***

0 commit comments

Comments
 (0)