From 6670e6b0bbff52641723c710f1c7d9eb516afa72 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 15 Jan 2020 15:54:18 +0300 Subject: [PATCH] dnn: prevent unloading of InferenceEngine plugins --- modules/dnn/src/op_inf_engine.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp index c4e3f08..a5319e1 100644 --- a/modules/dnn/src/op_inf_engine.cpp +++ b/modules/dnn/src/op_inf_engine.cpp @@ -563,11 +563,45 @@ static std::map& getShar return sharedPlugins; } #else -InferenceEngine::Core& getCore() +static bool init_IE_plugins() +{ + // load and hold IE plugins + static InferenceEngine::Core* init_core = new InferenceEngine::Core(); // 'delete' is never called + (void)init_core->GetAvailableDevices(); + return true; +} +static InferenceEngine::Core& create_IE_Core_instance() { static InferenceEngine::Core core; return core; } +static InferenceEngine::Core& create_IE_Core_pointer() +{ + // load and hold IE plugins + static InferenceEngine::Core* core = new InferenceEngine::Core(); // 'delete' is never called + return *core; +} +InferenceEngine::Core& getCore() +{ + // to make happy memory leak tools use: + // - OPENCV_DNN_INFERENCE_ENGINE_HOLD_PLUGINS=0 + // - OPENCV_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND=0 + static bool param_DNN_INFERENCE_ENGINE_HOLD_PLUGINS = utils::getConfigurationParameterBool("OPENCV_DNN_INFERENCE_ENGINE_HOLD_PLUGINS", true); + static bool init_IE_plugins_ = param_DNN_INFERENCE_ENGINE_HOLD_PLUGINS && init_IE_plugins(); CV_UNUSED(init_IE_plugins_); + + static bool param_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND = + utils::getConfigurationParameterBool("OPENCV_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND", +#ifdef _WIN32 + true +#else + false +#endif + ); + static InferenceEngine::Core& core = param_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND + ? create_IE_Core_pointer() + : create_IE_Core_instance(); + return core; +} #endif #if !defined(OPENCV_DNN_IE_VPU_TYPE_DEFAULT) -- 2.7.4