[Mlir-commits] [mlir] 92bc3fb - [mlir][sparse] move SparseTensorReader functions into the _mlir_ciface_ section
wren romano
llvmlistbot at llvm.org
Mon Nov 14 13:50:36 PST 2022
Author: wren romano
Date: 2022-11-14T13:50:29-08:00
New Revision: 92bc3fb5b1f2ed1bd65acbac5334854a17b70d33
URL: https://github.com/llvm/llvm-project/commit/92bc3fb5b1f2ed1bd65acbac5334854a17b70d33
DIFF: https://github.com/llvm/llvm-project/commit/92bc3fb5b1f2ed1bd65acbac5334854a17b70d33.diff
LOG: [mlir][sparse] move SparseTensorReader functions into the _mlir_ciface_ section
Depends On D137735
Reviewed By: aartbik
Differential Revision: https://reviews.llvm.org/D137737
Added:
Modified:
mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
Removed:
################################################################################
diff --git a/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp b/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
index 1e9a363d1091..43506391a27d 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
@@ -564,6 +564,63 @@ MLIR_SPARSETENSOR_FOREVERY_V(IMPL_LEXINSERT)
MLIR_SPARSETENSOR_FOREVERY_V(IMPL_EXPINSERT)
#undef IMPL_EXPINSERT
+void _mlir_ciface_getSparseTensorReaderDimSizes(
+ void *p, StridedMemRefType<index_type, 1> *dref) {
+ assert(p);
+ ASSERT_NO_STRIDE(dref);
+ index_type *dimSizes = MEMREF_GET_PAYLOAD(dref);
+ SparseTensorReader &file = *static_cast<SparseTensorReader *>(p);
+ const index_type *sizes = file.getDimSizes();
+ index_type rank = file.getRank();
+ for (uint64_t r = 0; r < rank; ++r)
+ dimSizes[r] = sizes[r];
+}
+
+#define IMPL_GETNEXT(VNAME, V) \
+ void _mlir_ciface_getSparseTensorReaderNext##VNAME( \
+ void *p, StridedMemRefType<index_type, 1> *iref, \
+ StridedMemRefType<V, 0> *vref) { \
+ assert(p &&vref); \
+ ASSERT_NO_STRIDE(iref); \
+ index_type *indices = MEMREF_GET_PAYLOAD(iref); \
+ SparseTensorReader *stfile = static_cast<SparseTensorReader *>(p); \
+ index_type rank = stfile->getRank(); \
+ V *value = MEMREF_GET_PAYLOAD(vref); \
+ *value = stfile->readCOOElement<V>(rank, indices); \
+ }
+MLIR_SPARSETENSOR_FOREVERY_V(IMPL_GETNEXT)
+#undef IMPL_GETNEXT
+
+void _mlir_ciface_outSparseTensorWriterMetaData(
+ void *p, index_type rank, index_type nnz,
+ StridedMemRefType<index_type, 1> *dref) {
+ assert(p);
+ ASSERT_NO_STRIDE(dref);
+ assert(rank != 0);
+ index_type *dimSizes = MEMREF_GET_PAYLOAD(dref);
+ SparseTensorWriter &file = *static_cast<SparseTensorWriter *>(p);
+ file << rank << " " << nnz << std::endl;
+ for (index_type r = 0; r < rank - 1; ++r)
+ file << dimSizes[r] << " ";
+ file << dimSizes[rank - 1] << std::endl;
+}
+
+#define IMPL_OUTNEXT(VNAME, V) \
+ void _mlir_ciface_outSparseTensorWriterNext##VNAME( \
+ void *p, index_type rank, StridedMemRefType<index_type, 1> *iref, \
+ StridedMemRefType<V, 0> *vref) { \
+ assert(p &&vref); \
+ ASSERT_NO_STRIDE(iref); \
+ index_type *indices = MEMREF_GET_PAYLOAD(iref); \
+ SparseTensorWriter &file = *static_cast<SparseTensorWriter *>(p); \
+ for (uint64_t r = 0; r < rank; ++r) \
+ file << (indices[r] + 1) << " "; \
+ V *value = MEMREF_GET_PAYLOAD(vref); \
+ file << *value << std::endl; \
+ }
+MLIR_SPARSETENSOR_FOREVERY_V(IMPL_OUTNEXT)
+#undef IMPL_OUTNEXT
+
//===----------------------------------------------------------------------===//
//
// Public functions which accept only C-style data structures to interact
@@ -674,37 +731,10 @@ index_type getSparseTensorReaderDimSize(void *p, index_type d) {
return static_cast<SparseTensorReader *>(p)->getDimSize(d);
}
-void _mlir_ciface_getSparseTensorReaderDimSizes(
- void *p, StridedMemRefType<index_type, 1> *dref) {
- assert(p);
- ASSERT_NO_STRIDE(dref);
- index_type *dimSizes = MEMREF_GET_PAYLOAD(dref);
- SparseTensorReader &file = *static_cast<SparseTensorReader *>(p);
- const index_type *sizes = file.getDimSizes();
- index_type rank = file.getRank();
- for (uint64_t r = 0; r < rank; ++r)
- dimSizes[r] = sizes[r];
-}
-
void delSparseTensorReader(void *p) {
delete static_cast<SparseTensorReader *>(p);
}
-#define IMPL_GETNEXT(VNAME, V) \
- void _mlir_ciface_getSparseTensorReaderNext##VNAME( \
- void *p, StridedMemRefType<index_type, 1> *iref, \
- StridedMemRefType<V, 0> *vref) { \
- assert(p &&vref); \
- ASSERT_NO_STRIDE(iref); \
- index_type *indices = MEMREF_GET_PAYLOAD(iref); \
- SparseTensorReader *stfile = static_cast<SparseTensorReader *>(p); \
- index_type rank = stfile->getRank(); \
- V *value = MEMREF_GET_PAYLOAD(vref); \
- *value = stfile->readCOOElement<V>(rank, indices); \
- }
-MLIR_SPARSETENSOR_FOREVERY_V(IMPL_GETNEXT)
-#undef IMPL_GETNEXT
-
void *createSparseTensorWriter(char *filename) {
SparseTensorWriter *file =
(filename[0] == 0) ? &std::cout : new std::ofstream(filename);
@@ -720,36 +750,6 @@ void delSparseTensorWriter(void *p) {
delete file;
}
-void _mlir_ciface_outSparseTensorWriterMetaData(
- void *p, index_type rank, index_type nnz,
- StridedMemRefType<index_type, 1> *dref) {
- assert(p);
- ASSERT_NO_STRIDE(dref);
- assert(rank != 0);
- index_type *dimSizes = MEMREF_GET_PAYLOAD(dref);
- SparseTensorWriter &file = *static_cast<SparseTensorWriter *>(p);
- file << rank << " " << nnz << std::endl;
- for (index_type r = 0; r < rank - 1; ++r)
- file << dimSizes[r] << " ";
- file << dimSizes[rank - 1] << std::endl;
-}
-
-#define IMPL_OUTNEXT(VNAME, V) \
- void _mlir_ciface_outSparseTensorWriterNext##VNAME( \
- void *p, index_type rank, StridedMemRefType<index_type, 1> *iref, \
- StridedMemRefType<V, 0> *vref) { \
- assert(p &&vref); \
- ASSERT_NO_STRIDE(iref); \
- index_type *indices = MEMREF_GET_PAYLOAD(iref); \
- SparseTensorWriter &file = *static_cast<SparseTensorWriter *>(p); \
- for (uint64_t r = 0; r < rank; ++r) \
- file << (indices[r] + 1) << " "; \
- V *value = MEMREF_GET_PAYLOAD(vref); \
- file << *value << std::endl; \
- }
-MLIR_SPARSETENSOR_FOREVERY_V(IMPL_OUTNEXT)
-#undef IMPL_OUTNEXT
-
} // extern "C"
#undef MEMREF_GET_PAYLOAD
More information about the Mlir-commits
mailing list