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

Commit 5e77383

Browse files
author
Sven Verdoolaege
committed
inline extractDomainToIds
1 parent 48ec08e commit 5e77383

File tree

3 files changed

+75
-49
lines changed

3 files changed

+75
-49
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright (c) 2017-2018, Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#include "tc/core/check.h"
19+
20+
namespace tc {
21+
namespace polyhedral {
22+
23+
/*
24+
* Extract a mapping from the domain elements active at "tree"
25+
* to identifiers "ids", where all branches in "tree"
26+
* are assumed to have been mapped to these identifiers.
27+
* The result lives in a space of the form "tupleId"["ids"...].
28+
*/
29+
inline isl::multi_union_pw_aff extractDomainToIds(
30+
const detail::ScheduleTree* root,
31+
const detail::ScheduleTree* tree,
32+
const std::vector<mapping::MappingId>& ids,
33+
isl::id tupleId) {
34+
using namespace polyhedral::detail;
35+
36+
auto space = isl::space(tree->ctx_, 0);
37+
auto empty = isl::union_set::empty(space);
38+
space = space.add_named_tuple_id_ui(tupleId, ids.size());
39+
auto zero = isl::multi_val::zero(space);
40+
auto domainToIds = isl::multi_union_pw_aff(empty, zero);
41+
42+
for (auto mapping : tree->collect(tree, ScheduleTreeType::Mapping)) {
43+
auto mappingNode = mapping->as<ScheduleTreeMapping>();
44+
auto list = isl::union_pw_aff_list(tree->ctx_, ids.size());
45+
for (auto id : ids) {
46+
if (mappingNode->mapping.count(id) == 0) {
47+
break;
48+
}
49+
auto idMap = mappingNode->mapping.at(id);
50+
list = list.add(idMap);
51+
}
52+
// Ignore this node if it does not map to all required ids.
53+
if (static_cast<size_t>(list.size()) != ids.size()) {
54+
continue;
55+
}
56+
auto nodeToIds = isl::multi_union_pw_aff(space, list);
57+
auto active = activeDomainPoints(root, mapping);
58+
TC_CHECK(active.intersect(domainToIds.domain()).is_empty())
59+
<< "conflicting mappings; are the filters in the tree disjoint?";
60+
nodeToIds = nodeToIds.intersect_domain(active);
61+
domainToIds = domainToIds.union_add(nodeToIds);
62+
}
63+
64+
auto active = activeDomainPoints(root, tree);
65+
TC_CHECK(active.is_subset(domainToIds.domain()))
66+
<< "not all domain points of\n"
67+
<< active << "\nwere mapped to the required ids";
68+
69+
return domainToIds;
70+
}
71+
72+
} // namespace polyhedral
73+
} // namespace tc

tc/core/polyhedral/schedule_utils.cc

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -265,54 +265,5 @@ isl::multi_union_pw_aff partialScheduleMupa(
265265
return band ? prefix.flat_range_product(band->mupa_) : prefix;
266266
}
267267

268-
/*
269-
* Extract a mapping from the domain elements active at "tree"
270-
* to identifiers "ids", where all branches in "tree"
271-
* are assumed to have been mapped to these identifiers.
272-
* The result lives in a space of the form "tupleId"["ids"...].
273-
*/
274-
isl::multi_union_pw_aff extractDomainToIds(
275-
const detail::ScheduleTree* root,
276-
const detail::ScheduleTree* tree,
277-
const std::vector<mapping::MappingId>& ids,
278-
isl::id tupleId) {
279-
using namespace polyhedral::detail;
280-
281-
auto space = isl::space(tree->ctx_, 0);
282-
auto empty = isl::union_set::empty(space);
283-
space = space.add_named_tuple_id_ui(tupleId, ids.size());
284-
auto zero = isl::multi_val::zero(space);
285-
auto domainToIds = isl::multi_union_pw_aff(empty, zero);
286-
287-
for (auto mapping : tree->collect(tree, ScheduleTreeType::Mapping)) {
288-
auto mappingNode = mapping->as<ScheduleTreeMapping>();
289-
auto list = isl::union_pw_aff_list(tree->ctx_, ids.size());
290-
for (auto id : ids) {
291-
if (mappingNode->mapping.count(id) == 0) {
292-
break;
293-
}
294-
auto idMap = mappingNode->mapping.at(id);
295-
list = list.add(idMap);
296-
}
297-
// Ignore this node if it does not map to all required ids.
298-
if (static_cast<size_t>(list.size()) != ids.size()) {
299-
continue;
300-
}
301-
auto nodeToIds = isl::multi_union_pw_aff(space, list);
302-
auto active = activeDomainPoints(root, mapping);
303-
TC_CHECK(active.intersect(domainToIds.domain()).is_empty())
304-
<< "conflicting mappings; are the filters in the tree disjoint?";
305-
nodeToIds = nodeToIds.intersect_domain(active);
306-
domainToIds = domainToIds.union_add(nodeToIds);
307-
}
308-
309-
auto active = activeDomainPoints(root, tree);
310-
TC_CHECK(active.is_subset(domainToIds.domain()))
311-
<< "not all domain points of\n"
312-
<< active << "\nwere mapped to the required ids";
313-
314-
return domainToIds;
315-
}
316-
317268
} // namespace polyhedral
318269
} // namespace tc

tc/core/polyhedral/schedule_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,5 @@ bool isMappingTo(const detail::ScheduleTree* tree) {
140140

141141
} // namespace polyhedral
142142
} // namespace tc
143+
144+
#include "tc/core/polyhedral/schedule_utils-inl.h"

0 commit comments

Comments
 (0)