From 8c29e0a4d0fc1fe4e4f44e98bb61965ee835eaa1 Mon Sep 17 00:00:00 2001 From: urays Date: Thu, 9 Jul 2026 22:34:20 +0800 Subject: [PATCH] fix: parse integer MTX files and fix tensor buffer ownership Accept MatrixMarket integer fields alongside real fields, transfer unpacked tensor index/value buffers to Array ownership, and avoid leaking copied fill values. --- src/index_notation/kernel.cpp | 6 +++--- src/lower/lowerer_impl_imperative.cpp | 2 +- src/storage/file_io_mtx.cpp | 2 +- src/taco_tensor_t.cpp | 15 +++++---------- src/tensor.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/index_notation/kernel.cpp b/src/index_notation/kernel.cpp index f01bb5bbd..5da34afab 100644 --- a/src/index_notation/kernel.cpp +++ b/src/index_notation/kernel.cpp @@ -66,9 +66,9 @@ void unpackResults(size_t numResults, const vector arguments, } else if (modeType.getName() == Sparse.getName()) { auto size = ((int*)tensorData->indices[i][0])[num]; Array pos = Array(type(), tensorData->indices[i][0], - num+1, Array::UserOwns); + num+1, Array::Free); Array idx = Array(type(), tensorData->indices[i][1], - size, Array::UserOwns); + size, Array::Free); modeIndices.push_back(ModeIndex({pos, idx})); num = size; } else { @@ -76,7 +76,7 @@ void unpackResults(size_t numResults, const vector arguments, } } storage.setIndex(Index(format, modeIndices)); - storage.setValues(Array(storage.getComponentType(), tensorData->vals, num)); + storage.setValues(Array(storage.getComponentType(), tensorData->vals, num, Array::Free)); } } diff --git a/src/lower/lowerer_impl_imperative.cpp b/src/lower/lowerer_impl_imperative.cpp index 3c8814f24..c1f614463 100644 --- a/src/lower/lowerer_impl_imperative.cpp +++ b/src/lower/lowerer_impl_imperative.cpp @@ -1932,7 +1932,7 @@ std::vector LowererImplImperative::constructInnerLoopCasePreamble(ir:: for(size_t i = 0; i < coordComparisons.size(); ++i) { Expr nonZeroCase; if(coordComparisons[i].defined() && valueComparisons[i].defined()) { - nonZeroCase = taco::ir::conjunction({coordComparisons[i], valueComparisons[i]}); + nonZeroCase = conjunction({coordComparisons[i], valueComparisons[i]}); } else if (valueComparisons[i].defined()) { nonZeroCase = valueComparisons[i]; } else if (coordComparisons[i].defined()) { diff --git a/src/storage/file_io_mtx.cpp b/src/storage/file_io_mtx.cpp index 33bd85258..77faa824b 100644 --- a/src/storage/file_io_mtx.cpp +++ b/src/storage/file_io_mtx.cpp @@ -51,7 +51,7 @@ TensorBase dispatchReadMTX(std::istream& stream, const T& format, bool pack) { << "Unknown type of MatrixMarket"; // formats = [coordinate array] // field = [real integer complex pattern] - taco_uassert(field=="real") << "MatrixMarket field not available"; + taco_uassert(field=="real" || field=="integer") << "MatrixMarket field not available"; // symmetry = [general symmetric skew-symmetric Hermitian] taco_uassert((symmetry=="general") || (symmetry=="symmetric")) << "MatrixMarket symmetry not available"; diff --git a/src/taco_tensor_t.cpp b/src/taco_tensor_t.cpp index 2337be2a9..e0cba59f3 100644 --- a/src/taco_tensor_t.cpp +++ b/src/taco_tensor_t.cpp @@ -40,15 +40,7 @@ taco_tensor_t* init_taco_tensor_t(int32_t order, int32_t csize, t->indices = (uint8_t ***) alloc_mem(order * sizeof(uint8_t***)); t->csize = csize; - int fill_bytes = csize / 8; - t->fill_value = (uint8_t*) alloc_mem(fill_bytes); - - if (fill_ptr) { - uint8_t* fill_inp = (uint8_t*) fill_ptr; - for (int i = 0; i < fill_bytes; ++i) { - t->fill_value[i] = fill_inp[i]; - } - } + t->fill_value = (uint8_t*) fill_ptr; for (int32_t i = 0; i < order; i++) { t->dimensions[i] = dimensions[i]; @@ -61,6 +53,9 @@ taco_tensor_t* init_taco_tensor_t(int32_t order, int32_t csize, case taco_mode_sparse: t->indices[i] = (uint8_t **) alloc_mem(2 * sizeof(uint8_t **)); break; + case taco_mode_dia1: + t->indices[i] = (uint8_t **) alloc_mem(3 * sizeof(uint8_t **)); + break; } } return t; @@ -76,4 +71,4 @@ void deinit_taco_tensor_t(taco_tensor_t* t) { free_mem(t->mode_ordering); free_mem(t->mode_types); free_mem(t); -} \ No newline at end of file +} diff --git a/src/tensor.cpp b/src/tensor.cpp index 257c396c3..36348c3e8 100644 --- a/src/tensor.cpp +++ b/src/tensor.cpp @@ -275,19 +275,19 @@ static size_t unpackTensorData(const taco_tensor_t& tensorData, numVals *= ((int*)tensorData.indices[i][0])[0]; } else if (modeType.getName() == Sparse.getName()) { auto size = ((int*)tensorData.indices[i][0])[numVals]; - Array pos = Array(type(), tensorData.indices[i][0], numVals+1, Array::UserOwns); - Array idx = Array(type(), tensorData.indices[i][1], size, Array::UserOwns); + Array pos = Array(type(), tensorData.indices[i][0], numVals+1, Array::Free); + Array idx = Array(type(), tensorData.indices[i][1], size, Array::Free); modeIndices.push_back(ModeIndex({pos, idx})); numVals = size; } else if (modeType.getName() == Singleton.getName()) { - Array idx = Array(type(), tensorData.indices[i][1], numVals, Array::UserOwns); + Array idx = Array(type(), tensorData.indices[i][1], numVals, Array::Free); modeIndices.push_back(ModeIndex({makeArray(type(), 0), idx})); } else { taco_not_supported_yet; } } storage.setIndex(Index(format, modeIndices)); - storage.setValues(Array(tensor.getComponentType(), tensorData.vals, numVals)); + storage.setValues(Array(tensor.getComponentType(), tensorData.vals, numVals, Array::Free)); return numVals; }