MLIR
20.0.0git
|
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 | |
SparseTensorReader & | operator= (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 SparseTensorReader * | create (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... | |
This class abstracts over the information stored in file headers, as well as providing the buffers and methods for parsing those headers.
|
strong |
|
inlineexplicit |
|
delete |
|
inline |
Definition at line 131 of file File.h.
References closeFile().
void SparseTensorReader::assertMatchesShape | ( | uint64_t | rank, |
const uint64_t * | shape | ||
) | const |
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().
void SparseTensorReader::closeFile | ( | ) |
Closes the file.
Definition at line 34 of file File.cpp.
Referenced by readToBuffers(), and ~SparseTensorReader().
|
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().
|
inline |
|
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().
|
inline |
|
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().
|
inline |
|
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().
|
inline |
|
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().
void SparseTensorReader::openFile | ( | ) |
|
delete |
void SparseTensorReader::readHeader | ( | ) |
|
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().
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().