Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
olpipi committed Jun 19, 2024
1 parent d2692b0 commit c3d58a5
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 14 deletions.
8 changes: 7 additions & 1 deletion cmake/developer_package/plugins/create_plugins_hpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ foreach(dev_map IN LISTS OV_DEVICE_MAPPING)
string(REPLACE ":" ";" dev_map "${dev_map}")
list(GET dev_map 0 mapped_dev_name)
list(GET dev_map 1 actual_dev_name)
list(LENGTH dev_map length)
if(${length} EQUAL 2)
set(shared_library_name)
else()
list(GET dev_map 2 shared_library_name)
endif()

# definitions
set(dev_config "{")
Expand Down Expand Up @@ -54,7 +60,7 @@ foreach(dev_map IN LISTS OV_DEVICE_MAPPING)
{ \"${mapped_dev_name}\", Value { ${_OV_CREATE_PLUGIN_FUNC}, ${_OV_CREATE_EXTENSION_FUNC}, ${dev_config} } },")
else()
set(OV_PLUGINS_MAP_DEFINITION "${OV_PLUGINS_MAP_DEFINITION}
{ \"${mapped_dev_name}\", Value { \"${actual_dev_name}\", ${dev_config} } },")
{ \"${mapped_dev_name}\", Value { \"${actual_dev_name}\", ${dev_config}, \"${shared_library_name}\" } },")
endif()
endforeach()

Expand Down
20 changes: 13 additions & 7 deletions cmake/developer_package/plugins/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ endif()
#
# ov_add_plugin(NAME <targetName>
# DEVICE_NAME <deviceName>
# [SHARED_LIBRARY_NAME]
# [PSEUDO_DEVICE]
# [PSEUDO_PLUGIN_FOR <actual_device>]
# [AS_EXTENSION]
Expand All @@ -38,7 +39,7 @@ endif()
#
function(ov_add_plugin)
set(options SKIP_INSTALL PSEUDO_DEVICE ADD_CLANG_FORMAT AS_EXTENSION SKIP_REGISTRATION)
set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR PSEUDO_PLUGIN_FOR)
set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR PSEUDO_PLUGIN_FOR SHARED_LIBRARY_NAME)
set(multiValueArgs DEFAULT_CONFIG SOURCES OBJECT_LIBRARIES CPPLINT_FILTERS)
cmake_parse_arguments(OV_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

Expand All @@ -50,6 +51,10 @@ function(ov_add_plugin)
message(FATAL_ERROR "Please, specify device name for ${OV_PLUGIN_NAME}")
endif()

if (NOT OV_PLUGIN_SHARED_LIBRARY_NAME)
set(OV_PLUGIN_SHARED_LIBRARY_NAME)
endif()

# create and configure target

if(NOT OV_PLUGIN_PSEUDO_PLUGIN_FOR)
Expand Down Expand Up @@ -155,7 +160,7 @@ function(ov_add_plugin)

# append plugin to the list to register

list(APPEND PLUGIN_FILES "${OV_PLUGIN_DEVICE_NAME}:${OV_PLUGIN_NAME}")
list(APPEND PLUGIN_FILES "${OV_PLUGIN_DEVICE_NAME}:${OV_PLUGIN_NAME}:${OV_PLUGIN_SHARED_LIBRARY_NAME}")
set(PLUGIN_FILES "${PLUGIN_FILES}" CACHE INTERNAL "" FORCE)
set(${OV_PLUGIN_DEVICE_NAME}_CONFIG "${OV_PLUGIN_DEFAULT_CONFIG}" CACHE INTERNAL "" FORCE)
set(${OV_PLUGIN_DEVICE_NAME}_PSEUDO_PLUGIN_FOR "${OV_PLUGIN_PSEUDO_PLUGIN_FOR}" CACHE INTERNAL "" FORCE)
Expand Down Expand Up @@ -185,7 +190,7 @@ macro(ov_register_in_plugins_xml)
foreach(name IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" name "${name}")
list(LENGTH name length)
if(NOT ${length} EQUAL 2)
if(NOT ${length} EQUAL 3)
message(FATAL_ERROR "Unexpected error, please, contact developer of this script")
endif()
list(GET name 0 device_name)
Expand All @@ -207,7 +212,7 @@ macro(ov_register_in_plugins_xml)
foreach(name IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" name "${name}")
list(LENGTH name length)
if(NOT ${length} EQUAL 2)
if(NOT ${length} EQUAL 3)
message(FATAL_ERROR "Unexpected error, please, contact developer of this script")
endif()
list(GET name 0 device_name)
Expand Down Expand Up @@ -265,7 +270,7 @@ function(ov_target_link_plugins TARGET_NAME)
foreach(name IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" name "${name}")
list(LENGTH name length)
if(NOT ${length} EQUAL 2)
if(NOT ${length} EQUAL 3)
message(FATAL_ERROR "Unexpected error, please, contact developer of this script")
endif()

Expand All @@ -289,16 +294,17 @@ function(ov_generate_plugins_hpp)
foreach(name IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" name "${name}")
list(LENGTH name length)
if(NOT ${length} EQUAL 2)
if(NOT ${length} EQUAL 3)
message(FATAL_ERROR "Unexpected error, please, contact developer of this script")
endif()

# create device mapping: pseudo device => actual device
list(GET name 0 device_name)
if(BUILD_SHARED_LIBS)
list(GET name 1 library_name)
list(GET name 2 shared_library_name)
ov_plugin_get_file_name(${library_name} library_name)
list(APPEND device_mapping "${device_name}:${library_name}")
list(APPEND device_mapping "${device_name}:${library_name}:${shared_library_name}")
else()
if(${device_name}_PSEUDO_PLUGIN_FOR)
list(APPEND device_mapping "${device_name}:${${device_name}_PSEUDO_PLUGIN_FOR}")
Expand Down
1 change: 1 addition & 0 deletions cmake/developer_package/plugins/plugins.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Value {
struct Value {
std::string m_plugin_path;
std::map<std::string, std::string> m_default_config;
std::string shared_library_name;
};

#endif
Expand Down
23 changes: 17 additions & 6 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
}
};
#endif

std::string dev_name = device_name;
#ifdef PROXY_PLUGIN_ENABLED
auto&& config = desc.defaultConfig;
Expand Down Expand Up @@ -471,14 +470,14 @@ void ov::CoreImpl::register_compile_time_plugins() {
if (pluginRegistry.find(deviceName) == pluginRegistry.end()) {
const auto& value = plugin.second;
ov::AnyMap config = any_copy(value.m_default_config);
PluginDescriptor desc{value.m_create_plugin_func, config, value.m_create_extensions_func};
PluginDescriptor desc{value.m_create_plugin_func, "", config, value.m_create_extensions_func};
register_plugin_in_registry_unsafe(deviceName, desc);
}
#else
const auto& pluginPath = ov::util::get_compiled_plugin_path(plugin.second.m_plugin_path);
if (pluginRegistry.find(deviceName) == pluginRegistry.end() && ov::util::file_exists(pluginPath)) {
ov::AnyMap config = any_copy(plugin.second.m_default_config);
PluginDescriptor desc{pluginPath, config};
PluginDescriptor desc{pluginPath, plugin.second.shared_library_name, config};
register_plugin_in_registry_unsafe(deviceName, desc);
}
#endif
Expand Down Expand Up @@ -537,12 +536,18 @@ void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_fi

// fill value in plugin registry for later lazy initialization
{
PluginDescriptor desc{pluginPath, config, listOfExtentions};
PluginDescriptor desc{pluginPath, "", config, listOfExtentions};
register_plugin_in_registry_unsafe(deviceName, desc);
}
}
}

namespace {
bool check_plugin_name(const std::string& plugin_name, const std::string& real_plugin_name) {
return !plugin_name.compare(real_plugin_name);
}
} // namespace

ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::LoadTime, "CoreImpl::get_plugin");

Expand Down Expand Up @@ -593,6 +598,12 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const {
std::shared_ptr<ov::IPlugin> plugin_impl;
reinterpret_cast<ov::CreatePluginFunc*>(ov::util::get_symbol(so, ov::create_plugin_function))(plugin_impl);
plugin = Plugin{plugin_impl, so};
if (!desc.sharedLibraryName.empty() && !check_plugin_name(desc.sharedLibraryName, plugin.get_name()))
OPENVINO_THROW("Loaded shared library with real name ",
plugin.get_name(),
"\ninstead of name ",
desc.sharedLibraryName,
"\n");
}

{
Expand Down Expand Up @@ -1179,7 +1190,7 @@ void ov::CoreImpl::register_plugin(const std::string& plugin,
OPENVINO_THROW("Device name must not contain dot '.' symbol");
}

PluginDescriptor desc{ov::util::get_plugin_path(plugin), properties};
PluginDescriptor desc{ov::util::get_plugin_path(plugin), "", properties};
register_plugin_in_registry_unsafe(device_name, desc);
}

Expand Down Expand Up @@ -1251,7 +1262,7 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& configMap, const st
if (!config.empty()) {
auto base_desc = pluginRegistry.find(clearDeviceName);
if (pluginRegistry.find(deviceName) == pluginRegistry.end() && base_desc != pluginRegistry.end()) {
PluginDescriptor desc{base_desc->second.libraryLocation, config, base_desc->second.listOfExtentions};
PluginDescriptor desc{base_desc->second.libraryLocation, base_desc->second.sharedLibraryName, config, base_desc->second.listOfExtentions};
pluginRegistry[deviceName] = desc;
}

Expand Down
5 changes: 5 additions & 0 deletions src/inference/src/dev/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore

struct PluginDescriptor {
ov::util::FilePath libraryLocation;
std::string sharedLibraryName;
ov::AnyMap defaultConfig;
std::vector<ov::util::FilePath> listOfExtentions;
CreatePluginEngineFunc* pluginCreateFunc = nullptr;
Expand All @@ -121,17 +122,21 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore
PluginDescriptor() = default;

PluginDescriptor(const ov::util::FilePath& libraryLocation,
const std::string& sharedLibraryName = "",
const ov::AnyMap& defaultConfig = {},
const std::vector<ov::util::FilePath>& listOfExtentions = {}) {
this->libraryLocation = libraryLocation;
this->sharedLibraryName = sharedLibraryName;
this->defaultConfig = defaultConfig;
this->listOfExtentions = listOfExtentions;
}

PluginDescriptor(CreatePluginEngineFunc* pluginCreateFunc,
const std::string& sharedLibraryName = "",
const ov::AnyMap& defaultConfig = {},
CreateExtensionFunc* extensionCreateFunc = nullptr) {
this->pluginCreateFunc = pluginCreateFunc;
this->sharedLibraryName = sharedLibraryName;
this->defaultConfig = defaultConfig;
this->extensionCreateFunc = extensionCreateFunc;
}
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/auto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ endif()
if(ENABLE_AUTO AND ENABLE_MULTI)
ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "MULTI"
SHARED_LIBRARY_NAME "AUTO"
PSEUDO_DEVICE
SOURCES ${SOURCES}
VERSION_DEFINES_FOR src/plugin.cpp)

ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "AUTO"
SHARED_LIBRARY_NAME "AUTO"
PSEUDO_DEVICE
PSEUDO_PLUGIN_FOR "MULTI")
elseif(ENABLE_AUTO)
ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "AUTO"
SHARED_LIBRARY_NAME "AUTO"
PSEUDO_DEVICE
SOURCES ${SOURCES}
VERSION_DEFINES_FOR src/plugin.cpp)
elseif(ENABLE_MULTI)
ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "MULTI"
SHARED_LIBRARY_NAME "AUTO"
PSEUDO_DEVICE
SOURCES ${SOURCES}
VERSION_DEFINES_FOR src/plugin.cpp)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/auto_batch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp)

ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "BATCH"
SHARED_LIBRARY_NAME "BATCH"
PSEUDO_DEVICE
SOURCES ${SOURCES} ${HEADERS}
VERSION_DEFINES_FOR src/plugin.cpp ADD_CLANG_FORMAT)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/hetero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp)

ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "HETERO"
SHARED_LIBRARY_NAME "HETERO"
PSEUDO_DEVICE
SOURCES ${SOURCES} ${HEADERS}
VERSION_DEFINES_FOR src/version.cpp
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ list(REMOVE_ITEM HEADERS ${FILES_TO_REMOVE})

ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "CPU"
SHARED_LIBRARY_NAME "CPU"
AS_EXTENSION
VERSION_DEFINES_FOR src/plugin.cpp
SOURCES ${SOURCES} ${HEADERS})
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ file(GLOB_RECURSE PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/*.cpp ${

ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "GPU"
SHARED_LIBRARY_NAME "GPU"
SOURCES ${PLUGIN_SOURCES}
DEFAULT_CONFIG ${PLUGIN_DEFAULT_CONFIG}
VERSION_DEFINES_FOR src/plugin/plugin.cpp)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(TARGET_NAME ${NPU_PLUGIN_TARGET})

ov_add_plugin(NAME ${NPU_PLUGIN_TARGET}
DEVICE_NAME ${NPU_DEVICE_NAME}
SHARED_LIBRARY_NAME "NPU"
SOURCES ${SOURCES}
VERSION_DEFINES_FOR ${NPU_PLUGIN_ENGINE_SOURCE_FILE}
)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/template/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif()
# adds a shared library with plugin
ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "TEMPLATE"
SHARED_LIBRARY_NAME "TEMPLATE"
SOURCES ${SOURCES} ${HEADERS}
${skip_plugin}
VERSION_DEFINES_FOR plugin.cpp
Expand Down

0 comments on commit c3d58a5

Please sign in to comment.