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

Commit 518a7a9

Browse files
committed
insertCopiesUnder: forcibly unroll copy loops for register promotion
When copying to registers, loop unrolling is mandatory. Otherwise, promoted arrays will be accessed with non-constant subscripts, which prevents CUDA from placing them to registers as they are not indirectly addressable. Request unrolling when inserting copies to registers. This has not been an issue until now since we only promote groups of 1 element to registers. This will be relaxed in the following commits.
1 parent 515be20 commit 518a7a9

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

tc/core/polyhedral/memory_promotion.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,20 @@ isl::multi_aff dropDummyTensorDimensions(
459459
space = add_range(space, list.n());
460460
return isl::multi_aff(space, list);
461461
}
462+
463+
inline void unrollAllMembers(detail::ScheduleTreeElemBand* band) {
464+
band->unroll_ = std::vector<bool>(band->nMember(), true);
465+
}
466+
462467
} // namespace
463468

464469
ScheduleTree* insertCopiesUnder(
465470
Scop& scop,
466471
ScheduleTree* tree,
467472
const TensorReferenceGroup& group,
468473
isl::id tensorId,
469-
isl::id groupId) {
474+
isl::id groupId,
475+
bool unrollAllCopies) {
470476
const ScheduleTree* root = scop.scheduleRoot();
471477
auto ctx = root->ctx_;
472478
isl::id readId = isl::id(ctx, std::string(kReadIdName));
@@ -494,6 +500,11 @@ ScheduleTree* insertCopiesUnder(
494500
auto readBandNode = ScheduleTree::makeBand(readSchedule);
495501
auto writeBandNode = ScheduleTree::makeBand(writeSchedule);
496502

503+
if (unrollAllCopies) {
504+
unrollAllMembers(readBandNode->elemAs<detail::ScheduleTreeElemBand>());
505+
unrollAllMembers(writeBandNode->elemAs<detail::ScheduleTreeElemBand>());
506+
}
507+
497508
auto extension =
498509
promotion.wrap().identity().domain_factor_domain().domain_factor_domain();
499510

tc/core/polyhedral/memory_promotion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ detail::ScheduleTree* insertCopiesUnder(
214214
detail::ScheduleTree* tree,
215215
const TensorReferenceGroup& group,
216216
isl::id tensorId,
217-
isl::id groupId);
217+
isl::id groupId,
218+
bool unrollAllCopies);
218219
} // namespace polyhedral
219220
} // namespace tc

tc/core/polyhedral/scop.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ void Scop::promoteGroup(
192192
sizes.back() += 1;
193193
}
194194
promotedDecls_[groupId] = PromotedDecl{tensorId, sizes, kind};
195-
insertCopiesUnder(*this, tree, *gr, tensorId, groupId);
195+
insertCopiesUnder(
196+
*this,
197+
tree,
198+
*gr,
199+
tensorId,
200+
groupId,
201+
kind == PromotedDecl::Kind::Register);
196202

197203
// FIXME: we can now store a unique pointer...
198204
auto group = std::shared_ptr<TensorReferenceGroup>(std::move(gr));

0 commit comments

Comments
 (0)