Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
isl_mu_wrappers.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <vector>
19 
20 #include <isl/interface/isl.h>
21 
22 #include "tc/external/isl.h"
23 
24 namespace isl {
25 
26 // Via "class-specific" get:
27 // pma -> pa
28 // umpa -> upa
29 //
30 // Via "class-specific" foreach:
31 // pa -> foreach_piece (set, aff)
32 // pma -> foreach_piece (set, ma)
33 // upma -> foreach_pma (pma)
34 // upa -> foreach_pa (pa)
35 //
36 // Via multi.h' get:
37 // multi -> base e.g.:
38 // mupa -> upa
39 // mpa -> pa
40 // ma -> a
41 // mv -> v
42 //
43 // Via "class-specific" extract(space)
44 // mupa -> mpa
45 // umpa -> pma
46 // upa -> pa
47 //
48 // Reverse listing:
49 // mv -> v
50 //
51 // ma -> a
52 //
53 // pa -> (set, aff)
54 //
55 // pma -> (set, ma) -> (set, aff)
56 //
57 // upa : extract -> pa -> (set, aff)
58 //
59 // mpa -> pa -> (set, aff)
60 //
61 // upma -> upa -> pa -> (set, aff)
62 // : extract -> pma -> (set, ma) -> (set, aff)
63 //
64 // mupa -> upa -> pa -> (set, aff)
65 // : extract -> mpa -> pa -> (set, aff)
66 
67 // You have simple expressions, like isl_val for values and isl_aff for affine
68 // functions. If you want vectors instead, you do multi expressions, multi_val
69 // and multi_aff.
70 // In this particular case vector spaces have named dimensions
71 // and a tuple name, so there's a set space associated to each multi_* so
72 // multi_val is a vector in the vector space ```multi_val.get_space()``` and
73 // as everywhere in isl, spaces can be parametric, so you may have a
74 // parametric vector in a vector space that has both set and parameter
75 // dimensions.
76 //
77 // union is a different story, union_* are defined over different spaces
78 // for affine functions, it means they have different domain spaces.
79 //
80 // multi_* is a vector, we just need to differentiate vectors in different
81 // spaces of the same dimensionality. It is a math vector except that we don't
82 // have non-elementwise operations.
83 //
84 // multi_aff is a vector-valued function, but just a plain aff is a
85 // scalar-valued multivariate function plus parameters everywhere.
86 
87 // Use the following API as follows:
88 // isl::MUPA M(mupa);
89 // cout << "MUPA: " << M.mupa << endl;
90 // cout << "UPA: " << M[0].upa << endl;
91 // cout << "PA: " << M[0][0].pa << endl;
92 // cout << "PA[0] set: " << M[0][0][0].first << endl;
93 // cout << "PA[0] aff: " << M[0][0][0].second << endl;
94 //
95 
96 //
97 // multi_val is a vector of val in the vector space ```multi_val.get_space()```
98 // A val however is not attached to any (exposed) space (internally it seems
99 // to have one, see ```isl/isl_val_private.h```).
100 //
101 /* WARNING: this does not allow inplace modifications .. ugh */
102 struct MV : std::vector<isl::val> {
103  explicit MV(isl::multi_val mv_) : mv(mv_) {
104  this->reserve(mv.dim(isl::dim_type::set));
105  for (size_t i = 0; i < mv.dim(isl::dim_type::set); ++i) {
106  this->push_back(mv.get_val(i));
107  }
108  }
109  isl::multi_val mv;
110 };
111 
112 //
113 // multi_aff is a vector of aff in the vector space ```multi_aff.get_space()```
114 //
115 /* WARNING: this does not allow inplace modifications .. ugh */
116 struct MA : std::vector<isl::aff> {
117  explicit MA(isl::multi_aff ma_) : ma(ma_) {
118  this->reserve(ma.dim(isl::dim_type::set));
119  for (size_t i = 0; i < ma.dim(isl::dim_type::set); ++i) {
120  this->push_back(ma.get_aff(i));
121  }
122  }
123  isl::multi_aff ma;
124 };
125 
126 /* WARNING: this does not allow inplace modifications .. ugh */
127 struct PA : std::vector<std::pair<isl::set, isl::aff>> {
128  explicit PA(isl::pw_aff pa_) : pa(pa_) {
129  this->reserve(pa.n_piece());
130  auto f = [&](isl::set s, isl::aff a) {
131  this->push_back(std::make_pair(s, a));
132  };
133  pa.foreach_piece(f);
134  }
135  isl::pw_aff pa;
136 };
137 
138 /* WARNING: this does not allow inplace modifications .. ugh */
139 struct PMA : std::vector<std::pair<isl::set, isl::multi_aff>> {
140  explicit PMA(isl::pw_multi_aff pma_) : pma(pma_) {
141  this->reserve(pma.n_piece());
142  auto f = [&](isl::set s, isl::multi_aff ma) {
143  this->push_back(std::make_pair(s, ma));
144  };
145  pma.foreach_piece(f);
146  }
147  isl::pw_multi_aff pma;
148 };
149 
150 /* WARNING: this does not allow inplace modifications .. ugh */
151 struct UPA : std::vector<PA> {
152  explicit UPA(isl::union_pw_aff upa_) : upa(upa_) {
153  std::vector<PA> res;
154  auto f = [&](isl::pw_aff pa) { this->push_back(PA(pa)); };
155  upa.foreach_pw_aff(f);
156  }
157  PA extract(isl::space s) const {
158  return PA(upa.extract_pw_aff(s));
159  }
160  isl::union_pw_aff upa;
161 };
162 
163 struct MPA : std::vector<PA> {
164  explicit MPA(isl::multi_pw_aff mpa_) : mpa(mpa_) {
165  this->reserve(mpa.dim(isl::dim_type::set));
166  for (size_t i = 0; i < mpa.dim(isl::dim_type::set); ++i) {
167  this->push_back(PA(mpa.get_pw_aff(i)));
168  }
169  }
170  isl::multi_pw_aff mpa;
171 };
172 
173 /* WARNING: this does not allow inplace modifications .. ugh */
174 struct UPMA : std::vector<UPA> {
175  explicit UPMA(isl::union_pw_multi_aff upma_) : upma(upma_) {
176  this->reserve(upma.dim(isl::dim_type::set));
177  for (size_t i = 0; i < upma.dim(isl::dim_type::set); ++i) {
178  this->push_back(UPA(upma.get_union_pw_aff(i)));
179  }
180  }
181  std::vector<PMA> pmas(isl::union_pw_multi_aff upma) const {
182  std::vector<PMA> res;
183  auto f = [&](isl::pw_multi_aff pma) { res.push_back(PMA(pma)); };
184  upma.foreach_pw_multi_aff(f);
185  return res;
186  }
187  PMA extract(isl::space s) const {
188  return PMA(upma.extract_pw_multi_aff(s));
189  }
190  isl::union_pw_multi_aff upma;
191 };
192 
193 /* WARNING: this does not allow inplace modifications .. ugh */
194 struct MUPA : std::vector<UPA> {
195  explicit MUPA(isl::multi_union_pw_aff mupa_) : mupa(mupa_) {
196  this->reserve(mupa.dim(isl::dim_type::set));
197  for (size_t i = 0; i < mupa.dim(isl::dim_type::set); ++i) {
198  this->push_back(UPA(mupa.get_union_pw_aff(i)));
199  }
200  }
201  MPA extract(isl::space s) const {
202  return MPA(mupa.extract_multi_pw_aff(s));
203  }
204  isl::multi_union_pw_aff mupa;
205 };
206 
207 /* WARNING: this does not allow inplace modifications .. ugh */
208 struct UNION_SET : std::vector<isl::set> {
209  UNION_SET(isl::union_set us_) : us(us_) {
210  us_.foreach_set([&](isl::set s) { this->push_back(s); });
211  }
212  isl::union_set us;
213 };
214 
215 template <typename T, isl::dim_type DT>
216 struct DimIds : public std::vector<isl::id> {
217  DimIds(T s) {
218  this->reserve(s.dim(DT));
219  for (size_t i = 0; i < s.dim(DT); ++i) {
220  this->push_back(s.get_dim_id(DT, i));
221  }
222  }
223 };
224 
225 } // namespace isl
Definition: isl_mu_wrappers.h:216
Definition: isl_mu_wrappers.h:174
Definition: isl_mu_wrappers.h:163
UNION_SET(isl::union_set us_)
Definition: isl_mu_wrappers.h:209
isl::union_set us
Definition: isl_mu_wrappers.h:212
Definition: isl_mu_wrappers.h:116
PA extract(isl::space s) const
Definition: isl_mu_wrappers.h:157
isl::multi_val mv
Definition: isl_mu_wrappers.h:109
UPMA(isl::union_pw_multi_aff upma_)
Definition: isl_mu_wrappers.h:175
isl::pw_aff pa
Definition: isl_mu_wrappers.h:135
MA(isl::multi_aff ma_)
Definition: isl_mu_wrappers.h:117
Definition: isl_mu_wrappers.h:194
MPA(isl::multi_pw_aff mpa_)
Definition: isl_mu_wrappers.h:164
isl::multi_union_pw_aff mupa
Definition: isl_mu_wrappers.h:204
UPA(isl::union_pw_aff upa_)
Definition: isl_mu_wrappers.h:152
PMA(isl::pw_multi_aff pma_)
Definition: isl_mu_wrappers.h:140
Definition: isl_mu_wrappers.h:151
isl::pw_multi_aff pma
Definition: isl_mu_wrappers.h:147
Definition: isl_mu_wrappers.h:102
isl::union_pw_aff upa
Definition: isl_mu_wrappers.h:160
PMA extract(isl::space s) const
Definition: isl_mu_wrappers.h:187
Definition: isl_mu_wrappers.h:139
isl::multi_aff ma
Definition: isl_mu_wrappers.h:123
DimIds(T s)
Definition: isl_mu_wrappers.h:217
Definition: isl_mu_wrappers.h:208
isl::multi_pw_aff mpa
Definition: isl_mu_wrappers.h:170
std::vector< PMA > pmas(isl::union_pw_multi_aff upma) const
Definition: isl_mu_wrappers.h:181
PA(isl::pw_aff pa_)
Definition: isl_mu_wrappers.h:128
MUPA(isl::multi_union_pw_aff mupa_)
Definition: isl_mu_wrappers.h:195
isl::union_pw_multi_aff upma
Definition: isl_mu_wrappers.h:190
MPA extract(isl::space s) const
Definition: isl_mu_wrappers.h:201
Definition: isl_mu_wrappers.h:127
MV(isl::multi_val mv_)
Definition: isl_mu_wrappers.h:103