Add property to configure internal name under the proxy plugin (#18727)

This commit is contained in:
Ilya Churaev
2023-07-25 09:22:02 +04:00
committed by GitHub
parent 99557e3356
commit 29ca4b99c5
5 changed files with 48 additions and 8 deletions

View File

@@ -50,7 +50,13 @@ ov::ICore::~ICore() = default;
namespace {
#ifdef PROXY_PLUGIN_ENABLED
static constexpr const char* internal_plugin_suffix = "_ov_internal";
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 = 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
template <typename F>
@@ -362,7 +368,7 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
auto fallback = it->second.as<std::string>();
// Change fallback name if fallback is configured to the HW plugin under the proxy with the same name
if (alias == fallback)
fallback += internal_plugin_suffix;
fallback = get_internal_plugin_name(fallback, config);
if (defaultConfig.find(ov::device::priorities.name()) == defaultConfig.end()) {
defaultConfig[ov::device::priorities.name()] = std::vector<std::string>{dev_name, fallback};
} else {
@@ -396,7 +402,7 @@ 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 += internal_plugin_suffix;
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
@@ -416,7 +422,7 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
}
} 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 += internal_plugin_suffix;
dev_name = get_internal_plugin_name(dev_name, config);
PluginDescriptor desc = PluginDescriptor(ov::proxy::create_plugin);
fill_config(desc.defaultConfig, config, dev_name);
pluginRegistry[device_name] = desc;
@@ -425,6 +431,7 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
const static std::vector<ov::PropertyName> proxy_conf_properties = {ov::proxy::configuration::alias,
ov::proxy::configuration::fallback,
ov::proxy::configuration::internal_name,
ov::proxy::configuration::priority};
// Register real plugin
@@ -883,9 +890,6 @@ ov::SupportedOpsMap ov::CoreImpl::query_model(const std::shared_ptr<const ov::Mo
bool ov::CoreImpl::is_hidden_device(const std::string& device_name) const {
#ifdef PROXY_PLUGIN_ENABLED
std::lock_guard<std::mutex> lock(get_mutex());
if (device_name.find(internal_plugin_suffix) != std::string::npos)
return true;
// Alias hides the device
for (auto&& it : pluginRegistry) {
auto it_priority = it.second.defaultConfig.find(ov::proxy::alias_for.name());

View File

@@ -47,7 +47,7 @@ add_subdirectory(src/graph)
file(GLOB_RECURSE PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/intel_gpu/plugin/*.hpp)
if(ENABLE_PROXY)
set(PLUGIN_DEFAULT_CONFIG "PROXY_CONFIGURATION_ALIAS:GPU;PROXY_CONFIGURATION_PRIORITY:0")
set(PLUGIN_DEFAULT_CONFIG "PROXY_CONFIGURATION_ALIAS:GPU;PROXY_CONFIGURATION_PRIORITY:0;PROXY_CONFIGURATION_INTERNAL_NAME:OCL_GPU")
endif()
ov_add_plugin(NAME ${TARGET_NAME}

View File

@@ -34,6 +34,7 @@ Proxy plugin cannot be created explicitly. In order to use proxy plugin under th
- `ov::proxy::configuration::alias` is an alias name for high level plugin.
- `ov::proxy::configuration::priority` is a device priority under alias (lower value means the higher priority), this value allows to configure the device order.
- `ov::proxy::configuration::fallback` the name of other hardware device for the fallback.
- `ov::proxy::configuration::internal_name` the name which will be used as internal name in case if real device name has a collision with proxy name.
After the creation the proxy plugin has next properties:
- `ov::device::priorities` is fallback order inside the proxy plugin.

View File

@@ -35,6 +35,13 @@ static constexpr Property<int32_t, PropertyMutability::RW> priority{"PROXY_CONFI
*/
static constexpr Property<std::string, PropertyMutability::RW> fallback{"PROXY_CONFIGURATION_FALLBACK"};
/**
* @brief Read-write property to set internal name if proxy hides plugin under the plugin name.
* value type: string the internal name for hardware plugin
* @ingroup ov_runtime_cpp_prop_api
*/
static constexpr Property<std::string, PropertyMutability::RW> internal_name{"PROXY_CONFIGURATION_INTERNAL_NAME"};
} // namespace configuration
/**

View File

@@ -35,6 +35,34 @@ TEST_F(ProxyTests, alias_for_the_same_name) {
EXPECT_TRUE(mock_reference_dev.empty());
}
TEST_F(ProxyTests, alias_for_the_same_name_with_custom_internal_name) {
register_plugin_support_reshape(core,
"CBD",
{{ov::proxy::configuration::alias.name(), "CBD"},
{ov::proxy::configuration::fallback.name(), "DEK"},
{ov::proxy::configuration::internal_name.name(), "CBD_INTERNAL"},
{ov::proxy::configuration::priority.name(), 0}});
register_plugin_support_subtract(core, "DEK", {{ov::proxy::configuration::alias.name(), "CBD"}});
auto available_devices = core.get_available_devices();
// 0, 1, 2 is ABC plugin
// 1, 3, 4 is BDE plugin
// ABC doesn't support subtract operation
std::unordered_map<std::string, std::string> mock_reference_dev = {{"CBD.0", "CBD_INTERNAL"},
{"CBD.1", "CBD_INTERNAL DEK"},
{"CBD.2", "CBD_INTERNAL"}};
for (const auto& it : mock_reference_dev) {
EXPECT_EQ(core.get_property(it.first, ov::device::priorities), it.second);
}
for (const auto& dev : available_devices) {
auto it = mock_reference_dev.find(dev);
if (it != mock_reference_dev.end()) {
mock_reference_dev.erase(it);
}
}
// All devices should be found
EXPECT_TRUE(mock_reference_dev.empty());
}
TEST_F(ProxyTests, fallback_to_alias_name) {
register_plugin_support_reshape(
core,