diff --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp --- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp @@ -171,7 +171,7 @@ class SparseTensorStorageBase { public: /// Dimension size query. - virtual uint64_t getDimSize(uint64_t) = 0; + virtual uint64_t getDimSize(uint64_t) const = 0; /// Overhead storage. virtual void getPointers(std::vector **, uint64_t) { fatal("p64"); } @@ -225,7 +225,7 @@ virtual ~SparseTensorStorageBase() = default; private: - void fatal(const char *tp) { + static void fatal(const char *tp) { fprintf(stderr, "unsupported %s\n", tp); exit(1); } @@ -293,8 +293,8 @@ /// Get the rank of the tensor. uint64_t getRank() const { return sizes.size(); } - /// Get the size in the given dimension of the tensor. - uint64_t getDimSize(uint64_t d) override { + /// Get the size of the given dimension of the tensor. + uint64_t getDimSize(uint64_t d) const override { assert(d < getRank()); return sizes[d]; } @@ -549,7 +549,7 @@ } /// Finds the lexicographic differing dimension. - uint64_t lexDiff(const uint64_t *cursor) { + uint64_t lexDiff(const uint64_t *cursor) const { for (uint64_t r = 0, rank = getRank(); r < rank; r++) if (cursor[r] > idx[r]) return r; @@ -566,7 +566,7 @@ } private: - std::vector sizes; // per-dimension sizes + const std::vector sizes; // per-dimension sizes std::vector rev; // "reverse" permutation std::vector idx; // index cursor std::vector> pointers; @@ -718,7 +718,7 @@ /// Writes the sparse tensor to extended FROSTT format. template -void outSparseTensor(void *tensor, void *dest, bool sort) { +static void outSparseTensor(void *tensor, void *dest, bool sort) { assert(tensor && dest); auto coo = static_cast *>(tensor); if (sort) @@ -749,7 +749,7 @@ /// Initializes sparse tensor from an external COO-flavored format. template -SparseTensorStorage * +static SparseTensorStorage * toMLIRSparseTensor(uint64_t rank, uint64_t nse, uint64_t *shape, V *values, uint64_t *indices, uint64_t *perm, uint8_t *sparse) { const DimLevelType *sparsity = (DimLevelType *)(sparse); @@ -791,8 +791,9 @@ /// Converts a sparse tensor to an external COO-flavored format. template -void fromMLIRSparseTensor(void *tensor, uint64_t *pRank, uint64_t *pNse, - uint64_t **pShape, V **pValues, uint64_t **pIndices) { +static void fromMLIRSparseTensor(void *tensor, uint64_t *pRank, uint64_t *pNse, + uint64_t **pShape, V **pValues, + uint64_t **pIndices) { auto sparseTensor = static_cast *>(tensor); uint64_t rank = sparseTensor->getRank();