24 #include <unordered_map>
25 #include <unordered_set>
29 namespace polyhedral {
31 enum class AccessType : short { Read, Write };
40 struct ScopedFootprintDim {
42 ScopedFootprintDim(isl::aff lb, isl::val s) : lowerBound(lb), size(s) {}
54 struct ScopedFootprint : std::vector<ScopedFootprintDim> {
55 isl::set footprint(isl::set domain)
const;
56 isl::multi_aff lowerBounds()
const;
63 class TensorReference {
66 return type == AccessType::Read;
69 bool isWrite()
const {
70 return type == AccessType::Write;
75 isl::map originalAccess;
79 isl::map scopedAccess;
88 class TensorReferenceGroup;
89 using TensorGroupsInfo = std::vector<std::unique_ptr<TensorReferenceGroup>>;
90 typedef std::unordered_map<isl::id, TensorGroupsInfo, isl::IslIdIslHash>
101 class TensorReferenceGroup {
103 TensorReferenceGroup() {}
106 static TensorGroups accessedBySubtree(
107 const detail::ScheduleTree* tree,
110 bool isReadOnly()
const;
113 isl::set writeFootprint()
const;
114 isl::set readFootprint()
const;
115 isl::set footprint()
const {
116 return writeFootprint().unite(readFootprint());
120 isl::map scopedWrites()
const;
121 isl::map scopedReads()
const;
122 isl::map scopedAccesses()
const {
123 return scopedWrites().unite(scopedReads());
129 isl::union_map originalWrites()
const;
130 isl::union_map originalReads()
const;
131 isl::union_map originalAccesses()
const {
132 return originalWrites().unite(originalReads());
137 isl::set approximateFootprint()
const {
138 return approximation.footprint(scopedAccesses().domain());
141 isl::multi_aff promotion()
const;
142 isl::set promotedFootprint()
const;
144 std::vector<size_t> approximationSizes()
const;
146 std::unordered_set<isl::id, isl::IslIdIslHash> referenceIds()
const;
148 static std::unique_ptr<TensorReferenceGroup> makeJoint(
149 std::unique_ptr<TensorReferenceGroup>&& g1,
150 std::unique_ptr<TensorReferenceGroup>&& g2);
151 static std::unique_ptr<TensorReferenceGroup> makeSingleton(
152 isl::map originalAccess,
153 isl::map scopedAccess,
157 std::vector<std::unique_ptr<TensorReference>> references;
158 ScopedFootprint approximation;
161 inline std::ostream&
operator<<(std::ostream& os,
const ScopedFootprint& fp) {
163 for (
const auto& f : fp) {
167 os << f.lowerBound <<
" of size " << f.size <<
"\n";
173 inline std::ostream&
operator<<(std::ostream& os,
const TensorReference& tr) {
174 os << ((tr.isRead()) ?
"rd" :
"wr") <<
" scopedAccess: " << tr.scopedAccess;
181 const TensorReferenceGroup& tg) {
182 os <<
" with footprint BB: " << tg.approximation <<
" ";
183 for (
const auto& tr : tg.references) {
189 inline std::ostream&
operator<<(std::ostream& os,
const TensorGroupsInfo& ti) {
190 for (
const auto& tg : ti) {
196 inline std::ostream&
operator<<(std::ostream& os,
const TensorGroups& tg) {
198 for (
const auto& kvp : tg) {
199 os <<
"id: " << kvp.first <<
"; acc: " << kvp.second;
200 if (++i < tg.size()) {
207 detail::ScheduleTree* insertCopiesUnder(
209 detail::ScheduleTree* tree,
210 const TensorReferenceGroup& group,
212 isl::id groupId = isl::id());
std::ostream & operator<<(std::ostream &out, const MappingOptionsAsCpp &mo)
Definition: mapping_options_cpp_printer.h:79