@@ -31,71 +31,12 @@ namespace polyhedral {
31
31
using detail::ScheduleTree;
32
32
33
33
namespace {
34
- std::pair<isl::val, isl::aff> outputRange (
35
- isl::basic_set wrappedAccess,
36
- isl::constraint cstr) {
37
- auto emptyRange =
38
- std::make_pair (isl::val::nan (wrappedAccess.get_ctx ()), isl::aff ());
39
- int pos = cstr.dim (isl::dim_type::set) - 1 ;
40
- if (!cstr.is_lower_bound (isl::dim_type::set, pos)) {
41
- return emptyRange;
42
- }
43
- if (cstr.involves_dims (isl::dim_type::div, 0 , cstr.dim (isl::dim_type::div))) {
44
- return emptyRange;
45
- }
46
-
47
- auto lowerBound = cstr.get_bound (isl::dim_type::set, pos).ceil ();
48
- auto aff = lowerBound.neg ().add_coefficient_si (isl::dim_type::in, pos, 1 );
49
- lowerBound = lowerBound.drop_dims (isl::dim_type::in, pos, 1 );
50
-
51
- auto range = wrappedAccess.max_val (aff);
52
- if (range.is_int ()) {
53
- return std::make_pair (range + 1 , lowerBound);
54
- }
55
- return emptyRange;
56
- }
57
-
58
- std::pair<isl::val, isl::aff> outputRangeSingle (isl::map access) {
59
- CHECK_EQ (access.dim (isl::dim_type::out), 1u )
60
- << " expected 1-dim output, call outputRanges instead" ;
61
- access = access.detect_equalities ();
62
- auto wrappedAccess = access.wrap ().flatten ().compute_divs ().simple_hull ();
34
+ ScopedFootprint outputRanges (isl::map access) {
35
+ ScopedFootprint footprint;
63
36
64
37
// TODO: also compute strides
65
38
66
- isl::val minRange;
67
- isl::aff lowerBoundWithMinRange;
68
- for (auto cstr : wrappedAccess.get_constraint_list ()) {
69
- auto range = outputRange (wrappedAccess, cstr);
70
- if (range.first .is_nan ()) {
71
- continue ;
72
- }
73
- if (minRange.is_null () || range.first < minRange) {
74
- minRange = range.first ;
75
- lowerBoundWithMinRange = range.second ;
76
- }
77
- }
78
- if (minRange.is_null ()) {
79
- return std::make_pair (
80
- isl::val::nan (access.get_ctx ()), lowerBoundWithMinRange);
81
- }
82
-
83
- return std::make_pair (minRange, lowerBoundWithMinRange);
84
- }
85
-
86
- ScopedFootprint outputRanges (isl::map access) {
87
- int nSubscripts = access.dim (isl::dim_type::out);
88
- ScopedFootprint footprint;
89
- for (int i = 0 ; i < nSubscripts; ++i) {
90
- auto singleDim =
91
- access.project_out (isl::dim_type::out, 0 , i)
92
- .project_out (isl::dim_type::out, 1 , nSubscripts - i - 1 );
93
- auto range = outputRangeSingle (singleDim);
94
- if (range.first .is_nan ()) {
95
- return {};
96
- }
97
- footprint.emplace_back (range.second , range.first );
98
- }
39
+ footprint.box = access.get_range_simple_fixed_box_hull ();
99
40
return footprint;
100
41
}
101
42
@@ -117,15 +58,16 @@ std::unique_ptr<TensorReferenceGroup> TensorReferenceGroup::makeSingleton(
117
58
auto ref = std::unique_ptr<TensorReference>(new TensorReference);
118
59
auto refId = scopedAccess.get_space ().domain ().unwrap ().get_tuple_id (
119
60
isl::dim_type::out);
61
+ scopedAccess = scopedAccess.domain_factor_domain ();
120
62
ref->originalAccess = originalAccess.domain_factor_domain ();
121
- ref->scopedAccess = scopedAccess. domain_factor_domain () ;
63
+ ref->scopedAccess = scopedAccess;
122
64
ref->type = type;
123
65
ref->refId = refId;
124
66
auto group = std::unique_ptr<TensorReferenceGroup>(new TensorReferenceGroup);
125
67
group->references .push_back (std::move (ref));
126
68
group->approximation = outputRanges (scopedAccess);
127
69
128
- if (group->approximation .size () != scopedAccess. dim (isl::dim_type::out )) {
70
+ if (! group->approximation .box . is_valid ( )) {
129
71
std::stringstream ss;
130
72
ss << " could not compute rectangular overapproximation of: "
131
73
<< scopedAccess;
@@ -136,32 +78,25 @@ std::unique_ptr<TensorReferenceGroup> TensorReferenceGroup::makeSingleton(
136
78
}
137
79
138
80
isl::set ScopedFootprint::footprint (isl::set domain) const {
139
- auto space = add_range (domain .get_space (), size () );
81
+ auto space = box .get_space ();
140
82
auto accessed = isl::map::universe (space).intersect_domain (domain);
141
83
auto lspace = isl::local_space (accessed.get_space ().range ());
142
84
143
- for (size_t i = 0 ; i < size (); ++i) {
144
- auto dim = at (i);
85
+ for (size_t i = 0 ; i < dim (); ++i) {
86
+ auto dimLowerBound = lowerBound (i);
145
87
auto rhs = isl::aff (lspace, isl::dim_type::set, i);
146
- isl::map partial = (isl::aff_map (dim. lowerBound ) <= rhs) &
147
- (isl::aff_map (dim. lowerBound + dim. size ) > rhs);
88
+ isl::map partial = (isl::aff_map (dimLowerBound ) <= rhs) &
89
+ (isl::aff_map (dimLowerBound + size (i) ) > rhs);
148
90
accessed = accessed & partial;
149
91
}
150
92
return accessed.range ();
151
93
}
152
94
153
95
isl::multi_aff ScopedFootprint::lowerBounds () const {
154
- if (size () == 0 ) {
96
+ if (dim () == 0 ) {
155
97
throw promotion::PromotionNYI (" promotion for scalars" );
156
98
}
157
- auto space = add_range (at (0 ).lowerBound .get_space ().domain (), size ());
158
- auto ma = isl::multi_aff::zero (space);
159
-
160
- int i = 0 ;
161
- for (const auto & a : *this ) {
162
- ma = ma.set_aff (i++, a.lowerBound );
163
- }
164
- return ma;
99
+ return box.get_offset ();
165
100
}
166
101
167
102
bool TensorReferenceGroup::isReadOnly () const {
@@ -173,28 +108,28 @@ bool TensorReferenceGroup::isReadOnly() const {
173
108
}
174
109
175
110
isl::set TensorReferenceGroup::promotedFootprint () const {
176
- auto space =
177
- scopedAccesses ().get_space ().range ().reset_tuple_id (isl::dim_type::set);
178
- auto sizes = approximationSizes ();
179
- if (sizes.size () != space.dim (isl::dim_type::set)) {
111
+ auto space = scopedAccesses ().get_space ().range ();
112
+ auto sizes = approximation.box .get_size ();
113
+ if (!sizes.get_space ().has_equal_tuples (space)) {
180
114
throw promotion::GroupingError (" unexpected dimensionality mismatch" );
181
115
}
182
116
183
117
isl::set footprint = isl::set::universe (space);
184
118
auto lspace = isl::local_space (space);
185
119
for (size_t i = 0 , e = sizes.size (); i < e; ++i) {
186
120
auto aff = isl::aff (lspace, isl::dim_type::out, i);
121
+ auto size = sizes.get_val (i);
187
122
footprint =
188
- footprint & (isl::aff_set (aff) >= 0 ) & (isl::aff_set (aff) < sizes[i] );
123
+ footprint & (isl::aff_set (aff) >= 0 ) & (isl::aff_set (aff) < size );
189
124
}
190
125
return footprint;
191
126
}
192
127
193
128
std::vector<size_t > TensorReferenceGroup::approximationSizes () const {
194
129
std::vector<size_t > result;
195
- result.reserve (approximation.size ());
196
- for (const auto & dim : approximation) {
197
- result.push_back (dim. size .get_num_si ());
130
+ result.reserve (approximation.dim ());
131
+ for (const auto & size : approximation. box . get_size (). get_val_list () ) {
132
+ result.push_back (size.get_num_si ());
198
133
}
199
134
return result;
200
135
}
@@ -381,9 +316,7 @@ isl::multi_aff TensorReferenceGroup::promotion() const {
381
316
// lower bounds space is S -> P; which we transform into [S -> O] -> P
382
317
auto lowerBounds = approximation.lowerBounds ().pullback (
383
318
isl::multi_aff::domain_map (accessSpace));
384
- auto promotion = isl::multi_aff::range_map (accessSpace)
385
- .reset_tuple_id (isl::dim_type::out) -
386
- lowerBounds;
319
+ auto promotion = isl::multi_aff::range_map (accessSpace) - lowerBounds;
387
320
return promotion;
388
321
}
389
322
0 commit comments