[Mlir-commits] [mlir] 427f120 - [mlir][sparse] minor edits in runtime lib Cpp files (#68165)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 3 16:28:58 PDT 2023


Author: Aart Bik
Date: 2023-10-03T16:28:54-07:00
New Revision: 427f120f60becd23d6e037ccd14104adde8a3af9

URL: https://github.com/llvm/llvm-project/commit/427f120f60becd23d6e037ccd14104adde8a3af9
DIFF: https://github.com/llvm/llvm-project/commit/427f120f60becd23d6e037ccd14104adde8a3af9.diff

LOG: [mlir][sparse] minor edits in runtime lib Cpp files (#68165)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
index be1c4f72e1200da..78c1a0544e3a521 100644
--- a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
+++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
@@ -1,4 +1,4 @@
-//===- File.h - Parsing sparse tensors from files ---------------*- C++ -*-===//
+//===- File.h - Reading/writing sparse tensors from/to files ----*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements reading and writing files in one of the following
-// external formats:
+// This file implements reading and writing sparse tensor files in one of the
+// following external formats:
 //
 // (1) Matrix Market Exchange (MME): *.mtx
 //     https://math.nist.gov/MatrixMarket/formats.html

diff  --git a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
index bb227bf2c2dd438..c49ec0998fb444f 100644
--- a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
@@ -1,4 +1,4 @@
-//===- File.cpp - Parsing sparse tensors from files -----------------------===//
+//===- File.cpp - Reading/writing sparse tensors from/to files ------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,20 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements parsing and printing of files in one of the
-// following external formats:
-//
-// (1) Matrix Market Exchange (MME): *.mtx
-//     https://math.nist.gov/MatrixMarket/formats.html
-//
-// (2) Formidable Repository of Open Sparse Tensors and Tools (FROSTT): *.tns
-//     http://frostt.io/tensors/file-formats.html
-//
-// This file is part of the lightweight runtime support library for sparse
-// tensor manipulations.  The functionality of the support library is meant
-// to simplify benchmarking, testing, and debugging MLIR code operating on
-// sparse tensors.  However, the provided functionality is **not** part of
-// core MLIR itself.
+// This file implements reading and writing sparse tensor files.
 //
 //===----------------------------------------------------------------------===//
 

diff  --git a/mlir/lib/ExecutionEngine/SparseTensor/NNZ.cpp b/mlir/lib/ExecutionEngine/SparseTensor/NNZ.cpp
index c6fd669ad513f46..d3c3951c15468d0 100644
--- a/mlir/lib/ExecutionEngine/SparseTensor/NNZ.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensor/NNZ.cpp
@@ -8,19 +8,12 @@
 //
 // This file contains method definitions for `SparseTensorNNZ`.
 //
-// This file is part of the lightweight runtime support library for sparse
-// tensor manipulations.  The functionality of the support library is meant
-// to simplify benchmarking, testing, and debugging MLIR code operating on
-// sparse tensors.  However, the provided functionality is **not** part of
-// core MLIR itself.
-//
 //===----------------------------------------------------------------------===//
 
 #include "mlir/ExecutionEngine/SparseTensor/Storage.h"
 
 using namespace mlir::sparse_tensor;
 
-//===----------------------------------------------------------------------===//
 SparseTensorNNZ::SparseTensorNNZ(const std::vector<uint64_t> &lvlSizes,
                                  const std::vector<DimLevelType> &lvlTypes)
     : lvlSizes(lvlSizes), lvlTypes(lvlTypes), nnz(getLvlRank()) {

diff  --git a/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp b/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
index 2c4f0123ed4417c..77861e074e9333b 100644
--- a/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp
@@ -9,14 +9,7 @@
 // This file contains method definitions for `SparseTensorStorageBase`.
 // In particular we want to ensure that the default implementations of
 // the "partial method specialization" trick aren't inline (since there's
-// no benefit).  Though this also helps ensure that we avoid weak-vtables:
-// <https://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers>
-//
-// This file is part of the lightweight runtime support library for sparse
-// tensor manipulations.  The functionality of the support library is meant
-// to simplify benchmarking, testing, and debugging MLIR code operating on
-// sparse tensors.  However, the provided functionality is **not** part of
-// core MLIR itself.
+// no benefit).
 //
 //===----------------------------------------------------------------------===//
 
@@ -32,10 +25,6 @@ SparseTensorStorageBase::SparseTensorStorageBase( // NOLINT
       lvlSizes(lvlSizes, lvlSizes + lvlRank),
       lvlTypes(lvlTypes, lvlTypes + lvlRank),
       lvl2dim(lvl2dim, lvl2dim + lvlRank) {
-  // TODO: If we do get any nullptrs, I'm pretty sure these assertions
-  // will run too late (i.e., after copying things into vectors above).
-  // But since those fields are const I'm not sure there's any clean way
-  // to assert things before copying...
   assert(dimSizes && "Got nullptr for dimension sizes");
   assert(lvlSizes && "Got nullptr for level sizes");
   assert(lvlTypes && "Got nullptr for level types");
@@ -44,18 +33,15 @@ SparseTensorStorageBase::SparseTensorStorageBase( // NOLINT
   assert(dimRank > 0 && "Trivial shape is unsupported");
   for (uint64_t d = 0; d < dimRank; ++d)
     assert(dimSizes[d] > 0 && "Dimension size zero has trivial storage");
-  // Validate level-indexed parameters.
+  // Validate lvl-indexed parameters.
   assert(lvlRank > 0 && "Trivial shape is unsupported");
   for (uint64_t l = 0; l < lvlRank; ++l) {
     assert(lvlSizes[l] > 0 && "Level size zero has trivial storage");
-    const auto dlt = lvlTypes[l]; // Avoid redundant bounds checking.
-    // We use `MLIR_SPARSETENSOR_FATAL` here instead of `assert` so that
-    // when this ctor is successful then all the methods can rely on the
-    // fact that each level-type satisfies one of these options (even
-    // when `NDEBUG` is true), thereby reducing the need to re-assert things.
-    if (!(isDenseDLT(dlt) || isCompressedDLT(dlt) || isSingletonDLT(dlt)))
+    const auto dlt = lvlTypes[l];
+    if (!(isDenseDLT(dlt) || isCompressedDLT(dlt) || isSingletonDLT(dlt))) {
       MLIR_SPARSETENSOR_FATAL("unsupported level type: %d\n",
                               static_cast<uint8_t>(dlt));
+    }
   }
 }
 


        


More information about the Mlir-commits mailing list