[Core] port PR-22525 and PR-22804 (#22554)
### Details: - Port: https://github.com/openvinotoolkit/openvino/pull/22525 - Port: https://github.com/openvinotoolkit/openvino/pull/22804 ### Tickets: - CVS-131048 --------- Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com>
This commit is contained in:
parent
376428b59a
commit
6758735364
|
|
@ -50,8 +50,9 @@ public:
|
|||
* 1. (default) Use XML configuration file in case of dynamic libraries build;
|
||||
* 2. Use strictly defined configuration in case of static libraries build.
|
||||
*
|
||||
* @param xml_config_file Path to the .xml file with plugins to load from. If the XML configuration file is not
|
||||
* specified, default OpenVINO Runtime plugins are loaded from:
|
||||
* @param xml_config_file Path to the .xml file with plugins to load from. If path contains only file name
|
||||
* with extension, file will be searched in a folder with OpenVINO runtime shared library.
|
||||
* If the XML configuration file is not specified, default OpenVINO Runtime plugins are loaded from:
|
||||
* 1. (dynamic build) default `plugins.xml` file located in the same folder as OpenVINO runtime shared library;
|
||||
* 2. (static build) statically defined configuration. In this case path to the .xml file is ignored.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,26 +16,37 @@
|
|||
namespace ov {
|
||||
|
||||
std::string find_plugins_xml(const std::string& xml_file) {
|
||||
if (xml_file.empty()) {
|
||||
const auto ov_library_path = ov::util::get_ov_lib_path();
|
||||
|
||||
// plugins.xml can be found in either:
|
||||
|
||||
// 1. openvino-X.Y.Z relative to libopenvino.so folder
|
||||
std::ostringstream str;
|
||||
str << "openvino-" << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH;
|
||||
const auto sub_folder = str.str();
|
||||
|
||||
// register plugins from default openvino-<openvino version>/plugins.xml config
|
||||
auto xmlConfigFileDefault = ov::util::path_join({ov_library_path, sub_folder, "plugins.xml"});
|
||||
if (ov::util::file_exists(xmlConfigFileDefault))
|
||||
return xmlConfigFileDefault;
|
||||
|
||||
// 2. in folder with libopenvino.so
|
||||
xmlConfigFileDefault = ov::util::path_join({ov_library_path, "plugins.xml"});
|
||||
if (ov::util::file_exists(xmlConfigFileDefault))
|
||||
return xmlConfigFileDefault;
|
||||
std::string xml_file_name = xml_file;
|
||||
if (xml_file_name.empty()) {
|
||||
// Default plugin xml file name, will search in OV folder.
|
||||
xml_file_name = "plugins.xml";
|
||||
} else {
|
||||
// If file path contains file separator, return file path;
|
||||
// Otherwise search it in OV folder with no restriction on file name and extension.
|
||||
if (xml_file_name.find(util::FileTraits<char>().file_separator) != xml_file_name.npos) {
|
||||
return xml_file_name;
|
||||
}
|
||||
}
|
||||
const auto ov_library_path = ov::util::get_ov_lib_path();
|
||||
|
||||
// plugins xml can be found in either:
|
||||
// 1. openvino-X.Y.Z relative to libopenvino.so folder
|
||||
std::ostringstream str;
|
||||
str << "openvino-" << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH;
|
||||
const auto sub_folder = str.str();
|
||||
|
||||
// register plugins from default openvino-<openvino version>/plugins.xml config
|
||||
auto xmlConfigFileDefault = ov::util::path_join({ov_library_path, sub_folder, xml_file_name});
|
||||
if (ov::util::file_exists(xmlConfigFileDefault)) {
|
||||
return xmlConfigFileDefault;
|
||||
}
|
||||
|
||||
// 2. in folder with libopenvino.so
|
||||
xmlConfigFileDefault = ov::util::path_join({ov_library_path, xml_file_name});
|
||||
if (ov::util::file_exists(xmlConfigFileDefault)) {
|
||||
return xmlConfigFileDefault;
|
||||
}
|
||||
|
||||
return xml_file;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright (C) 2018-2024 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include "common_test_utils/file_utils.hpp"
|
||||
#include "file_utils.h"
|
||||
#include "openvino/runtime/core.hpp"
|
||||
#include "openvino/util/file_util.hpp"
|
||||
|
||||
#ifndef OPENVINO_STATIC_LIBRARY
|
||||
|
||||
static void create_plugin_xml(const std::string& file_name, const std::string& plugin_name = "1") {
|
||||
std::ofstream file(file_name);
|
||||
|
||||
file << "<ie><plugins><plugin location=\"";
|
||||
file << ov::test::utils::getExecutableDirectory();
|
||||
file << ov::util::FileTraits<char>::file_separator;
|
||||
file << ov::util::FileTraits<char>::library_prefix();
|
||||
file << "mock_engine";
|
||||
file << OV_BUILD_POSTFIX;
|
||||
file << ov::util::FileTraits<char>::dot_symbol;
|
||||
file << ov::util::FileTraits<char>::library_ext();
|
||||
file << "\" name=\"" << plugin_name << "\"></plugin></plugins></ie>";
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
static void remove_plugin_xml(const std::string& file_name) {
|
||||
ov::test::utils::removeFile(file_name);
|
||||
}
|
||||
|
||||
TEST(CoreBaseTest, LoadPluginXML) {
|
||||
std::string xml_file_name = "test_plugin.xml";
|
||||
std::string xml_file_path =
|
||||
InferenceEngine::getIELibraryPath() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
create_plugin_xml(xml_file_path);
|
||||
EXPECT_NO_THROW(ov::Core core(xml_file_name));
|
||||
remove_plugin_xml(xml_file_path);
|
||||
}
|
||||
|
||||
TEST(CoreBaseTest, LoadPluginDifferentXMLExtension) {
|
||||
std::string xml_file_name = "test_plugin.test";
|
||||
std::string xml_file_path =
|
||||
InferenceEngine::getIELibraryPath() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
create_plugin_xml(xml_file_path);
|
||||
EXPECT_NO_THROW(ov::Core core(xml_file_name));
|
||||
remove_plugin_xml(xml_file_path);
|
||||
}
|
||||
|
||||
TEST(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
|
||||
std::string xml_file_name = "test_plugin.xml";
|
||||
std::string xml_file_path =
|
||||
InferenceEngine::getIELibraryPath() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
create_plugin_xml(xml_file_path);
|
||||
EXPECT_NO_THROW(ov::Core core(xml_file_path));
|
||||
remove_plugin_xml(xml_file_path);
|
||||
}
|
||||
|
||||
TEST(CoreBaseTest, LoadAbsoluteCWPathPluginXML) {
|
||||
std::string xml_file_name = "test_plugin.xml";
|
||||
std::string xml_file_path =
|
||||
ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
create_plugin_xml(xml_file_path);
|
||||
EXPECT_NO_THROW(ov::Core core(xml_file_path));
|
||||
remove_plugin_xml(xml_file_path);
|
||||
}
|
||||
|
||||
TEST(CoreBaseTest, LoadRelativeCWPathPluginXML) {
|
||||
std::string xml_file_name = "test_plugin.xml";
|
||||
std::string xml_file_path =
|
||||
ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
create_plugin_xml(xml_file_path);
|
||||
EXPECT_NO_THROW(ov::Core core(xml_file_name));
|
||||
remove_plugin_xml(xml_file_path);
|
||||
}
|
||||
|
||||
TEST(CoreBaseTest, LoadOVFolderOverCWPathPluginXML) {
|
||||
std::string xml_file_name = "test_plugin.xml";
|
||||
std::string cwd_file_path =
|
||||
ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
std::string ov_file_path =
|
||||
InferenceEngine::getIELibraryPath() + ov::util::FileTraits<char>::file_separator + xml_file_name;
|
||||
create_plugin_xml(cwd_file_path);
|
||||
create_plugin_xml(ov_file_path, "2");
|
||||
ov::Core core(xml_file_name);
|
||||
auto version = core.get_versions("2");
|
||||
EXPECT_EQ(1, version.size());
|
||||
version = core.get_versions("1");
|
||||
EXPECT_EQ(0, version.size());
|
||||
remove_plugin_xml(cwd_file_path);
|
||||
remove_plugin_xml(ov_file_path);
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue