[Mlir-commits] [mlir] 461c461 - [mlir][sparse] Rename SparseTensorFile to SparseTensorReader.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 10 08:24:47 PDT 2022


Author: bixia1
Date: 2022-10-10T08:24:37-07:00
New Revision: 461c461a7cbf36c094dbd9663bd36cf0e7c2bd9a

URL: https://github.com/llvm/llvm-project/commit/461c461a7cbf36c094dbd9663bd36cf0e7c2bd9a
DIFF: https://github.com/llvm/llvm-project/commit/461c461a7cbf36c094dbd9663bd36cf0e7c2bd9a.diff

LOG: [mlir][sparse] Rename SparseTensorFile to SparseTensorReader.

This is to prepare for adding SparseTensorWriter.

Reviewed By: wrengr

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
index c8e7fa818f04b..f5420912de3e8 100644
--- a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
+++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
@@ -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 @@ class SparseTensorFile final {
     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.

diff  --git a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
index 932d49652cc17..b5c940b65345e 100644
--- 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 @@ 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();

diff  --git a/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp b/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
index 888553c187b11..91cfe0fb0f21e 100644
--- a/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
@@ -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

diff  --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
index f02bb9ad35ca7..61166fda1cb7d 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
@@ -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();


        


More information about the Mlir-commits mailing list