[Lldb-commits] [libclc] [libcxxabi] [compiler-rt] [mlir] [flang] [clang] [lld] [clang-tools-extra] [llvm] [libcxx] [libc] [libunwind] [lldb] [mlir][sparse][CRunnerUtils] Add shuffle in CRunnerUtils (P

2024-01-09 Thread Aart Bik via lldb-commits


@@ -176,6 +177,14 @@ extern "C" void rtdrand(void *g) {
   delete generator;
 }
 
+extern "C" void _mlir_ciface_shuffle(StridedMemRefType *mref,
+ void *g) {
+  std::mt19937 *generator = static_cast(g);
+  uint64_t s = mref->sizes[0];

aartbik wrote:

One last nit, we may want to ensure that the rank one tensor has the right 
properties

assert(mref->strides[0] == 1);  // consecutive

also,although offset is typically zero, I think we need to compute

uint64_t *data = mref->data + mref->offset

and then do

std::iota(data, data + s, 0);

https://github.com/llvm/llvm-project/pull/77124
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] refine sparse fusion with empty tensors materialization (PR #66563)

2023-09-18 Thread Aart Bik via lldb-commits

aartbik wrote:

I have to fix a merge conflict on the test. Coming up.


https://github.com/llvm/llvm-project/pull/66563
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] Update Enum name for CompressedWithHigh (PR #67845)

2023-09-29 Thread Aart Bik via lldb-commits

https://github.com/aartbik approved this pull request.


https://github.com/llvm/llvm-project/pull/67845
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] Print new syntax (PR #68130)

2023-10-03 Thread Aart Bik via lldb-commits


@@ -533,7 +533,7 @@ func.func @sparse_compression(%tensor: tensor<8x8xf64, 
#CSR>,
 //   CHECK: %[[A13:.*]]:4 = scf.for %[[A14:.*]] = %[[A11]] to %[[A7]] 
step %[[A12]] iter_args(%[[A15:.*]] = %[[A0]], %[[A16:.*]] = %[[A1]], 
%[[A17:.*]] = %[[A2]], %[[A18:.*]] = %[[A3]]) -> (memref, 
memref, memref, !sparse_tensor.storage_specifier
 //   CHECK:   %[[A19:.*]] = memref.load %[[A6]]{{\[}}%[[A14]]] : 
memref
 //   CHECK:   %[[A20:.*]] = memref.load %[[A4]]{{\[}}%[[A19]]] : 
memref
-//   CHECK:   %[[A21:.*]]:4 = func.call 
@_insert_dense_compressed_no_8_8_f64_0_0(%[[A15]], %[[A16]], %[[A17]], 
%[[A18]], %[[A8]], %[[A19]], %[[A20]]) : (memref, memref, 
memref, !sparse_tensor.storage_specifier
+//   CHECK:   %[[A21:.*]]:4 = func.call 
@"_insert_dense_compressed(nonordered)_8_8_f64_0_0"(%[[A15]], %[[A16]], 
%[[A17]], %[[A18]], %[[A8]], %[[A19]], %[[A20]]) : (memref, 
memref, memref, !sparse_tensor.storage_specifier

aartbik wrote:

here and elsewhere, let's use compressed(nonordered) in the printing of type, 
but not in the generation for methods names (replace ( ) with _ perhaps, so we 
keep valid C identifiiers)

https://github.com/llvm/llvm-project/pull/68130
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] Print new syntax (PR #68130)

2023-10-03 Thread Aart Bik via lldb-commits


@@ -586,30 +586,56 @@ Attribute SparseTensorEncodingAttr::parse(AsmParser 
&parser, Type type) {
 }
 
 void SparseTensorEncodingAttr::print(AsmPrinter &printer) const {
-  // Print the struct-like storage in dictionary fashion.
-  printer << "<{ lvlTypes = [ ";
-  llvm::interleaveComma(getLvlTypes(), printer, [&](DimLevelType dlt) {
-printer << "\"" << toMLIRString(dlt) << "\"";
-  });
-  printer << " ]";
+  auto map = static_cast(getDimToLvl());
+  auto lvlTypes = getLvlTypes();
+  // Empty affine map indicates identity map
+  if (!map) {
+map = AffineMap::getMultiDimIdentityMap(getLvlTypes().size(), 
getContext());
+  }
+  // Modified version of AsmPrinter::Impl::printAffineMap.

aartbik wrote:

I would remove this. This is diverged sufficiently to no longer refer to 
printAffineMap

https://github.com/llvm/llvm-project/pull/68130
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] Print new syntax (PR #68130)

2023-10-03 Thread Aart Bik via lldb-commits


@@ -472,8 +472,11 @@ class SparseInsertGenerator
 llvm::raw_svector_ostream nameOstream(nameBuffer);
 nameOstream << kInsertFuncNamePrefix;
 const Level lvlRank = stt.getLvlRank();
-for (Level l = 0; l < lvlRank; l++)
-  nameOstream << toMLIRString(stt.getLvlType(l)) << "_";
+for (Level l = 0; l < lvlRank; l++) {
+  std::string lvlType = toMLIRString(stt.getLvlType(l));
+  replaceWithUnderscore(lvlType);

aartbik wrote:

std::string::replace ?

https://github.com/llvm/llvm-project/pull/68130
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] introduce MapRef, unify conversion/codegen for reader (PR #68360)

2023-10-05 Thread Aart Bik via lldb-commits

https://github.com/aartbik updated 
https://github.com/llvm/llvm-project/pull/68360

>From 6094912685a0cfa5c13e023e8ec97238a84fca2f Mon Sep 17 00:00:00 2001
From: Aart Bik 
Date: Thu, 5 Oct 2023 13:22:28 -0700
Subject: [PATCH 1/4] [mlir][sparse] introduce MapRef, unify conversion/codegen
 for reader

This revision introduces a MapRef, which will support a future
generalization beyond permutations (e.g. block sparsity). This
revision also unifies the conversion/codegen paths for the
sparse_tensor.new operation from file (eg. the readers). Note
that more unification is planned as well as general affine
dim2lvl and lvl2dim (all marked with TODOs).
---
 .../mlir/ExecutionEngine/SparseTensor/File.h  | 156 ++--
 .../ExecutionEngine/SparseTensor/MapRef.h |  96 ++
 .../ExecutionEngine/SparseTensor/Storage.h| 108 +--
 .../ExecutionEngine/SparseTensorRuntime.h |   8 -
 .../SparseTensor/Transforms/CodegenUtils.cpp  |  89 +
 .../SparseTensor/Transforms/CodegenUtils.h|  18 ++
 .../Transforms/SparseTensorCodegen.cpp|  73 ++--
 .../Transforms/SparseTensorConversion.cpp | 111 ++-
 .../SparseTensor/CMakeLists.txt   |   1 +
 .../ExecutionEngine/SparseTensor/MapRef.cpp   |  52 ++
 .../ExecutionEngine/SparseTensorRuntime.cpp   |  60 +++---
 mlir/test/Dialect/SparseTensor/codegen.mlir   | 172 +-
 .../test/Dialect/SparseTensor/conversion.mlir |  18 +-
 13 files changed, 475 insertions(+), 487 deletions(-)
 create mode 100644 mlir/include/mlir/ExecutionEngine/SparseTensor/MapRef.h
 create mode 100644 mlir/lib/ExecutionEngine/SparseTensor/MapRef.cpp

diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h 
b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
index 78c1a0544e3a521..9157bfa7e773239 100644
--- a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
+++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h
@@ -20,6 +20,7 @@
 #ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_FILE_H
 #define MLIR_EXECUTIONENGINE_SPARSETENSOR_FILE_H
 
+#include "mlir/ExecutionEngine/SparseTensor/MapRef.h"
 #include "mlir/ExecutionEngine/SparseTensor/Storage.h"
 
 #include 
@@ -75,6 +76,10 @@ inline V readValue(char **linePtr, bool isPattern) {
 
 } // namespace detail
 
+//===--===//
+//
+//  Reader class.
+//
 
//===--===//
 
 /// This class abstracts over the information stored in file headers,
@@ -132,6 +137,7 @@ class SparseTensorReader final {
   /// Reads and parses the file's header.
   void readHeader();
 
+  /// Returns the stored value kind.
   ValueKind getValueKind() const { return valueKind_; }
 
   /// Checks if a header has been successfully read.
@@ -185,58 +191,37 @@ class SparseTensorReader final {
   /// valid after parsing the header.
   void assertMatchesShape(uint64_t rank, const uint64_t *shape) const;
 
-  /// Reads a sparse tensor element from the next line in the input file and
-  /// returns the value of the element. Stores the coordinates of the element
-  /// to the `dimCoords` array.
-  template 
-  V readElement(uint64_t dimRank, uint64_t *dimCoords) {
-assert(dimRank == getRank() && "rank mismatch");
-char *linePtr = readCoords(dimCoords);
-return detail::readValue(&linePtr, isPattern());
-  }
-
-  /// Allocates a new COO object for `lvlSizes`, initializes it by reading
-  /// all the elements from the file and applying `dim2lvl` to their
-  /// dim-coordinates, and then closes the file. Templated on V only.
-  template 
-  SparseTensorCOO *readCOO(uint64_t lvlRank, const uint64_t *lvlSizes,
-  const uint64_t *dim2lvl);
-
   /// Allocates a new sparse-tensor storage object with the given encoding,
   /// initializes it by reading all the elements from the file, and then
   /// closes the file. Templated on P, I, and V.
   template 
   SparseTensorStorage *
   readSparseTensor(uint64_t lvlRank, const uint64_t *lvlSizes,
-   const DimLevelType *lvlTypes, const uint64_t *lvl2dim,
-   const uint64_t *dim2lvl) {
-auto *lvlCOO = readCOO(lvlRank, lvlSizes, dim2lvl);
+   const DimLevelType *lvlTypes, const uint64_t *dim2lvl,
+   const uint64_t *lvl2dim) {
+const uint64_t dimRank = getRank();
+MapRef map(dimRank, lvlRank, dim2lvl, lvl2dim);
+auto *coo = readCOO(map, lvlSizes);
 auto *tensor = SparseTensorStorage::newFromCOO(
-getRank(), getDimSizes(), lvlRank, lvlTypes, lvl2dim, *lvlCOO);
-delete lvlCOO;
+dimRank, getDimSizes(), lvlRank, lvlTypes, lvl2dim, *coo);
+delete coo;
 return tensor;
   }
 
   /// Reads the COO tensor from the file, stores the coordinates and values to
   /// the given buffers, returns a boolean value to indicate whether the COO
   /// elements are sorted.
-  /// Precondition: the buffers sho

[Lldb-commits] [lldb] [mlir][sparse] introduce MapRef, unify conversion/codegen for reader (PR #68360)

2023-10-06 Thread Aart Bik via lldb-commits

https://github.com/aartbik closed 
https://github.com/llvm/llvm-project/pull/68360
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] add a forwarding insertion to SparseTensorStorage (PR #68939)

2023-10-12 Thread Aart Bik via lldb-commits

https://github.com/aartbik closed 
https://github.com/llvm/llvm-project/pull/68939
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [mlir][sparse] remove unused sparse tensor iterator (PR #68951)

2023-10-12 Thread Aart Bik via lldb-commits

https://github.com/aartbik created 
https://github.com/llvm/llvm-project/pull/68951

None

>From 64011a22c3e9b97515e34139d0fbb03e0b1fe330 Mon Sep 17 00:00:00 2001
From: Aart Bik 
Date: Thu, 12 Oct 2023 21:24:05 -0700
Subject: [PATCH] [mlir][sparse] remove unused sparse tensor iterator

---
 .../mlir/Dialect/SparseTensor/IR/Enums.h  |   3 -
 .../ExecutionEngine/SparseTensorRuntime.h |  22 +---
 .../ExecutionEngine/SparseTensorRuntime.cpp   | 109 +-
 3 files changed, 7 insertions(+), 127 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h 
b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
index f1643d66c26a195..1434c649acd29b4 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
@@ -146,11 +146,8 @@ enum class Action : uint32_t {
   kEmptyForward = 1,
   kFromCOO = 2,
   kSparseToSparse = 3,
-  kFuture = 4, // not used
   kToCOO = 5,
-  kToIterator = 6,
   kPack = 7,
-  // Sort an unordered COO in place.
   kSortCOOInPlace = 8,
 };
 
diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h 
b/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h
index f9312c866f36317..e8dd50d6730c784 100644
--- a/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h
+++ b/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h
@@ -39,9 +39,9 @@ extern "C" {
 
 /// This is the "swiss army knife" method for materializing sparse
 /// tensors into the computation.  The types of the `ptr` argument and
-/// the result depend on the action, as explained in the following table
-/// (where "STS" means a sparse-tensor-storage object, "COO" means
-/// a coordinate-scheme object, and "Iterator" means an iterator object).
+/// the result depend on the action, as explained in the following table,
+/// where "STS" means a sparse-tensor-storage object and "COO" means
+/// a coordinate-scheme object.
 ///
 /// Action: `ptr`:  Returns:
 /// kEmpty  -   STS, empty
@@ -49,8 +49,8 @@ extern "C" {
 /// kFromCOOCOO STS, copied from the COO source
 /// kSparseToSparse STS STS, copied from the STS source
 /// kToCOO  STS COO, copied from the STS source
-/// kToIterator STS Iterator 
(@getNext/@delSparseTensorIterator)
 /// kPack   buffers STS, from level buffers
+/// kSortCOOInPlace STS STS, sorted in place
 MLIR_CRUNNERUTILS_EXPORT void *_mlir_ciface_newSparseTensor( // NOLINT
 StridedMemRefType *dimSizesRef,
 StridedMemRefType *lvlSizesRef,
@@ -90,14 +90,6 @@ MLIR_SPARSETENSOR_FOREVERY_O(DECL_SPARSECOORDINATES)
   MLIR_SPARSETENSOR_FOREVERY_V(DECL_FORWARDINGINSERT)
 #undef DECL_FORWARDINGINSERT
 
-/// Coordinate-scheme method for getting the next element while iterating.
-#define DECL_GETNEXT(VNAME, V) 
\
-  MLIR_CRUNNERUTILS_EXPORT bool _mlir_ciface_getNext##VNAME(   
\
-  void *iter, StridedMemRefType *cref,  
\
-  StridedMemRefType *vref);
-MLIR_SPARSETENSOR_FOREVERY_V(DECL_GETNEXT)
-#undef DECL_GETNEXT
-
 /// Tensor-storage method to insert elements in lexicographical
 /// level-coordinate order.
 #define DECL_LEXINSERT(VNAME, V)   
\
@@ -201,12 +193,6 @@ MLIR_CRUNNERUTILS_EXPORT void delSparseTensor(void 
*tensor);
 MLIR_SPARSETENSOR_FOREVERY_V(DECL_DELCOO)
 #undef DECL_DELCOO
 
-/// Releases the memory for an iterator object.
-#define DECL_DELITER(VNAME, V) 
\
-  MLIR_CRUNNERUTILS_EXPORT void delSparseTensorIterator##VNAME(void *iter);
-MLIR_SPARSETENSOR_FOREVERY_V(DECL_DELITER)
-#undef DECL_DELITER
-
 /// Helper function to read a sparse tensor filename from the environment,
 /// defined with the naming convention ${TENSOR0}, ${TENSOR1}, etc.
 MLIR_CRUNNERUTILS_EXPORT char *getTensorFilename(index_type id);
diff --git a/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp 
b/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
index cd1b663578a48ce..ae33a869497a01c 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
@@ -63,71 +63,18 @@ using namespace mlir::sparse_tensor;
 
 
//===--===//
 //
-// Implementation details for public functions, which don't have a good
-// place to live in the C++ library this file is wrapping.
+// Utilities for manipulating `StridedMemRefType`.
 //
 
//===--===//
 
 namespace {
 
-/// Wrapper class to avoid memory leakage issues.  The `SparseTensorCOO`
-/// class provides a standard C++ iterator interface, where the iterator
-/// is implemented as per `std::vector`'s iterator.  However, for MLIR's
-/// usage we need to have an iterator which also holds onto the underlying