@@ -29,12 +29,12 @@ class SparseTensorLevel {
29
29
// / the given position `p` that the immediate parent level is current at.
30
30
// / Returns a pair of values for *posLo* and *loopHi* respectively.
31
31
// /
32
- // / For dense level, the *posLo* is the linearized position at beginning,
32
+ // / For a dense level, the *posLo* is the linearized position at beginning,
33
33
// / while *loopHi* is the largest *coordinate*, it also implies that the
34
34
// / smallest *coordinate* to start the loop is 0.
35
35
// /
36
- // / For sparse level, [posLo, loopHi) specifies the range of index pointer to
37
- // / load coordinate from the coordinate buffer.
36
+ // / For a sparse level, [posLo, loopHi) specifies the range of index pointer
37
+ // / to load coordinate from the coordinate buffer.
38
38
// /
39
39
// / `bound` is only used when the level is `non-unique` and deduplication is
40
40
// / required. It specifies the max upper bound of the non-unique segment.
@@ -68,7 +68,7 @@ enum class IterKind : uint8_t {
68
68
kFilter ,
69
69
};
70
70
71
- // / Helper class that helps generating loop conditions, etc, to traverse a
71
+ // / Helper class that generates loop conditions, etc, to traverse a
72
72
// / sparse tensor level.
73
73
class SparseIterator {
74
74
SparseIterator (SparseIterator &&) = delete ;
@@ -103,17 +103,18 @@ class SparseIterator {
103
103
//
104
104
105
105
// Whether the iterator support random access (i.e., support look up by
106
- // *coordinate*).
107
- // A random access iterator also traverses a dense space.
106
+ // *coordinate*). A random access iterator must also traverses a dense space.
108
107
virtual bool randomAccessible () const = 0;
108
+
109
109
// Whether the iterator can simply traversed by a for loop.
110
110
virtual bool iteratableByFor () const { return false ; };
111
+
111
112
// Get the upper bound of the sparse space that the iterator might visited. A
112
113
// sparse space is a subset of a dense space [0, bound), this function returns
113
114
// *bound*.
114
115
virtual Value upperBound (OpBuilder &b, Location l) const = 0;
115
116
116
- // Serialize and deserialize the current status to/from a set of values. The
117
+ // Serializes and deserializes the current status to/from a set of values. The
117
118
// ValueRange should contain values that specifies the current postion and
118
119
// loop bound.
119
120
//
@@ -131,7 +132,7 @@ class SparseIterator {
131
132
// Core functions.
132
133
//
133
134
134
- // Get the current position and the optional *position high* (for non-unique
135
+ // Gets the current position and the optional *position high* (for non-unique
135
136
// iterators), the value is essentially the number of sparse coordinate that
136
137
// the iterator is current visiting. It should be able to uniquely identify
137
138
// the sparse range for the next level. See SparseTensorLevel::peekRangeAt();
@@ -143,16 +144,17 @@ class SparseIterator {
143
144
llvm_unreachable (" unsupported" );
144
145
};
145
146
146
- // Initialize the iterator according to the parent iterator's state.
147
+ // Initializes the iterator according to the parent iterator's state.
147
148
virtual void genInit (OpBuilder &, Location, const SparseIterator *) = 0;
148
149
149
- // Return a pair of values for *upper*, *lower* bound respectively.
150
+ // Returns a pair of values for *upper*, *lower* bound respectively.
150
151
virtual std::pair<Value, Value> genForCond (OpBuilder &b, Location l) {
151
152
assert (randomAccessible ());
152
153
// Random-access iterator is traversed by coordinate, i.e., [curCrd, UB).
153
154
return {getCrd (), upperBound (b, l)};
154
155
}
155
156
157
+ // Returns a boolean value that equals `!it.end()`
156
158
virtual Value genNotEnd (OpBuilder &b, Location l) = 0;
157
159
std::pair<Value, ValueRange> genWhileCond (OpBuilder &b, Location l,
158
160
ValueRange vs) {
@@ -221,21 +223,30 @@ std::unique_ptr<SparseTensorLevel> makeSparseTensorLevel(OpBuilder &builder,
221
223
Location loc, Value t,
222
224
unsigned tid, Level l);
223
225
224
- // / Helper function to create a SparseIterator object.
226
+ // / Helper function to create a simple SparseIterator object that iterate over
227
+ // / the SparseTensorLevel.
225
228
std::unique_ptr<SparseIterator>
226
229
makeSimpleIterator (const SparseTensorLevel &stl);
227
230
231
+ // / Helper function to create a synthetic SparseIterator object that iterate
232
+ // / over a dense space specified by [0,`sz`).
228
233
std::pair<std::unique_ptr<SparseTensorLevel>, std::unique_ptr<SparseIterator>>
229
234
makeSynLevelAndIterator (Value sz, unsigned tid, unsigned lvl);
230
235
236
+ // / Helper function to create a SparseIterator object that iterate over a
237
+ // / sliced space, the orignal space (before slicing) is traversed by `sit`.
231
238
std::unique_ptr<SparseIterator>
232
239
makeSlicedLevelIterator (std::unique_ptr<SparseIterator> &&sit, Value offset,
233
240
Value stride, Value size);
234
241
242
+ // / Helper function to create a SparseIterator object that iterate over the
243
+ // / non-empty subsections set.
235
244
std::unique_ptr<SparseIterator> makeNonEmptySubSectIterator (
236
245
OpBuilder &b, Location l, const SparseIterator *parent,
237
246
std::unique_ptr<SparseIterator> &&delegate, Value size, unsigned stride);
238
247
248
+ // / Helper function to create a SparseIterator object that iterate over a
249
+ // / non-empty subsection created by NonEmptySubSectIterator.
239
250
std::unique_ptr<SparseIterator> makeTraverseSubSectIterator (
240
251
const SparseIterator &subsectIter, const SparseIterator &parent,
241
252
std::unique_ptr<SparseIterator> &&delegate, Value size, unsigned stride);
0 commit comments