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

Commit 3137885

Browse files
author
Sven Verdoolaege
committed
use templated isl types TensorReferenceGroup::promotion
1 parent 1061470 commit 3137885

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

tc/core/polyhedral/cuda/codegen.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,9 @@ void emitMappedTensorAccess(
723723
// MA = multi_aff, PMA = pw_multi_aff
724724
auto access =
725725
makeMultiAffAccess(tensorId, subscripts, context); // MA :: D -> O
726-
auto promotion = promotionInfo.group->promotion(); // MA :: [S -> O] -> P
727-
promotion = promotion.set_range_tuple_id(promotionInfo.groupId);
726+
auto prePromotion = promotionInfo.group->promotion(); // MA :: [S -> O] -> P
727+
auto promotion =
728+
prePromotion.set_range_tuple_id<Promoted>(promotionInfo.groupId);
728729
auto iteratorMap = context.iteratorMap(); // PMA :: A -> D
729730
auto schedule = isl::map::from(promotionInfo.outerSchedule.intersect_domain(
730731
context.domain())); // map :: D -> S

tc/core/polyhedral/memory_promotion.cc

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ isl::Map<Domain, Range> removeRangeStrides(
5252
TC_CHECK_EQ(strides.size(), offsets.size());
5353

5454
auto space = relation.get_space();
55-
auto stridesMA = isl::MultiAff<Range, Range>::identity(space.range().map_from_set());
55+
auto stridesMA =
56+
isl::MultiAff<Range, Range>::identity(space.range().map_from_set());
5657
stridesMA = stridesMA / strides;
5758

5859
return relation.sum(offsets.neg().asMap()).apply_range(stridesMA.asMap());
@@ -63,8 +64,10 @@ isl::Map<Domain, Range> removeRangeStrides(
6364
// If the range has strides, remove them first.
6465
ScopedFootprint outputRanges(isl::Map<Scope, Tensor> access) {
6566
ScopedFootprint footprint;
66-
footprint.strideValues = isl::MultiVal<Tensor>::zero(access.get_space().range());
67-
footprint.strideOffsets = isl::MultiAff<Scope, Tensor>::zero(access.get_space());
67+
footprint.strideValues =
68+
isl::MultiVal<Tensor>::zero(access.get_space().range());
69+
footprint.strideOffsets =
70+
isl::MultiAff<Scope, Tensor>::zero(access.get_space());
6871

6972
int nSubscripts = footprint.strideValues.size();
7073
for (int i = 0; i < nSubscripts; ++i) {
@@ -159,8 +162,8 @@ isl::Set<Tensor> TensorReferenceGroup::promotedFootprint() const {
159162
for (size_t i = 0, e = sizes.size(); i < e; ++i) {
160163
auto aff = identity.get_aff(i);
161164
auto size = sizes.get_val(i);
162-
footprint =
163-
footprint & aff.asPwAff().nonneg_set() & (size - aff).asPwAff().pos_set();
165+
footprint = footprint & aff.asPwAff().nonneg_set() &
166+
(size - aff).asPwAff().pos_set();
164167
}
165168
return footprint;
166169
}
@@ -181,8 +184,8 @@ isl::Map<Scope, Tensor> referenceScopedAccessesImpl(
181184
if (group.references.size() == 0) {
182185
throw promotion::GroupingError("no references in the group");
183186
}
184-
auto accesses =
185-
isl::Map<Scope, Tensor>::empty(group.references.front()->scopedAccess.get_space());
187+
auto accesses = isl::Map<Scope, Tensor>::empty(
188+
group.references.front()->scopedAccess.get_space());
186189

187190
for (const auto& ref : group.references) {
188191
if (ref->type != type) {
@@ -369,22 +372,25 @@ TensorGroups TensorReferenceGroup::accessedWithin(
369372
// elements of the promoted array get assigned different values of the original
370373
// array in different outer loop iterations; it's impossible to project out the
371374
// outer schedule dimensions.
372-
isl::multi_aff TensorReferenceGroup::promotion() const {
375+
isl::MultiAff<isl::Pair<Scope, Tensor>, Tensor>
376+
TensorReferenceGroup::promotion() const {
373377
// access space is S -> O
374378
auto map = scopedAccesses();
375379
auto accessSpace = map.get_space();
376380

377381
// Construct a projection multi-aff in [S -> O] -> S
378382
// for further precomposition.
379-
auto originalSpaceInserter = isl::MultiAff<isl::Pair<Scope, Tensor>, Scope>::domain_map(accessSpace);
383+
auto originalSpaceInserter =
384+
isl::MultiAff<isl::Pair<Scope, Tensor>, Scope>::domain_map(accessSpace);
380385

381386
// Lower bounds and offsets space is S -> O; transform into [S -> O] -> O.
382-
isl::multi_aff lowerBounds =
387+
auto lowerBounds =
383388
approximation.lowerBounds().pullback(originalSpaceInserter);
384-
isl::multi_aff offsets = approximation.strideOffsets.pullback(originalSpaceInserter);
389+
auto offsets = approximation.strideOffsets.pullback(originalSpaceInserter);
385390

386391
// Create promotion starting by identity in [S -> O] -> O.
387-
auto original = isl::multi_aff::range_map(accessSpace);
392+
auto original =
393+
isl::MultiAff<isl::Pair<Scope, Tensor>, Tensor>::range_map(accessSpace);
388394
auto promotion =
389395
(original - offsets) / approximation.strideValues - lowerBounds;
390396

@@ -416,7 +422,8 @@ isl::Set<Tensor> tensorElementsSet(const Scop& scop, isl::id tensorId) {
416422
auto tensorSpace = tensorTuple.get_space();
417423

418424
auto tensorElements = isl::Set<Tensor>::universe(tensorSpace);
419-
auto identity = isl::MultiAff<Tensor,Tensor>::identity(tensorSpace.map_from_set());
425+
auto identity =
426+
isl::MultiAff<Tensor, Tensor>::identity(tensorSpace.map_from_set());
420427
for (int i = 0; i < nDim; ++i) {
421428
auto minAff = halide2isl::makeIslAffFromExpr(
422429
space, halideParameter.min_constraint(i));
@@ -508,7 +515,8 @@ ScheduleTree* insertCopiesUnder(
508515
// control flow, but we should only write back elements that are actually
509516
// written to. In any case, intersect the footprint with the set of existing
510517
// tensor elements.
511-
auto promotedFootprint = group.promotedFootprint().set_tuple_id<Promoted>(groupId);
518+
auto promotedFootprint =
519+
group.promotedFootprint().set_tuple_id<Promoted>(groupId);
512520
auto scheduleUniverse =
513521
isl::set::universe(promotionSpace.domain().unwrap().domain());
514522
auto arrayId = promotionSpace.domain().unwrap().get_map_range_tuple_id();
@@ -517,9 +525,10 @@ ScheduleTree* insertCopiesUnder(
517525
approximatedRead = approximatedRead.product(promotedFootprint);
518526
auto readExtension =
519527
extension.intersect_range(approximatedRead).set_range_tuple_id(readId);
520-
auto writtenElements =
521-
group.scopedWrites().intersect_range(tensorElements).wrap()
522-
.product(promotedFootprint);
528+
auto writtenElements = group.scopedWrites()
529+
.intersect_range(tensorElements)
530+
.wrap()
531+
.product(promotedFootprint);
523532
auto writeExtension =
524533
extension.intersect_range(writtenElements).set_range_tuple_id(writeId);
525534

tc/core/polyhedral/memory_promotion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class TensorReferenceGroup {
145145
// and relative to the scoping point.
146146
isl::map approximateScopedAccesses() const;
147147

148-
isl::multi_aff promotion() const;
148+
isl::MultiAff<isl::Pair<Scope, Tensor>, Tensor> promotion() const;
149149
isl::Set<Tensor> promotedFootprint() const;
150150

151151
std::vector<size_t> approximationSizes() const;

0 commit comments

Comments
 (0)