9 #ifndef MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_SPARSETENSORITERATOR_H_
10 #define MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_SPARSETENSORITERATOR_H_
16 namespace sparse_tensor {
32 std::to_string(
lvl) +
"]";
49 virtual std::pair<Value, Value>
92 unsigned cursorValsCnt,
95 cursorValsCnt(cursorValsCnt), cursorValsStorageRef(cursorValStorage){};
104 unsigned extraCursorCnt = 0)
106 extraCursorCnt +
wrap.cursorValsCnt,
107 wrap.cursorValsStorageRef) {
108 assert(
wrap.cursorValsCnt ==
wrap.cursorValsStorageRef.size());
109 cursorValsStorageRef.append(extraCursorCnt,
nullptr);
110 assert(cursorValsStorageRef.size() ==
wrap.cursorValsCnt + extraCursorCnt);
126 return ValueRange(cursorValsStorageRef).take_front(cursorValsCnt);
131 assert(vals.size() == cursorValsCnt);
132 std::copy(vals.begin(), vals.end(), cursorValsStorageRef.begin());
166 llvm_unreachable(
"unsupported");
197 llvm_unreachable(
"Unsupported");
224 return std::make_pair(
genNotEnd(b, l), rem);
244 "by coordinate, call locate() instead.");
245 seek(pos.take_front(cursorValsCnt));
246 return pos.drop_front(cursorValsCnt);
254 return ref.take_front(cursorValsCnt);
280 const unsigned cursorValsCnt;
297 std::pair<std::unique_ptr<SparseTensorLevel>, std::unique_ptr<SparseIterator>>
303 std::unique_ptr<SparseIterator>
309 std::unique_ptr<SparseIterator>
317 std::unique_ptr<SparseIterator> &&delegate,
Value size,
unsigned stride,
static void copy(Location loc, Value dst, Value src, Value size, OpBuilder &builder)
Copies the given number of bytes from src to dst pointers.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Helper class that generates loop conditions, etc, to traverse a sparse tensor level.
virtual std::pair< Value, Value > genForCond(OpBuilder &b, Location l)
void updateCrd(Value crd)
MutableArrayRef< Value > getMutCursorVals()
virtual void genInitImpl(OpBuilder &, Location, const SparseIterator *)=0
ValueRange forward(OpBuilder &b, Location l)
SparseIterator(IterKind kind, unsigned cursorValsCnt, SmallVectorImpl< Value > &cursorValStorage, const SparseIterator &delegate)
void setSparseEmitStrategy(SparseEmitStrategy strategy)
virtual bool isBatchIterator() const =0
virtual void locateImpl(OpBuilder &b, Location l, Value crd)
void genInit(OpBuilder &b, Location l, const SparseIterator *p)
SparseEmitStrategy emitStrategy
virtual Value upperBound(OpBuilder &b, Location l) const =0
ValueRange getBatchCrds() const
virtual ~SparseIterator()=default
virtual Value derefImpl(OpBuilder &b, Location l)=0
Value genNotEnd(OpBuilder &b, Location l)
void locate(OpBuilder &b, Location l, Value crd)
virtual void deserialize(ValueRange vs)
SmallVector< Value > batchCrds
SparseIterator(IterKind kind, const SparseIterator &wrap, unsigned extraCursorCnt=0)
virtual ValueRange forwardIf(OpBuilder &b, Location l, Value cond)
virtual Value genNotEndImpl(OpBuilder &b, Location l)=0
void inherentBatch(const SparseIterator &parent)
ValueRange linkNewScope(ValueRange pos)
virtual std::string getDebugInterfacePrefix() const =0
ValueRange getCursor() const
virtual bool iteratableByFor() const
virtual SmallVector< Value > serialize() const
virtual ValueRange getCurPosition() const
Value deref(OpBuilder &b, Location l)
virtual bool randomAccessible() const =0
virtual ValueRange forwardImpl(OpBuilder &b, Location l)=0
void seek(ValueRange vals)
virtual SmallVector< Type > getCursorValTypes(OpBuilder &b) const =0
SparseIterator(IterKind kind, unsigned tid, unsigned lvl, unsigned cursorValsCnt, SmallVectorImpl< Value > &cursorValStorage)
std::pair< Value, ValueRange > genWhileCond(OpBuilder &b, Location l, ValueRange vs)
The base class for all types of sparse tensor levels.
virtual std::pair< Value, Value > peekRangeAt(OpBuilder &b, Location l, ValueRange batchPrefix, ValueRange parentPos, Value inPadZone=nullptr) const =0
Peeks the lower and upper bound to fully traverse the level with the given position parentPos,...
virtual Value peekCrdAt(OpBuilder &b, Location l, ValueRange batchPrefix, Value iv) const =0
std::string toString() const
virtual ~SparseTensorLevel()=default
virtual ValueRange getLvlBuffers() const =0
SparseTensorLevel(unsigned tid, unsigned lvl, LevelType lt, Value lvlSize)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
bool isUniqueLT(LevelType lt)
std::string toMLIRString(LevelType lt)
std::unique_ptr< SparseTensorLevel > makeSparseTensorLevel(OpBuilder &b, Location l, Value t, unsigned tid, Level lvl)
Helper function to create a TensorLevel object from given tensor.
std::unique_ptr< SparseIterator > makeTraverseSubSectIterator(OpBuilder &b, Location l, const SparseIterator &subsectIter, const SparseIterator &parent, std::unique_ptr< SparseIterator > &&wrap, Value loopBound, unsigned stride, SparseEmitStrategy strategy)
Helper function to create a SparseIterator object that iterates over a non-empty subsection created b...
uint64_t Level
The type of level identifiers and level-ranks.
std::unique_ptr< SparseIterator > makeSimpleIterator(const SparseTensorLevel &stl, SparseEmitStrategy strategy)
Helper function to create a simple SparseIterator object that iterate over the SparseTensorLevel.
std::pair< std::unique_ptr< SparseTensorLevel >, std::unique_ptr< SparseIterator > > makeSynLevelAndIterator(Value sz, unsigned tid, unsigned lvl, SparseEmitStrategy strategy)
Helper function to create a synthetic SparseIterator object that iterates over a dense space specifie...
std::unique_ptr< SparseIterator > makePaddedIterator(std::unique_ptr< SparseIterator > &&sit, Value padLow, Value padHigh, SparseEmitStrategy strategy)
Helper function to create a SparseIterator object that iterates over a padded sparse level (the padde...
std::unique_ptr< SparseIterator > makeSlicedLevelIterator(std::unique_ptr< SparseIterator > &&sit, Value offset, Value stride, Value size, SparseEmitStrategy strategy)
Helper function to create a SparseIterator object that iterates over a sliced space,...
std::unique_ptr< SparseIterator > makeNonEmptySubSectIterator(OpBuilder &b, Location l, const SparseIterator *parent, Value loopBound, std::unique_ptr< SparseIterator > &&delegate, Value size, unsigned stride, SparseEmitStrategy strategy)
Helper function to create a SparseIterator object that iterate over the non-empty subsections set.
Include the generated interface declarations.
SparseEmitStrategy
Defines a scope for reinterpret map pass.
This enum defines all the sparse representations supportable by the SparseTensor dialect.