[Mlir-commits] [mlir] [mlir][sparse] minor edits in runtime lib Cpp files (PR #68165)
Aart Bik
llvmlistbot at llvm.org
Tue Oct 3 15:58:41 PDT 2023
https://github.com/aartbik created https://github.com/llvm/llvm-project/pull/68165
None
>From 3565d0b0d6e80c32bfbcc39c4bb7274a13b2239c Mon Sep 17 00:00:00 2001
From: Aart Bik <ajcbik at google.com>
Date: Tue, 3 Oct 2023 15:57:08 -0700
Subject: [PATCH] [mlir][sparse] minor edits in runtime lib Cpp files
---
.../mlir/ExecutionEngine/SparseTensor/File.h | 6 +++---
.../lib/ExecutionEngine/SparseTensor/File.cpp | 17 ++-------------
mlir/lib/ExecutionEngine/SparseTensor/NNZ.cpp | 7 -------
.../ExecutionEngine/SparseTensor/Storage.cpp | 21 +++----------------
4 files changed, 8 insertions(+), 43 deletions(-)
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..3d6eb72ce73245c 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..50c7da96715a6f2 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,15 +33,11 @@ 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.
+ 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