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

Commit b0b73cb

Browse files
committed
promoteToSharedBelow: extract out isInThreadMappedScope
This function will be reused in an upcoming commit.
1 parent 5b448f0 commit b0b73cb

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

tc/core/polyhedral/cuda/memory_promotion_heuristic.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,22 @@ std::vector<detail::ScheduleTree*> bandsSplitAfterDepth(
429429
return functional::Map(splitAtDepth, bands);
430430
}
431431

432+
/*
433+
* Check if "node" or any of its ancestors until "root" are thread mappings.
434+
*/
435+
bool isInThreadMappedScope(
436+
const detail::ScheduleTree* root,
437+
const detail::ScheduleTree* node) {
438+
auto ancestors = node->ancestors(root);
439+
ancestors.push_back(node);
440+
for (auto ancestor : ancestors) {
441+
if (isMappingTo<mapping::ThreadId>(ancestor)) {
442+
return true;
443+
}
444+
}
445+
return false;
446+
}
447+
432448
/*
433449
* Promote to shared memory in "scop" below "node". Use at most
434450
* "remainingMemory" bytes, and update the variable to reflect the amount of
@@ -443,13 +459,9 @@ void promoteToSharedBelow(
443459
// Promotion to shared below threads does not make sense because the computed
444460
// groups would be specific to threads thus not benefiting from coalescing or
445461
// inter-thread communication through shared memory (use registers instead).
446-
auto ancestors = node->ancestors(root);
447-
ancestors.push_back(node);
448-
for (auto ancestor : ancestors) {
449-
if (isMappingTo<mapping::ThreadId>(ancestor)) {
450-
throw promotion::IncorrectScope(
451-
"shared memory promotion below thread mapping");
452-
}
462+
if (isInThreadMappedScope(root, node)) {
463+
throw promotion::IncorrectScope(
464+
"shared memory promotion below thread mapping");
453465
}
454466
// Children of a sequence/set band must be filters, but promotion would
455467
// insert an extension node.

0 commit comments

Comments
 (0)