[Mlir-commits] [mlir] 33e8ab8 - [mlir][sparse] support pattern-only matrices from Matrix Market
Aart Bik
llvmlistbot at llvm.org
Tue Apr 26 15:50:28 PDT 2022
Author: Aart Bik
Date: 2022-04-26T15:50:21-07:00
New Revision: 33e8ab8ea089229e6c31855fbccda278e43f9df1
URL: https://github.com/llvm/llvm-project/commit/33e8ab8ea089229e6c31855fbccda278e43f9df1
DIFF: https://github.com/llvm/llvm-project/commit/33e8ab8ea089229e6c31855fbccda278e43f9df1.diff
LOG: [mlir][sparse] support pattern-only matrices from Matrix Market
We simply set nonzero entries to the value "1" in this case.
Reviewed By: bixia
Differential Revision: https://reviews.llvm.org/D124475
Added:
Modified:
mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
index b4faa1955d9d9..e904bad64c370 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
@@ -639,7 +639,7 @@ static char *toLower(char *token) {
/// Read the MME header of a general sparse matrix of type real.
static void readMMEHeader(FILE *file, char *filename, char *line,
- uint64_t *idata, bool *isSymmetric) {
+ uint64_t *idata, bool *isPattern, bool *isSymmetric) {
char header[64];
char object[64];
char format[64];
@@ -651,15 +651,16 @@ static void readMMEHeader(FILE *file, char *filename, char *line,
fprintf(stderr, "Corrupt header in %s\n", filename);
exit(1);
}
+ // Set properties
+ *isPattern = (strcmp(toLower(field), "pattern") == 0);
*isSymmetric = (strcmp(toLower(symmetry), "symmetric") == 0);
// Make sure this is a general sparse matrix.
if (strcmp(toLower(header), "%%matrixmarket") ||
strcmp(toLower(object), "matrix") ||
- strcmp(toLower(format), "coordinate") || strcmp(toLower(field), "real") ||
+ strcmp(toLower(format), "coordinate") ||
+ (strcmp(toLower(field), "real") && !(*isPattern)) ||
(strcmp(toLower(symmetry), "general") && !(*isSymmetric))) {
- fprintf(stderr,
- "Cannot find a general sparse matrix with type real in %s\n",
- filename);
+ fprintf(stderr, "Cannot find a general sparse matrix in %s\n", filename);
exit(1);
}
// Skip comments.
@@ -726,9 +727,10 @@ static SparseTensorCOO<V> *openSparseTensorCOO(char *filename, uint64_t rank,
// Perform some file format dependent set up.
char line[kColWidth];
uint64_t idata[512];
+ bool isPattern = false;
bool isSymmetric = false;
if (strstr(filename, ".mtx")) {
- readMMEHeader(file, filename, line, idata, &isSymmetric);
+ readMMEHeader(file, filename, line, idata, &isPattern, &isSymmetric);
} else if (strstr(filename, ".tns")) {
readExtFROSTTHeader(file, filename, line, idata);
} else {
@@ -759,7 +761,8 @@ static SparseTensorCOO<V> *openSparseTensorCOO(char *filename, uint64_t rank,
}
// The external formats always store the numerical values with the type
// double, but we cast these values to the sparse tensor object type.
- double value = strtod(linePtr, &linePtr);
+ // For a pattern tensor, we arbitrarily pick the value 1 for all entries.
+ double value = isPattern ? 1.0 : strtod(linePtr, &linePtr);
tensor->add(indices, value);
// We currently chose to deal with symmetric matrices by fully constructing
// them. In the future, we may want to make symmetry implicit for storage
More information about the Mlir-commits
mailing list