From 274267647349e8f8f129e91dd066071b04f309fb Mon Sep 17 00:00:00 2001 From: wangchuanxia Date: Mon, 14 Oct 2024 19:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=95=E4=BE=8B=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E4=B8=AA=E5=AE=9E=E4=BE=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchuanxia --- .../neural_network_core/backend_manager.cpp | 18 ++++++++++++++++++ .../neural_network_core/backend_manager.h | 17 +---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/frameworks/native/neural_network_core/backend_manager.cpp b/frameworks/native/neural_network_core/backend_manager.cpp index c0b543d..699df8d 100644 --- a/frameworks/native/neural_network_core/backend_manager.cpp +++ b/frameworks/native/neural_network_core/backend_manager.cpp @@ -28,6 +28,24 @@ BackendManager::~BackendManager() m_backendIDGroup.clear(); } +BackendManager& BackendManager::GetInstance() +{ + // if libneural_network_runtime.so loaded + if (dlopen("libneural_network_runtime.so", RTLD_NOLOAD) != nullptr) { + // if libneural_network_runtime_ext.so not loaded, try to dlopen it + if (dlopen("libneural_network_runtime_ext.so", RTLD_NOLOAD) == nullptr) { + LOGI("dlopen libneural_network_runtime_ext.so."); + void* libHandle = dlopen("libneural_network_runtime_ext.so", RTLD_NOW | RTLD_GLOBAL); + if (libHandle == nullptr) { + LOGW("Failed to dlopen libneural_network_runtime_ext.so."); + } + } + } + + static BackendManager instance; + return instance; +} + const std::vector& BackendManager::GetAllBackendsID() { const std::lock_guard lock(m_mtx); diff --git a/frameworks/native/neural_network_core/backend_manager.h b/frameworks/native/neural_network_core/backend_manager.h index 118502c..954fab5 100644 --- a/frameworks/native/neural_network_core/backend_manager.h +++ b/frameworks/native/neural_network_core/backend_manager.h @@ -41,22 +41,7 @@ public: const std::string& backendName, std::function()> creator); void RemoveBackend(const std::string& backendName); - static BackendManager& GetInstance() - { - // if libneural_network_runtime.so loaded - if (dlopen("libneural_network_runtime.so", RTLD_NOLOAD) != nullptr) { - // if libneural_network_runtime_ext.so not loaded, try to dlopen it - if (dlopen("libneural_network_runtime_ext.so", RTLD_NOLOAD) == nullptr) { - LOGI("dlopen libneural_network_runtime_ext.so."); - void* libHandle = dlopen("libneural_network_runtime_ext.so", RTLD_NOW | RTLD_GLOBAL); - if (libHandle == nullptr) { - LOGW("Failed to dlopen libneural_network_runtime_ext.so."); - } - } - } - static BackendManager instance; - return instance; - } + static BackendManager& GetInstance(); private: BackendManager() = default; -- Gitee