Register new plugin extensions (#17614)

* Register new plugin extensions

* Fixed build
This commit is contained in:
Ilya Churaev 2023-05-19 13:44:11 +04:00 committed by GitHub
parent b95aa84b45
commit 4eebd3a976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -38,6 +38,7 @@
#include "openvino/util/shared_object.hpp"
#include "ov_plugins.hpp"
#include "preprocessing/preprocessing.hpp"
#include "so_extension.hpp"
#include "xml_parse_utils.h"
ov::ICore::~ICore() = default;
@ -523,6 +524,7 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const {
}
} else {
TryToRegisterLibraryAsExtensionUnsafe(desc.libraryLocation);
try_to_register_plugin_extensions(desc.libraryLocation);
}
return plugins.emplace(deviceName, plugin).first->second;
@ -1084,12 +1086,13 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& configMap, const st
});
}
}
void ov::CoreImpl::add_extension(const std::vector<ov::Extension::Ptr>& extensions) {
std::lock_guard<std::mutex> lock(get_mutex());
void ov::CoreImpl::add_extensions_unsafe(const std::vector<ov::Extension::Ptr>& extensions) const {
for (const auto& ext : extensions) {
ov_extensions.emplace_back(ext);
if (auto op_base_ext = std::dynamic_pointer_cast<ov::BaseOpExtension>(ext)) {
auto ext_obj = ext;
if (auto so_ext = std::dynamic_pointer_cast<ov::detail::SOExtension>(ext_obj))
ext_obj = so_ext->extension();
if (auto op_base_ext = std::dynamic_pointer_cast<ov::BaseOpExtension>(ext_obj)) {
for (const auto& attached_ext : op_base_ext->get_attached_extensions()) {
ov_extensions.emplace_back(attached_ext);
}
@ -1097,6 +1100,11 @@ void ov::CoreImpl::add_extension(const std::vector<ov::Extension::Ptr>& extensio
}
}
void ov::CoreImpl::add_extension(const std::vector<ov::Extension::Ptr>& extensions) {
std::lock_guard<std::mutex> lock(get_mutex());
add_extensions_unsafe(extensions);
}
const std::vector<InferenceEngine::IExtensionPtr>& ov::CoreImpl::GetExtensions() const {
return extensions;
}

View File

@ -22,6 +22,7 @@
#include "openvino/runtime/common.hpp"
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/threading/executor_manager.hpp"
#include "so_extension.hpp"
namespace ov {
@ -143,7 +144,7 @@ private:
mutable std::unordered_set<std::string> opsetNames;
// TODO: make extensions to be optional with conditional compilation
mutable std::vector<InferenceEngine::IExtensionPtr> extensions;
std::vector<ov::Extension::Ptr> ov_extensions;
mutable std::vector<ov::Extension::Ptr> ov_extensions;
std::map<std::string, PluginDescriptor> pluginRegistry;
@ -176,6 +177,17 @@ private:
ov::AnyMap create_compile_config(const ov::Plugin& plugin, const ov::AnyMap& origConfig) const;
template <typename C, typename = FileUtils::enableIfSupportedChar<C>>
void try_to_register_plugin_extensions(const std::basic_string<C>& path) const {
try {
auto plugin_extensions = ov::detail::load_extensions(path);
add_extensions_unsafe(plugin_extensions);
} catch (const std::runtime_error&) {
// in case of shared library is not opened
}
}
void add_extensions_unsafe(const std::vector<ov::Extension::Ptr>& extensions) const;
// Legacy API
void AddExtensionUnsafe(const InferenceEngine::IExtensionPtr& extension) const;
template <typename C, typename = FileUtils::enableIfSupportedChar<C>>