Skip to content

Commit f8ce460

Browse files
authored
[mlir][sparse] cleanup sparse runtime library (#82807)
remove some obsoleted APIs from the library that have been fully replaced with actual direct IR codegen
1 parent a24421f commit f8ce460

File tree

5 files changed

+12
-121
lines changed

5 files changed

+12
-121
lines changed

mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,9 @@ constexpr bool isComplexPrimaryType(PrimaryType valTy) {
145145
/// The actions performed by @newSparseTensor.
146146
enum class Action : uint32_t {
147147
kEmpty = 0,
148-
kEmptyForward = 1,
149-
kFromCOO = 2,
150-
kFromReader = 4,
151-
kToCOO = 5,
152-
kPack = 7,
153-
kSortCOOInPlace = 8,
148+
kFromReader = 1,
149+
kPack = 2,
150+
kSortCOOInPlace = 3,
154151
};
155152

156153
/// This enum defines all supported storage format without the level properties.

mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,6 @@ class SparseTensorStorageBase {
149149
MLIR_SPARSETENSOR_FOREVERY_V(DECL_GETVALUES)
150150
#undef DECL_GETVALUES
151151

152-
/// Element-wise forwarding insertions. The first argument is the
153-
/// dimension-coordinates for the value being inserted.
154-
#define DECL_FORWARDINGINSERT(VNAME, V) \
155-
virtual void forwardingInsert(const uint64_t *, V);
156-
MLIR_SPARSETENSOR_FOREVERY_V(DECL_FORWARDINGINSERT)
157-
#undef DECL_FORWARDINGINSERT
158-
159152
/// Element-wise insertion in lexicographic coordinate order. The first
160153
/// argument is the level-coordinates for the value being inserted.
161154
#define DECL_LEXINSERT(VNAME, V) virtual void lexInsert(const uint64_t *, V);
@@ -171,9 +164,6 @@ class SparseTensorStorageBase {
171164
MLIR_SPARSETENSOR_FOREVERY_V(DECL_EXPINSERT)
172165
#undef DECL_EXPINSERT
173166

174-
/// Finalizes forwarding insertions.
175-
virtual void endForwardingInsert() = 0;
176-
177167
/// Finalizes lexicographic insertions.
178168
virtual void endLexInsert() = 0;
179169

@@ -248,7 +238,7 @@ class SparseTensorStorage final : public SparseTensorStorageBase {
248238
static SparseTensorStorage<P, C, V> *
249239
newEmpty(uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank,
250240
const uint64_t *lvlSizes, const LevelType *lvlTypes,
251-
const uint64_t *dim2lvl, const uint64_t *lvl2dim, bool forwarding);
241+
const uint64_t *dim2lvl, const uint64_t *lvl2dim);
252242

253243
/// Allocates a new sparse tensor and initializes it from the given COO.
254244
static SparseTensorStorage<P, C, V> *
@@ -284,13 +274,6 @@ class SparseTensorStorage final : public SparseTensorStorageBase {
284274
*out = &values;
285275
}
286276

287-
/// Partially specialize forwarding insertions based on template types.
288-
void forwardingInsert(const uint64_t *dimCoords, V val) final {
289-
assert(dimCoords && coo);
290-
map.pushforward(dimCoords, lvlCursor.data());
291-
coo->add(lvlCursor, val);
292-
}
293-
294277
/// Partially specialize lexicographical insertions based on template types.
295278
void lexInsert(const uint64_t *lvlCoords, V val) final {
296279
assert(lvlCoords);
@@ -345,21 +328,6 @@ class SparseTensorStorage final : public SparseTensorStorageBase {
345328
}
346329
}
347330

348-
/// Finalizes forwarding insertions.
349-
void endForwardingInsert() final {
350-
// Ensure COO is sorted.
351-
assert(coo);
352-
coo->sort();
353-
// Now actually insert the `elements`.
354-
const auto &elements = coo->getElements();
355-
const uint64_t nse = elements.size();
356-
assert(values.size() == 0);
357-
values.reserve(nse);
358-
fromCOO(elements, 0, nse, 0);
359-
delete coo;
360-
coo = nullptr;
361-
}
362-
363331
/// Finalizes lexicographic insertions.
364332
void endLexInsert() final {
365333
if (!allDense) {
@@ -653,13 +621,10 @@ template <typename P, typename C, typename V>
653621
SparseTensorStorage<P, C, V> *SparseTensorStorage<P, C, V>::newEmpty(
654622
uint64_t dimRank, const uint64_t *dimSizes, uint64_t lvlRank,
655623
const uint64_t *lvlSizes, const LevelType *lvlTypes,
656-
const uint64_t *dim2lvl, const uint64_t *lvl2dim, bool forwarding) {
657-
SparseTensorCOO<V> *lvlCOO = nullptr;
658-
if (forwarding)
659-
lvlCOO = new SparseTensorCOO<V>(lvlRank, lvlSizes);
624+
const uint64_t *dim2lvl, const uint64_t *lvl2dim) {
660625
return new SparseTensorStorage<P, C, V>(dimRank, dimSizes, lvlRank, lvlSizes,
661-
lvlTypes, dim2lvl, lvl2dim, lvlCOO,
662-
!forwarding);
626+
lvlTypes, dim2lvl, lvl2dim, nullptr,
627+
true);
663628
}
664629

665630
template <typename P, typename C, typename V>

mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@ extern "C" {
3838
/// This is the "swiss army knife" method for materializing sparse
3939
/// tensors into the computation. The types of the `ptr` argument and
4040
/// the result depend on the action, as explained in the following table,
41-
/// where "STS" means a sparse-tensor-storage object and "COO" means
42-
/// a coordinate-scheme object.
41+
/// where "STS" means a sparse-tensor-storage object.
4342
///
4443
/// Action: `ptr`: Returns:
44+
/// ---------------------------------------------------------------------------
4545
/// kEmpty - STS, empty
46-
/// kEmptyForward - STS, empty, with forwarding COO
47-
/// kFromCOO COO STS, copied from the COO source
4846
/// kFromReader reader STS, input from reader
49-
/// kToCOO STS COO, copied from the STS source
5047
/// kPack buffers STS, from level buffers
5148
/// kSortCOOInPlace STS STS, sorted in place
5249
MLIR_CRUNNERUTILS_EXPORT void *_mlir_ciface_newSparseTensor( // NOLINT
@@ -80,14 +77,6 @@ MLIR_SPARSETENSOR_FOREVERY_O(DECL_SPARSEPOSITIONS)
8077
MLIR_SPARSETENSOR_FOREVERY_O(DECL_SPARSECOORDINATES)
8178
#undef DECL_SPARSECOORDINATES
8279

83-
/// Tensor-storage method for a dim to lvl forwarding insertion.
84-
#define DECL_FORWARDINGINSERT(VNAME, V) \
85-
MLIR_CRUNNERUTILS_EXPORT void _mlir_ciface_forwardingInsert##VNAME( \
86-
void *tensor, StridedMemRefType<V, 0> *vref, \
87-
StridedMemRefType<index_type, 1> *dimCoordsRef); \
88-
MLIR_SPARSETENSOR_FOREVERY_V(DECL_FORWARDINGINSERT)
89-
#undef DECL_FORWARDINGINSERT
90-
9180
/// Tensor-storage method to insert elements in lexicographical
9281
/// level-coordinate order.
9382
#define DECL_LEXINSERT(VNAME, V) \
@@ -160,21 +149,12 @@ MLIR_CRUNNERUTILS_EXPORT index_type sparseLvlSize(void *tensor, index_type l);
160149
/// Tensor-storage method to get the size of the given dimension.
161150
MLIR_CRUNNERUTILS_EXPORT index_type sparseDimSize(void *tensor, index_type d);
162151

163-
/// Tensor-storage method to finalize forwarding insertions.
164-
MLIR_CRUNNERUTILS_EXPORT void endForwardingInsert(void *tensor);
165-
166152
/// Tensor-storage method to finalize lexicographic insertions.
167153
MLIR_CRUNNERUTILS_EXPORT void endLexInsert(void *tensor);
168154

169155
/// Releases the memory for the tensor-storage object.
170156
MLIR_CRUNNERUTILS_EXPORT void delSparseTensor(void *tensor);
171157

172-
/// Releases the memory for the coordinate-scheme object.
173-
#define DECL_DELCOO(VNAME, V) \
174-
MLIR_CRUNNERUTILS_EXPORT void delSparseTensorCOO##VNAME(void *coo);
175-
MLIR_SPARSETENSOR_FOREVERY_V(DECL_DELCOO)
176-
#undef DECL_DELCOO
177-
178158
/// Helper function to read a sparse tensor filename from the environment,
179159
/// defined with the naming convention ${TENSOR0}, ${TENSOR1}, etc.
180160
MLIR_CRUNNERUTILS_EXPORT char *getTensorFilename(index_type id);

mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ MLIR_SPARSETENSOR_FOREVERY_FIXED_O(IMPL_GETCOORDINATES)
7474
MLIR_SPARSETENSOR_FOREVERY_V(IMPL_GETVALUES)
7575
#undef IMPL_GETVALUES
7676

77-
#define IMPL_FORWARDINGINSERT(VNAME, V) \
78-
void SparseTensorStorageBase::forwardingInsert(const uint64_t *, V) { \
79-
FATAL_PIV("forwardingInsert" #VNAME); \
80-
}
81-
MLIR_SPARSETENSOR_FOREVERY_V(IMPL_FORWARDINGINSERT)
82-
#undef IMPL_FORWARDINGINSERT
83-
8477
#define IMPL_LEXINSERT(VNAME, V) \
8578
void SparseTensorStorageBase::lexInsert(const uint64_t *, V) { \
8679
FATAL_PIV("lexInsert" #VNAME); \

mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -117,32 +117,14 @@ extern "C" {
117117
switch (action) { \
118118
case Action::kEmpty: { \
119119
return SparseTensorStorage<P, C, V>::newEmpty( \
120-
dimRank, dimSizes, lvlRank, lvlSizes, lvlTypes, dim2lvl, lvl2dim, \
121-
false); \
122-
} \
123-
case Action::kEmptyForward: { \
124-
return SparseTensorStorage<P, C, V>::newEmpty( \
125-
dimRank, dimSizes, lvlRank, lvlSizes, lvlTypes, dim2lvl, lvl2dim, \
126-
true); \
127-
} \
128-
case Action::kFromCOO: { \
129-
assert(ptr && "Received nullptr for SparseTensorCOO object"); \
130-
auto &coo = *static_cast<SparseTensorCOO<V> *>(ptr); \
131-
return SparseTensorStorage<P, C, V>::newFromCOO( \
132-
dimRank, dimSizes, lvlRank, lvlSizes, lvlTypes, dim2lvl, lvl2dim, \
133-
coo); \
120+
dimRank, dimSizes, lvlRank, lvlSizes, lvlTypes, dim2lvl, lvl2dim); \
134121
} \
135122
case Action::kFromReader: { \
136123
assert(ptr && "Received nullptr for SparseTensorReader object"); \
137124
SparseTensorReader &reader = *static_cast<SparseTensorReader *>(ptr); \
138125
return static_cast<void *>(reader.readSparseTensor<P, C, V>( \
139126
lvlRank, lvlSizes, lvlTypes, dim2lvl, lvl2dim)); \
140127
} \
141-
case Action::kToCOO: { \
142-
assert(ptr && "Received nullptr for SparseTensorStorage object"); \
143-
auto &tensor = *static_cast<SparseTensorStorage<P, C, V> *>(ptr); \
144-
return tensor.toCOO(); \
145-
} \
146128
case Action::kPack: { \
147129
assert(ptr && "Received nullptr for SparseTensorStorage object"); \
148130
intptr_t *buffers = static_cast<intptr_t *>(ptr); \
@@ -341,21 +323,6 @@ MLIR_SPARSETENSOR_FOREVERY_O(IMPL_SPARSECOORDINATES)
341323
#undef IMPL_SPARSECOORDINATES
342324
#undef IMPL_GETOVERHEAD
343325

344-
#define IMPL_FORWARDINGINSERT(VNAME, V) \
345-
void _mlir_ciface_forwardingInsert##VNAME( \
346-
void *t, StridedMemRefType<V, 0> *vref, \
347-
StridedMemRefType<index_type, 1> *dimCoordsRef) { \
348-
assert(t &&vref); \
349-
ASSERT_NO_STRIDE(dimCoordsRef); \
350-
const index_type *dimCoords = MEMREF_GET_PAYLOAD(dimCoordsRef); \
351-
assert(dimCoords); \
352-
const V *value = MEMREF_GET_PAYLOAD(vref); \
353-
static_cast<SparseTensorStorageBase *>(t)->forwardingInsert(dimCoords, \
354-
*value); \
355-
}
356-
MLIR_SPARSETENSOR_FOREVERY_V(IMPL_FORWARDINGINSERT)
357-
#undef IMPL_FORWARDINGINSERT
358-
359326
#define IMPL_LEXINSERT(VNAME, V) \
360327
void _mlir_ciface_lexInsert##VNAME( \
361328
void *t, StridedMemRefType<index_type, 1> *lvlCoordsRef, \
@@ -427,8 +394,8 @@ void _mlir_ciface_getSparseTensorReaderDimSizes(
427394
const uint64_t cSize = MEMREF_GET_USIZE(cref); \
428395
const uint64_t vSize = MEMREF_GET_USIZE(vref); \
429396
ASSERT_USIZE_EQ(lvl2dimRef, dimRank); \
430-
assert(cSize >= lvlRank * vSize); \
431-
assert(vSize >= reader.getNSE() && "Not enough space in buffers"); \
397+
assert(cSize >= lvlRank * reader.getNSE()); \
398+
assert(vSize >= reader.getNSE()); \
432399
(void)dimRank; \
433400
(void)cSize; \
434401
(void)vSize; \
@@ -488,10 +455,6 @@ index_type sparseDimSize(void *tensor, index_type d) {
488455
return static_cast<SparseTensorStorageBase *>(tensor)->getDimSize(d);
489456
}
490457

491-
void endForwardingInsert(void *tensor) {
492-
return static_cast<SparseTensorStorageBase *>(tensor)->endForwardingInsert();
493-
}
494-
495458
void endLexInsert(void *tensor) {
496459
return static_cast<SparseTensorStorageBase *>(tensor)->endLexInsert();
497460
}
@@ -500,13 +463,6 @@ void delSparseTensor(void *tensor) {
500463
delete static_cast<SparseTensorStorageBase *>(tensor);
501464
}
502465

503-
#define IMPL_DELCOO(VNAME, V) \
504-
void delSparseTensorCOO##VNAME(void *coo) { \
505-
delete static_cast<SparseTensorCOO<V> *>(coo); \
506-
}
507-
MLIR_SPARSETENSOR_FOREVERY_V(IMPL_DELCOO)
508-
#undef IMPL_DELCOO
509-
510466
char *getTensorFilename(index_type id) {
511467
constexpr size_t bufSize = 80;
512468
char var[bufSize];

0 commit comments

Comments
 (0)