From 219c55f2e5f2f25affd9399612212153ad5bc8f8 Mon Sep 17 00:00:00 2001 From: wang-yangsong Date: Wed, 29 May 2024 10:30:01 +0800 Subject: [PATCH 1/2] crush fix Signed-off-by: wang-yangsong --- .../hdi_prepared_model_v2_1.cpp | 12 ++++++++++++ .../neural_network_runtime/hdi_prepared_model_v2_1.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.cpp b/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.cpp index e876df8..4f5b25b 100644 --- a/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.cpp +++ b/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.cpp @@ -166,6 +166,17 @@ HDIPreparedModelV2_1::HDIPreparedModelV2_1(OHOS::sptr hdiP hdiPreparedModel->GetVersion(m_hdiVersion.first, m_hdiVersion.second); } +HDIPreparedModelV2_1::~HDIPreparedModelV2_1() +{ + for (auto addr : m_addrs) { + auto memManager = MemoryManager::GetInstance(); + OH_NN_ReturnCode ret = memManager->UnMapMemory(addr); + if (ret != OH_NN_SUCCESS) { + LOGE("~HDIPreparedModelV2_1 UnMapMemory failed"); + } + } +} + OH_NN_ReturnCode HDIPreparedModelV2_1::ExportModelCache(std::vector& modelCache) { if (!modelCache.empty()) { @@ -187,6 +198,7 @@ OH_NN_ReturnCode HDIPreparedModelV2_1::ExportModelCache(std::vector& mod LOGE("Export the %{public}zuth model cache failed, cannot not map fd to address.", i + 1); return OH_NN_MEMORY_ERROR; } + m_addrs.emplace_back(addr); Buffer modelbuffer {addr, iBuffers[i].bufferSize}; modelCache.emplace_back(modelbuffer); } diff --git a/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.h b/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.h index 889956a..4fd74b7 100644 --- a/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.h +++ b/frameworks/native/neural_network_runtime/hdi_prepared_model_v2_1.h @@ -34,6 +34,7 @@ namespace NeuralNetworkRuntime { class HDIPreparedModelV2_1 : public PreparedModel { public: explicit HDIPreparedModelV2_1(OHOS::sptr hdiPreparedModel); + ~HDIPreparedModelV2_1() override; OH_NN_ReturnCode ExportModelCache(std::vector& modelCache) override; @@ -54,6 +55,7 @@ private: // first: major version, second: minor version std::pair m_hdiVersion; OHOS::sptr m_hdiPreparedModel {nullptr}; + std::vector m_addrs; }; } // namespace NeuralNetworkRuntime } // OHOS -- Gitee From 30e6b2124c1c42b5bd5f5550a24f0e4f029ff51e Mon Sep 17 00:00:00 2001 From: wang-yangsong Date: Thu, 30 May 2024 15:25:57 +0800 Subject: [PATCH 2/2] bugfix Signed-off-by: wang-yangsong --- frameworks/native/neural_network_runtime/hdi_device_v2_1.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/neural_network_runtime/hdi_device_v2_1.cpp b/frameworks/native/neural_network_runtime/hdi_device_v2_1.cpp index 9b9f0f6..0d80246 100644 --- a/frameworks/native/neural_network_runtime/hdi_device_v2_1.cpp +++ b/frameworks/native/neural_network_runtime/hdi_device_v2_1.cpp @@ -389,6 +389,7 @@ void* HDIDeviceV2_1::AllocateBuffer(size_t length) auto addr = memManager->MapMemory(buffer.fd, length); if (addr == nullptr) { LOGE("Map fd to address failed."); + m_iDevice->ReleaseBuffer(buffer); } return addr; } -- Gitee