Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit fed4151

Browse files
Merge pull request #479 from facebookresearch/pr/cpp
avoid using functions that will not be added to mainline isl C++ interface
2 parents 4e83a3c + 8f8a3c2 commit fed4151

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed

tc/core/halide2isl.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ isl::map extractAccess(
264264
// the allocation could be accessed.
265265
isl::set access = isl::set::universe(tensorSpace);
266266

267+
auto identity = isl::multi_aff::identity(tensorSpace.map_from_set());
267268
for (size_t i = 0; i < args.size(); i++) {
268269
// Then add one equality constraint per dimension to encode the
269270
// point in the allocation actually read/written for each point in
270271
// the iteration space. In the case of gathers or scatters, we may
271272
// have to leave some things unconstrained.
272273

273274
// The coordinate written to in the range ...
274-
auto rangePoint =
275-
isl::pw_aff(isl::local_space(tensorSpace), isl::dim_type::set, i);
275+
auto rangePoint = identity.get_aff(i);
276276
// ... equals the coordinate accessed as a function of the parameters.
277277
auto domainPoint = halide2isl::makeIslAffFromExpr(tensorSpace, args[i]);
278278
if (!domainPoint.is_null()) {
@@ -441,7 +441,7 @@ isl::schedule makeScheduleTreeHelper(
441441
isl::id id(set.get_ctx(), kStatementLabel + std::to_string(stmtIndex));
442442
statements->emplace(id, op);
443443
auto tupleSpace = isl::space(set.get_ctx(), 0);
444-
tupleSpace = tupleSpace.named_set_from_params_id(id, outer.n());
444+
tupleSpace = tupleSpace.named_set_from_params_id(id, outer.size());
445445
IterationDomain iterationDomain;
446446
iterationDomain.paramSpace = set.get_space();
447447
iterationDomain.tuple = isl::multi_id(tupleSpace, outer);

tc/core/polyhedral/cuda/memory_promotion_heuristic.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,16 @@ bool hasReuseWithin(
206206
* dimensions unchanged.
207207
*/
208208
isl::map makeNextElementMap(isl::space setSpace, unsigned dim) {
209-
if (dim < 0 || dim >= setSpace.dim(isl::dim_type::set)) {
209+
auto mapSpace = setSpace.map_from_set();
210+
auto identityMA = isl::multi_aff::identity(mapSpace);
211+
212+
size_t size = identityMA.size();
213+
if (dim < 0 || dim >= size) {
210214
std::stringstream ss;
211-
ss << dim << " is out of [0, " << setSpace.dim(isl::dim_type::set)
212-
<< ") range";
215+
ss << dim << " is out of [0, " << size << ") range";
213216
throw promotion::OutOfRangeException(ss.str());
214217
}
215218

216-
auto mapSpace = setSpace.map_from_set();
217-
auto identityMA = isl::multi_aff::identity(mapSpace);
218219
auto aff = identityMA.get_aff(dim);
219220
identityMA = identityMA.set_aff(dim, aff + 1);
220221
return isl::map(identityMA);
@@ -266,6 +267,7 @@ bool promotionImprovesCoalescing(
266267
isl::union_map schedule) {
267268
auto originalAccesses = group.originalAccesses();
268269

270+
auto tensorDim = group.approximation.dim();
269271
auto markers = collectBranchMarkers(root, node);
270272
for (auto marker : markers) {
271273
auto mapping = findThreadMappingAncestor(root, marker);
@@ -280,8 +282,7 @@ bool promotionImprovesCoalescing(
280282
for (auto access : isl::UnionAsVector<isl::union_map>(scheduledAccesses)) {
281283
auto scheduleSpace = access.get_space().domain();
282284
auto tensorSpace = access.get_space().range();
283-
auto elementToNext = makeNextElementMap(
284-
tensorSpace, tensorSpace.dim(isl::dim_type::set) - 1);
285+
auto elementToNext = makeNextElementMap(tensorSpace, tensorDim - 1);
285286
auto scheduleToNextX = makeNextElementMap(scheduleSpace, depth - 1);
286287
auto accessedByAdjacentX =
287288
scheduleToNextX.apply_domain(access).apply_range(access);

tc/core/polyhedral/memory_promotion.cc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ ScopedFootprint outputRanges(isl::map access) {
7777
footprint.box = access.get_range_simple_fixed_box_hull();
7878
return footprint;
7979
}
80-
81-
// Given a set space, construct a map space with the input as domain and
82-
// a range of the given size.
83-
isl::space add_range(isl::space space, unsigned dim) {
84-
auto range = space.params().unnamed_set_from_params(dim);
85-
return space.map_from_domain_and_range(range);
86-
}
87-
8880
} // namespace
8981

9082
// Access has the shape :: [S -> ref] -> O
@@ -119,14 +111,14 @@ isl::map TensorReferenceGroup::approximateScopedAccesses() const {
119111
auto scopedDomain = scopedAccesses().domain();
120112
auto space = approximation.box.get_space();
121113
auto accessed = isl::map::universe(space).intersect_domain(scopedDomain);
122-
auto lspace = isl::local_space(accessed.get_space().range());
123114

115+
auto identity = isl::multi_aff::identity(space.range().map_from_set());
124116
for (size_t i = 0; i < approximation.dim(); ++i) {
125117
auto offset = approximation.lowerBound(i);
126118
auto stride = approximation.stride(i);
127119
auto strideOffset = approximation.strideOffset(i);
128120
auto size = approximation.size(i);
129-
auto rhs = isl::aff(lspace, isl::dim_type::set, i);
121+
auto rhs = identity.get_aff(i);
130122
auto lowerBound = offset * stride + strideOffset;
131123
auto upperBound = (offset + size) * stride + strideOffset;
132124
auto partial =
@@ -160,9 +152,9 @@ isl::set TensorReferenceGroup::promotedFootprint() const {
160152
}
161153

162154
isl::set footprint = isl::set::universe(space);
163-
auto lspace = isl::local_space(space);
155+
auto identity = isl::multi_aff::identity(space.map_from_set());
164156
for (size_t i = 0, e = sizes.size(); i < e; ++i) {
165-
auto aff = isl::aff(lspace, isl::dim_type::out, i);
157+
auto aff = identity.get_aff(i);
166158
auto size = sizes.get_val(i);
167159
footprint =
168160
footprint & (isl::aff_set(aff) >= 0) & (isl::aff_set(aff) < size);
@@ -422,12 +414,13 @@ isl::set tensorElementsSet(const Scop& scop, isl::id tensorId) {
422414
space = space.named_set_from_params_id(tensorId, nDim);
423415

424416
auto tensorElements = isl::set::universe(space);
417+
auto identity = isl::multi_aff::identity(space.range().map_from_set());
425418
for (int i = 0; i < nDim; ++i) {
426419
auto minAff = halide2isl::makeIslAffFromExpr(
427420
space, halideParameter.min_constraint(i));
428421
auto extentAff = halide2isl::makeIslAffFromExpr(
429422
space, halideParameter.extent_constraint(i));
430-
auto aff = isl::aff(isl::local_space(space), isl::dim_type::set, i);
423+
auto aff = identity.get_aff(i);
431424
tensorElements = tensorElements & (minAff <= isl::aff_set(aff)) &
432425
(isl::aff_set(aff) < (minAff + extentAff));
433426
}
@@ -456,7 +449,7 @@ isl::multi_aff dropDummyTensorDimensions(
456449
}
457450
}
458451

459-
space = add_range(space, list.size());
452+
space = addRange(space, list.size());
460453
return isl::multi_aff(space, list);
461454
}
462455

tc/core/polyhedral/schedule_tree_elem.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ void ScheduleTreeElemBand::drop(size_t pos, size_t n) {
159159
TC_CHECK_GE(nMember(), pos + n) << "range out of bounds";
160160
auto nBegin = nMember();
161161

162-
mupa_ = mupa_.drop_dims(isl::dim_type::set, pos, n);
162+
auto list = mupa_.get_union_pw_aff_list();
163+
auto space = mupa_.get_space().domain();
164+
list = list.drop(pos, n);
165+
space = addRange(space, list.size());
166+
mupa_ = isl::multi_union_pw_aff(space, list);
163167

164168
std::copy(
165169
coincident_.begin() + pos + n,

tc/core/polyhedral/unroll.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ isl::val boundInstancesAndMarkUnroll(
9393
auto partial = band->mupa_;
9494
auto n = band->nMember();
9595

96+
auto list = partial.get_union_pw_aff_list();
97+
auto space = partial.get_space().domain();
9698
for (int i = n - 1; i >= 0; --i) {
9799
auto member = partial.get_union_pw_aff(i);
98100
auto outerMap = prefix;
99101
if (i > 0) {
100-
auto outer = partial.drop_dims(isl::dim_type::set, i, n - i);
102+
list = list.drop(i, 1);
103+
auto outer = isl::multi_union_pw_aff(addRange(space, list.size()), list);
101104
outerMap = outerMap.flat_range_product(isl::union_map::from(outer));
102105
}
103106
bound = bound.mul(relativeRange(outerMap, member));

tc/external/detail/islpp.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,19 @@ inline bool operator!=(const isl::id& id1, const isl::id& id2) {
280280
///////////////////////////////////////////////////////////////////////////////
281281
// Helper functions
282282
///////////////////////////////////////////////////////////////////////////////
283+
284+
// Given a set space, construct a map space with the input as domain and
285+
// a range of the given size.
286+
inline isl::space addRange(isl::space space, unsigned dim) {
287+
auto range = space.params().unnamed_set_from_params(dim);
288+
return space.map_from_domain_and_range(range);
289+
}
290+
283291
// Given a space and a list of values, this returns the corresponding multi_val.
284292
template <typename T>
285293
isl::multi_val makeMultiVal(isl::space s, const std::vector<T>& vals) {
286294
isl::multi_val mv = isl::multi_val::zero(s);
287-
TC_CHECK_EQ(vals.size(), s.dim(isl::dim_type::set));
295+
TC_CHECK_EQ(vals.size(), static_cast<size_t>(mv.size()));
288296
for (size_t i = 0; i < vals.size(); ++i) {
289297
mv = mv.set_val(i, isl::val(s.get_ctx(), vals[i]));
290298
}

test/test_cuda_mapper.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,7 @@ TEST_F(PolyhedralMapperTest, Match1) {
535535

536536
auto mscop = TileAndMapThreads(std::move(scop), {16, 16}, {32ul, 8ul});
537537
auto f = match(
538-
band(sequence(
539-
filter([](isl::union_set f) {
540-
return f.get_space().dim(isl::dim_type::param) == 3;
541-
}),
542-
filter())),
538+
band(sequence(filter([](isl::union_set f) { return true; }), filter())),
543539
schedule);
544540
EXPECT_EQ(1u, f.size());
545541
}

0 commit comments

Comments
 (0)