From e800c664f0e925f6acb30dfa054906e3059ce125 Mon Sep 17 00:00:00 2001 From: bixia1 Date: Mon, 13 Feb 2023 12:43:03 -0800 Subject: [PATCH] [mlir][sparse] Extend readCOOIndices to support overhead types beyond index_type. This is to prepare for implementing the C API for reading a COO tensor to the given buffers for indices and values. Reviewed By: wrengr Differential Revision: https://reviews.llvm.org/D143861 --- mlir/include/mlir/ExecutionEngine/SparseTensor/File.h | 14 +++++++++++++- mlir/lib/ExecutionEngine/SparseTensor/File.cpp | 13 ------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h index fa36b7e..ec9a05f 100644 --- a/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h +++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/File.h @@ -261,7 +261,19 @@ private: /// for the generated library. /// /// Precondition: `indices` is valid for `getRank()`. - char *readCOOIndices(uint64_t *indices); + template + char *readCOOIndices(I *indices) { + readLine(); + // Local variable for tracking the parser's position in the `line` buffer. + char *linePtr = line; + for (uint64_t dimRank = getRank(), d = 0; d < dimRank; ++d) { + // Parse the 1-based index. + uint64_t idx = strtoul(linePtr, &linePtr, 10); + // Store the 0-based index. + indices[d] = static_cast(idx - 1); + } + return linePtr; + } /// The internal implementation of `readCOO`. We template over /// `IsPattern` and `IsSymmetric` in order to perform LICM without diff --git a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp index 19fbaf2..bb227bf 100644 --- a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp @@ -53,19 +53,6 @@ void SparseTensorReader::readLine() { MLIR_SPARSETENSOR_FATAL("Cannot read next line of %s\n", filename); } -char *SparseTensorReader::readCOOIndices(uint64_t *indices) { - readLine(); - // Local variable for tracking the parser's position in the `line` buffer. - char *linePtr = line; - for (uint64_t rank = getRank(), r = 0; r < rank; ++r) { - // Parse the 1-based index. - uint64_t idx = strtoul(linePtr, &linePtr, 10); - // Store the 0-based index. - indices[r] = idx - 1; - } - return linePtr; -} - /// Reads and parses the file's header. void SparseTensorReader::readHeader() { assert(file && "Attempt to readHeader() before openFile()"); -- 2.7.4