diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h --- a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h +++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h @@ -42,7 +42,7 @@ /// This class abstracts over the information stored in file headers, /// as well as providing the buffers and methods for parsing those headers. -class SparseTensorFile final { +class SparseTensorReader final { public: enum class ValueKind : uint8_t { // The value before calling `readHeader`. @@ -56,18 +56,18 @@ kUndefined = 5 }; - explicit SparseTensorFile(const char *filename) : filename(filename) { + explicit SparseTensorReader(const char *filename) : filename(filename) { assert(filename && "Received nullptr for filename"); } // Disallows copying, to avoid duplicating the `file` pointer. - SparseTensorFile(const SparseTensorFile &) = delete; - SparseTensorFile &operator=(const SparseTensorFile &) = delete; + SparseTensorReader(const SparseTensorReader &) = delete; + SparseTensorReader &operator=(const SparseTensorReader &) = delete; // This dtor tries to avoid leaking the `file`. (Though it's better // to call `closeFile` explicitly when possible, since there are // circumstances where dtors are not called reliably.) - ~SparseTensorFile() { closeFile(); } + ~SparseTensorReader() { closeFile(); } /// Opens the file for reading. void openFile(); @@ -194,7 +194,7 @@ inline SparseTensorCOO * openSparseTensorCOO(const char *filename, uint64_t rank, const uint64_t *shape, const uint64_t *perm, PrimaryType valTp) { - SparseTensorFile stfile(filename); + SparseTensorReader stfile(filename); stfile.openFile(); stfile.readHeader(); // Check tensor element type against the value type in the input file. diff --git a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp --- a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp @@ -31,7 +31,7 @@ using namespace mlir::sparse_tensor; /// Opens the file for reading. -void SparseTensorFile::openFile() { +void SparseTensorReader::openFile() { if (file) MLIR_SPARSETENSOR_FATAL("Already opened file %s\n", filename); file = fopen(filename, "r"); @@ -40,7 +40,7 @@ } /// Closes the file. -void SparseTensorFile::closeFile() { +void SparseTensorReader::closeFile() { if (file) { fclose(file); file = nullptr; @@ -55,14 +55,14 @@ // `char const* *restrict`). // /// Attempts to read a line from the file. -char *SparseTensorFile::readLine() { +char *SparseTensorReader::readLine() { if (fgets(line, kColWidth, file)) return line; MLIR_SPARSETENSOR_FATAL("Cannot read next line of %s\n", filename); } /// Reads and parses the file's header. -void SparseTensorFile::readHeader() { +void SparseTensorReader::readHeader() { assert(file && "Attempt to readHeader() before openFile()"); if (strstr(filename, ".mtx")) readMMEHeader(); @@ -75,15 +75,15 @@ /// Asserts the shape subsumes the actual dimension sizes. Is only /// valid after parsing the header. -void SparseTensorFile::assertMatchesShape(uint64_t rank, - const uint64_t *shape) const { +void SparseTensorReader::assertMatchesShape(uint64_t rank, + const uint64_t *shape) const { assert(rank == getRank() && "Rank mismatch"); for (uint64_t r = 0; r < rank; ++r) assert((shape[r] == 0 || shape[r] == idata[2 + r]) && "Dimension size mismatch"); } -bool SparseTensorFile::canReadAs(PrimaryType valTy) const { +bool SparseTensorReader::canReadAs(PrimaryType valTy) const { switch (valueKind_) { case ValueKind::kInvalid: assert(false && "Must readHeader() before calling canReadAs()"); @@ -129,7 +129,7 @@ } /// Read the MME header of a general sparse matrix of type real. -void SparseTensorFile::readMMEHeader() { +void SparseTensorReader::readMMEHeader() { char header[64]; char object[64]; char format[64]; @@ -181,7 +181,7 @@ /// format, we assume that the file starts with optional comments followed /// by two lines that define the rank, the number of nonzeros, and the /// dimensions sizes (one per rank) of the sparse tensor. -void SparseTensorFile::readExtFROSTTHeader() { +void SparseTensorReader::readExtFROSTTHeader() { // Skip comments. while (true) { readLine(); diff --git a/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp b/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp --- a/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp @@ -100,7 +100,7 @@ #undef FATAL_PIV -// TODO: try to unify this with `SparseTensorFile::assertMatchesShape` +// TODO: try to unify this with `SparseTensorReader::assertMatchesShape` // (which is used by `openSparseTensorCOO`). It's easy enough to resolve // the `std::vector` vs pointer mismatch for `dimSizes`; but it's trickier // to resolve the presence/absence of `perm` (without introducing extra diff --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp --- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp @@ -501,7 +501,7 @@ void readSparseTensorShape(char *filename, std::vector *out) { assert(out && "Received nullptr for out-parameter"); - SparseTensorFile stfile(filename); + SparseTensorReader stfile(filename); stfile.openFile(); stfile.readHeader(); stfile.closeFile();