MLIR  19.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
mlir::sparse_tensor::SparseTensorReader Class Referencefinal

This class abstracts over the information stored in file headers, as well as providing the buffers and methods for parsing those headers. More...

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

Public Types

enum class  ValueKind : uint8_t {
  kInvalid = 0 , kPattern = 1 , kReal = 2 , kInteger = 3 ,
  kComplex = 4 , kUndefined = 5
}
 

Public Member Functions

 SparseTensorReader (const char *filename)
 
 SparseTensorReader (const SparseTensorReader &)=delete
 
SparseTensorReaderoperator= (const SparseTensorReader &)=delete
 
 ~SparseTensorReader ()
 
void openFile ()
 Opens the file for reading. More...
 
void closeFile ()
 Closes the file. More...
 
void readHeader ()
 Reads and parses the file's header. More...
 
ValueKind getValueKind () const
 Returns the stored value kind. More...
 
bool isValid () const
 Checks if a header has been successfully read. More...
 
bool canReadAs (PrimaryType valTy) const
 Checks if the file's ValueKind can be converted into the given tensor PrimaryType. More...
 
bool isPattern () const
 Gets the MME "pattern" property setting. More...
 
bool isSymmetric () const
 Gets the MME "symmetric" property setting. More...
 
uint64_t getRank () const
 Gets the dimension-rank of the tensor. More...
 
uint64_t getNSE () const
 Gets the number of stored elements. More...
 
const uint64_t * getDimSizes () const
 Gets the dimension-sizes array. More...
 
uint64_t getDimSize (uint64_t d) const
 Safely gets the size of the given dimension. More...
 
void assertMatchesShape (uint64_t rank, const uint64_t *shape) const
 Asserts the shape subsumes the actual dimension sizes. More...
 
template<typename P , typename I , typename V >
SparseTensorStorage< P, I, V > * readSparseTensor (uint64_t lvlRank, const uint64_t *lvlSizes, const LevelType *lvlTypes, const uint64_t *dim2lvl, const uint64_t *lvl2dim)
 Allocates a new sparse-tensor storage object with the given encoding, initializes it by reading all the elements from the file, and then closes the file. More...
 
template<typename C , typename V >
bool readToBuffers (uint64_t lvlRank, const uint64_t *dim2lvl, const uint64_t *lvl2dim, C *lvlCoordinates, V *values)
 Reads the COO tensor from the file, stores the coordinates and values to the given buffers, returns a boolean value to indicate whether the COO elements are sorted. More...
 

Static Public Member Functions

static SparseTensorReadercreate (const char *filename, uint64_t dimRank, const uint64_t *dimShape, PrimaryType valTp)
 Factory method to allocate a new reader, open the file, read the header, and validate that the actual contents of the file match the expected dimShape and valTp. More...
 

Detailed Description

This class abstracts over the information stored in file headers, as well as providing the buffers and methods for parsing those headers.

Definition at line 87 of file File.h.

Member Enumeration Documentation

◆ ValueKind

Enumerator
kInvalid 
kPattern 
kReal 
kInteger 
kComplex 
kUndefined 

Definition at line 89 of file File.h.

Constructor & Destructor Documentation

◆ SparseTensorReader() [1/2]

mlir::sparse_tensor::SparseTensorReader::SparseTensorReader ( const char *  filename)
inlineexplicit

Definition at line 101 of file File.h.

Referenced by create().

◆ SparseTensorReader() [2/2]

mlir::sparse_tensor::SparseTensorReader::SparseTensorReader ( const SparseTensorReader )
delete

◆ ~SparseTensorReader()

mlir::sparse_tensor::SparseTensorReader::~SparseTensorReader ( )
inline

Definition at line 131 of file File.h.

References closeFile().

Member Function Documentation

◆ assertMatchesShape()

void SparseTensorReader::assertMatchesShape ( uint64_t  rank,
const uint64_t *  shape 
) const

Asserts the shape subsumes the actual dimension sizes.

Is only valid after parsing the header.

Definition at line 65 of file File.cpp.

References getRank().

Referenced by create().

◆ canReadAs()

bool SparseTensorReader::canReadAs ( PrimaryType  valTy) const

Checks if the file's ValueKind can be converted into the given tensor PrimaryType.

Is only valid after parsing the header.

Definition at line 73 of file File.cpp.

References mlir::sparse_tensor::isComplexPrimaryType(), mlir::sparse_tensor::isFloatingPrimaryType(), mlir::sparse_tensor::isRealPrimaryType(), kComplex, kInteger, kInvalid, kPattern, kReal, and kUndefined.

Referenced by create().

◆ closeFile()

void SparseTensorReader::closeFile ( )

Closes the file.

Definition at line 34 of file File.cpp.

Referenced by readToBuffers(), and ~SparseTensorReader().

◆ create()

static SparseTensorReader* mlir::sparse_tensor::SparseTensorReader::create ( const char *  filename,
uint64_t  dimRank,
const uint64_t *  dimShape,
PrimaryType  valTp 
)
inlinestatic

Factory method to allocate a new reader, open the file, read the header, and validate that the actual contents of the file match the expected dimShape and valTp.

Definition at line 112 of file File.h.

References assertMatchesShape(), canReadAs(), openFile(), readHeader(), and SparseTensorReader().

◆ getDimSize()

uint64_t mlir::sparse_tensor::SparseTensorReader::getDimSize ( uint64_t  d) const
inline

Safely gets the size of the given dimension.

Is only valid after parsing the header.

Definition at line 187 of file File.h.

References getRank().

◆ getDimSizes()

const uint64_t* mlir::sparse_tensor::SparseTensorReader::getDimSizes ( ) const
inline

Gets the dimension-sizes array.

The pointer itself is always valid; however, the values stored therein are only valid after parsing the header.

Definition at line 183 of file File.h.

Referenced by readSparseTensor().

◆ getNSE()

uint64_t mlir::sparse_tensor::SparseTensorReader::getNSE ( ) const
inline

Gets the number of stored elements.

Is only valid after parsing the header.

Definition at line 175 of file File.h.

References isValid().

◆ getRank()

uint64_t mlir::sparse_tensor::SparseTensorReader::getRank ( ) const
inline

Gets the dimension-rank of the tensor.

Is only valid after parsing the header.

Definition at line 168 of file File.h.

References isValid().

Referenced by assertMatchesShape(), getDimSize(), readSparseTensor(), and readToBuffers().

◆ getValueKind()

ValueKind mlir::sparse_tensor::SparseTensorReader::getValueKind ( ) const
inline

Returns the stored value kind.

Definition at line 143 of file File.h.

◆ isPattern()

bool mlir::sparse_tensor::SparseTensorReader::isPattern ( ) const
inline

Gets the MME "pattern" property setting.

Is only valid after parsing the header.

Definition at line 154 of file File.h.

References isValid(), and kPattern.

Referenced by readToBuffers().

◆ isSymmetric()

bool mlir::sparse_tensor::SparseTensorReader::isSymmetric ( ) const
inline

Gets the MME "symmetric" property setting.

Is only valid after parsing the header.

Definition at line 161 of file File.h.

References isValid().

◆ isValid()

bool mlir::sparse_tensor::SparseTensorReader::isValid ( ) const
inline

Checks if a header has been successfully read.

Definition at line 146 of file File.h.

References kInvalid.

Referenced by getNSE(), getRank(), isPattern(), isSymmetric(), readHeader(), and readToBuffers().

◆ openFile()

void SparseTensorReader::openFile ( )

Opens the file for reading.

Definition at line 21 of file File.cpp.

Referenced by create().

◆ operator=()

SparseTensorReader& mlir::sparse_tensor::SparseTensorReader::operator= ( const SparseTensorReader )
delete

◆ readHeader()

void SparseTensorReader::readHeader ( )

Reads and parses the file's header.

Definition at line 50 of file File.cpp.

References isValid().

Referenced by create().

◆ readSparseTensor()

template<typename P , typename I , typename V >
SparseTensorStorage<P, I, V>* mlir::sparse_tensor::SparseTensorReader::readSparseTensor ( uint64_t  lvlRank,
const uint64_t *  lvlSizes,
const LevelType lvlTypes,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim 
)
inline

Allocates a new sparse-tensor storage object with the given encoding, initializes it by reading all the elements from the file, and then closes the file.

Templated on P, I, and V.

Definition at line 201 of file File.h.

References getDimSizes(), getRank(), and mlir::sparse_tensor::SparseTensorStorage< P, C, V >::newFromCOO().

◆ readToBuffers()

template<typename C , typename V >
bool mlir::sparse_tensor::SparseTensorReader::readToBuffers ( uint64_t  lvlRank,
const uint64_t *  dim2lvl,
const uint64_t *  lvl2dim,
C *  lvlCoordinates,
V *  values 
)

Reads the COO tensor from the file, stores the coordinates and values to the given buffers, returns a boolean value to indicate whether the COO elements are sorted.

Definition at line 314 of file File.h.

References closeFile(), getRank(), isPattern(), and isValid().


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