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

Commit a630d04

Browse files
author
Sven Verdoolaege
committed
ScheduleTreeElemMappingFilter: store mapping between identifiers and functions
Store this mapping in addition to the filter derived from the mapping. The mapping is needed in the next commit. The mapping is constructed in ScheduleTree::makeMappingFilter and passed to the ScheduleTreeElemMappingFilter constructor. Some of the sanity checks are therefore moved from the constructor to ScheduleTree::makeMappingFilter.
1 parent 5df21f8 commit a630d04

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

tc/core/polyhedral/cuda/memory_promotion_heuristic.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ bool isThreadMapping(const detail::ScheduleTree* tree) {
4646
using namespace detail;
4747

4848
if (auto filterNode = tree->elemAs<ScheduleTreeElemMappingFilter>()) {
49-
for (auto id : filterNode->mappingIds) {
50-
if (isThreadId(id)) {
49+
for (auto& kvp : filterNode->mapping) {
50+
if (isThreadId(kvp.first)) {
5151
return true;
5252
}
5353
}

tc/core/polyhedral/schedule_print.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ std::ostream& ScheduleTreeElemFilter::write(std::ostream& os) const {
202202
std::ostream& ScheduleTreeElemMappingFilter::write(std::ostream& os) const {
203203
WS w;
204204
os << w.tab() << "mapping_filter(ids(";
205-
for (const auto& id : mappingIds) {
206-
os << id << ", ";
205+
for (auto& kvp : mapping) {
206+
os << kvp.first << ", ";
207207
}
208208
os << ")";
209209
for (const auto& u : filter_.get_set_list()) {

tc/core/polyhedral/schedule_tree-inl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ inline ScheduleTreeUPtr ScheduleTree::makeMappingFilter(
2323
const std::vector<MappingIdType>& mappedIds,
2424
isl::union_pw_aff_list mappedAffs,
2525
std::vector<ScheduleTreeUPtr>&& children) {
26-
std::vector<mapping::MappingId> ids;
27-
for (auto id : mappedIds) {
28-
ids.push_back(id);
26+
CHECK_EQ(mappedIds.size(), static_cast<size_t>(mappedAffs.n()))
27+
<< "expected as many mapped ids as affs";
28+
ScheduleTreeElemMappingFilter::Mapping mapping;
29+
for (size_t i = 0, n = mappedAffs.n(); i < n; ++i) {
30+
mapping.emplace(mappedIds.at(i), mappedAffs.get(i));
2931
}
30-
CHECK_GE(ids.size(), 1u) << "empty mapping";
32+
CHECK_GE(mapping.size(), 1u) << "empty mapping";
33+
CHECK_EQ(mappedIds.size(), mapping.size())
34+
<< "some id is used more than once in the mapping";
3135
auto ctx = mappedIds[0].get_ctx();
3236
ScheduleTreeUPtr res(new ScheduleTree(ctx));
3337
res->elem_ = std::unique_ptr<ScheduleTreeElemMappingFilter>(
34-
new ScheduleTreeElemMappingFilter(ids, mappedAffs));
38+
new ScheduleTreeElemMappingFilter(mapping));
3539
res->type_ = ScheduleTreeType::MappingFilter;
3640
res->appendChildren(std::move(children));
3741
return res;

tc/core/polyhedral/schedule_tree_elem.h

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <memory>
1919
#include <sstream>
20-
#include <unordered_set>
20+
#include <unordered_map>
2121
#include <vector>
2222

2323
#include "tc/external/isl.h"
@@ -139,34 +139,29 @@ struct ScheduleTreeElemFilter : public ScheduleTreeElemBase {
139139
};
140140

141141
struct ScheduleTreeElemMappingFilter : public ScheduleTreeElemFilter {
142+
using Mapping = std::unordered_map<
143+
mapping::MappingId,
144+
isl::union_pw_aff,
145+
typename mapping::MappingId::Hash>;
142146
static constexpr std::initializer_list<detail::ScheduleTreeType>
143147
NodeDerivedTypes{detail::ScheduleTreeType::None};
144148
static constexpr detail::ScheduleTreeType NodeType =
145149
detail::ScheduleTreeType::MappingFilter;
146150
ScheduleTreeElemMappingFilter() = delete;
147151
ScheduleTreeElemMappingFilter(const ScheduleTreeElemMappingFilter& eb)
148-
: ScheduleTreeElemFilter(eb.filter_), mappingIds(eb.mappingIds) {}
149-
ScheduleTreeElemMappingFilter(
150-
const std::vector<mapping::MappingId>& mappedIds,
151-
isl::union_pw_aff_list mappedAffs)
152-
: ScheduleTreeElemFilter(isl::union_set()),
153-
mappingIds(mappedIds.begin(), mappedIds.end()) {
154-
// Check that ids are unique.
155-
CHECK_EQ(mappedIds.size(), mappingIds.size())
156-
<< "some id is used more than once in the mapping";
152+
: ScheduleTreeElemFilter(eb.filter_), mapping(eb.mapping) {}
153+
ScheduleTreeElemMappingFilter(const Mapping& mapping)
154+
: ScheduleTreeElemFilter(isl::union_set()), mapping(mapping) {
155+
CHECK_GT(mapping.size(), 0u) << "empty mapping filter";
157156

158-
CHECK_EQ(mappedIds.size(), static_cast<size_t>(mappedAffs.n()))
159-
<< "expected as many mapped ids as affs";
160-
CHECK_GT(mappedIds.size(), 0u) << "empty mapping filter";
161-
162-
auto domain = mappedAffs.get(0).domain();
163-
for (size_t i = 1, n = mappedAffs.n(); i < n; ++i) {
164-
CHECK(domain.is_equal(mappedAffs.get(i).domain()));
157+
auto domain = mapping.cbegin()->second.domain();
158+
for (auto& kvp : mapping) {
159+
CHECK(domain.is_equal(kvp.second.domain()));
165160
}
166161
filter_ = domain.universe();
167-
for (size_t i = 0, n = mappedAffs.n(); i < n; ++i) {
168-
auto upa = mappedAffs.get(i);
169-
auto id = mappedIds.at(i);
162+
for (auto& kvp : mapping) {
163+
auto upa = kvp.second;
164+
auto id = kvp.first;
170165
// Create mapping filter by equating the
171166
// parameter mappedIds[i] to the "i"-th affine function.
172167
upa = upa.sub(isl::union_pw_aff::param_on_domain(domain.universe(), id));
@@ -183,9 +178,8 @@ struct ScheduleTreeElemMappingFilter : public ScheduleTreeElemFilter {
183178
return NodeType;
184179
}
185180

186-
const std::
187-
unordered_set<mapping::MappingId, typename mapping::MappingId::Hash>
188-
mappingIds;
181+
// Mapping from identifiers to affine functions on domain elements.
182+
const Mapping mapping;
189183
};
190184

191185
struct ScheduleTreeElemSequence : public ScheduleTreeElemBase {

0 commit comments

Comments
 (0)