@@ -31,71 +31,12 @@ namespace polyhedral {
3131using detail::ScheduleTree;
3232
3333namespace {
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;
6336
6437 // TODO: also compute strides
6538
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 ();
9940 return footprint;
10041}
10142
@@ -117,15 +58,16 @@ std::unique_ptr<TensorReferenceGroup> TensorReferenceGroup::makeSingleton(
11758 auto ref = std::unique_ptr<TensorReference>(new TensorReference);
11859 auto refId = scopedAccess.get_space ().domain ().unwrap ().get_tuple_id (
11960 isl::dim_type::out);
61+ scopedAccess = scopedAccess.domain_factor_domain ();
12062 ref->originalAccess = originalAccess.domain_factor_domain ();
121- ref->scopedAccess = scopedAccess. domain_factor_domain () ;
63+ ref->scopedAccess = scopedAccess;
12264 ref->type = type;
12365 ref->refId = refId;
12466 auto group = std::unique_ptr<TensorReferenceGroup>(new TensorReferenceGroup);
12567 group->references .push_back (std::move (ref));
12668 group->approximation = outputRanges (scopedAccess);
12769
128- if (group->approximation .size () != scopedAccess. dim (isl::dim_type::out )) {
70+ if (! group->approximation .box . is_valid ( )) {
12971 std::stringstream ss;
13072 ss << " could not compute rectangular overapproximation of: "
13173 << scopedAccess;
@@ -136,32 +78,25 @@ std::unique_ptr<TensorReferenceGroup> TensorReferenceGroup::makeSingleton(
13678}
13779
13880isl::set ScopedFootprint::footprint (isl::set domain) const {
139- auto space = add_range (domain .get_space (), size () );
81+ auto space = box .get_space ();
14082 auto accessed = isl::map::universe (space).intersect_domain (domain);
14183 auto lspace = isl::local_space (accessed.get_space ().range ());
14284
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);
14587 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);
14890 accessed = accessed & partial;
14991 }
15092 return accessed.range ();
15193}
15294
15395isl::multi_aff ScopedFootprint::lowerBounds () const {
154- if (size () == 0 ) {
96+ if (dim () == 0 ) {
15597 throw promotion::PromotionNYI (" promotion for scalars" );
15698 }
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 ();
165100}
166101
167102bool TensorReferenceGroup::isReadOnly () const {
@@ -173,28 +108,28 @@ bool TensorReferenceGroup::isReadOnly() const {
173108}
174109
175110isl::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)) {
180114 throw promotion::GroupingError (" unexpected dimensionality mismatch" );
181115 }
182116
183117 isl::set footprint = isl::set::universe (space);
184118 auto lspace = isl::local_space (space);
185119 for (size_t i = 0 , e = sizes.size (); i < e; ++i) {
186120 auto aff = isl::aff (lspace, isl::dim_type::out, i);
121+ auto size = sizes.get_val (i);
187122 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 );
189124 }
190125 return footprint;
191126}
192127
193128std::vector<size_t > TensorReferenceGroup::approximationSizes () const {
194129 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 ());
198133 }
199134 return result;
200135}
@@ -381,9 +316,7 @@ isl::multi_aff TensorReferenceGroup::promotion() const {
381316 // lower bounds space is S -> P; which we transform into [S -> O] -> P
382317 auto lowerBounds = approximation.lowerBounds ().pullback (
383318 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;
387320 return promotion;
388321}
389322
0 commit comments