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

Commit 2263130

Browse files
author
Sven Verdoolaege
committed
mapCopiesToThreads: extract out isThreadMapping
This reduces the code size of mapCopiesToThreads and allows isThreadMapping to be reused in the next commit.
1 parent cf358bc commit 2263130

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

tc/core/polyhedral/cuda/memory_promotion_heuristic.cc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@
3232
namespace tc {
3333
namespace polyhedral {
3434
namespace {
35+
36+
/*
37+
* Is "tree" a mapping filter that maps a thread identifier?
38+
*/
39+
bool isThreadMapping(const detail::ScheduleTree* tree) {
40+
using namespace detail;
41+
42+
if (auto filterNode = tree->elemAs<ScheduleTreeElemMappingFilter>()) {
43+
for (auto id : filterNode->mappingIds) {
44+
if (id.isThreadId()) {
45+
return true;
46+
}
47+
}
48+
}
49+
return false;
50+
}
51+
3552
// Map global<->shared copy bands to threads, starting from the innermost
3653
// loop as it iterates over the last subscript and will result in coalescing.
3754
void mapCopiesToThreads(MappedScop& mscop, bool unroll) {
@@ -73,14 +90,10 @@ void mapCopiesToThreads(MappedScop& mscop, bool unroll) {
7390
// Check that we are not mapping to threads below other thread mappings.
7491
std::unordered_set<mapping::ThreadId, mapping::ThreadId::Hash> usedThreads;
7592
for (auto n : node->ancestors(root)) {
76-
if (auto filterNode = n->elemAs<ScheduleTreeElemMappingFilter>()) {
77-
for (auto id : filterNode->mappingIds) {
78-
if (id.isThreadId()) {
79-
throw promotion::PromotionBelowThreadsException(
80-
"attempted to map memory copies to threads below "
81-
"another thread mapping");
82-
}
83-
}
93+
if (isThreadMapping(n)) {
94+
throw promotion::PromotionBelowThreadsException(
95+
"attempted to map memory copies to threads below "
96+
"another thread mapping");
8497
}
8598
}
8699

0 commit comments

Comments
 (0)