MLIR  19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
mlir::sparse_tensor::SparseTensorStorage< P, C, V > Class Template Referencefinal

A memory-resident sparse tensor using a storage scheme based on per-level sparse/dense annotations. More...

#include "mlir/ExecutionEngine/SparseTensor/Storage.h"

+ Inheritance diagram for mlir::sparse_tensor::SparseTensorStorage< P, C, V >:

Public Member Functions

 SparseTensorStorage (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim, SparseTensorCOO< V > *lvlCOO, bool initializeValuesIfAllDense)
 Constructs a sparse tensor with the given encoding, and allocates overhead storage according to some simple heuristics. More...
 
 SparseTensorStorage (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim, SparseTensorCOO< V > &lvlCOO)
 Constructs a sparse tensor with the given encoding, and initializes the contents from the COO. More...
 
 SparseTensorStorage (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim, const intptr_t *lvlBufs)
 Constructs a sparse tensor with the given encoding, and initializes the contents from the level buffers. More...
 
 ~SparseTensorStorage () final=default
 
void getPositions (std::vector< P > **out, uint64_t lvl) final
 Partially specialize these getter methods based on template types. More...
 
void getCoordinates (std::vector< C > **out, uint64_t lvl) final
 
void getValues (std::vector< V > **out) final
 
void lexInsert (const uint64_t *lvlCoords, V val) final
 Partially specialize lexicographical insertions based on template types. More...
 
void expInsert (uint64_t *lvlCoords, V *values, bool *filled, uint64_t *added, uint64_t count, uint64_t expsz) final
 Partially specialize expanded insertions based on template types. More...
 
void endLexInsert () final
 Finalizes lexicographic insertions. More...
 
SparseTensorCOO< V > * toCOO ()
 Allocates a new COO object and initializes it with the contents. More...
 
void sortInPlace ()
 Sort the unordered tensor in place, the method assumes that it is an unordered COO tensor. More...
 
- Public Member Functions inherited from mlir::sparse_tensor::SparseTensorStorageBase
 SparseTensorStorageBase (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim)
 Constructs a new sparse-tensor storage object with the given encoding. More...
 
virtual ~SparseTensorStorageBase ()=default
 
uint64_t getDimRank () const
 Gets the number of tensor-dimensions. More...
 
uint64_t getLvlRank () const
 Gets the number of storage-levels. More...
 
const std::vector< uint64_t > & getDimSizes () const
 Gets the tensor-dimension sizes array. More...
 
uint64_t getDimSize (uint64_t d) const
 Safely looks up the size of the given tensor-dimension. More...
 
const std::vector< uint64_t > & getLvlSizes () const
 Gets the storage-level sizes array. More...
 
uint64_t getLvlSize (uint64_t l) const
 Safely looks up the size of the given storage-level. More...
 
const std::vector< LevelType > & getLvlTypes () const
 Gets the level-types array. More...
 
LevelType getLvlType (uint64_t l) const
 Safely looks up the type of the given level. More...
 
bool isDenseLvl (uint64_t l) const
 Safely checks if the level uses dense storage. More...
 
bool isCompressedLvl (uint64_t l) const
 Safely checks if the level uses compressed storage. More...
 
bool isLooseCompressedLvl (uint64_t l) const
 Safely checks if the level uses loose compressed storage. More...
 
bool isSingletonLvl (uint64_t l) const
 Safely checks if the level uses singleton storage. More...
 
bool isNOutOfMLvl (uint64_t l) const
 Safely checks if the level uses n out of m storage. More...
 
bool isOrderedLvl (uint64_t l) const
 Safely checks if the level is ordered. More...
 
bool isUniqueLvl (uint64_t l) const
 Safely checks if the level is unique. More...
 

Static Public Member Functions

static SparseTensorStorage< P, C, V > * newEmpty (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim)
 Allocates a new empty sparse tensor. More...
 
static SparseTensorStorage< P, C, V > * newFromCOO (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim, SparseTensorCOO< V > &lvlCOO)
 Allocates a new sparse tensor and initializes it from the given COO. More...
 
static SparseTensorStorage< P, C, V > * packFromLvlBuffers (uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim, uint64_t srcRank, const intptr_t *buffers)
 Allocates a new sparse tensor and initialize it with the data stored level buffers directly. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mlir::sparse_tensor::SparseTensorStorageBase
 SparseTensorStorageBase (const SparseTensorStorageBase &)=default
 
SparseTensorStorageBaseoperator= (const SparseTensorStorageBase &)=delete
 
- Protected Attributes inherited from mlir::sparse_tensor::SparseTensorStorageBase
const MapRef map
 
const bool allDense
 

Detailed Description

template<typename P, typename C, typename V>
class mlir::sparse_tensor::SparseTensorStorage< P, C, V >

A memory-resident sparse tensor using a storage scheme based on per-level sparse/dense annotations.

This data structure provides a bufferized form of a sparse tensor type. In contrast to generating setup methods for each differently annotated sparse tensor, this method provides a convenient "one-size-fits-all" solution that simply takes an input tensor and annotations to implement all required setup in a general manner.

Definition at line 189 of file Storage.h.

Constructor & Destructor Documentation

◆ SparseTensorStorage() [1/3]

template<typename P , typename C , typename V >
mlir::sparse_tensor::SparseTensorStorage< P, C, V >::SparseTensorStorage ( uint64_t  dimRank,
const uint64_t *  dimSizes,
uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim,
SparseTensorCOO< V > *  lvlCOO,
bool  initializeValuesIfAllDense 
)

Constructs a sparse tensor with the given encoding, and allocates overhead storage according to some simple heuristics.

When the bool argument is true and lvlTypes are all dense, then this ctor will also initialize the values array with zeros. That argument should be true when an empty tensor is intended; whereas it should usually be false when the ctor will be followed up by some other form of initialization.

Definition at line 656 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::allDense, mlir::sparse_tensor::detail::checkedMul(), mlir::sparse_tensor::SparseTensorCOO< V >::getRank(), mlir::sparse_tensor::SparseTensorStorageBase::isCompressedLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isDenseLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isLooseCompressedLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isNOutOfMLvl(), and mlir::sparse_tensor::SparseTensorStorageBase::isSingletonLvl().

◆ SparseTensorStorage() [2/3]

template<typename P , typename C , typename V >
mlir::sparse_tensor::SparseTensorStorage< P, C, V >::SparseTensorStorage ( uint64_t  dimRank,
const uint64_t *  dimSizes,
uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim,
SparseTensorCOO< V > &  lvlCOO 
)

Constructs a sparse tensor with the given encoding, and initializes the contents from the COO.

This ctor performs the same heuristic overhead-storage allocation as the ctor above.

Definition at line 700 of file Storage.h.

References mlir::sparse_tensor::SparseTensorCOO< V >::getElements(), mlir::sparse_tensor::SparseTensorCOO< V >::getRank(), and mlir::sparse_tensor::SparseTensorCOO< V >::sort().

◆ SparseTensorStorage() [3/3]

template<typename P , typename C , typename V >
mlir::sparse_tensor::SparseTensorStorage< P, C, V >::SparseTensorStorage ( uint64_t  dimRank,
const uint64_t *  dimSizes,
uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim,
const intptr_t *  lvlBufs 
)

Constructs a sparse tensor with the given encoding, and initializes the contents from the level buffers.

This ctor allocates exactly the required amount of overhead storage, not using any heuristics. It assumes that the data provided by lvlBufs can be directly used to interpret the result sparse tensor and performs NO integrity test on the input data. It also assume that the trailing COO coordinate buffer is passed in as a single AoS memory.

Definition at line 719 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::isCompressedLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isDenseLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isLooseCompressedLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isNOutOfMLvl(), mlir::sparse_tensor::SparseTensorStorageBase::isSingletonLvl(), and mlir::sparse_tensor::SparseTensorStorageBase::isUniqueLvl().

◆ ~SparseTensorStorage()

template<typename P , typename C , typename V >
mlir::sparse_tensor::SparseTensorStorage< P, C, V >::~SparseTensorStorage ( )
finaldefault

Member Function Documentation

◆ endLexInsert()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::endLexInsert ( )
inlinefinalvirtual

Finalizes lexicographic insertions.

Implements mlir::sparse_tensor::SparseTensorStorageBase.

Definition at line 331 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::allDense.

◆ expInsert()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::expInsert ( uint64_t *  lvlCoords,
V *  values,
bool *  filled,
uint64_t *  added,
uint64_t  count,
uint64_t  expsz 
)
inlinefinal

Partially specialize expanded insertions based on template types.

Definition at line 301 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::getLvlRank(), and mlir::sparse_tensor::SparseTensorStorage< P, C, V >::lexInsert().

◆ getCoordinates()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::getCoordinates ( std::vector< C > **  out,
uint64_t  lvl 
)
inlinefinal

◆ getPositions()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::getPositions ( std::vector< P > **  out,
uint64_t  lvl 
)
inlinefinal

Partially specialize these getter methods based on template types.

Definition at line 261 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::getLvlRank().

◆ getValues()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::getValues ( std::vector< V > **  out)
inlinefinal

Definition at line 271 of file Storage.h.

◆ lexInsert()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::lexInsert ( const uint64_t *  lvlCoords,
val 
)
inlinefinal

◆ newEmpty()

template<typename P , typename C , typename V >
SparseTensorStorage< P, C, V > * mlir::sparse_tensor::SparseTensorStorage< P, C, V >::newEmpty ( uint64_t  dimRank,
const uint64_t *  dimSizes,
uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim 
)
static

Allocates a new empty sparse tensor.

Definition at line 620 of file Storage.h.

◆ newFromCOO()

template<typename P , typename C , typename V >
SparseTensorStorage< P, C, V > * mlir::sparse_tensor::SparseTensorStorage< P, C, V >::newFromCOO ( uint64_t  dimRank,
const uint64_t *  dimSizes,
uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim,
SparseTensorCOO< V > &  lvlCOO 
)
static

Allocates a new sparse tensor and initializes it from the given COO.

Definition at line 630 of file Storage.h.

Referenced by mlir::sparse_tensor::SparseTensorReader::readSparseTensor().

◆ packFromLvlBuffers()

template<typename P , typename C , typename V >
SparseTensorStorage< P, C, V > * mlir::sparse_tensor::SparseTensorStorage< P, C, V >::packFromLvlBuffers ( uint64_t  dimRank,
const uint64_t *  dimSizes,
uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim,
uint64_t  srcRank,
const intptr_t *  buffers 
)
static

Allocates a new sparse tensor and initialize it with the data stored level buffers directly.

Definition at line 640 of file Storage.h.

◆ sortInPlace()

template<typename P , typename C , typename V >
void mlir::sparse_tensor::SparseTensorStorage< P, C, V >::sortInPlace ( )
inline

Sort the unordered tensor in place, the method assumes that it is an unordered COO tensor.

Definition at line 352 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::getLvlRank().

◆ toCOO()

template<typename P , typename C , typename V >
SparseTensorCOO<V>* mlir::sparse_tensor::SparseTensorStorage< P, C, V >::toCOO ( )
inline

Allocates a new COO object and initializes it with the contents.

Callers must make sure to delete the COO when they're done with it.

Definition at line 342 of file Storage.h.

References mlir::sparse_tensor::SparseTensorStorageBase::getDimRank(), and mlir::sparse_tensor::SparseTensorStorageBase::getDimSizes().


The documentation for this class was generated from the following file: