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

[wip] Register promotion improvements #161

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions include/tc/core/polyhedral/scop.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ struct Scop {
return activePromotions_;
}

std::vector<std::pair<isl::union_set, Scop::PromotionInfo>> activePromotions(
isl::union_set activePoints,
isl::id tensorId) const;

detail::ScheduleTree* scheduleRoot() {
return scheduleTreeUPtr.get();
}
Expand Down Expand Up @@ -408,6 +412,11 @@ struct Scop {
isl::schedule_constraints constraints,
const SchedulerOptionsView& schedulerOptions);

// Get the indexes of active promotions in the activePromotions_.
std::vector<size_t> activePromotionsIndexes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activePromotionsIndices

isl::union_set domain,
isl::id tensorId) const;

public:
// Halide stuff
struct {
Expand Down
65 changes: 51 additions & 14 deletions src/core/polyhedral/scop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,47 @@ void checkFiltersDisjointStatements(const ScheduleTree* root) {
}
} // namespace

std::vector<size_t> Scop::activePromotionsIndexes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activePromotionsIndices

isl::union_set activePoints,
isl::id tensorId) const {
std::vector<size_t> result;

for (size_t i = 0, e = activePromotions_.size(); i < e; ++i) {
const auto& kvp = activePromotions_[i];
if (kvp.first.intersect(activePoints).is_empty()) {
continue;
}

auto groupId = kvp.second.groupId;
if (promotedDecls_.count(groupId) != 0 &&
promotedDecls_.at(groupId).tensorId == tensorId) {
result.push_back(i);
}
}

return result;
}

std::vector<std::pair<isl::union_set, Scop::PromotionInfo>>
Scop::activePromotions(isl::union_set activePoints, isl::id tensorId) const {
std::vector<std::pair<isl::union_set, Scop::PromotionInfo>> result;

for (auto idx : activePromotionsIndexes(activePoints, tensorId)) {
result.emplace_back(activePromotions_[idx]);
}

return result;
}

namespace {
template <typename T>
T projectOutNamedParam(T t, isl::id paramId) {
auto space = t.get_space();
int pos = space.find_dim_by_id(isl::dim_type::param, paramId);
return (pos == -1) ? t : t.project_out(isl::dim_type::param, pos, 1);
}
} // namespace

void Scop::promoteGroup(
PromotedDecl::Kind kind,
isl::id tensorId,
Expand All @@ -188,20 +229,16 @@ void Scop::promoteGroup(
bool forceLastExtentOdd) {
auto activePoints = activeDomainPoints(scheduleRoot(), tree);

for (const auto& kvp : activePromotions_) {
if (kvp.first.intersect(activePoints).is_empty()) {
continue;
}

auto groupId = kvp.second.groupId;
if (promotedDecls_.count(groupId) != 0 &&
promotedDecls_[groupId].tensorId == tensorId) {
// FIXME: allow double promotion if copies are inserted properly,
// in particular if the new promotion is strictly smaller in scope
// and size than the existing ones (otherwise we would need to find
// the all the existing ones and change their copy relations).
return;
}
auto activeProms = activePromotions(activePoints, tensorId);
if (activeProms.size() != 0) {
// FIXME: allow double promotion if copies are inserted properly,
// in particular if the new promotion is strictly smaller in scope
// and size than the existing ones (otherwise we would need to find
// the all the existing ones and change their copy relations).
std::cerr << "FIXME: not promoting because another promotion of tensor "
<< tensorId << " is active in " << activeProms[0].first
<< std::endl;
return;
}

auto groupId = nextGroupIdForTensor(tensorId);
Expand Down