Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bindings/python/src/pyopenvino/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void regclass_Core(py::module m) {
)");

cls.def("register_plugins",
&ov::Core::register_plugins,
static_cast<void (ov::Core::*)(const std::string&)>(&ov::Core::register_plugins),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also consider how path is represented in Python API. In many places it's Union[str, bytes, pathlib.Path]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can still be like that just mapped as default to use fs::path on C++ side, but it should be recommended to use Path type

py::arg("xml_config_file"),
R"(
Registers a device plugin to OpenVINO Runtime Core instance using XML configuration
Expand Down
22 changes: 20 additions & 2 deletions src/inference/include/openvino/runtime/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class OPENVINO_RUNTIME_API Core {
*/
explicit Core(const std::string& xml_config_file = {});

/** @brief Constructs an OpenVINO Core instance with devices and their plugins description. */
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
explicit Core(const Path& xml_config_file) : Core(xml_config_file.string()) {}

/**
* @brief Returns device plugins version information.
* Device name can be complex and identify multiple devices at once like `HETERO:CPU,GPU`;
Expand Down Expand Up @@ -833,13 +837,19 @@ class OPENVINO_RUNTIME_API Core {
* - If `plugin` specifies file name (`libplugin_name.so`) or plugin name (`plugin_name`), it will be searched by
* file name (`libplugin_name.so`) in CWD or in paths pointed by PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
* environment variables depending on the platform.
* @note For security purposes it suggested to specify absolute path to register plugin.
* @note For security, use an absolute path to register plugin.
*
* @param device_name Device name to register a plugin for.
* @param config Plugin configuration options
*/
void register_plugin(const std::string& plugin, const std::string& device_name, const ov::AnyMap& config = {});

/** @brief Register a new device and plugin that enables this device inside OpenVINO Runtime. */
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void register_plugin(const Path& plugin_path, const std::string& device_name, const AnyMap& config = {}) {
register_plugin(plugin_path.string(), device_name, config);
}

/**
* @brief Unloads the previously loaded plugin identified by @p device_name from OpenVINO Runtime.
* The method is needed to remove loaded plugin instance and free its resources. If plugin for a
Expand Down Expand Up @@ -875,12 +885,20 @@ class OPENVINO_RUNTIME_API Core {
* for different systems with different configurations.
* - `properties` are set to a plugin via the ov::Core::set_property method.
* - `extensions` are set to a plugin via the ov::Core::add_extension method.
* @note For security purposes it suggested to specify absolute path to register plugin.
* @note For security, use an absolute path to register plugin.
*
* @param xml_config_file A path to .xml file with plugins to register.
*/
void register_plugins(const std::string& xml_config_file);

/** @brief Registers a device plugin to the OpenVINO Runtime Core instance using an XML configuration file with
* plugins description.
*/
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void register_plugins(const Path& xml_config_file) {
register_plugins(xml_config_file.string());
}

/**
* @brief Creates a new remote shared context object on the specified accelerator device
* using specified plugin-specific low-level device API parameters (device handle, pointer, context, etc.).
Expand Down
11 changes: 11 additions & 0 deletions src/inference/tests/functional/ov_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ TEST_F(CoreBaseTest, LoadPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST_F(CoreBaseTest, LoadPluginXMLWithFsPath) {
std::string xml_file_name = "test_plugin.xml";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create it as path at start and modify it?
Is better to change this test to cover some unicode case see tests

const auto xml_file_path = std::filesystem::path(ov::test::utils::getOpenvinoLibDirectory() +
ov::util::FileTraits<char>::file_separator + xml_file_name);
create_plugin_xml(xml_file_path.string(), "1");
ov::Core core(xml_file_path);
auto versions = core.get_versions("1");
EXPECT_FALSE(versions.empty());
remove_plugin_xml(xml_file_path.string());
}

TEST_F(CoreBaseTest, LoadPluginDifferentXMLExtension) {
std::string xml_file_name = "test_plugin.test";
std::string xml_file_path =
Expand Down
18 changes: 18 additions & 0 deletions src/inference/tests/functional/ov_register_plugin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@ TEST(RegisterPluginTests, registerNewPluginNoThrows) {
core.unload_plugin(mock_plugin_name);
}

TEST(RegisterPluginTests, registerNewPluginWithFsPathNoThrows) {
ov::Core core;
auto plugin = std::make_shared<ov::test::utils::MockPlugin>();
std::shared_ptr<ov::IPlugin> base_plugin = plugin;
std::shared_ptr<void> m_so;
mockPlugin(core, base_plugin, m_so);

std::string mock_plugin_name{"MOCK_HARDWARE_FS"};
std::filesystem::path plugin_path =
ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IS path version called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How as inputs are strings?

std::string("mock_engine") + OV_BUILD_POSTFIX);

OV_ASSERT_NO_THROW(core.register_plugin(plugin_path, mock_plugin_name));
OV_ASSERT_NO_THROW(core.get_property(mock_plugin_name, ov::supported_properties));

core.unload_plugin(mock_plugin_name);
}

TEST(RegisterPluginTests, registerExistingPluginThrows) {
ov::Core core;
auto plugin = std::make_shared<ov::test::utils::MockPlugin>();
Expand Down
Loading