From 361b250fc433e9c1d1488b0201560e6031845be2 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 20 Oct 2023 10:44:42 +0400 Subject: [PATCH] WA issues with dynamic protobuf usage in Fes (#20612) --- src/frontends/common/src/manager.cpp | 20 +------------ src/frontends/common/src/plugin_loader.cpp | 21 +++++++++++++- src/frontends/common/src/plugin_loader.hpp | 10 ++++++- .../frontend/shared/src/library_extension.cpp | 28 +++++++++++++++++++ thirdparty/dependencies.cmake | 8 +++--- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/frontends/common/src/manager.cpp b/src/frontends/common/src/manager.cpp index 35df484c2ca..6194fca7583 100644 --- a/src/frontends/common/src/manager.cpp +++ b/src/frontends/common/src/manager.cpp @@ -20,21 +20,6 @@ class FrontEndManager::Impl { std::mutex m_loading_mutex; std::vector m_plugins; - // Note, static methods below are required to create an order of initialization of static variables - // e.g. if users (not encouraged) created ov::Model globally, we need to ensure proper order of initialization - - /// \return map of shared object per frontend - static std::unordered_map>& get_shared_objects_map() { - static std::unordered_map> shared_objects_map; - return shared_objects_map; - } - - /// \return Mutex to guard access the shared object map - static std::mutex& get_shared_objects_mutex() { - static std::mutex shared_objects_map_mutex; - return shared_objects_map_mutex; - } - public: Impl() { search_all_plugins(); @@ -46,10 +31,6 @@ public: auto fe_obj = std::make_shared(); fe_obj->m_shared_object = std::make_shared(plugin.get_so_pointer()); fe_obj->m_actual = plugin.get_creator().m_creator(); - - std::lock_guard guard(get_shared_objects_mutex()); - get_shared_objects_map().emplace(plugin.get_creator().m_name, fe_obj->m_shared_object); - return fe_obj; } @@ -164,6 +145,7 @@ private: {".xml", {"ir", "ir"}}, {".onnx", {"onnx", "onnx"}}, {".pb", {"tf", "tensorflow"}}, + {".pbtxt", {"tf", "tensorflow"}}, {".tflite", {"tflite", "tensorflow_lite"}}, {".pdmodel", {"paddle", "paddle"}}, // {".ts", {"pytorch", "pytorch"}}, diff --git a/src/frontends/common/src/plugin_loader.cpp b/src/frontends/common/src/plugin_loader.cpp index a044152d8d5..a98eff766bb 100644 --- a/src/frontends/common/src/plugin_loader.cpp +++ b/src/frontends/common/src/plugin_loader.cpp @@ -16,17 +16,32 @@ #include -#include #include #include #include "openvino/util/file_util.hpp" +#include "openvino/util/log.hpp" #include "openvino/util/shared_object.hpp" #include "plugin_loader.hpp" using namespace ov; using namespace ov::frontend; +// Note, static methods below are required to create an order of initialization of static variables +// e.g. if users (not encouraged) created ov::Model globally, we need to ensure proper order of initialization + +/// \return map of shared object per frontend +std::unordered_map>& ov::frontend::get_shared_objects_map() { + static std::unordered_map> shared_objects_map; + return shared_objects_map; +} + +/// \return Mutex to guard access the shared object map +std::mutex& ov::frontend::get_shared_objects_mutex() { + static std::mutex shared_objects_map_mutex; + return shared_objects_map_mutex; +} + #ifdef OPENVINO_STATIC_LIBRARY # include "ov_frontends.hpp" @@ -131,6 +146,10 @@ bool PluginInfo::load() { m_load_failed = true; return false; } + + std::lock_guard guard(get_shared_objects_mutex()); + get_shared_objects_map().emplace(get_creator().m_name, get_so_pointer()); + return true; } diff --git a/src/frontends/common/src/plugin_loader.hpp b/src/frontends/common/src/plugin_loader.hpp index 93e6a5cc2eb..dccf8ddf7a3 100644 --- a/src/frontends/common/src/plugin_loader.hpp +++ b/src/frontends/common/src/plugin_loader.hpp @@ -4,7 +4,12 @@ #pragma once -#include +#include +#include +#include +#include + +#include "openvino/frontend/manager.hpp" #ifdef _WIN32 static const char PathSeparator[] = ";"; @@ -15,6 +20,9 @@ static const char PathSeparator[] = ":"; namespace ov { namespace frontend { +std::unordered_map>& get_shared_objects_map(); +std::mutex& get_shared_objects_mutex(); + /// \brief Internal data structure holding by each frontend. Includes library handle and extensions. class FrontEndSharedData { friend inline void add_extension_to_shared_data(std::shared_ptr& obj, diff --git a/src/frontends/tests/frontend/shared/src/library_extension.cpp b/src/frontends/tests/frontend/shared/src/library_extension.cpp index a2257f8fca1..8a6bb23d82f 100644 --- a/src/frontends/tests/frontend/shared/src/library_extension.cpp +++ b/src/frontends/tests/frontend/shared/src/library_extension.cpp @@ -9,6 +9,7 @@ #include "common_test_utils/file_utils.hpp" #include "openvino/op/relu.hpp" #include "openvino/op/swish.hpp" +#include "openvino/runtime/core.hpp" #include "utils.hpp" using namespace ov::frontend; @@ -88,3 +89,30 @@ TEST_P(FrontendLibraryExtensionTest, verifyFunctions) { nodes.end()); } } + +TEST_P(FrontendLibraryExtensionTest, loadExtensionBeforeFrontend) { + // release all frontends internally + ov::shutdown(); + + const auto& lib_path = get_lib_path("test_builtin_extensions"); + + ov::Core core; + core.add_extension(lib_path); + + auto model = core.read_model(m_param.m_modelName); + ASSERT_NE(nullptr, model); + + const auto nodes = model->get_ops(); + ASSERT_EQ(std::find_if(nodes.begin(), + nodes.end(), + [](const std::shared_ptr& n) { + return ov::is_type(n); + }), + nodes.end()); + ASSERT_NE(std::find_if(nodes.begin(), + nodes.end(), + [](const std::shared_ptr& n) { + return ov::is_type(n); + }), + nodes.end()); +} diff --git a/thirdparty/dependencies.cmake b/thirdparty/dependencies.cmake index fac4752c318..4eed13c9a79 100644 --- a/thirdparty/dependencies.cmake +++ b/thirdparty/dependencies.cmake @@ -414,14 +414,14 @@ if(ENABLE_OV_PADDLE_FRONTEND OR ENABLE_OV_ONNX_FRONTEND OR ENABLE_OV_TF_FRONTEND if(CMAKE_VERBOSE_MAKEFILE) set(Protobuf_DEBUG ON) endif() - if(OV_VCPKG_BUILD) - set(protobuf_config CONFIG) - endif() # try to find newer version first (major is changed) # see https://protobuf.dev/support/version-support/ and # https://github.com/protocolbuffers/protobuf/commit/d61f75ff6db36b4f9c0765f131f8edc2f86310fa - find_package(Protobuf 4.22.0 QUIET ${protobuf_config}) + find_package(Protobuf 4.22.0 QUIET CONFIG) if(NOT Protobuf_FOUND) + if(OV_VCPKG_BUILD) + set(protobuf_config CONFIG) + endif() # otherwise, fallback to existing default find_package(Protobuf 3.20.3 REQUIRED ${protobuf_config}) endif()