[mlir][sparse] Rename SparseTensorFile to SparseTensorReader.
authorbixia1 <bixia@google.com>
Fri, 7 Oct 2022 19:01:38 +0000 (12:01 -0700)
committerbixia1 <bixia@google.com>
Mon, 10 Oct 2022 15:24:37 +0000 (08:24 -0700)
This is to prepare for adding SparseTensorWriter.

Reviewed By: wrengr

Differential Revision: https://reviews.llvm.org/D135477

mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
mlir/lib/ExecutionEngine/SparseTensor/File.cpp
mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
mlir/lib/ExecutionEngine/SparseTensorUtils.cpp

index c8e7fa8..f542091 100644 (file)
@@ -42,7 +42,7 @@ namespace sparse_tensor {
 
 /// 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 @@ public:
     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 @@ template <typename V>
 inline SparseTensorCOO<V> *
 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.
index 932d496..b5c940b 100644 (file)
@@ -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 @@ void SparseTensorFile::openFile() {
 }
 
 /// Closes the file.
-void SparseTensorFile::closeFile() {
+void SparseTensorReader::closeFile() {
   if (file) {
     fclose(file);
     file = nullptr;
@@ -55,14 +55,14 @@ void SparseTensorFile::closeFile() {
 // `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 @@ void SparseTensorFile::readHeader() {
 
 /// 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 @@ static inline bool strne(const char *lhs, const char *rhs) {
 }
 
 /// 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 @@ void SparseTensorFile::readMMEHeader() {
 /// 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();
index 888553c..91cfe0f 100644 (file)
@@ -100,7 +100,7 @@ MLIR_SPARSETENSOR_FOREVERY_V(IMPL_EXPINSERT)
 
 #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
index f02bb9a..61166fd 100644 (file)
@@ -501,7 +501,7 @@ char *getTensorFilename(index_type id) {
 
 void readSparseTensorShape(char *filename, std::vector<uint64_t> *out) {
   assert(out && "Received nullptr for out-parameter");
-  SparseTensorFile stfile(filename);
+  SparseTensorReader stfile(filename);
   stfile.openFile();
   stfile.readHeader();
   stfile.closeFile();