WA issues with dynamic protobuf usage in Fes (#20612)

This commit is contained in:
Ilya Lavrenov 2023-10-20 10:44:42 +04:00 committed by GitHub
parent ec2ae003aa
commit 361b250fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 25 deletions

View File

@ -20,21 +20,6 @@ class FrontEndManager::Impl {
std::mutex m_loading_mutex;
std::vector<PluginInfo> 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 <frontend_name, frontend_so_ptr>
static std::unordered_map<std::string, std::shared_ptr<void>>& get_shared_objects_map() {
static std::unordered_map<std::string, std::shared_ptr<void>> 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<FrontEnd>();
fe_obj->m_shared_object = std::make_shared<FrontEndSharedData>(plugin.get_so_pointer());
fe_obj->m_actual = plugin.get_creator().m_creator();
std::lock_guard<std::mutex> 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"}},

View File

@ -16,17 +16,32 @@
#include <sys/stat.h>
#include <openvino/util/log.hpp>
#include <string>
#include <vector>
#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 <frontend_name, frontend_so_ptr>
std::unordered_map<std::string, std::shared_ptr<void>>& ov::frontend::get_shared_objects_map() {
static std::unordered_map<std::string, std::shared_ptr<void>> 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<std::mutex> guard(get_shared_objects_mutex());
get_shared_objects_map().emplace(get_creator().m_name, get_so_pointer());
return true;
}

View File

@ -4,7 +4,12 @@
#pragma once
#include <openvino/frontend/manager.hpp>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#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<std::string, std::shared_ptr<void>>& 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<void>& obj,

View File

@ -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<ov::Node>& n) {
return ov::is_type<ov::op::v0::Relu>(n);
}),
nodes.end());
ASSERT_NE(std::find_if(nodes.begin(),
nodes.end(),
[](const std::shared_ptr<ov::Node>& n) {
return ov::is_type<ov::op::v4::Swish>(n);
}),
nodes.end());
}

View File

@ -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()