Removed core member remapped devices and use proxy config instead (#18791)

This commit is contained in:
Ilya Churaev 2023-07-26 12:20:43 +04:00 committed by GitHub
parent 3228522b53
commit 18505b99b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 22 deletions

View File

@ -50,23 +50,12 @@ ov::ICore::~ICore() = default;
namespace {
#ifdef PROXY_PLUGIN_ENABLED
std::string get_internal_plugin_name(std::unordered_map<std::string, std::string>& remapped_devices,
const std::string& device_name,
const ov::AnyMap& properties) {
std::string get_internal_plugin_name(const std::string& device_name, const ov::AnyMap& properties) {
static constexpr const char* internal_plugin_suffix = "_ov_internal";
{
auto it = remapped_devices.find(device_name);
if (it != remapped_devices.end())
return it->second;
}
auto plugin_name = device_name + internal_plugin_suffix;
{
auto it = properties.find(ov::proxy::configuration::internal_name.name());
if (it != properties.end())
plugin_name = it->second.as<std::string>();
}
remapped_devices[device_name] = plugin_name;
return plugin_name;
auto it = properties.find(ov::proxy::configuration::internal_name.name());
if (it != properties.end())
return it->second.as<std::string>();
return device_name + internal_plugin_suffix;
}
#endif
@ -411,11 +400,15 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
// Create proxy plugin for alias
auto alias = config.at(ov::proxy::configuration::alias.name()).as<std::string>();
if (alias == device_name)
dev_name = get_internal_plugin_name(remapped_devices, dev_name, config);
dev_name = get_internal_plugin_name(dev_name, config);
// Alias can be registered by several plugins
if (pluginRegistry.find(alias) == pluginRegistry.end()) {
// Register new plugin
PluginDescriptor desc = PluginDescriptor(ov::proxy::create_plugin);
// Add internal name for proxy in order to modify fallback order before the initialization
if (alias == device_name)
desc.defaultConfig[ov::proxy::configuration::internal_name.name()] = dev_name;
fill_config(desc.defaultConfig, config, dev_name);
pluginRegistry[alias] = desc;
add_mutex(alias);
@ -427,12 +420,16 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
"Cannot register plugin for ",
dev_name,
" plugin with the same name already registered!");
// Add internal name for proxy in order to modify fallback order before the initialization
if (alias == device_name)
plugin.defaultConfig[ov::proxy::configuration::internal_name.name()] = dev_name;
fill_config(plugin.defaultConfig, config, dev_name);
}
} else if (config.find(ov::proxy::configuration::fallback.name()) != config.end()) {
// Fallback without alias means that we need to replace original plugin to proxy
dev_name = get_internal_plugin_name(remapped_devices, dev_name, config);
dev_name = get_internal_plugin_name(dev_name, config);
PluginDescriptor desc = PluginDescriptor(ov::proxy::create_plugin);
desc.defaultConfig[ov::proxy::configuration::internal_name.name()] = dev_name;
fill_config(desc.defaultConfig, config, dev_name);
pluginRegistry[device_name] = desc;
add_mutex(device_name);
@ -629,13 +626,14 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const {
if (it != desc.defaultConfig.end()) {
// Fix fallback names in case if proxy plugin got a conflict in the process of plugins registration
auto priorities = it->second.as<std::vector<std::string>>();
auto internal_name = desc.defaultConfig.find(ov::proxy::configuration::internal_name.name());
for (auto&& priority : priorities) {
if (priority == deviceName) {
OPENVINO_ASSERT(remapped_devices.find(deviceName) != remapped_devices.end(),
OPENVINO_ASSERT(internal_name != desc.defaultConfig.end(),
"Cannot create proxy device ",
deviceName,
". Device has incorrect configuration.");
priority = remapped_devices.at(deviceName);
priority = internal_name->second.as<std::string>();
}
}
initial_config[ov::device::priorities.name()] = priorities;

View File

@ -152,8 +152,6 @@ private:
mutable std::vector<ov::Extension::Ptr> ov_extensions;
std::map<std::string, PluginDescriptor> pluginRegistry;
// Map of remapped devices which have conflict with proxy device
std::unordered_map<std::string, std::string> remapped_devices;
const bool m_new_api;

View File

@ -64,6 +64,7 @@ ov::AnyMap remove_device_properties(ov::AnyMap& config, const std::vector<std::s
ov::AnyMap remove_proxy_properties(ov::AnyMap& config, bool rem_device_properties = false) {
const static std::vector<ov::PropertyName> proxy_properties = {ov::device::id,
ov::internal::config_device_id,
ov::proxy::configuration::internal_name,
ov::device::priorities,
ov::proxy::alias_for,
ov::proxy::device_priorities};