Skip to content

Commit 1c2456d

Browse files
authored
[mlir][sparse] remove very thin header file from sparse runtime support (#82820)
1 parent 9966008 commit 1c2456d

File tree

7 files changed

+70
-82
lines changed

7 files changed

+70
-82
lines changed

mlir/include/mlir/ExecutionEngine/SparseTensor/ErrorHandling.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

mlir/include/mlir/ExecutionEngine/SparseTensor/File.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ class SparseTensorReader final {
115115
SparseTensorReader *reader = new SparseTensorReader(filename);
116116
reader->openFile();
117117
reader->readHeader();
118-
if (!reader->canReadAs(valTp))
119-
MLIR_SPARSETENSOR_FATAL(
120-
"Tensor element type %d not compatible with values in file %s\n",
121-
static_cast<int>(valTp), filename);
118+
if (!reader->canReadAs(valTp)) {
119+
fprintf(stderr,
120+
"Tensor element type %d not compatible with values in file %s\n",
121+
static_cast<int>(valTp), filename);
122+
exit(1);
123+
}
122124
reader->assertMatchesShape(dimRank, dimShape);
123125
return reader;
124126
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "mlir/ExecutionEngine/Float16bits.h"
2121
#include "mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h"
2222
#include "mlir/ExecutionEngine/SparseTensor/COO.h"
23-
#include "mlir/ExecutionEngine/SparseTensor/ErrorHandling.h"
2423
#include "mlir/ExecutionEngine/SparseTensor/MapRef.h"
2524

2625
namespace mlir {

mlir/lib/ExecutionEngine/SparseTensor/File.cpp

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ using namespace mlir::sparse_tensor;
1919

2020
/// Opens the file for reading.
2121
void SparseTensorReader::openFile() {
22-
if (file)
23-
MLIR_SPARSETENSOR_FATAL("Already opened file %s\n", filename);
22+
if (file) {
23+
fprintf(stderr, "Already opened file %s\n", filename);
24+
exit(1);
25+
}
2426
file = fopen(filename, "r");
25-
if (!file)
26-
MLIR_SPARSETENSOR_FATAL("Cannot find file %s\n", filename);
27+
if (!file) {
28+
fprintf(stderr, "Cannot find file %s\n", filename);
29+
exit(1);
30+
}
2731
}
2832

2933
/// Closes the file.
@@ -36,19 +40,23 @@ void SparseTensorReader::closeFile() {
3640

3741
/// Attempts to read a line from the file.
3842
void SparseTensorReader::readLine() {
39-
if (!fgets(line, kColWidth, file))
40-
MLIR_SPARSETENSOR_FATAL("Cannot read next line of %s\n", filename);
43+
if (!fgets(line, kColWidth, file)) {
44+
fprintf(stderr, "Cannot read next line of %s\n", filename);
45+
exit(1);
46+
}
4147
}
4248

4349
/// Reads and parses the file's header.
4450
void SparseTensorReader::readHeader() {
4551
assert(file && "Attempt to readHeader() before openFile()");
46-
if (strstr(filename, ".mtx"))
52+
if (strstr(filename, ".mtx")) {
4753
readMMEHeader();
48-
else if (strstr(filename, ".tns"))
54+
} else if (strstr(filename, ".tns")) {
4955
readExtFROSTTHeader();
50-
else
51-
MLIR_SPARSETENSOR_FATAL("Unknown format %s\n", filename);
56+
} else {
57+
fprintf(stderr, "Unknown format %s\n", filename);
58+
exit(1);
59+
}
5260
assert(isValid() && "Failed to read the header");
5361
}
5462

@@ -57,7 +65,7 @@ void SparseTensorReader::readHeader() {
5765
void SparseTensorReader::assertMatchesShape(uint64_t rank,
5866
const uint64_t *shape) const {
5967
assert(rank == getRank() && "Rank mismatch");
60-
for (uint64_t r = 0; r < rank; ++r)
68+
for (uint64_t r = 0; r < rank; r++)
6169
assert((shape[r] == 0 || shape[r] == idata[2 + r]) &&
6270
"Dimension size mismatch");
6371
}
@@ -87,13 +95,13 @@ bool SparseTensorReader::canReadAs(PrimaryType valTy) const {
8795
// integer and floating primary-types.
8896
return isRealPrimaryType(valTy);
8997
}
90-
MLIR_SPARSETENSOR_FATAL("Unknown ValueKind: %d\n",
91-
static_cast<uint8_t>(valueKind_));
98+
fprintf(stderr, "Unknown ValueKind: %d\n", static_cast<uint8_t>(valueKind_));
99+
return false;
92100
}
93101

94102
/// Helper to convert C-style strings (i.e., '\0' terminated) to lower case.
95103
static inline void toLower(char *token) {
96-
for (char *c = token; *c; ++c)
104+
for (char *c = token; *c; c++)
97105
*c = tolower(*c);
98106
}
99107

@@ -116,33 +124,38 @@ void SparseTensorReader::readMMEHeader() {
116124
char symmetry[64];
117125
// Read header line.
118126
if (fscanf(file, "%63s %63s %63s %63s %63s\n", header, object, format, field,
119-
symmetry) != 5)
120-
MLIR_SPARSETENSOR_FATAL("Corrupt header in %s\n", filename);
127+
symmetry) != 5) {
128+
fprintf(stderr, "Corrupt header in %s\n", filename);
129+
exit(1);
130+
}
121131
// Convert all to lowercase up front (to avoid accidental redundancy).
122132
toLower(header);
123133
toLower(object);
124134
toLower(format);
125135
toLower(field);
126136
toLower(symmetry);
127137
// Process `field`, which specify pattern or the data type of the values.
128-
if (streq(field, "pattern"))
138+
if (streq(field, "pattern")) {
129139
valueKind_ = ValueKind::kPattern;
130-
else if (streq(field, "real"))
140+
} else if (streq(field, "real")) {
131141
valueKind_ = ValueKind::kReal;
132-
else if (streq(field, "integer"))
142+
} else if (streq(field, "integer")) {
133143
valueKind_ = ValueKind::kInteger;
134-
else if (streq(field, "complex"))
144+
} else if (streq(field, "complex")) {
135145
valueKind_ = ValueKind::kComplex;
136-
else
137-
MLIR_SPARSETENSOR_FATAL("Unexpected header field value in %s\n", filename);
146+
} else {
147+
fprintf(stderr, "Unexpected header field value in %s\n", filename);
148+
exit(1);
149+
}
138150
// Set properties.
139151
isSymmetric_ = streq(symmetry, "symmetric");
140152
// Make sure this is a general sparse matrix.
141153
if (strne(header, "%%matrixmarket") || strne(object, "matrix") ||
142154
strne(format, "coordinate") ||
143-
(strne(symmetry, "general") && !isSymmetric_))
144-
MLIR_SPARSETENSOR_FATAL("Cannot find a general sparse matrix in %s\n",
145-
filename);
155+
(strne(symmetry, "general") && !isSymmetric_)) {
156+
fprintf(stderr, "Cannot find a general sparse matrix in %s\n", filename);
157+
exit(1);
158+
}
146159
// Skip comments.
147160
while (true) {
148161
readLine();
@@ -152,8 +165,10 @@ void SparseTensorReader::readMMEHeader() {
152165
// Next line contains M N NNZ.
153166
idata[0] = 2; // rank
154167
if (sscanf(line, "%" PRIu64 "%" PRIu64 "%" PRIu64 "\n", idata + 2, idata + 3,
155-
idata + 1) != 3)
156-
MLIR_SPARSETENSOR_FATAL("Cannot find size in %s\n", filename);
168+
idata + 1) != 3) {
169+
fprintf(stderr, "Cannot find size in %s\n", filename);
170+
exit(1);
171+
}
157172
}
158173

159174
/// Read the "extended" FROSTT header. Although not part of the documented
@@ -168,12 +183,17 @@ void SparseTensorReader::readExtFROSTTHeader() {
168183
break;
169184
}
170185
// Next line contains RANK and NNZ.
171-
if (sscanf(line, "%" PRIu64 "%" PRIu64 "\n", idata, idata + 1) != 2)
172-
MLIR_SPARSETENSOR_FATAL("Cannot find metadata in %s\n", filename);
186+
if (sscanf(line, "%" PRIu64 "%" PRIu64 "\n", idata, idata + 1) != 2) {
187+
fprintf(stderr, "Cannot find metadata in %s\n", filename);
188+
exit(1);
189+
}
173190
// Followed by a line with the dimension sizes (one per rank).
174-
for (uint64_t r = 0; r < idata[0]; ++r)
175-
if (fscanf(file, "%" PRIu64, idata + 2 + r) != 1)
176-
MLIR_SPARSETENSOR_FATAL("Cannot find dimension size %s\n", filename);
191+
for (uint64_t r = 0; r < idata[0]; r++) {
192+
if (fscanf(file, "%" PRIu64, idata + 2 + r) != 1) {
193+
fprintf(stderr, "Cannot find dimension size %s\n", filename);
194+
exit(1);
195+
}
196+
}
177197
readLine(); // end of line
178198
// The FROSTT format does not define the data type of the nonzero elements.
179199
valueKind_ = ValueKind::kUndefined;

mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ SparseTensorStorageBase::SparseTensorStorageBase( // NOLINT
5151

5252
// Helper macro for wrong "partial method specialization" errors.
5353
#define FATAL_PIV(NAME) \
54-
MLIR_SPARSETENSOR_FATAL("<P,I,V> type mismatch for: " #NAME);
54+
fprintf(stderr, "<P,I,V> type mismatch for: " #NAME); \
55+
exit(1);
5556

5657
#define IMPL_GETPOSITIONS(PNAME, P) \
5758
void SparseTensorStorageBase::getPositions(std::vector<P> **, uint64_t) { \

mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
#include "mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h"
5454
#include "mlir/ExecutionEngine/SparseTensor/COO.h"
55-
#include "mlir/ExecutionEngine/SparseTensor/ErrorHandling.h"
5655
#include "mlir/ExecutionEngine/SparseTensor/File.h"
5756
#include "mlir/ExecutionEngine/SparseTensor/Storage.h"
5857

@@ -139,8 +138,8 @@ extern "C" {
139138
return ptr; \
140139
} \
141140
} \
142-
MLIR_SPARSETENSOR_FATAL("unknown action: %d\n", \
143-
static_cast<uint32_t>(action)); \
141+
fprintf(stderr, "unknown action %d\n", static_cast<uint32_t>(action)); \
142+
exit(1); \
144143
}
145144

146145
#define CASE_SECSAME(p, v, P, V) CASE(p, p, v, P, P, V)
@@ -283,10 +282,10 @@ void *_mlir_ciface_newSparseTensor( // NOLINT
283282
CASE_SECSAME(OverheadType::kU64, PrimaryType::kC32, uint64_t, complex32);
284283

285284
// Unsupported case (add above if needed).
286-
MLIR_SPARSETENSOR_FATAL(
287-
"unsupported combination of types: <P=%d, C=%d, V=%d>\n",
288-
static_cast<int>(posTp), static_cast<int>(crdTp),
289-
static_cast<int>(valTp));
285+
fprintf(stderr, "unsupported combination of types: <P=%d, C=%d, V=%d>\n",
286+
static_cast<int>(posTp), static_cast<int>(crdTp),
287+
static_cast<int>(valTp));
288+
exit(1);
290289
}
291290
#undef CASE
292291
#undef CASE_SECSAME
@@ -468,8 +467,10 @@ char *getTensorFilename(index_type id) {
468467
char var[bufSize];
469468
snprintf(var, bufSize, "TENSOR%" PRIu64, id);
470469
char *env = getenv(var);
471-
if (!env)
472-
MLIR_SPARSETENSOR_FATAL("Environment variable %s is not set\n", var);
470+
if (!env) {
471+
fprintf(stderr, "Environment variable %s is not set\n", var);
472+
exit(1);
473+
}
473474
return env;
474475
}
475476

utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9300,7 +9300,6 @@ cc_library(
93009300
hdrs = [
93019301
"include/mlir/ExecutionEngine/SparseTensor/ArithmeticUtils.h",
93029302
"include/mlir/ExecutionEngine/SparseTensor/COO.h",
9303-
"include/mlir/ExecutionEngine/SparseTensor/ErrorHandling.h",
93049303
"include/mlir/ExecutionEngine/SparseTensor/File.h",
93059304
"include/mlir/ExecutionEngine/SparseTensor/MapRef.h",
93069305
"include/mlir/ExecutionEngine/SparseTensor/Storage.h",

0 commit comments

Comments
 (0)