Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[core] Migrate common utils functions to std path (#33396)

Pawel Raasz497153f8893a
diff --git a/src/bindings/c/tests/test_model_repo.cpp b/src/bindings/c/tests/test_model_repo.cpp
index 524546fb779..75e0dbb38d5 100644
--- a/src/bindings/c/tests/test_model_repo.cpp
+++ b/src/bindings/c/tests/test_model_repo.cpp
@@ -37,8 +37,8 @@ std::string generate_test_xml_file() {
plugin_xml_file << " <plugins>\n";
plugin_xml_file << " <plugin location=\"";
plugin_xml_file << ov::test::utils::getExecutableDirectory();
- plugin_xml_file << ov::util::FileTraits<char>::file_separator;
- plugin_xml_file << ov::util::FileTraits<char>::library_prefix();
+ plugin_xml_file << ov::test::utils::FileTraits<char>::file_separator;
+ plugin_xml_file << ov::test::utils::FileTraits<char>::library_prefix();
plugin_xml_file << "mock_engine";
plugin_xml_file << OV_BUILD_POSTFIX;
plugin_xml_file << ov::util::library_extension().string();
diff --git a/src/bindings/js/node/tests/unit/core.test.js b/src/bindings/js/node/tests/unit/core.test.js
index ae12d0ddb33..d12274231b8 100644
--- a/src/bindings/js/node/tests/unit/core.test.js
+++ b/src/bindings/js/node/tests/unit/core.test.js
@@ -72,7 +72,7 @@ describe("ov.Core tests", () => {
it('Core.addExtension("not_exists") with non-existed library', () => {
const notExistsExt = "not_exists";
- assert.throws(() => core.addExtension(notExistsExt), /Cannot load library 'not_exists'/);
+ assert.throws(() => core.addExtension(notExistsExt), /Cannot load library "not_exists"/);
});
it("Core.queryModel() with empty parameters should throw an error", () => {
diff --git a/src/bindings/python/tests/test_runtime/test_core.py b/src/bindings/python/tests/test_runtime/test_core.py
index 77b5a05309d..fc0e994eea4 100644
--- a/src/bindings/python/tests/test_runtime/test_core.py
+++ b/src/bindings/python/tests/test_runtime/test_core.py
@@ -374,7 +374,7 @@ def test_register_plugin():
core.register_plugin(lib_name, device)
with pytest.raises(RuntimeError) as e:
core.get_versions(device)
- assert f"Cannot load library '{full_lib_name}'" in str(e.value)
+ assert f'Cannot load library "{full_lib_name}"' in str(e.value)
@pytest.mark.dynamic_library
@@ -390,7 +390,7 @@ def test_register_plugins():
with pytest.raises(RuntimeError) as e:
core.get_versions(device)
- assert f"Cannot load library '{full_lib_name}'" in str(e.value)
+ assert f'Cannot load library "{full_lib_name}"' in str(e.value)
@pytest.mark.dynamic_library
@@ -405,7 +405,7 @@ def test_core_register_plugins():
with pytest.raises(RuntimeError) as e:
core.get_versions(device)
- assert f"Cannot load library '{full_lib_name}'" in str(e.value)
+ assert f'Cannot load library "{full_lib_name}"' in str(e.value)
def test_unload_plugin(device):
diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp
index df3651cc39f..692c98d5ad9 100644
--- a/src/common/util/include/openvino/util/file_util.hpp
+++ b/src/common/util/include/openvino/util/file_util.hpp
@@ -15,70 +15,7 @@
#include "openvino/util/util.hpp"
#include "openvino/util/wstring_convert_util.hpp"
-namespace ov {
-namespace util {
-
-/// OS specific file traits
-template <class C>
-struct FileTraits;
-
-template <>
-struct FileTraits<char> {
- static constexpr const auto file_separator =
-#ifdef _WIN32
- '\\';
-#else
- '/';
-#endif
- static constexpr const auto dot_symbol = '.';
- static std::string library_ext() {
-#ifdef _WIN32
- return {"dll"};
-#else
- return {"so"};
-#endif
- }
- static std::string library_prefix() {
-#ifdef _WIN32
-# if defined(__MINGW32__) || defined(__MINGW64__)
- return {"lib"};
-# else
- return {""};
-# endif
-#else
- return {"lib"};
-#endif
- }
-};
-
-template <>
-struct FileTraits<wchar_t> {
- static constexpr const auto file_separator =
-#ifdef _WIN32
- L'\\';
-#else
- L'/';
-#endif
- static constexpr const auto dot_symbol = L'.';
- static std::wstring library_ext() {
-#ifdef _WIN32
- return {L"dll"};
-#else
- return {L"so"};
-#endif
- }
- static std::wstring library_prefix() {
-#ifdef _WIN32
-# if defined(__MINGW32__) || defined(__MINGW64__)
- return {L"lib"};
-# else
- return {L""};
-# endif
-#else
- return {L"lib"};
-#endif
- }
-};
+namespace ov::util {
inline std::filesystem::path library_prefix() {
#if defined(_WIN32) && (defined(__MINGW32__) || defined(__MINGW64__))
@@ -111,8 +48,11 @@ std::filesystem::path make_path(Source&& source) {
if constexpr (std::is_same_v<std::add_const_t<std::remove_pointer_t<std::decay_t<Source>>>, const wchar_t>) {
return {std::wstring(std::forward<Source>(source))};
} else if constexpr (std::is_same_v<std::filesystem::path::string_type, std::wstring> &&
- std::is_same_v<std::decay_t<Source>, std::string>) {
- return {ov::util::string_to_wstring(std::forward<Source>(source))};
+ std::disjunction_v<std::is_same<std::decay_t<Source>, std::string>,
+ std::is_same<std::decay_t<Source>, const char*>,
+ std::is_same<std::decay_t<Source>, char*>,
+ std::is_same<std::decay_t<Source>, std::string_view>>) {
+ return {string_to_wstring(std::forward<Source>(source))};
} else {
return {std::forward<Source>(source)};
}
@@ -136,7 +76,7 @@ const std::string& path_to_string(const Path& path) {
*/
template <class Path, typename std::enable_if_t<std::is_same_v<std::decay_t<Path>, std::wstring>>* = nullptr>
std::string path_to_string(const Path& path) {
- return ov::util::wstring_to_string(path);
+ return wstring_to_string(path);
}
#endif
@@ -148,7 +88,7 @@ std::string path_to_string(const Path& path) {
* @return A char string.
*/
inline auto path_to_string(const std::filesystem::path& path) -> decltype(path_to_string(path.native())) {
- return ov::util::path_to_string(path.native());
+ return path_to_string(path.native());
}
/// \brief Remove path components which would allow traversing up a directory tree.
@@ -156,18 +96,15 @@ inline auto path_to_string(const std::filesystem::path& path) -> decltype(path_t
/// \return A sanitized path
std::string sanitize_path(const std::string& path);
-/// \brief Returns the name with extension for a given path
-/// \param path The path to the output file
-std::string get_file_name(const std::string& path);
-
/**
* @brief Interface function to get absolute path of file
* @param path - path to file, can be relative to current working directory
* @return Absolute path of file
* @throw runtime_error if absolute path can't be resolved
*/
-std::string get_absolute_file_path(const std::string& path);
+std::filesystem::path get_absolute_file_path(const std::filesystem::path& path);
+/** @{ */
/**
* @brief Interface function to create directories recursively by given path
* @param path - path to file, can be relative to current working directory
@@ -175,14 +112,11 @@ std::string get_absolute_file_path(const std::string& path);
*/
void create_directory_recursive(const std::filesystem::path& path);
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-/**
- * @brief Interface function to create directorty recursively by given path
- * @param path - path to file wide-string, can be relative to current working directory
- * @throw runtime_error if any error occurred
- */
-void create_directory_recursive(const std::wstring& path);
-#endif
+template <class Path>
+void create_directory_recursive(const Path& path) {
+ return create_directory_recursive(make_path(path));
+}
+/** @} */
/**
* @brief Interface function to check if directory exists for given path
@@ -191,29 +125,29 @@ void create_directory_recursive(const std::wstring& path);
*/
bool directory_exists(const std::filesystem::path& path);
+/** @{ */
/**
* @brief Returns file size for file
* @param[in] path The file name
* @return file size
*/
-
-inline int64_t file_size(const std::filesystem::path& path) {
+inline int64_t file_size(const std::filesystem::path& path) noexcept {
std::error_code ec;
const auto size = std::filesystem::file_size(path, ec);
return ec ? -1 : static_cast<int64_t>(size);
}
-#ifdef _MSC_VER
-inline int64_t file_size(const char* path) {
- return file_size(ov::util::string_to_wstring(path));
+template <class Path>
+inline int64_t file_size(const Path& path) noexcept {
+ return ov::util::file_size(make_path(path));
}
-#endif
+/** @} */
+/** @{ */
/**
* @brief Tests whether file exists at given path.
* @param[in] path The file path.
* @return True if file exists, false otherwise.
- * @{
*/
inline bool file_exists(const std::filesystem::path& path) noexcept {
#if defined(__ANDROID__) || defined(ANDROID)
@@ -226,64 +160,45 @@ inline bool file_exists(const std::filesystem::path& path) noexcept {
return std::filesystem::exists(f_status) && !std::filesystem::is_directory(f_status);
}
-template <class T>
-inline bool file_exists(const std::basic_string<T>& path) noexcept {
+template <class Path>
+inline bool file_exists(const Path& path) noexcept {
return file_exists(make_path(path));
}
/** @} */
-std::string get_file_ext(const std::string& path);
std::filesystem::path get_directory(const std::filesystem::path& path);
std::filesystem::path path_join(std::initializer_list<std::filesystem::path>&& paths);
std::wstring path_join_w(std::initializer_list<std::wstring>&& paths);
-void iterate_files(const std::string& path,
- const std::function<void(const std::string& file, bool is_dir)>& func,
- bool recurse = false,
+/**
+ * @brief Iterates over files in given directory and applies provided function to each file found.
+ *
+ * @param path Root directory path to iterate files from.
+ * @param func Function to apply to each file found.
+ * @param include_links Whether to include symbolic links.
+ */
+void iterate_files(const std::filesystem::path& path,
+ const std::function<void(const std::filesystem::path& file)>& func,
bool include_links = false);
-void convert_path_win_style(std::string& path);
-
-std::string get_ov_lib_path();
-
-// TODO: remove this using. replace with Path.
-using FilePath = std::filesystem::path::string_type;
-
-// TODO: remove this function after get_plugin_path using Path
-inline std::string from_file_path(const std::filesystem::path& path) {
- return path.string();
-}
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
/**
- * @brief Returns a unicode path to openvino libraries
- * @return A `std::wstring` path to openvino libraries
+ * @brief Recusive iterates over files in given directory and applies provided function to each file found.
+ *
+ * @param path Root directory path to iterate files from.
+ * @param func Function to apply to each file found.
+ * @param recurse Whether to recurse into subdirectories.
+ * @param include_links Whether to include symbolic links.
*/
-std::wstring get_ov_lib_path_w();
-
-inline std::wstring get_ov_library_path() {
- return get_ov_lib_path_w();
-}
+void recursive_iterate_files(const std::filesystem::path& path,
+ const std::function<void(const std::filesystem::path& file)>& func,
+ bool include_links = false);
-#else
-
-inline std::string get_ov_library_path() {
- return get_ov_lib_path();
-}
-
-#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
-template <typename C,
- typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
-inline std::basic_string<C> make_plugin_library_name(const std::basic_string<C>& path,
- const std::basic_string<C>& input) {
- std::basic_string<C> separator(1, FileTraits<C>::file_separator);
- if (path.empty())
- separator = {};
- return path + separator + FileTraits<C>::library_prefix() + input + FileTraits<C>::dot_symbol +
- FileTraits<C>::library_ext();
-}
+/**
+ * @brief Gets a path to OpenVINO libraries.
+ * @return Path to OpenVINO libraries.
+ */
+std::filesystem::path get_ov_lib_path();
inline std::filesystem::path make_plugin_library_name(const std::filesystem::path& lib_name) {
return library_prefix().concat(lib_name.filename().native()).concat(library_extension().native());
@@ -294,6 +209,12 @@ inline std::filesystem::path make_plugin_library_name(const std::filesystem::pat
return dir_path / make_plugin_library_name(lib_name);
}
+template <typename C, typename = std::enable_if_t<(std::is_same_v<C, char> || std::is_same_v<C, wchar_t>)>>
+inline std::basic_string<C> make_plugin_library_name(const std::basic_string<C>& path,
+ const std::basic_string<C>& input) {
+ return path_to_string(make_plugin_library_name(make_path(path), make_path(input)));
+}
+
/**
* @brief Format plugin path (canonicalize, complete to absolute or complete to file name) for further
* dynamic loading by OS
@@ -329,14 +250,13 @@ std::filesystem::path get_plugin_path(const std::filesystem::path& plugin,
* @param path - binary file path to load
* @return binary vector
*/
-std::vector<uint8_t> load_binary(const std::string& path);
+std::vector<uint8_t> load_binary(const std::filesystem::path& path);
/**
* @brief save binary data to file
* @param path - binary file path to store
*/
-void save_binary(const std::string& path, const std::vector<uint8_t>& binary);
-void save_binary(const std::string& path, const char* binary, size_t bin_size);
+void save_binary(const std::filesystem::path& path, const void* binary, size_t bin_size);
/**
* @brief Trim OpenVINO project file name path if OpenVINO project directory found.
@@ -354,15 +274,4 @@ void save_binary(const std::string& path, const char* binary, size_t bin_size);
*/
const char* trim_file_name(const char* const fname);
-template <typename C>
-using enableIfSupportedChar =
- typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type;
-
-template <typename C, typename = enableIfSupportedChar<C>>
-inline std::basic_string<C> make_path(const std::basic_string<C>& folder, const std::basic_string<C>& file) {
- if (folder.empty())
- return file;
- return folder + ov::util::FileTraits<C>::file_separator + file;
-}
-} // namespace util
-} // namespace ov
+} // namespace ov::util
diff --git a/src/common/util/include/openvino/util/mmap_object.hpp b/src/common/util/include/openvino/util/mmap_object.hpp
index 1678bbd5cec..9dae3bd725e 100644
--- a/src/common/util/include/openvino/util/mmap_object.hpp
+++ b/src/common/util/include/openvino/util/mmap_object.hpp
@@ -9,6 +9,7 @@
#pragma once
+#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
@@ -43,7 +44,7 @@ public:
* @param path Path to a file which memory will be mmaped.
* @return MappedMemory shared ptr object which keep mmaped memory and control the lifetime.
*/
-std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::string& path);
+std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::filesystem::path& path);
/**
* @brief Returns mapped memory for a file from provided file handle (cross-platform).
@@ -54,18 +55,4 @@ std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::string& path);
* @return MappedMemory shared ptr object which keep mmaped memory and control the lifetime.
*/
std::shared_ptr<ov::MappedMemory> load_mmap_object(FileHandle handle);
-
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
-/**
- * @brief Returns mapped memory for a file from provided path.
- * Instead of reading files, we can map the memory via MapViewOfFile for Windows
- * in order to avoid time-consuming reading and reduce memory consumption.
- *
- * @param path Path to a file which memory will be mmaped.
- * @return MappedMemory shared ptr object which keep mmaped memory and control the lifetime.
- */
-std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::wstring& path);
-
-#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
} // namespace ov
diff --git a/src/common/util/include/openvino/util/shared_object.hpp b/src/common/util/include/openvino/util/shared_object.hpp
index 1be6a7021dc..fefafccc6b5 100644
--- a/src/common/util/include/openvino/util/shared_object.hpp
+++ b/src/common/util/include/openvino/util/shared_object.hpp
@@ -9,36 +9,24 @@
#pragma once
+#include <filesystem>
#include <memory>
-#include "openvino/util/util.hpp"
-
-namespace ov {
-namespace util {
+namespace ov::util {
/**
* @brief Loads a library with the name specified.
* @param path Full or relative path to the plugin library
* @return Reference to shared object
*/
-std::shared_ptr<void> load_shared_object(const char* path);
+std::shared_ptr<void> load_shared_object(const std::filesystem::path& path);
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-/**
- * @brief Loads a library with the wide char name specified.
- * @param path Full or relative path to the plugin library
- * @return Reference to shared object
- */
-std::shared_ptr<void> load_shared_object(const wchar_t* path);
-#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Searches for a function symbol in the loaded module
* @param shared_object shared object reference
- * @param symbolName Name of the function to find
+ * @param symbol_name Name of the function to find
* @return A pointer to the function if found
* @throws Exception if the function is not found
*/
-void* get_symbol(const std::shared_ptr<void>& shared_object, const char* symbolName);
-
-} // namespace util
-} // namespace ov
+void* get_symbol(const std::shared_ptr<void>& shared_object, const char* symbol_name);
+} // namespace ov::util
diff --git a/src/common/util/include/openvino/util/xml_parse_utils.hpp b/src/common/util/include/openvino/util/xml_parse_utils.hpp
index 23b91cc67c7..1c10077bf59 100644
--- a/src/common/util/include/openvino/util/xml_parse_utils.hpp
+++ b/src/common/util/include/openvino/util/xml_parse_utils.hpp
@@ -213,19 +213,12 @@ struct ParseResult {
*
* @return The ParseResult.
*/
-inline ParseResult parse_xml(const char* file_path) {
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
- std::wstring wFilePath = ov::util::string_to_wstring(file_path);
- const wchar_t* resolvedFilepath = wFilePath.c_str();
-#else
- const char* resolvedFilepath = file_path;
-#endif
-
+inline ParseResult parse_xml(const std::filesystem::path& file_path) {
try {
- auto xml = std::unique_ptr<pugi::xml_document>{new pugi::xml_document{}};
- const auto load_result = xml->load_file(resolvedFilepath);
+ auto xml = std::make_unique<pugi::xml_document>();
+ const auto load_result = xml->load_file(file_path.c_str());
- const auto error_msg = [&]() -> std::string {
+ auto error_msg = [&]() -> std::string {
if (load_result.status == pugi::status_ok)
return {};
@@ -244,7 +237,7 @@ inline ParseResult parse_xml(const char* file_path) {
return ss.str();
}();
- return {std::move(xml), error_msg};
+ return {std::move(xml), std::move(error_msg)};
} catch (std::exception& e) {
return {std::move(nullptr), std::string("Error loading XML file: ") + e.what()};
}
diff --git a/src/common/util/src/file_util.cpp b/src/common/util/src/file_util.cpp
index bcb1635a311..e1784c5fe7b 100644
--- a/src/common/util/src/file_util.cpp
+++ b/src/common/util/src/file_util.cpp
@@ -4,13 +4,12 @@
#include "openvino/util/file_util.hpp"
-#include <sys/stat.h>
-
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
+#include <string_view>
#include "openvino/util/common_util.hpp"
@@ -21,61 +20,11 @@
# include <direct.h>
# include <shlwapi.h>
# include <windows.h>
-/// @brief Max length of absolute file path
-# define MAX_ABS_PATH _MAX_PATH
-/// @brief Get absolute file path, returns NULL in case of error
-# define get_absolute_path(result, path) _fullpath(result, path.c_str(), MAX_ABS_PATH)
-/// @brief Windows-specific 'stat' wrapper
-# define stat _stat
-# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-# define wstat _wstat
-# endif
-/// @brief Windows-specific 'mkdir' wrapper
-# define makedir(dir) _mkdir(dir.c_str())
-# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-# define wmakedir(dir) _wmkdir(dir.c_str())
-# endif
-// Copied from linux libc sys/stat.h:
-# if !defined(__MINGW32__) && !defined(__MINGW64__)
-# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-# endif
#else
# include <dirent.h>
# include <dlfcn.h>
-# include <ftw.h>
-# include <limits.h>
-# include <sys/file.h>
-# include <sys/time.h>
-# include <unistd.h>
-
-# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-# include <codecvt>
-# include <locale>
-# endif
-
-/// @brief Max length of absolute file path
-# define MAX_ABS_PATH PATH_MAX
-/// @brief Get absolute file path, returns NULL in case of error
-# define get_absolute_path(result, path) realpath(path.c_str(), result)
-/// @brief mkdir wrapper
-# define makedir(dir) mkdir(dir.c_str(), 0755)
-# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-# define wmakedir(dir) mkdir(ov::util::wstring_to_string(dir).c_str(), 0755)
-# endif
#endif
-std::string ov::util::get_file_name(const std::string& s) {
- if (const auto path = make_path(s); path.has_parent_path()) {
- return path_to_string(path.filename());
- } else {
- return s;
- }
-}
-
-std::string ov::util::get_file_ext(const std::string& path) {
- return path_to_string(make_path(path).extension());
-}
-
std::filesystem::path ov::util::get_directory(const std::filesystem::path& path) {
if (path.empty()) {
return {};
@@ -107,129 +56,51 @@ std::wstring ov::util::path_join_w(std::initializer_list<std::wstring>&& paths)
return ::path_join<>(std::move(paths)).wstring();
}
-#ifndef _WIN32
-static void iterate_files_worker(const std::string& path,
- const std::function<void(const std::string& file, bool is_dir)>& func,
- bool recurse,
- bool include_links) {
- DIR* dir;
- struct dirent* ent;
- if ((dir = opendir(path.c_str())) != nullptr) {
- try {
- while ((ent = readdir(dir)) != nullptr) {
- std::string name = ent->d_name;
- std::string path_name = ov::util::path_join({path, name});
- switch (ent->d_type) {
- case DT_DIR:
- if (name != "." && name != "..") {
- if (recurse) {
- ov::util::iterate_files(path_name, func, recurse);
- }
- func(path_name, true);
- }
- break;
- case DT_LNK:
- if (include_links) {
- func(path_name, false);
- }
- break;
- case DT_REG:
- case DT_UNKNOWN:
- // Comment from READDIR(3):
- // only some filesystems have full support for returning the file type in d_type.
- // All applications must properly handle a return of DT_UNKNOWN.
- func(path_name, false);
- break;
- default:
- break;
- }
- }
- } catch (...) {
- std::exception_ptr p = std::current_exception();
- closedir(dir);
- std::rethrow_exception(std::move(p));
- }
- closedir(dir);
- } else {
- throw std::runtime_error("error enumerating file " + path);
+namespace {
+void process_dir_entry(const std::filesystem::directory_entry& dir_entry,
+ const std::function<void(const std::filesystem::path& file)>& func) {
+ const auto& status = dir_entry.status();
+ if (!std::filesystem::is_directory(status) && !std::filesystem::is_symlink(status)) {
+ func(dir_entry.path());
}
}
-#endif
-void ov::util::iterate_files(const std::string& path,
- const std::function<void(const std::string& file, bool is_dir)>& func,
- bool recurse,
+void process_dir_entry_include_links(const std::filesystem::directory_entry& dir_entry,
+ const std::function<void(const std::filesystem::path& file)>& func) {
+ const auto& status = dir_entry.status();
+ if (!std::filesystem::is_directory(status)) {
+ func(dir_entry.path());
+ }
+}
+} // namespace
+
+void ov::util::iterate_files(const std::filesystem::path& path,
+ const std::function<void(const std::filesystem::path& file)>& func,
bool include_links) {
- std::vector<std::string> files;
- std::vector<std::string> dirs;
-#ifdef _WIN32
-# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
- std::wstring pathw = string_to_wstring(path);
- std::wstring file_match = path_join_w({pathw, L"*"});
- WIN32_FIND_DATAW data;
- HANDLE hFind = FindFirstFileW(file_match.c_str(), &data);
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- bool is_dir = data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
- if (is_dir) {
- if (std::wstring(data.cFileName) != L"." && std::wstring(data.cFileName) != L"..") {
- std::wstring dir_pathw = path_join_w({pathw, data.cFileName});
- std::string dir_path = wstring_to_string(dir_pathw);
- if (recurse) {
- iterate_files(dir_path, func, recurse);
- }
- func(dir_path, true);
- }
- } else {
- std::wstring file_namew = path_join_w({pathw, data.cFileName});
- std::string file_name = wstring_to_string(file_namew);
- func(file_name, false);
- }
- } while (FindNextFileW(hFind, &data));
- FindClose(hFind);
+ std::error_code ec;
+ const auto dir_iter = std::filesystem::directory_iterator(path, ec);
+ if (ec) {
+ throw std::runtime_error("error enumerating file " + path_to_string(path) + ", err: " + ec.message());
}
-# else
- std::string file_match = path_join({path, "*"});
- WIN32_FIND_DATAA data;
- HANDLE hFind = FindFirstFileA(file_match.c_str(), &data);
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- bool is_dir = data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
- if (is_dir) {
- if (std::string(data.cFileName) != "." && std::string(data.cFileName) != "..") {
- std::string dir_path = path_join({path, data.cFileName});
- if (recurse) {
- iterate_files(dir_path, func, recurse);
- }
- func(dir_path, true);
- }
- } else {
- std::string file_name = path_join({path, data.cFileName});
- func(file_name, false);
- }
- } while (FindNextFileA(hFind, &data));
- FindClose(hFind);
+
+ const auto dir_entry_func = include_links ? process_dir_entry_include_links : process_dir_entry;
+ for (const auto& dir_entry : dir_iter) {
+ dir_entry_func(dir_entry, func);
}
-# endif
-#else
- iterate_files_worker(
- path,
- [&files, &dirs](const std::string& file, bool is_dir) {
- if (is_dir) {
- dirs.push_back(file);
- } else {
- files.push_back(file);
- }
- },
- recurse,
- include_links);
-#endif
+}
- for (const auto& f : files) {
- func(f, false);
+void ov::util::recursive_iterate_files(const std::filesystem::path& path,
+ const std::function<void(const std::filesystem::path& file)>& func,
+ bool include_links) {
+ std::error_code ec;
+ const auto dir_iter = std::filesystem::recursive_directory_iterator(path, ec);
+ if (ec) {
+ throw std::runtime_error("error enumerating file " + path_to_string(path) + ", err: " + ec.message());
}
- for (const auto& f : dirs) {
- func(f, true);
+
+ const auto dir_entry_func = include_links ? process_dir_entry_include_links : process_dir_entry;
+ for (const auto& dir_entry : dir_iter) {
+ dir_entry_func(dir_entry, func);
}
}
@@ -241,31 +112,19 @@ std::string ov::util::sanitize_path(const std::string& path) {
return (start == std::string::npos) ? "" : sanitized_path.substr(start);
}
-void ov::util::convert_path_win_style(std::string& path) {
- std::replace(path.begin(), path.end(), '/', '\\');
-}
-
-std::string ov::util::get_absolute_file_path(const std::string& path) {
- std::string absolutePath;
- absolutePath.resize(MAX_ABS_PATH);
- std::ignore = get_absolute_path(&absolutePath[0], path);
- if (!absolutePath.empty()) {
- // on Linux if file does not exist or no access, function will return NULL, but
- // `absolutePath` will contain resolved path
- absolutePath.resize(absolutePath.find('\0'));
- return absolutePath;
+std::filesystem::path ov::util::get_absolute_file_path(const std::filesystem::path& path) {
+ std::error_code ec;
+ if (path.empty() || path.is_absolute()) {
+ return path;
+ } else if (auto abs_path = std::filesystem::absolute(std::filesystem::weakly_canonical(path, ec)); !ec) {
+ return abs_path;
+ } else {
+ std::stringstream ss;
+ ss << "Can't get absolute file path for [" << path_to_string(path) << "], err = " << ec.message();
+ throw std::runtime_error(ss.str());
}
- std::stringstream ss;
- ss << "Can't get absolute file path for [" << path << "], err = " << strerror(errno);
- throw std::runtime_error(ss.str());
}
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-void ov::util::create_directory_recursive(const std::wstring& path) {
- create_directory_recursive(make_path(path));
-}
-#endif
-
void ov::util::create_directory_recursive(const std::filesystem::path& path) {
namespace fs = std::filesystem;
auto dir_path = fs::weakly_canonical(path);
@@ -291,26 +150,22 @@ bool ov::util::directory_exists(const std::filesystem::path& path) {
return std::filesystem::is_directory(std::filesystem::status(path));
}
-namespace {
-
-template <typename C,
- typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
-std::basic_string<C> get_path_name(const std::basic_string<C>& s) {
- size_t i = s.rfind(ov::util::FileTraits<C>::file_separator, s.length());
- if (i != std::string::npos) {
- return (s.substr(0, i));
+std::filesystem::path ov::util::get_ov_lib_path() {
+#ifdef _WIN32
+# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
+ WCHAR ov_library_path[MAX_PATH];
+ HMODULE hm = NULL;
+ if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<LPCWSTR>(get_ov_lib_path),
+ &hm)) {
+ std::stringstream ss;
+ ss << "GetModuleHandle returned " << GetLastError();
+ throw std::runtime_error(ss.str());
}
+ GetModuleFileNameW(hm, (LPWSTR)ov_library_path, sizeof(ov_library_path) / sizeof(ov_library_path[0]));
+ return std::filesystem::path(ov_library_path).parent_path();
- return {};
-}
-
-#if defined __GNUC__ || defined __clang__
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wunused-function"
-#endif
-
-std::string get_ov_library_path_a() {
-#ifdef _WIN32
+# else
CHAR ov_library_path[MAX_PATH];
HMODULE hm = NULL;
if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
@@ -321,54 +176,17 @@ std::string get_ov_library_path_a() {
throw std::runtime_error(ss.str());
}
GetModuleFileNameA(hm, (LPSTR)ov_library_path, sizeof(ov_library_path));
- return get_path_name(std::string(ov_library_path));
+ return make_path(ov_library_path).parent_path();
+# endif
#elif defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
Dl_info info;
dladdr(reinterpret_cast<void*>(ov::util::get_ov_lib_path), &info);
- return get_path_name(ov::util::get_absolute_file_path(info.dli_fname)).c_str();
+ return ov::util::get_absolute_file_path(info.dli_fname).parent_path();
#else
# error "Unsupported OS"
-#endif // _WIN32
-}
-
-#if defined __GNUC__ || defined __clang__
-# pragma GCC diagnostic pop
-#endif
-
-} // namespace
-
-std::string ov::util::get_ov_lib_path() {
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
- return ov::util::wstring_to_string(ov::util::get_ov_lib_path_w());
-#else
- return get_ov_library_path_a();
#endif
}
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
-std::wstring ov::util::get_ov_lib_path_w() {
-# ifdef _WIN32
- WCHAR ov_library_path[MAX_PATH];
- HMODULE hm = NULL;
- if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
- reinterpret_cast<LPCWSTR>(get_ov_lib_path),
- &hm)) {
- std::stringstream ss;
- ss << "GetModuleHandle returned " << GetLastError();
- throw std::runtime_error(ss.str());
- }
- GetModuleFileNameW(hm, (LPWSTR)ov_library_path, sizeof(ov_library_path) / sizeof(ov_library_path[0]));
- return get_path_name(std::wstring(ov_library_path));
-# elif defined(__linux__) || defined(__APPLE__) || defined(__EMSCRIPTEN__)
- return ov::util::string_to_wstring(get_ov_library_path_a());
-# else
-# error "Unsupported OS"
-# endif
-}
-
-#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
std::filesystem::path ov::util::get_plugin_path(const std::filesystem::path& plugin) {
// Assume `plugin` may contain:
// 1. /path/to/libexample.so absolute path
@@ -391,7 +209,7 @@ std::filesystem::path ov::util::get_plugin_path(const std::filesystem::path& plu
}
std::filesystem::path ov::util::get_compiled_plugin_path(const std::filesystem::path& plugin) {
- const auto ov_library_path = make_path(get_ov_lib_path());
+ const auto ov_library_path = get_ov_lib_path();
// plugin can be found either:
const std::filesystem::path sub_folder_path{std::string("openvino-") + OpenVINO_VERSION};
@@ -430,73 +248,44 @@ std::filesystem::path ov::util::get_plugin_path(const std::filesystem::path& plu
}
}
-std::vector<uint8_t> ov::util::load_binary(const std::string& path) {
-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
- std::wstring widefilename = ov::util::string_to_wstring(path);
- const wchar_t* filename = widefilename.c_str();
- FILE* fp = _wfopen(filename, L"rb");
-#else
- const char* filename = path.c_str();
- FILE* fp = fopen(filename, "rb");
-#endif
-
- if (fp) {
- fseek(fp, 0, SEEK_END);
- auto sz = ftell(fp);
- if (sz < 0) {
- fclose(fp);
- return {};
- }
- auto nsize = static_cast<size_t>(sz);
-
- fseek(fp, 0, SEEK_SET);
-
- std::vector<uint8_t> ret(nsize);
-
- auto res = fread(ret.data(), sizeof(uint8_t), nsize, fp);
- (void)res;
- fclose(fp);
- return ret;
+std::vector<uint8_t> ov::util::load_binary(const std::filesystem::path& path) {
+ std::vector<uint8_t> buffer;
+ if (auto input = std::ifstream(path, std::ios::binary); input.is_open()) {
+ buffer.reserve(std::filesystem::file_size(path));
+ input.read(reinterpret_cast<char*>(buffer.data()), buffer.capacity());
}
-
- return {};
-}
-
-void ov::util::save_binary(const std::string& path, const std::vector<uint8_t>& binary) {
- save_binary(path, reinterpret_cast<const char*>(&binary[0]), binary.size());
- return;
+ return buffer;
}
-void ov::util::save_binary(const std::string& path, const char* binary, size_t bin_size) {
-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
- std::wstring widefilename = ov::util::string_to_wstring(path);
- const wchar_t* filename = widefilename.c_str();
-#else
- const char* filename = path.c_str();
-#endif
- std::ofstream out_file(filename, std::ios::out | std::ios::binary);
- if (out_file.is_open()) {
- out_file.write(binary, bin_size);
+void ov::util::save_binary(const std::filesystem::path& path, const void* binary, size_t bin_size) {
+ if (std::ofstream out_file(path, std::ios::binary); out_file.is_open()) {
+ out_file.write(reinterpret_cast<const char*>(binary), bin_size);
} else {
- throw std::runtime_error("Could not save binary to " + path);
+ throw std::runtime_error("Could not save binary to " + path_to_string(path));
}
}
const char* ov::util::trim_file_name(const char* const fname) {
- static const auto pattern_native_sep =
- std::string(OV_NATIVE_PARENT_PROJECT_ROOT_DIR) + FileTraits<char>::file_separator;
-
- const auto has_native_sep_pattern_ptr = std::strstr(fname, pattern_native_sep.c_str());
- auto fname_trim_ptr = has_native_sep_pattern_ptr ? has_native_sep_pattern_ptr + pattern_native_sep.size() : fname;
-
-#if defined(_WIN32)
- // On windows check also forward slash as in some case the __FILE__ can have it instead native backward slash.
- if (fname_trim_ptr == fname) {
- static const auto pattern_fwd_sep = std::string(OV_NATIVE_PARENT_PROJECT_ROOT_DIR) + '/';
- if (const auto has_fwd_sep_pattern_ptr = std::strstr(fname, pattern_fwd_sep.c_str())) {
- fname_trim_ptr = has_fwd_sep_pattern_ptr + pattern_fwd_sep.size();
+ constexpr auto parent_project_root = std::string_view(OV_NATIVE_PARENT_PROJECT_ROOT_DIR);
+#ifdef _WIN32
+ constexpr auto native_path_separator = '\\';
+ constexpr auto portable_path_separator = '/';
+#else
+ constexpr auto native_path_separator = '/';
+#endif
+
+ if (auto fname_trim_ptr = std::strstr(fname, parent_project_root.data()); fname_trim_ptr) {
+ fname_trim_ptr += parent_project_root.size();
+ if (*fname_trim_ptr == native_path_separator
+#ifdef _WIN32
+ // On windows check also forward slash as in some case the __FILE__ can have it instead native backward
+ // slash.
+ || *fname_trim_ptr == portable_path_separator
+#endif
+ ) {
+ return fname_trim_ptr + 1;
}
}
-#endif
- return fname_trim_ptr;
+
+ return fname;
}
diff --git a/src/common/util/src/os/lin/lin_mmap_object.cpp b/src/common/util/src/os/lin/lin_mmap_object.cpp
index edf8fd106dd..791fdf326eb 100644
--- a/src/common/util/src/os/lin/lin_mmap_object.cpp
+++ b/src/common/util/src/os/lin/lin_mmap_object.cpp
@@ -63,11 +63,11 @@ class MapHolder : public MappedMemory {
public:
MapHolder() = default;
- void set(const std::string& path) {
+ void set(const std::filesystem::path& path) {
int mode = O_RDONLY;
int fd = open(path.c_str(), mode);
if (fd == -1) {
- throw std::runtime_error("Can not open file " + path +
+ throw std::runtime_error("Can not open file " + util::path_to_string(path) +
" for mapping. Ensure that file exists and has appropriate permissions");
}
set_from_fd(fd);
@@ -84,7 +84,7 @@ public:
if (m_size > 0) {
m_data = mmap(nullptr, m_size, prot, MAP_SHARED, fd, 0);
if (m_data == MAP_FAILED) {
- throw std::runtime_error("Can not create file mapping for fd=" + std::to_string(fd) +
+ throw std::runtime_error("Can not create file mapping for " + std::to_string(fd) +
", err=" + std::strerror(errno));
}
} else {
@@ -107,7 +107,7 @@ public:
}
};
-std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::string& path) {
+std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::filesystem::path& path) {
auto holder = std::make_shared<MapHolder>();
holder->set(path);
return holder;
diff --git a/src/common/util/src/os/lin/lin_shared_object_loader.cpp b/src/common/util/src/os/lin/lin_shared_object_loader.cpp
index 5e895ad90ff..096bc87bc90 100644
--- a/src/common/util/src/os/lin/lin_shared_object_loader.cpp
+++ b/src/common/util/src/os/lin/lin_shared_object_loader.cpp
@@ -10,10 +10,9 @@
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
-namespace ov {
-namespace util {
-std::shared_ptr<void> load_shared_object(const char* path) {
- auto shared_object = std::shared_ptr<void>{dlopen(path, RTLD_NOW), [](void* shared_object) {
+namespace ov::util {
+std::shared_ptr<void> load_shared_object(const std::filesystem::path& path) {
+ auto shared_object = std::shared_ptr<void>{dlopen(path.c_str(), RTLD_NOW), [](void* shared_object) {
if (shared_object != nullptr) {
if (0 != dlclose(shared_object)) {
std::cerr << "dlclose failed";
@@ -26,7 +25,7 @@ std::shared_ptr<void> load_shared_object(const char* path) {
}};
if (!shared_object) {
std::stringstream ss;
- ss << "Cannot load library '" << path << "'";
+ ss << "Cannot load library " << path;
if (auto error = dlerror()) {
ss << ": " << error;
}
@@ -35,26 +34,19 @@ std::shared_ptr<void> load_shared_object(const char* path) {
return shared_object;
}
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-std::shared_ptr<void> load_shared_object(const wchar_t* path) {
- return load_shared_object(ov::util::wstring_to_string(path).c_str());
-}
-#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
void* get_symbol(const std::shared_ptr<void>& shared_object, const char* symbol_name) {
if (!shared_object) {
std::stringstream ss;
ss << "Cannot get '" << symbol_name << "' content from unknown library!";
throw std::runtime_error(ss.str());
}
- void* procAddr = nullptr;
- procAddr = dlsym(shared_object.get(), symbol_name);
- if (procAddr == nullptr) {
+ void* proc_addr = nullptr;
+ proc_addr = dlsym(shared_object.get(), symbol_name);
+ if (proc_addr == nullptr) {
std::stringstream ss;
ss << "dlSym cannot locate method '" << symbol_name << "': " << dlerror();
throw std::runtime_error(ss.str());
}
- return procAddr;
+ return proc_addr;
}
-} // namespace util
-} // namespace ov
+} // namespace ov::util
diff --git a/src/common/util/src/os/win/win_mmap_object.cpp b/src/common/util/src/os/win/win_mmap_object.cpp
index d0472dd1f0d..e2e37f106c2 100644
--- a/src/common/util/src/os/win/win_mmap_object.cpp
+++ b/src/common/util/src/os/win/win_mmap_object.cpp
@@ -61,21 +61,12 @@ public:
}
}
- void set(const std::string& path) {
- // Note that file can't be changed (renamed/deleted) until it's unmapped. FILE_SHARE_DELETE flag allow
- // rename/deletion, but it doesn't work with FAT32 filesystem (works on NTFS)
- auto h = ::CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- map(path, h);
- }
-
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
- void set(const std::wstring& path) {
+ void set(const std::filesystem::path& path) {
// Note that file can't be changed (renamed/deleted) until it's unmapped. FILE_SHARE_DELETE flag allow
// rename/deletion, but it doesn't work with FAT32 filesystem (works on NTFS)
auto h = ::CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- map(ov::util::wstring_to_string(path), h);
+ map(path, h);
}
-#endif
void set_from_handle(HANDLE h) {
map("<external_handle>", h);
@@ -89,9 +80,9 @@ public:
}
private:
- void map(const std::string& path, HANDLE h) {
+ void map(const std::filesystem::path& path, HANDLE h) {
if (h == INVALID_HANDLE_VALUE) {
- throw std::runtime_error("Can not open file " + path +
+ throw std::runtime_error("Can not open file " + util::path_to_string(path) +
" for mapping. Ensure that file exists and has appropriate permissions");
}
m_handle = HandleHolder(h);
@@ -101,7 +92,7 @@ private:
LARGE_INTEGER file_size_large;
if (::GetFileSizeEx(m_handle.get(), &file_size_large) == 0) {
- throw std::runtime_error("Can not get file size for " + path);
+ throw std::runtime_error("Can not get file size for " + util::path_to_string(path));
}
m_size = static_cast<uint64_t>(file_size_large.QuadPart);
@@ -109,7 +100,7 @@ private:
m_mapping =
HandleHolder(::CreateFileMapping(m_handle.get(), 0, access, m_size >> 32, m_size & 0xffffffff, 0));
if (m_mapping.get() == INVALID_HANDLE_VALUE) {
- throw std::runtime_error("Can not create file mapping for " + path);
+ throw std::runtime_error("Can not create file mapping for " + util::path_to_string(path));
}
m_data = ::MapViewOfFile(m_mapping.get(),
@@ -118,7 +109,7 @@ private:
0, // offset_align & 0xffffffff,
m_size);
if (!m_data) {
- throw std::runtime_error("Can not create map view for " + path);
+ throw std::runtime_error("Can not create map view for " + util::path_to_string(path));
}
} else {
m_data = nullptr;
@@ -132,7 +123,7 @@ private:
HandleHolder m_mapping;
};
-std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::string& path) {
+std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::filesystem::path& path) {
auto holder = std::make_shared<MapHolder>();
holder->set(path);
return holder;
@@ -150,13 +141,4 @@ std::shared_ptr<ov::MappedMemory> load_mmap_object(FileHandle handle) {
return holder;
}
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-
-std::shared_ptr<ov::MappedMemory> load_mmap_object(const std::wstring& path) {
- auto holder = std::make_shared<MapHolder>();
- holder->set(path);
- return holder;
-}
-#endif
-
} // namespace ov
diff --git a/src/common/util/src/os/win/win_shared_object_loader.cpp b/src/common/util/src/os/win/win_shared_object_loader.cpp
index e9d58c5c791..b3199596b22 100644
--- a/src/common/util/src/os/win/win_shared_object_loader.cpp
+++ b/src/common/util/src/os/win/win_shared_object_loader.cpp
@@ -71,56 +71,9 @@
#include <windows.h>
-namespace ov {
-namespace util {
-std::shared_ptr<void> load_shared_object(const char* path) {
-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
- return ov::util::load_shared_object(ov::util::string_to_wstring(path).c_str());
-#else
- void* shared_object = nullptr;
- using GetDllDirectoryA_Fnc = DWORD (*)(DWORD, LPSTR);
- GetDllDirectoryA_Fnc IEGetDllDirectoryA = nullptr;
- if (HMODULE hm = GetModuleHandleW(L"kernel32.dll")) {
- IEGetDllDirectoryA = reinterpret_cast<GetDllDirectoryA_Fnc>(GetProcAddress(hm, "GetDllDirectoryA"));
- }
-#if !WINAPI_PARTITION_SYSTEM
- // ExcludeCurrentDirectory
- if (IEGetDllDirectoryA && IEGetDllDirectoryA(0, NULL) <= 1) {
- SetDllDirectoryA("");
- }
- // LoadPluginFromDirectory
- if (IEGetDllDirectoryA) {
- DWORD nBufferLength = IEGetDllDirectoryA(0, NULL);
- std::vector<CHAR> lpBuffer(nBufferLength);
- IEGetDllDirectoryA(nBufferLength, &lpBuffer.front());
-
- // GetDirname
- auto dirname = get_directory(path);
-
- SetDllDirectoryA(dirname.c_str());
- shared_object = LoadLibraryA(path);
-
- SetDllDirectoryA(&lpBuffer.front());
- }
-#endif
- if (!shared_object) {
- shared_object = LoadLibraryA(path);
- }
+namespace ov::util {
- if (!shared_object) {
- char cwd[1024];
- std::stringstream ss;
- ss << "Cannot load library '" << path << "': " << GetLastError() << " from cwd: " << _getcwd(cwd, sizeof(cwd));
- throw std::runtime_error(ss.str());
- }
- return {shared_object, [](void* shared_object) {
- FreeLibrary(reinterpret_cast<HMODULE>(shared_object));
- }};
-#endif
-}
-
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
-std::shared_ptr<void> load_shared_object(const wchar_t* path) {
+std::shared_ptr<void> load_shared_object(const std::filesystem::path& path) {
void* shared_object = nullptr;
using GetDllDirectoryW_Fnc = DWORD (*)(DWORD, LPWSTR);
static GetDllDirectoryW_Fnc IEGetDllDirectoryW = nullptr;
@@ -136,36 +89,26 @@ std::shared_ptr<void> load_shared_object(const wchar_t* path) {
DWORD nBufferLength = IEGetDllDirectoryW(0, NULL);
std::vector<WCHAR> lpBuffer(nBufferLength);
IEGetDllDirectoryW(nBufferLength, &lpBuffer.front());
- auto dirname = [path] {
- auto pos = wcsrchr(path, '\\');
- if (pos == nullptr) {
- return std::wstring{path};
- }
- std::wstring original(path);
- original[pos - path] = 0;
- return original;
- }();
- SetDllDirectoryW(dirname.c_str());
- shared_object = LoadLibraryW(path);
+ const auto& dir_name = path.has_parent_path() ? path.parent_path() : path;
+ SetDllDirectoryW(dir_name.c_str());
+ shared_object = LoadLibraryW(path.c_str());
SetDllDirectoryW(&lpBuffer.front());
}
# endif
if (!shared_object) {
- shared_object = LoadLibraryW(path);
+ shared_object = LoadLibraryW(path.c_str());
}
if (!shared_object) {
- char cwd[1024];
std::stringstream ss;
- ss << "Cannot load library '" << ov::util::wstring_to_string(std::wstring(path)) << "': " << GetLastError()
- << " from cwd: " << _getcwd(cwd, sizeof(cwd));
+ ss << "Cannot load library \"" << path_to_string(path) << "\": " << GetLastError()
+ << " from cwd: " << path_to_string(std::filesystem::current_path());
throw std::runtime_error(ss.str());
}
return {shared_object, [](void* shared_object) {
FreeLibrary(reinterpret_cast<HMODULE>(shared_object));
}};
}
-#endif
void* get_symbol(const std::shared_ptr<void>& shared_object, const char* symbol_name) {
if (!shared_object) {
@@ -173,14 +116,13 @@ void* get_symbol(const std::shared_ptr<void>& shared_object, const char* symbol_
ss << "Cannot get '" << symbol_name << "' content from unknown library!";
throw std::runtime_error(ss.str());
}
- auto procAddr = reinterpret_cast<void*>(
+ auto proc_addr = reinterpret_cast<void*>(
GetProcAddress(reinterpret_cast<HMODULE>(const_cast<void*>(shared_object.get())), symbol_name));
- if (procAddr == nullptr) {
+ if (proc_addr == nullptr) {
std::stringstream ss;
ss << "GetProcAddress cannot locate method '" << symbol_name << "': " << GetLastError();
throw std::runtime_error(ss.str());
}
- return procAddr;
+ return proc_addr;
}
-} // namespace util
-} // namespace ov
+} // namespace ov::util
diff --git a/src/core/dev_api/openvino/core/so_extension.hpp b/src/core/dev_api/openvino/core/so_extension.hpp
index 3565bcb4baf..9a68aa3622a 100644
--- a/src/core/dev_api/openvino/core/so_extension.hpp
+++ b/src/core/dev_api/openvino/core/so_extension.hpp
@@ -37,7 +37,7 @@ inline std::filesystem::path resolve_extension_path(const std::filesystem::path&
inline std::vector<Extension::Ptr> load_extensions(const std::filesystem::path& path) {
const auto resolved_path = resolve_extension_path(path);
- auto so = ov::util::load_shared_object(resolved_path.c_str());
+ auto so = ov::util::load_shared_object(resolved_path);
using CreateFunction = void(std::vector<Extension::Ptr>&);
std::vector<Extension::Ptr> extensions;
reinterpret_cast<CreateFunction*>(ov::util::get_symbol(so, "create_extensions"))(extensions);
diff --git a/src/core/tests/check.cpp b/src/core/tests/check.cpp
index dc48165b5e6..9a29dc0043a 100644
--- a/src/core/tests/check.cpp
+++ b/src/core/tests/check.cpp
@@ -68,7 +68,7 @@ TEST(check, error_message_with_fs_path_and_unicode) {
const auto path = ov::test::utils::to_fs_path("这是.folder") / ov::test::utils::to_fs_path(L"这.txt");
auto description = std::string("Error detail");
const auto exp_error_str = std::string("Test read file: \"这是.folder") +
- ov::util::FileTraits<char>::file_separator +
+ ov::test::utils::FileTraits<char>::file_separator +
std::string("这.txt\", because: Error detail");
std::stringstream error;
diff --git a/src/core/tests/extension.cpp b/src/core/tests/extension.cpp
index 43e2c38ca36..42e81efd255 100644
--- a/src/core/tests/extension.cpp
+++ b/src/core/tests/extension.cpp
@@ -20,9 +20,9 @@ inline std::string get_extension_path() {
inline std::wstring get_extension_wdir() {
std::wstring dir = ov::util::string_to_wstring(ov::test::utils::getExecutableDirectory());
- dir.push_back(ov::util::FileTraits<wchar_t>::file_separator);
+ dir.push_back(ov::test::utils::FileTraits<wchar_t>::file_separator);
dir += ov::util::string_to_wstring("晚安_путь_к_файлу");
- dir.push_back(ov::util::FileTraits<wchar_t>::file_separator);
+ dir.push_back(ov::test::utils::FileTraits<wchar_t>::file_separator);
ov::util::create_directory_recursive(dir);
return dir;
}
diff --git a/src/frontends/common/src/manager.cpp b/src/frontends/common/src/manager.cpp
index b453c0e4474..f0a89ed5107 100644
--- a/src/frontends/common/src/manager.cpp
+++ b/src/frontends/common/src/manager.cpp
@@ -108,8 +108,8 @@ public:
void register_front_end(const std::string& name, const std::filesystem::path& library_path) {
auto lib_path = ov::util::get_plugin_path(library_path);
PluginInfo plugin;
- plugin.m_file_path = ov::util::path_to_string(lib_path);
- plugin.m_file_name = ov::util::path_to_string(lib_path.filename());
+ plugin.m_file_path = ov::util::get_plugin_path(ov::util::make_path(library_path));
+ plugin.m_file_name = plugin.m_file_path.filename();
FRONT_END_GENERAL_CHECK(plugin.load(), "Cannot load frontend ", plugin.get_name_from_file());
std::lock_guard<std::mutex> guard(m_loading_mutex);
m_plugins.push_back(std::move(plugin));
@@ -172,7 +172,7 @@ private:
#endif
}
if (!model_path.empty()) {
- auto ext = ov::util::get_file_ext(model_path);
+ auto ext = ov::util::path_to_string(ov::util::make_path(model_path).extension());
auto it = priority_fe_extensions.find(ext);
if (it != priority_fe_extensions.end()) {
// Priority FE is found by file extension, try this first
@@ -208,9 +208,8 @@ private:
}
void search_all_plugins() {
- auto fe_lib_dir = ov::util::get_ov_lib_path();
- if (!fe_lib_dir.empty())
- find_plugins(fe_lib_dir, m_plugins);
+ const auto fe_lib_dir = ov::util::get_ov_lib_path();
+ find_plugins(fe_lib_dir, m_plugins);
}
};
diff --git a/src/frontends/common/src/plugin_loader.cpp b/src/frontends/common/src/plugin_loader.cpp
index 56a9fb2daa4..2ee431d5028 100644
--- a/src/frontends/common/src/plugin_loader.cpp
+++ b/src/frontends/common/src/plugin_loader.cpp
@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <string>
+#include <string_view>
#include <vector>
#include "openvino/util/file_util.hpp"
@@ -76,38 +77,38 @@ void load_static_plugins(std::vector<PluginInfo>& res) {
#endif // OPENVINO_STATIC_LIBRARY
-// TODO: change to std::filesystem for C++17
-static std::vector<std::string> list_files(const std::string& path) {
- std::vector<std::string> res;
- try {
- const auto prefix = std::string(FRONTEND_LIB_PREFIX);
- const auto suffix = std::string(FRONTEND_LIB_SUFFIX);
- ov::util::iterate_files(
- path,
- [&res, &prefix, &suffix](const std::string& file_path, bool is_dir) {
- auto file = ov::util::get_file_name(file_path);
- if (!is_dir && (prefix.empty() || file.compare(0, prefix.length(), prefix) == 0) &&
- file.length() > suffix.length() &&
- file.rfind(suffix) == (file.length() - std::string(suffix).length())) {
- res.push_back(file_path);
+static bool is_fe_lib_name(const std::string_view& file_name) {
+ static constexpr auto prefix = std::string_view(FRONTEND_LIB_PREFIX);
+ static constexpr auto suffix = std::string_view(FRONTEND_LIB_SUFFIX);
+ auto prefix_pos = file_name.find(prefix);
+ auto suffix_pos = file_name.rfind(suffix);
+ return (prefix_pos == 0 && suffix_pos != std::string::npos && (suffix_pos == file_name.length() - suffix.length()));
+}
+
+static std::vector<std::filesystem::path> list_files(const std::filesystem::path& path) {
+ std::error_code ec;
+ std::vector<std::filesystem::path> res;
+ if (const auto dir_iter = std::filesystem::directory_iterator(path, ec); !ec) {
+ for (const auto& dir_entry : dir_iter) {
+ if (!std::filesystem::is_directory(dir_entry.status())) {
+ const auto file_name = dir_entry.path().filename().string();
+ if (is_fe_lib_name(file_name)) {
+ res.push_back(dir_entry.path());
}
- },
- false,
- true);
- } catch (...) {
- // Ignore exceptions
+ }
+ }
}
return res;
}
-void ov::frontend::find_plugins(const std::string& dir_name, std::vector<PluginInfo>& res) {
+void ov::frontend::find_plugins(const std::filesystem::path& dir_name, std::vector<PluginInfo>& res) {
#ifdef OPENVINO_STATIC_LIBRARY
load_static_plugins(res);
#endif // OPENVINO_STATIC_LIBRARY
for (const auto& file_path : list_files(dir_name)) {
PluginInfo plugin_info;
plugin_info.m_file_path = file_path;
- plugin_info.m_file_name = ov::util::get_file_name(file_path);
+ plugin_info.m_file_name = file_path.filename();
// if frontend is registered already (e.g. as static), skip found version
if (std::find_if(res.begin(), res.end(), [&plugin_info](const PluginInfo& pd) {
return plugin_info.get_name_from_file() == pd.get_name_from_file();
@@ -123,12 +124,13 @@ void ov::frontend::find_plugins(const std::string& dir_name, std::vector<PluginI
std::string PluginInfo::get_name_from_file() const {
const auto prefix = std::string(FRONTEND_LIB_PREFIX);
const auto suffix = std::string(FRONTEND_LIB_SUFFIX);
- auto prefix_pos = m_file_name.find(prefix);
- auto suffix_pos = m_file_name.rfind(suffix);
- if (prefix_pos == 0 && suffix_pos + suffix.length() == m_file_name.length()) {
- return m_file_name.substr(prefix_pos + prefix.length(), suffix_pos - prefix_pos - prefix.length());
+ auto file_name = ov::util::path_to_string(m_file_name);
+ auto prefix_pos = file_name.find(prefix);
+ auto suffix_pos = file_name.rfind(suffix);
+ if (prefix_pos == 0 && suffix_pos + suffix.length() == file_name.length()) {
+ return file_name.substr(prefix_pos + prefix.length(), suffix_pos - prefix_pos - prefix.length());
}
- return m_file_name;
+ return file_name;
}
bool PluginInfo::is_file_name_match(const std::string& name) const {
@@ -156,11 +158,7 @@ bool PluginInfo::load() {
bool PluginInfo::load_internal() {
std::shared_ptr<void> so;
try {
-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
- so = ov::util::load_shared_object(ov::util::string_to_wstring(m_file_path).c_str());
-#else
- so = ov::util::load_shared_object(m_file_path.c_str());
-#endif
+ so = ov::util::load_shared_object(m_file_path);
}
#ifdef ENABLE_OPENVINO_DEBUG
catch (const std::exception& ex) {
diff --git a/src/frontends/common/src/plugin_loader.hpp b/src/frontends/common/src/plugin_loader.hpp
index 16375881994..87ed867e515 100644
--- a/src/frontends/common/src/plugin_loader.hpp
+++ b/src/frontends/common/src/plugin_loader.hpp
@@ -44,8 +44,8 @@ class PluginInfo {
bool load_internal();
public:
- std::string m_file_name; // Plugin file name, e.g. "libopenvino_ir_frontend.so"
- std::string m_file_path; // Plugin file full path
+ std::filesystem::path m_file_name; // Plugin file name, e.g. "libopenvino_ir_frontend.so"
+ std::filesystem::path m_file_path; // Plugin file full path
PluginInfo() = default;
@@ -77,7 +77,7 @@ public:
// Searches for available plugins in a specified directory
// Appends found plugins to existing list
-void find_plugins(const std::string& dir_name, std::vector<PluginInfo>& res);
+void find_plugins(const std::filesystem::path& dir_name, std::vector<PluginInfo>& res);
} // namespace frontend
} // namespace ov
diff --git a/src/frontends/ir/src/frontend.cpp b/src/frontends/ir/src/frontend.cpp
index 74e832e60b6..75f99c87cb7 100644
--- a/src/frontends/ir/src/frontend.cpp
+++ b/src/frontends/ir/src/frontend.cpp
@@ -256,7 +256,7 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const
}
if (!weights_path.empty()) {
if (enable_mmap) {
- auto mapped_memory = ov::load_mmap_object(weights_path);
+ auto mapped_memory = ov::load_mmap_object(ov::util::make_path(weights_path));
weights = std::make_shared<ov::SharedBuffer<std::shared_ptr<MappedMemory>>>(mapped_memory->data(),
mapped_memory->size(),
mapped_memory);
diff --git a/src/frontends/ir/tests/meta_data_tests.cpp b/src/frontends/ir/tests/meta_data_tests.cpp
index af22889ff32..3a716e2ed7b 100644
--- a/src/frontends/ir/tests/meta_data_tests.cpp
+++ b/src/frontends/ir/tests/meta_data_tests.cpp
@@ -393,8 +393,8 @@ TEST_F(MetaData, get_meta_data_as_map) {
}
TEST_F(MetaData, get_meta_data_from_removed_file) {
- std::string file_path = ov::util::get_ov_lib_path() + ov::util::FileTraits<char>::file_separator +
- ov::test::utils::generateTestFilePrefix() + "_test_model.xml";
+ const auto file_path =
+ ov::util::get_ov_lib_path() / (ov::test::utils::generateTestFilePrefix() + "_test_model.xml");
// Create file
{
std::ofstream ir(file_path);
@@ -403,7 +403,7 @@ TEST_F(MetaData, get_meta_data_from_removed_file) {
auto model = core.read_model(file_path);
// Remove file (meta section wasn't read)
- std::remove(file_path.c_str());
+ std::filesystem::remove(file_path);
check_rt_info(model);
}
diff --git a/src/frontends/onnx/frontend/src/core/graph_iterator_proto.cpp b/src/frontends/onnx/frontend/src/core/graph_iterator_proto.cpp
index 63113f9fbb3..5d01b2ee0ce 100644
--- a/src/frontends/onnx/frontend/src/core/graph_iterator_proto.cpp
+++ b/src/frontends/onnx/frontend/src/core/graph_iterator_proto.cpp
@@ -92,7 +92,7 @@ bool extract_tensor_external_data(ov::frontend::onnx::TensorMetaInfo& tensor_met
}
}
const auto full_path =
- ov::util::get_absolute_file_path(ov::util::path_join({graph_iterator->get_model_dir(), ext_location}).string());
+ ov::util::get_absolute_file_path(ov::util::path_join({graph_iterator->get_model_dir(), ext_location}));
const int64_t file_size = ov::util::file_size(full_path);
if ((file_size <= 0 && ext_data_length > 0) ||
ext_data_offset + ext_data_length > static_cast<uint64_t>(file_size)) {
@@ -103,6 +103,8 @@ bool extract_tensor_external_data(ov::frontend::onnx::TensorMetaInfo& tensor_met
throw std::runtime_error(ss.str());
}
auto memory_mode = graph_iterator->get_memory_management_mode();
+ // Remove when cache map will use path instead string.
+ const auto full_path_str = ov::util::path_to_string(full_path);
if (ext_location == "*/_ORT_MEM_ADDR_/*") {
// Specific ONNX Runtime Case when it passes a model with self-managed data
tensor_meta_info.m_is_raw = true;
@@ -111,13 +113,13 @@ bool extract_tensor_external_data(ov::frontend::onnx::TensorMetaInfo& tensor_met
return true;
} else if (memory_mode == External_MMAP) {
auto cache = graph_iterator->get_mmap_cache();
- auto cached_mapped_memory = cache->find(full_path);
+ auto cached_mapped_memory = cache->find(full_path_str);
std::shared_ptr<ov::MappedMemory> mapped_memory;
if (cached_mapped_memory != cache->end()) {
mapped_memory = cached_mapped_memory->second;
} else {
mapped_memory = ov::load_mmap_object(full_path);
- (*cache)[full_path] = mapped_memory;
+ (*cache)[full_path_str] = mapped_memory;
}
tensor_meta_info.m_is_raw = true;
tensor_meta_info.m_tensor_data =
@@ -127,18 +129,17 @@ bool extract_tensor_external_data(ov::frontend::onnx::TensorMetaInfo& tensor_met
return true;
} else if (memory_mode == External_Stream) {
auto cache = graph_iterator->get_stream_cache();
- auto cached_stream = cache->find(full_path);
+ auto cached_stream = cache->find(full_path_str);
std::shared_ptr<std::ifstream> external_data_stream;
if (cached_stream != cache->end()) {
external_data_stream = cached_stream->second;
} else {
- external_data_stream = {
- new std::ifstream(full_path.c_str(), std::ios::binary | std::ios::in | std::ios::ate),
- [](std::ifstream* p) {
- p->close();
- delete p;
- }};
- (*cache)[full_path] = external_data_stream;
+ external_data_stream = {new std::ifstream(full_path, std::ios::binary | std::ios::in | std::ios::ate),
+ [](std::ifstream* p) {
+ p->close();
+ delete p;
+ }};
+ (*cache)[full_path_str] = external_data_stream;
}
if (external_data_stream->fail() || !external_data_stream->good()) {
@@ -158,7 +159,7 @@ bool extract_tensor_external_data(ov::frontend::onnx::TensorMetaInfo& tensor_met
tensor_meta_info.m_tensor_data_size);
return true;
} else if (memory_mode == Internal_MMAP || memory_mode == Internal_Stream) {
- tensor_meta_info.m_external_location = std::make_shared<std::string>(full_path);
+ tensor_meta_info.m_external_location = std::make_shared<std::string>(full_path_str);
tensor_meta_info.m_tensor_data = reinterpret_cast<uint8_t*>(ext_data_offset);
tensor_meta_info.m_tensor_data_size = ext_data_length;
return true;
diff --git a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp
index 926febdb509..f6da4da526a 100644
--- a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp
+++ b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp
@@ -41,20 +41,19 @@ TensorExternalData::TensorExternalData(const std::string& location, size_t offse
Buffer<ov::MappedMemory> TensorExternalData::load_external_mmap_data(const std::string& model_dir,
MappedMemoryHandles cache) const {
- const auto full_path =
- model_dir == "" ? m_data_location
- : ov::util::get_absolute_file_path(ov::util::path_join({model_dir, m_data_location}).string());
+ const auto full_path = model_dir.empty() ? ov::util::make_path(m_data_location)
+ : ov::util::make_path(ov::util::path_join({model_dir, m_data_location}));
const int64_t file_size = ov::util::file_size(full_path);
if (file_size <= 0 || m_offset + m_data_length > static_cast<uint64_t>(file_size)) {
throw error::invalid_external_data{*this};
}
- auto cached_mapped_memory = cache->find(full_path);
+ auto cached_mapped_memory = cache->find(ov::util::path_to_string(full_path));
std::shared_ptr<ov::MappedMemory> mapped_memory;
if (cached_mapped_memory != cache->end()) {
mapped_memory = cached_mapped_memory->second;
} else {
mapped_memory = ov::load_mmap_object(full_path);
- (*cache)[full_path] = mapped_memory;
+ (*cache)[ov::util::path_to_string(full_path)] = mapped_memory;
}
if (m_data_length > mapped_memory->size() || mapped_memory->size() == 0) {
throw error::invalid_external_data{*this};
diff --git a/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp b/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp
index cb71912f141..ed1e56f2bdd 100644
--- a/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp
+++ b/src/frontends/tensorflow/src/checkpoint_v1_reader.cpp
@@ -21,14 +21,10 @@ std::vector<std::string> list_files_in_dir(const std::string& directory_path) {
std::vector<std::string> res;
try {
ov::util::iterate_files(
- directory_path,
- [&res](const std::string& file_path, bool is_dir) {
- auto file = ov::util::get_file_name(file_path);
- if (!is_dir) {
- res.push_back(file_path);
- }
+ ov::util::make_path(directory_path),
+ [&res](const std::filesystem::path& file_path) {
+ res.push_back(ov::util::path_to_string(file_path));
},
- false,
true);
} catch (...) {
// Ignore exceptions
diff --git a/src/frontends/tensorflow/src/variables_index.cpp b/src/frontends/tensorflow/src/variables_index.cpp
index e6a8ce82fa3..b75e414750f 100644
--- a/src/frontends/tensorflow/src/variables_index.cpp
+++ b/src/frontends/tensorflow/src/variables_index.cpp
@@ -193,18 +193,18 @@ bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::string&
std::vector<char> suffix(32);
for (int32_t shard = 0; shard < m_total_shards; ++shard) {
std::snprintf(suffix.data(), suffix.size(), "data-%05d-of-%05d", shard, m_total_shards);
- std::string fullPath;
+ std::filesystem::path fullPath;
if (is_saved_model) {
- fullPath = ov::util::path_join({path, "variables", std::string("variables.") + suffix.data()}).string();
+ fullPath = ov::util::path_join({path, "variables", std::string("variables.") + suffix.data()});
} else {
- fullPath = path + "." + suffix.data();
+ fullPath = ov::util::make_path(path + "." + suffix.data());
}
if (m_mmap_enabled) {
m_data_files[shard].mmap = load_mmap_object(fullPath);
FRONT_END_GENERAL_CHECK(m_data_files[shard].mmap->data(), "Variable index data cannot be mapped");
} else {
- m_data_files[shard].stream = std::shared_ptr<std::ifstream>(
- new std::ifstream(fullPath.c_str(), std::ifstream::in | std::ifstream::binary));
+ m_data_files[shard].stream =
+ std::shared_ptr<std::ifstream>(new std::ifstream(fullPath, std::ifstream::in | std::ifstream::binary));
FRONT_END_GENERAL_CHECK(m_data_files[shard].stream->is_open(), "Variable index data file does not exist");
}
}
@@ -222,7 +222,7 @@ bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::wstring
std::vector<wchar_t> suffix(20);
for (int32_t shard = 0; shard < m_total_shards; ++shard) {
swprintf_s(suffix.data(), suffix.size(), L"data-%05d-of-%05d", shard, m_total_shards);
- std::wstring fullPath;
+ std::filesystem::path fullPath;
if (is_saved_model) {
fullPath = ov::util::path_join_w({path, L"variables", std::wstring(L"variables.") + suffix.data()});
} else {
@@ -232,8 +232,8 @@ bool VariablesIndex::read_variables(std::ifstream& vi_stream, const std::wstring
m_data_files[shard].mmap = load_mmap_object(fullPath);
FRONT_END_GENERAL_CHECK(m_data_files[shard].mmap->data(), "Variable index data cannot be mapped");
} else {
- m_data_files[shard].stream = std::shared_ptr<std::ifstream>(
- new std::ifstream(fullPath.c_str(), std::ifstream::in | std::ifstream::binary));
+ m_data_files[shard].stream =
+ std::shared_ptr<std::ifstream>(new std::ifstream(fullPath, std::ifstream::in | std::ifstream::binary));
FRONT_END_GENERAL_CHECK(m_data_files[shard].stream->is_open(), "Variable index data file does not exist");
}
}
diff --git a/src/inference/src/cpp/core.cpp b/src/inference/src/cpp/core.cpp
index 157e4e46dc0..393752e8f37 100644
--- a/src/inference/src/cpp/core.cpp
+++ b/src/inference/src/cpp/core.cpp
@@ -16,37 +16,34 @@ namespace ov {
namespace {
-std::string find_plugins_xml(const std::string& xml_file) {
- 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 {
+std::filesystem::path find_plugins_xml(const std::filesystem::path& xml_file) {
+ if (xml_file.has_parent_path()) {
// 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;
- }
+ return xml_file;
}
+
+ // Default plugin xml file name, will search in OV folder.
+ const auto& xml_file_name = xml_file.empty() ? std::filesystem::path("plugins.xml") : xml_file;
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}).string();
- if (ov::util::file_exists(xmlConfigFileDefault))
- return xmlConfigFileDefault;
-
// 2. in folder with libopenvino.so
- xmlConfigFileDefault = ov::util::path_join({std::move(ov_library_path), std::move(xml_file_name)}).string();
- if (ov::util::file_exists(xmlConfigFileDefault))
- return xmlConfigFileDefault;
-
- return xml_file;
+ const auto ov_version_folder = [] {
+ std::ostringstream str;
+ str << "openvino-" << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH;
+ return std::filesystem::path(str.str());
+ }();
+
+ if (auto xml_path = ov_library_path / ov_version_folder / xml_file_name; ov::util::file_exists(xml_path)) {
+ // register plugins from default openvino-<openvino version>/plugins.xml config
+ return xml_path;
+ } else if (xml_path = ov_library_path / xml_file_name; ov::util::file_exists(xml_path)) {
+ return xml_path;
+ } else {
+ return xml_file;
+ }
}
} // namespace
@@ -65,20 +62,17 @@ public:
Impl() : ov::CoreImpl() {}
};
-Core::Core(const std::string& xml_config_file) {
- _impl = std::make_shared<Impl>();
+Core::Core(const std::string& xml_config_file) : Core(ov::util::make_path(xml_config_file)) {}
- std::string xmlConfigFile = find_plugins_xml(xml_config_file);
- if (!xmlConfigFile.empty())
- OV_CORE_CALL_STATEMENT(
- // If XML is default, load default plugins by absolute paths
- _impl->register_plugins_in_registry(xmlConfigFile, xml_config_file.empty());)
+Core::Core(const std::filesystem::path& xml_config_file) : _impl(std::make_shared<Impl>()) {
+ if (const auto xml_path = find_plugins_xml(xml_config_file); !xml_path.empty()) {
+ // If XML is default, load default plugins by absolute paths
+ OV_CORE_CALL_STATEMENT(_impl->register_plugins_in_registry(xml_path, xml_config_file.empty());)
+ }
// Load plugins from the pre-compiled list
OV_CORE_CALL_STATEMENT(_impl->register_compile_time_plugins();)
}
-Core::Core(const std::filesystem::path& xml_config_file) : Core(ov::util::path_to_string(xml_config_file)) {}
-
std::map<std::string, Version> Core::get_versions(const std::string& device_name) const {
OV_CORE_CALL_STATEMENT({ return _impl->get_versions(device_name); })}
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
@@ -277,11 +271,11 @@ void Core::unload_plugin(const std::string& device_name) {
}
void Core::register_plugins(const std::string& xml_config_file) {
- OV_CORE_CALL_STATEMENT(_impl->register_plugins_in_registry(xml_config_file););
+ register_plugins(ov::util::make_path(xml_config_file));
}
void Core::register_plugins(const std::filesystem::path& xml_config_file) {
- register_plugins(ov::util::path_to_string(xml_config_file));
+ OV_CORE_CALL_STATEMENT(_impl->register_plugins_in_registry(xml_config_file););
}
RemoteContext Core::create_context(const std::string& device_name, const AnyMap& params) {
diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp
index 9ed93da99f4..ac5fea006ad 100644
--- a/src/inference/src/dev/core_impl.cpp
+++ b/src/inference/src/dev/core_impl.cpp
@@ -599,22 +599,19 @@ void ov::CoreImpl::register_compile_time_plugins() {
}
}
-void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_file, const bool& by_abs_path) {
+void ov::CoreImpl::register_plugins_in_registry(const std::filesystem::path& xml_config_file, const bool by_abs_path) {
using namespace ov::util;
- auto parse_result = pugixml::parse_xml(xml_config_file.c_str());
- if (!parse_result.error_msg.empty()) {
- OPENVINO_THROW(parse_result.error_msg);
- }
-
- pugi::xml_document& xml_doc = *parse_result.xml;
+ const auto parse_result = pugixml::parse_xml(xml_config_file);
+ OPENVINO_ASSERT(parse_result.error_msg.empty(), parse_result.error_msg);
- pugi::xml_node ie_node = xml_doc.document_element();
- pugi::xml_node devices_node = ie_node.child("plugins");
+ const auto& xml_doc = *parse_result.xml;
+ const auto ie_node = xml_doc.document_element();
+ const auto devices_node = ie_node.child("plugins");
std::lock_guard<std::mutex> lock(get_mutex());
- FOREACH_CHILD (pluginNode, devices_node, "plugin") {
- std::string device_name = pugixml::get_str_attr(pluginNode, "name");
+ FOREACH_CHILD (plugin_node, devices_node, "plugin") {
+ const auto device_name = pugixml::get_str_attr(plugin_node, "name");
if (m_plugin_registry.find(device_name) != m_plugin_registry.end()) {
OPENVINO_THROW("Device with \"", device_name, "\" is already registered in the OpenVINO Runtime");
}
@@ -622,39 +619,29 @@ void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_fi
OPENVINO_THROW("Device name must not contain dot '.' symbol");
}
- const auto& plugin_path =
- ov::util::get_plugin_path(ov::util::make_path(pugixml::get_str_attr(pluginNode, "location")),
- ov::util::make_path(xml_config_file),
- by_abs_path);
+ PluginDescriptor plugin_desc{
+ get_plugin_path(make_path(pugixml::get_str_attr(plugin_node, "location")), xml_config_file, by_abs_path)};
// check properties
- auto propertiesNode = pluginNode.child("properties");
- ov::AnyMap config;
-
- if (propertiesNode) {
- FOREACH_CHILD (propertyNode, propertiesNode, "property") {
- std::string key = pugixml::get_str_attr(propertyNode, "key");
- std::string value = pugixml::get_str_attr(propertyNode, "value");
- config[key] = value;
+ const auto properties_node = plugin_node.child("properties");
+ if (properties_node) {
+ FOREACH_CHILD (property_node, properties_node, "property") {
+ const auto key = pugixml::get_str_attr(property_node, "key");
+ plugin_desc.m_default_config[key] = pugixml::get_str_attr(property_node, "value");
}
}
// check extensions
- auto extensionsNode = pluginNode.child("extensions");
- std::vector<ov::util::FilePath> listOfExtentions;
-
- if (extensionsNode) {
- FOREACH_CHILD (extensionNode, extensionsNode, "extension") {
- const auto extension_location = pugixml::get_str_attr(extensionNode, "location");
- listOfExtentions.push_back(ov::util::make_path(extension_location));
+ const auto extensions_node = plugin_node.child("extensions");
+ if (extensions_node) {
+ FOREACH_CHILD (extension_node, extensions_node, "extension") {
+ const auto extension_location = pugixml::get_str_attr(extension_node, "location");
+ plugin_desc.m_list_of_extensions.push_back(make_path(extension_location));
}
}
// fill value in plugin registry for later lazy initialization
- {
- PluginDescriptor desc{plugin_path, config, listOfExtentions};
- register_plugin_in_registry_unsafe(device_name, desc);
- }
+ register_plugin_in_registry_unsafe(device_name, plugin_desc);
}
}
@@ -706,7 +693,7 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
desc.m_plugin_create_func(plugin_impl);
plugin = Plugin{plugin_impl, {}};
} else {
- so = ov::util::load_shared_object(desc.m_lib_location.c_str());
+ so = ov::util::load_shared_object(desc.m_lib_location);
std::shared_ptr<ov::IPlugin> plugin_impl;
reinterpret_cast<ov::CreatePluginFunc*>(ov::util::get_symbol(so, ov::create_plugin_function))(plugin_impl);
const auto& plugin_name = plugin_impl->get_device_name();
diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hpp
index 1deb1900476..71ce6781789 100644
--- a/src/inference/src/dev/core_impl.hpp
+++ b/src/inference/src/dev/core_impl.hpp
@@ -169,19 +169,19 @@ private:
struct PluginDescriptor {
std::filesystem::path m_lib_location{};
ov::AnyMap m_default_config{};
- std::vector<ov::util::FilePath> m_list_of_extensions{};
+ std::vector<std::filesystem::path> m_list_of_extensions{};
CreatePluginEngineFunc* m_plugin_create_func = nullptr;
CreateExtensionFunc* m_extension_create_func = nullptr;
mutable std::vector<Extension::Ptr> m_extensions{}; // mutable because of lazy init
PluginDescriptor() = default;
- PluginDescriptor(const ov::util::FilePath& lib_location,
+ PluginDescriptor(const std::filesystem::path& lib_location,
const ov::AnyMap& default_config = {},
- const std::vector<ov::util::FilePath>& list_of_extentions = {})
+ const std::vector<std::filesystem::path>& list_of_extensions = {})
: m_lib_location(lib_location),
m_default_config(default_config),
- m_list_of_extensions(list_of_extentions) {}
+ m_list_of_extensions(list_of_extensions) {}
PluginDescriptor(CreatePluginEngineFunc* plugin_create_func,
const ov::AnyMap& default_config = {},
@@ -237,10 +237,10 @@ public:
/**
* @brief Register plugins for devices which are located in .xml configuration file.
* @note The function supports UNICODE path
- * @param xml_config_file An .xml configuraion with device / plugin information
+ * @param xml_config_file An .xml configuration with device / plugin information
* @param by_abs_path A boolean value - register plugins by absolute file path or not
*/
- void register_plugins_in_registry(const std::string& xml_config_file, const bool& by_abs_path = false);
+ void register_plugins_in_registry(const std::filesystem::path& xml_config_file, const bool by_abs_path = false);
std::shared_ptr<const ov::Model> apply_auto_batching(const std::shared_ptr<const ov::Model>& model,
std::string& device_name,
diff --git a/src/inference/tests/functional/caching_test.cpp b/src/inference/tests/functional/caching_test.cpp
index 6b7a631c73b..c60254a0ece 100644
--- a/src/inference/tests/functional/caching_test.cpp
+++ b/src/inference/tests/functional/caching_test.cpp
@@ -188,12 +188,6 @@ public:
std::shared_ptr<ov::Model> m_model;
std::map<std::string, std::shared_ptr<ov::Model>> m_models;
- static std::string get_mock_engine_path() {
- std::string mockEngineName("mock_engine");
- return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- mockEngineName + OV_BUILD_POSTFIX);
- }
-
void initParamTest() {
m_type = std::get<0>(std::get<0>(GetParam()));
m_cacheDir = std::get<1>(GetParam());
@@ -241,8 +235,8 @@ public:
initParamTest();
mockPlugin = std::make_shared<MockCachingIPlugin>();
setupMock(*mockPlugin);
- std::string libraryPath = get_mock_engine_path();
- sharedObjectLoader = ov::util::load_shared_object(libraryPath.c_str());
+ const auto libraryPath = ov::util::make_path(ov::test::utils::get_mock_engine_path());
+ sharedObjectLoader = ov::util::load_shared_object(libraryPath);
injectPlugin = make_std_function<void(ov::IPlugin*)>("InjectPlugin");
ov::pass::Manager manager;
diff --git a/src/inference/tests/functional/get_supported_property_test.cpp b/src/inference/tests/functional/get_supported_property_test.cpp
index 433e559e649..2b27af26ded 100644
--- a/src/inference/tests/functional/get_supported_property_test.cpp
+++ b/src/inference/tests/functional/get_supported_property_test.cpp
@@ -27,9 +27,10 @@ public:
}
void reg_plugin(ov::Core& core, std::shared_ptr<ov::IPlugin>& plugin) {
- std::string libraryPath = ov::test::utils::get_mock_engine_path();
- if (!m_so)
- m_so = ov::util::load_shared_object(libraryPath.c_str());
+ if (!m_so) {
+ const auto libraryPath = ov::test::utils::get_mock_engine_path();
+ m_so = ov::util::load_shared_object(libraryPath);
+ }
std::function<void(ov::IPlugin*)> injectProxyEngine =
ov::test::utils::make_std_function<void(ov::IPlugin*)>(m_so, "InjectPlugin");
diff --git a/src/inference/tests/functional/ov_core_test.cpp b/src/inference/tests/functional/ov_core_test.cpp
index 724dde89e2e..f361dd788aa 100644
--- a/src/inference/tests/functional/ov_core_test.cpp
+++ b/src/inference/tests/functional/ov_core_test.cpp
@@ -61,8 +61,8 @@ static void create_plugin_xml(const std::filesystem::path& file_name, const std:
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 << ov::test::utils::FileTraits<char>::file_separator;
+ file << ov::test::utils::FileTraits<char>::library_prefix();
file << "mock_engine";
file << OV_BUILD_POSTFIX;
file << ov::util::library_extension().string();
@@ -78,7 +78,7 @@ static void remove_plugin_xml(const std::filesystem::path& file_name) {
TEST_F(CoreBaseTest, LoadPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string xml_file_path =
- ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
+ ov::test::utils::getOpenvinoLibDirectory() + ov::test::utils::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);
@@ -118,7 +118,7 @@ TEST_P(CoreBaseTestP, registerPlugins) {
TEST_F(CoreBaseTest, LoadPluginDifferentXMLExtension) {
std::string xml_file_name = "test_plugin.test";
std::string xml_file_path =
- ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
+ ov::test::utils::getOpenvinoLibDirectory() + ov::test::utils::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);
@@ -127,7 +127,7 @@ TEST_F(CoreBaseTest, LoadPluginDifferentXMLExtension) {
TEST_F(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string xml_file_path =
- ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
+ ov::test::utils::getOpenvinoLibDirectory() + ov::test::utils::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);
@@ -136,7 +136,7 @@ TEST_F(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
TEST_F(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;
+ ov::test::utils::getCurrentWorkingDir() + ov::test::utils::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);
@@ -145,7 +145,7 @@ TEST_F(CoreBaseTest, LoadAbsoluteCWPathPluginXML) {
TEST_F(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;
+ ov::test::utils::getCurrentWorkingDir() + ov::test::utils::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);
@@ -154,9 +154,9 @@ TEST_F(CoreBaseTest, LoadRelativeCWPathPluginXML) {
TEST_F(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;
+ ov::test::utils::getCurrentWorkingDir() + ov::test::utils::FileTraits<char>::file_separator + xml_file_name;
std::string ov_file_path =
- ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
+ ov::test::utils::getOpenvinoLibDirectory() + ov::test::utils::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);
diff --git a/src/inference/tests/functional/ov_register_plugin_test.cpp b/src/inference/tests/functional/ov_register_plugin_test.cpp
index cd3afd0c826..dd265ecff2c 100644
--- a/src/inference/tests/functional/ov_register_plugin_test.cpp
+++ b/src/inference/tests/functional/ov_register_plugin_test.cpp
@@ -28,9 +28,10 @@ using namespace std;
namespace {
void mockPlugin(ov::Core& core, std::shared_ptr<ov::IPlugin>& plugin, std::shared_ptr<void>& m_so) {
- std::string libraryPath = ov::test::utils::get_mock_engine_path();
- if (!m_so)
- m_so = ov::util::load_shared_object(libraryPath.c_str());
+ if (!m_so) {
+ const auto libraryPath = ov::test::utils::get_mock_engine_path();
+ m_so = ov::util::load_shared_object(libraryPath);
+ }
std::function<void(ov::IPlugin*)> injectProxyEngine =
ov::test::utils::make_std_function<void(ov::IPlugin*)>(m_so, "InjectPlugin");
@@ -89,8 +90,8 @@ TEST(RegisterPluginTests, getVersionforNoRegisteredPluginNoThrows) {
}
namespace {
-int get_mock_extension_counter(const std::string& so_path) {
- auto so = ov::util::load_shared_object(so_path.c_str());
+int get_mock_extension_counter(const std::filesystem::path& so_path) {
+ auto so = ov::util::load_shared_object(so_path);
using CreateFunction = int();
auto extension_count = reinterpret_cast<CreateFunction*>(ov::util::get_symbol(so, "get_mock_extension_counter"))();
return extension_count;
@@ -101,8 +102,7 @@ TEST(RegisterPluginTests, removeExtensionOnPluginUnload) {
ov::Core core;
std::string mock_plugin_name{"MOCK_HARDWARE"};
- auto mock_plugin_path = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine") + OV_BUILD_POSTFIX);
+ auto mock_plugin_path = ov::test::utils::get_mock_engine_path();
EXPECT_EQ(get_mock_extension_counter(mock_plugin_path), 0);
OV_ASSERT_NO_THROW(core.register_plugin(mock_plugin_path, mock_plugin_name));
diff --git a/src/inference/tests/functional/ov_shared_object_test.cpp b/src/inference/tests/functional/ov_shared_object_test.cpp
index d9ba48246df..945c240b06c 100644
--- a/src/inference/tests/functional/ov_shared_object_test.cpp
+++ b/src/inference/tests/functional/ov_shared_object_test.cpp
@@ -9,18 +9,11 @@
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
-using namespace ::testing;
-using namespace std;
-
+namespace ov::test {
class SharedObjectOVTests : public ::testing::Test {
protected:
- std::string get_mock_engine_name() {
- return ov::util::make_plugin_library_name<char>(ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine") + OV_BUILD_POSTFIX);
- }
-
- void loadDll(const string& libraryName) {
- shared_object = ov::util::load_shared_object(libraryName.c_str());
+ void loadDll(const std::filesystem::path& library_name) {
+ shared_object = ov::util::load_shared_object(library_name);
}
std::shared_ptr<void> shared_object;
@@ -34,7 +27,7 @@ protected:
};
TEST_F(SharedObjectOVTests, canLoadExistedPlugin) {
- loadDll(get_mock_engine_name());
+ loadDll(utils::get_mock_engine_path());
EXPECT_NE(nullptr, shared_object.get());
}
@@ -43,21 +36,22 @@ TEST_F(SharedObjectOVTests, loaderThrowsIfNoPlugin) {
}
TEST_F(SharedObjectOVTests, canFindExistedMethod) {
- loadDll(get_mock_engine_name());
+ loadDll(utils::get_mock_engine_path());
auto factory = make_std_function(ov::create_plugin_function);
EXPECT_NE(nullptr, factory);
}
TEST_F(SharedObjectOVTests, throwIfMethodNofFoundInLibrary) {
- loadDll(get_mock_engine_name());
+ loadDll(utils::get_mock_engine_path());
EXPECT_THROW(make_std_function("wrong_function"), std::runtime_error);
}
TEST_F(SharedObjectOVTests, canCallExistedMethod) {
- loadDll(get_mock_engine_name());
+ loadDll(utils::get_mock_engine_path());
auto factory = make_std_function(ov::create_plugin_function);
std::shared_ptr<ov::IPlugin> ptr;
EXPECT_NO_THROW(factory(ptr));
}
+} // namespace ov::test
diff --git a/src/inference/tests/unit/core.cpp b/src/inference/tests/unit/core.cpp
index 2e3d9a81ee5..87d02dac1a7 100644
--- a/src/inference/tests/unit/core.cpp
+++ b/src/inference/tests/unit/core.cpp
@@ -16,7 +16,7 @@
#include "openvino/runtime/device_id_parser.hpp"
#include "openvino/util/file_util.hpp"
-using namespace ov::util;
+namespace ov::test {
TEST(CoreTests, Throw_on_register_plugin_twice) {
ov::Core core;
@@ -29,8 +29,8 @@ TEST(CoreTests, Throw_on_register_plugin_twice) {
TEST(CoreTests, Throw_on_register_plugins_twice) {
ov::Core core;
- auto get_plugin_xml = [&]() -> std::string {
- std::string plugins_xml = "test_plugins.xml";
+ auto get_plugin_xml = [] {
+ std::filesystem::path plugins_xml = "test_plugins.xml";
std::ofstream file(plugins_xml);
file << "<ie><plugins><plugin location=\"libtest_plugin.so\" name=\"TEST_DEVICE\"></plugin></plugins></ie>";
file.flush();
@@ -38,17 +38,22 @@ TEST(CoreTests, Throw_on_register_plugins_twice) {
return plugins_xml;
};
- core.register_plugins(get_plugin_xml());
+ const auto plugins_xml_path = get_plugin_xml();
+ core.register_plugins(plugins_xml_path);
OV_EXPECT_THROW(core.register_plugins(get_plugin_xml()),
ov::Exception,
::testing::HasSubstr("Device with \"TEST_DEVICE\" is already registered in the OpenVINO Runtime"));
+
+ if (ov::util::file_exists(plugins_xml_path)) {
+ std::ignore = std::filesystem::remove(plugins_xml_path);
+ }
}
TEST(CoreTests_get_plugin_path_from_xml, Use_abs_path_as_is) {
auto xml_path = std::filesystem::path("path_to_plugins.xml");
auto lib_path = std::filesystem::absolute("test_name.ext"); // CWD/test_name.ext
for (auto&& as_abs_only : {true, false}) {
- const auto abs_path = get_plugin_path(lib_path, xml_path, as_abs_only);
+ const auto abs_path = ov::util::get_plugin_path(lib_path, xml_path, as_abs_only);
EXPECT_TRUE(abs_path.is_absolute());
EXPECT_EQ(abs_path, lib_path);
}
@@ -58,7 +63,7 @@ TEST(CoreTests_get_plugin_path_from_xml, Convert_relative_path_as_relative_to_xm
auto xml_path = std::filesystem::path("path_to_plugins.xml");
auto lib_path = std::filesystem::path(".") / "test_name.ext"; // ./test_name.ext
for (auto&& as_abs_only : {true, false}) {
- const auto abs_path = get_plugin_path(lib_path, xml_path, as_abs_only);
+ const auto abs_path = ov::util::get_plugin_path(lib_path, xml_path, as_abs_only);
EXPECT_TRUE(abs_path.is_absolute());
const auto ref_path = std::filesystem::absolute(std::filesystem::weakly_canonical(lib_path));
@@ -68,8 +73,8 @@ TEST(CoreTests_get_plugin_path_from_xml, Convert_relative_path_as_relative_to_xm
TEST(CoreTests_get_plugin_path_from_xml, Convert_filename_to_abs_path_if_as_abs_only) {
auto xml_path = std::filesystem::path("path_to_plugins.xml");
- auto name = std::filesystem::path("test_name.ext"); // test_name.ext
- auto abs_path = get_plugin_path(name, xml_path, true); // XMLDIR/libtest_name.ext.so
+ auto name = std::filesystem::path("test_name.ext"); // test_name.ext
+ auto abs_path = ov::util::get_plugin_path(name, xml_path, true); // XMLDIR/libtest_name.ext.so
EXPECT_TRUE(abs_path.is_absolute());
auto lib_name = ov::util::make_plugin_library_name(name);
@@ -79,8 +84,8 @@ TEST(CoreTests_get_plugin_path_from_xml, Convert_filename_to_abs_path_if_as_abs_
TEST(CoreTests_get_plugin_path_from_xml, Use_filename_if_not_as_abs_only) {
auto xml_path = std::filesystem::path("path_to_plugins.xml");
- auto name = std::filesystem::path("test_name.ext"); // test_name.ext
- auto lib_name = get_plugin_path(name, xml_path); // libtest_name.ext.so
+ auto name = std::filesystem::path("test_name.ext"); // test_name.ext
+ auto lib_name = ov::util::get_plugin_path(name, xml_path); // libtest_name.ext.so
auto ref_name = ov::util::make_plugin_library_name(name);
EXPECT_EQ(lib_name, ref_name);
}
@@ -88,14 +93,14 @@ TEST(CoreTests_get_plugin_path_from_xml, Use_filename_if_not_as_abs_only) {
TEST(CoreTests_get_plugin_path, Use_abs_path_as_is) {
auto lib_name = ov::util::make_plugin_library_name("test_name"); // libtest_name.so
auto lib_path = std::filesystem::absolute(std::filesystem::weakly_canonical("." / lib_name));
- auto abs_path = get_plugin_path(lib_path);
+ auto abs_path = ov::util::get_plugin_path(lib_path);
EXPECT_TRUE(abs_path.is_absolute());
EXPECT_EQ(abs_path, lib_path);
}
TEST(CoreTests_get_plugin_path, Relative_path_is_from_workdir) {
auto lib_name = ov::util::make_plugin_library_name(".", "test_name"); // ./libtest_name.so
- auto abs_path = get_plugin_path(lib_name);
+ auto abs_path = ov::util::get_plugin_path(lib_name);
EXPECT_TRUE(abs_path.is_absolute());
EXPECT_EQ(abs_path, std::filesystem::absolute(std::filesystem::weakly_canonical(lib_name)));
}
@@ -121,14 +126,14 @@ public:
};
TEST_F(CoreTests_get_plugin_path_Class, Filename_is_from_workdir_if_exists) {
- auto abs_path = get_plugin_path(lib_name); // libtest_name.so -> CWD/libtest_name.so
+ auto abs_path = ov::util::get_plugin_path(lib_name); // libtest_name.so -> CWD/libtest_name.so
EXPECT_TRUE(abs_path.is_absolute());
EXPECT_EQ(abs_path, std::filesystem::absolute(std::filesystem::weakly_canonical(lib_name)));
}
TEST(CoreTests_get_plugin_path, Use_filename_as_is_if_not_exist_in_workdir) {
auto lib_name = "test_name.ext";
- auto abs_path = get_plugin_path(lib_name); // libtest_name.ext.so -> libtest_name.ext.so
+ auto abs_path = ov::util::get_plugin_path(lib_name); // test_name.ext -> libtest_name.ext.so
EXPECT_FALSE(abs_path.is_absolute());
auto ref_path = ov::util::make_plugin_library_name(lib_name);
@@ -488,3 +493,4 @@ TEST_F(ApplyAutoBatchThreading, ApplyAutoBatch) {
core.apply_auto_batching(model, device, config);
});
}
+} // namespace ov::test
diff --git a/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp b/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp
index 3d916958092..f91a64a29b9 100644
--- a/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp
+++ b/src/plugins/auto/tests/functional/behavior/auto_func_test.cpp
@@ -26,12 +26,6 @@
namespace {
-std::string get_mock_engine_path() {
- std::string mockEngineName("mock_engine");
- return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- mockEngineName + OV_BUILD_POSTFIX);
-}
-
template <class T>
std::function<T> make_std_function(const std::shared_ptr<void> so, const std::string& functionName) {
std::function<T> ptr(reinterpret_cast<T*>(ov::util::get_symbol(so, functionName.c_str())));
@@ -619,9 +613,10 @@ void ov::auto_plugin::tests::AutoFuncTests::reg_plugin(ov::Core& core,
std::shared_ptr<ov::IPlugin>& plugin,
const std::string& device_name,
const ov::AnyMap& properties) {
- std::string libraryPath = get_mock_engine_path();
- if (!m_so)
- m_so = ov::util::load_shared_object(libraryPath.c_str());
+ if (!m_so) {
+ const auto libraryPath = ov::test::utils::get_mock_engine_path();
+ m_so = ov::util::load_shared_object(libraryPath);
+ }
plugin->set_device_name(device_name);
std::function<void(ov::IPlugin*)> injectProxyEngine = make_std_function<void(ov::IPlugin*)>(m_so, "InjectPlugin");
diff --git a/src/plugins/hetero/tests/functional/hetero_tests.cpp b/src/plugins/hetero/tests/functional/hetero_tests.cpp
index f37d87a538f..ab37768d942 100644
--- a/src/plugins/hetero/tests/functional/hetero_tests.cpp
+++ b/src/plugins/hetero/tests/functional/hetero_tests.cpp
@@ -29,12 +29,6 @@
namespace {
-std::string get_mock_engine_path() {
- std::string mock_engine_name("mock_engine");
- return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- mock_engine_name + OV_BUILD_POSTFIX);
-}
-
template <class T>
std::function<T> make_std_function(const std::shared_ptr<void> so, const std::string& functionName) {
std::function<T> ptr(reinterpret_cast<T*>(ov::util::get_symbol(so, functionName.c_str())));
@@ -893,9 +887,10 @@ private:
};
void ov::hetero::tests::HeteroTests::reg_plugin(std::shared_ptr<ov::IPlugin>& plugin) {
- std::string library_path = get_mock_engine_path();
- if (!m_so)
- m_so = ov::util::load_shared_object(library_path.c_str());
+ const auto library_path = ov::test::utils::get_mock_engine_path();
+ if (!m_so) {
+ m_so = ov::util::load_shared_object(library_path);
+ }
if (auto mock_plugin = std::dynamic_pointer_cast<MockPluginBase>(plugin))
mock_plugin->set_version(mock_plugin->get_const_version());
std::function<void(ov::IPlugin*)> injectProxyEngine = make_std_function<void(ov::IPlugin*)>(m_so, "InjectPlugin");
diff --git a/src/plugins/intel_cpu/src/utils/graph_serializer/deserializer.cpp b/src/plugins/intel_cpu/src/utils/graph_serializer/deserializer.cpp
index bf3718bd4bb..24fb161e3ae 100644
--- a/src/plugins/intel_cpu/src/utils/graph_serializer/deserializer.cpp
+++ b/src/plugins/intel_cpu/src/utils/graph_serializer/deserializer.cpp
@@ -35,6 +35,7 @@
#include "openvino/runtime/icore.hpp"
#include "openvino/runtime/shared_buffer.hpp"
#include "openvino/runtime/tensor.hpp"
+#include "openvino/util/file_util.hpp"
#include "openvino/util/mmap_object.hpp"
#include "openvino/util/xml_parse_utils.hpp"
#include "openvino/xml_util/xml_deserialize_util.hpp"
@@ -51,7 +52,7 @@ ModelDeserializer::ModelDeserializer(std::shared_ptr<ov::AlignedBuffer>& model_b
m_core(core),
m_decript_from_string(decript_from_string) {
if (!origin_weights_path.empty() && std::filesystem::exists(origin_weights_path)) {
- auto mmap = ov::load_mmap_object(origin_weights_path);
+ auto mmap = ov::load_mmap_object(ov::util::make_path(origin_weights_path));
m_origin_weights_buf =
std::make_shared<ov::SharedBuffer<std::shared_ptr<MappedMemory>>>(mmap->data(), mmap->size(), mmap);
}
@@ -72,7 +73,7 @@ ModelDeserializer::ModelDeserializer(std::istream& model_stream,
m_core(core),
m_decript_from_string(decript_from_string) {
if (!origin_weights_path.empty() && std::filesystem::exists(origin_weights_path)) {
- auto mmap = ov::load_mmap_object(origin_weights_path);
+ auto mmap = ov::load_mmap_object(ov::util::make_path(origin_weights_path));
m_origin_weights_buf =
std::make_shared<ov::SharedBuffer<std::shared_ptr<MappedMemory>>>(mmap->data(), mmap->size(), mmap);
}
diff --git a/src/plugins/intel_cpu/tests/functional/custom/extension/extension.cpp b/src/plugins/intel_cpu/tests/functional/custom/extension/extension.cpp
index 93136c8a773..0971e6bf09e 100644
--- a/src/plugins/intel_cpu/tests/functional/custom/extension/extension.cpp
+++ b/src/plugins/intel_cpu/tests/functional/custom/extension/extension.cpp
@@ -66,8 +66,9 @@ static void infer_model(ov::Core& core,
}
static std::string model_full_path(const char* path) {
- return ov::util::make_path<char>(ov::util::make_path<char>(ov::test::utils::getExecutableDirectory(), TEST_MODELS),
- path);
+ return ov::test::utils::makePath<char>(
+ ov::test::utils::makePath<char>(ov::test::utils::getExecutableDirectory(), TEST_MODELS),
+ path);
}
TEST(DISABLED_Extension, XmlModelWithCustomAbs) {
diff --git a/src/plugins/intel_gpu/src/graph/debug_helper.cpp b/src/plugins/intel_gpu/src/graph/debug_helper.cpp
index 807370f3385..6e664047332 100644
--- a/src/plugins/intel_gpu/src/graph/debug_helper.cpp
+++ b/src/plugins/intel_gpu/src/graph/debug_helper.cpp
@@ -472,7 +472,7 @@ NodeDebugHelper::NodeDebugHelper(const primitive_inst& inst)
auto filename = get_file_path_for_binary_dump(input_layout, name, config.get_dump_tensors_path());
mem_lock<char, mem_lock_type::read> lock(input_mem, m_stream);
- ov::util::save_binary(filename, lock.data(), input_mem->size());
+ ov::util::save_binary(ov::util::make_path(filename), lock.data(), input_mem->size());
GPU_DEBUG_COUT << " Dump layer src : " << layer_name << " to " << filename << std::endl;
debug_str_for_bin_load += (filename + ",");
} else {
@@ -532,7 +532,7 @@ NodeDebugHelper::~NodeDebugHelper() {
auto filename = get_file_path_for_binary_dump(output_layout, name, config.get_dump_tensors_path());
mem_lock<char, mem_lock_type::read> lock(output_mem, m_stream);
- ov::util::save_binary(filename, lock.data(), output_mem->size());
+ ov::util::save_binary(ov::util::make_path(filename), lock.data(), output_mem->size());
GPU_DEBUG_COUT << " Dump layer dst : " << layer_name << " to " << filename << std::endl;
debug_str_for_bin_load += (filename + ",");
} else {
@@ -561,7 +561,7 @@ NodeDebugHelper::~NodeDebugHelper() {
auto filename = get_file_path_for_binary_dump(output_layout, name, config.get_dump_tensors_path());
mem_lock<char, mem_lock_type::read> lock(output_mem, m_stream);
- ov::util::save_binary(filename, lock.data(), output_mem->size());
+ ov::util::save_binary(ov::util::make_path(filename), lock.data(), output_mem->size());
GPU_DEBUG_COUT << " Dump layer dst : " << layer_name << " to " << filename << std::endl;
debug_str_for_bin_load += (filename + ",");
} else {
@@ -588,7 +588,7 @@ NodeDebugHelper::~NodeDebugHelper() {
auto filename = get_file_path_for_binary_dump(output_layout, name, config.get_dump_tensors_path());
mem_lock<char, mem_lock_type::read> lock(output_mem, m_stream);
- ov::util::save_binary(filename, lock.data(), output_mem->size());
+ ov::util::save_binary(ov::util::make_path(filename), lock.data(), output_mem->size());
GPU_DEBUG_COUT << " Dump layer dst : " << layer_name << " to " << filename << std::endl;
debug_str_for_bin_load += (filename + ",");
} else {
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp
index 6670c05f32a..836e81ddb0e 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp
@@ -371,7 +371,7 @@ void kernels_cache::build_batch(const batch_program& batch, compiled_kernels& co
std::vector<uint8_t> bin;
{
std::lock_guard<std::mutex> lock(cacheAccessMutex);
- bin = ov::util::load_binary(cached_bin_name);
+ bin = ov::util::load_binary(ov::util::make_path(cached_bin_name));
}
if (!bin.empty()) {
precompiled_kernels.push_back(bin);
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
index f6cd1fd1aca..f4a90a40f32 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
@@ -354,7 +354,7 @@ private:
std::vector<uint8_t> cache;
{
std::lock_guard<std::mutex> lock(cacheAccessMutex);
- cache = ov::util::load_binary(generate_cache_path_from_key(config, key));
+ cache = ov::util::load_binary(ov::util::make_path(generate_cache_path_from_key(config, key)));
}
if (cache.empty()) {
diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cpp
index 8feb7aaf10a..da2af60a31f 100644
--- a/src/plugins/intel_gpu/src/graph/program.cpp
+++ b/src/plugins/intel_gpu/src/graph/program.cpp
@@ -9,6 +9,7 @@
#include "openvino/runtime/system_conf.hpp"
#include "openvino/runtime/threading/cpu_streams_info.hpp"
#include "openvino/util/weights_path.hpp"
+#include "openvino/util/file_util.hpp"
#include "intel_gpu/runtime/memory.hpp"
#include "intel_gpu/runtime/engine.hpp"
@@ -1961,7 +1962,7 @@ void program::load(cldnn::BinaryInputBuffer& ib,
}
} else if (!weights_path.empty()) {
ov::util::validate_weights_path(weights_path);
- weights_memory = std::make_shared<WeightsMemory>(ov::load_mmap_object(weights_path));
+ weights_memory = std::make_shared<WeightsMemory>(ov::load_mmap_object(ov::util::make_path(weights_path)));
} else {
OPENVINO_THROW("Weights path or model is required for cache mode OPTIMIZE_SIZE");
}
diff --git a/src/plugins/intel_gpu/src/runtime/file_util.cpp b/src/plugins/intel_gpu/src/runtime/file_util.cpp
index 81cd4843e48..b8eca5b4a66 100644
--- a/src/plugins/intel_gpu/src/runtime/file_util.cpp
+++ b/src/plugins/intel_gpu/src/runtime/file_util.cpp
@@ -9,7 +9,7 @@ namespace ov::intel_gpu {
void save_binary(const std::string &path, const std::vector<uint8_t>& binary) {
try {
- ov::util::save_binary(path, binary);
+ ov::util::save_binary(ov::util::make_path(path), binary.data(), binary.size());
} catch (std::runtime_error&) {}
}
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
index bcaec570e00..0621aa0d3be 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
@@ -180,16 +180,11 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
}
VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) {
- const std::string baseName = "openvino_intel_npu_compiler";
+ const std::filesystem::path baseName = "openvino_intel_npu_compiler";
try {
auto libpath = ov::util::make_plugin_library_name({}, baseName);
_logger.debug("Try to load openvino_intel_npu_compiler");
-
-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
- this->lib = ov::util::load_shared_object(ov::util::string_to_wstring(libpath).c_str());
-#else
- this->lib = ov::util::load_shared_object(libpath.c_str());
-#endif
+ this->lib = ov::util::load_shared_object(libpath);
} catch (const std::runtime_error& error) {
_logger.debug("Failed to load openvino_intel_npu_compiler");
OPENVINO_THROW(error.what());
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
index 7839a9181a8..3b5fc0adf5c 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
@@ -27,14 +27,6 @@
namespace {
-std::shared_ptr<void> load_library(const std::string& libpath) {
-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
- return ov::util::load_shared_object(ov::util::string_to_wstring(libpath).c_str());
-#else
- return ov::util::load_shared_object(libpath.c_str());
-#endif
-}
-
std::shared_ptr<intel_npu::ICompiler> get_compiler(std::shared_ptr<void> so) {
static constexpr auto CreateFuncName = "CreateNPUCompiler";
auto symbol = ov::util::get_symbol(so, CreateFuncName);
@@ -47,8 +39,8 @@ std::shared_ptr<intel_npu::ICompiler> get_compiler(std::shared_ptr<void> so) {
return compilerPtr;
}
-ov::SoPtr<intel_npu::ICompiler> load_compiler(const std::string& libpath) {
- auto compilerSO = load_library(libpath);
+ov::SoPtr<intel_npu::ICompiler> load_compiler(const std::filesystem::path& libpath) {
+ auto compilerSO = ov::util::load_shared_object(libpath);
auto compiler = get_compiler(compilerSO);
return ov::SoPtr<intel_npu::ICompiler>(compiler, compilerSO);
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
index c9884a011bf..2f1ee116408 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
@@ -33,6 +33,7 @@
#include "openvino/runtime/device_id_parser.hpp"
#include "openvino/runtime/internal_properties.hpp"
#include "openvino/runtime/properties.hpp"
+#include "openvino/util/file_util.hpp"
#include "transformations/convert_precision.hpp"
namespace {
@@ -1288,7 +1289,7 @@ std::shared_ptr<ov::npuw::CompiledModel> ov::npuw::CompiledModel::deserialize(
ov::FileHandle handle = handle_provider();
mapped_memory = ov::load_mmap_object(handle);
} else if (!weights_path.empty()) {
- mapped_memory = ov::load_mmap_object(weights_path);
+ mapped_memory = ov::load_mmap_object(ov::util::make_path(weights_path));
}
if (mapped_memory) {
weights = std::make_shared<ov::npuw::s11n::Weights>(mapped_memory->data(),
diff --git a/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp b/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp
index aaa0aaea97a..cd59bfe04b7 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp
@@ -14,6 +14,7 @@
#include "openvino/reference/convert.hpp"
#include "openvino/runtime/make_tensor.hpp"
#include "openvino/runtime/shared_buffer.hpp"
+#include "openvino/util/file_util.hpp"
#include "openvino/util/mmap_object.hpp"
#include "util.hpp"
@@ -70,7 +71,7 @@ ov::Tensor Const::eval() const {
ov::FileHandle handle = m_handle_provider();
mapped_memory = ov::load_mmap_object(handle);
} else {
- mapped_memory = ov::load_mmap_object(m_weights_path);
+ mapped_memory = ov::load_mmap_object(ov::util::make_path(m_weights_path));
}
m_mmaped_weights =
std::make_shared<ov::npuw::s11n::Weights>(mapped_memory->data(), mapped_memory->size(), mapped_memory);
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_api.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_api.cpp
index 76e8e7ea3b7..8c6875dfb95 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_api.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_api.cpp
@@ -11,18 +11,13 @@
namespace intel_npu {
ZeroApi::ZeroApi() {
- const std::string baseName = "ze_loader";
+ const std::filesystem::path baseName = "ze_loader";
try {
auto libpath = ov::util::make_plugin_library_name({}, baseName);
#if !defined(_WIN32) && !defined(ANDROID)
- libpath = libpath + LIB_ZE_LOADER_SUFFIX;
-#endif
-
-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
- this->lib = ov::util::load_shared_object(ov::util::string_to_wstring(libpath).c_str());
-#else
- this->lib = ov::util::load_shared_object(libpath.c_str());
+ libpath += LIB_ZE_LOADER_SUFFIX;
#endif
+ this->lib = ov::util::load_shared_object(libpath);
} catch (const std::runtime_error& error) {
OPENVINO_THROW(error.what());
}
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/mocks/register_in_ov.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/mocks/register_in_ov.cpp
index 86db405b809..2107541944f 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/mocks/register_in_ov.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/mocks/register_in_ov.cpp
@@ -11,16 +11,15 @@ namespace npuw {
namespace tests {
std::shared_ptr<void> reg_plugin(ov::Core& core, std::shared_ptr<ov::IPlugin>& plugin) {
- std::string mock_engine_path = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine") + OV_BUILD_POSTFIX);
- std::string plugin_path = ov::util::make_plugin_library_name(
- ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine_") + plugin->get_device_name() + OV_BUILD_POSTFIX);
+ const auto mock_engine_path = ov::test::utils::get_mock_engine_path();
+ const auto plugin_path =
+ ov::util::make_plugin_library_name(ov::util::make_path(ov::test::utils::getExecutableDirectory()),
+ std::string("mock_engine_") + plugin->get_device_name() + OV_BUILD_POSTFIX);
if (!std::filesystem::is_regular_file(plugin_path)) {
std::filesystem::copy(mock_engine_path, plugin_path);
}
- auto so = ov::util::load_shared_object(plugin_path.c_str());
+ auto so = ov::util::load_shared_object(plugin_path);
std::function<void(ov::IPlugin*)> injectProxyEngine =
make_std_function<void(ov::IPlugin*)>(so, "InjectPlugin");
diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/core_integration.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/core_integration.hpp
index e2ab0ac3adb..1014c9d50d8 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/core_integration.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_plugin/core_integration.hpp
@@ -99,7 +99,8 @@ public:
void TearDown() override {
for (std::size_t testIndex = 0; testIndex < ov::test::utils::test_unicode_postfix_vector.size(); testIndex++) {
std::wstring postfix = ov::test::utils::test_unicode_postfix_vector[testIndex];
- std::wstring unicode_path = ov::test::utils::stringToWString(ov::util::get_ov_lib_path() + "/") + postfix;
+ std::wstring unicode_path =
+ ov::test::utils::stringToWString(ov::util::path_to_string(ov::util::get_ov_lib_path()) + "/") + postfix;
#ifndef _WIN32
removeDirFilesRecursive(ov::util::wstring_to_string(unicode_path));
#else
diff --git a/src/plugins/proxy/tests/proxy_tests.cpp b/src/plugins/proxy/tests/proxy_tests.cpp
index dd7c44a4d87..bc73ca065cb 100644
--- a/src/plugins/proxy/tests/proxy_tests.cpp
+++ b/src/plugins/proxy/tests/proxy_tests.cpp
@@ -24,12 +24,6 @@
namespace {
-std::string get_mock_engine_path() {
- std::string mockEngineName("mock_engine");
- return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- mockEngineName + OV_BUILD_POSTFIX);
-}
-
template <class T>
std::function<T> make_std_function(const std::shared_ptr<void> so, const std::string& functionName) {
std::function<T> ptr(reinterpret_cast<T*>(ov::util::get_symbol(so, functionName.c_str())));
@@ -492,9 +486,10 @@ void ov::proxy::tests::ProxyTests::reg_plugin(ov::Core& core,
std::shared_ptr<ov::IPlugin>& plugin,
const std::string& device_name,
const ov::AnyMap& properties) {
- std::string libraryPath = get_mock_engine_path();
- if (!m_so)
- m_so = ov::util::load_shared_object(libraryPath.c_str());
+ if (!m_so) {
+ const auto libraryPath = ov::test::utils::get_mock_engine_path();
+ m_so = ov::util::load_shared_object(libraryPath);
+ }
if (auto mock_plugin = std::dynamic_pointer_cast<MockPluginBase>(plugin))
mock_plugin->set_version(mock_plugin->get_const_version());
plugin->set_device_name(device_name);
diff --git a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp
index 43445b82448..45eaa4e013c 100644
--- a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp
+++ b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp
@@ -359,15 +359,16 @@ TEST_P(CompileModelLoadFromFileTestBase, CanLoadFromFileWithoutException) {
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
TEST_P(CompileModelLoadFromFileTestBase, CanCreateCacheDirAndDumpBinariesUnicodePath) {
- std::string cache_path = ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator +
- "compiledModel_" + utils::generateTestFilePrefix() + "_cache";
+ std::string cache_path = ov::test::utils::getCurrentWorkingDir() +
+ ov::test::utils::FileTraits<char>::file_separator + "compiledModel_" +
+ utils::generateTestFilePrefix() + "_cache";
std::wstring postfix = L"_" + ov::test::utils::test_unicode_postfix_vector[0];
std::wstring cache_path_w = ov::util::string_to_wstring(cache_path) + postfix;
auto cache_path_mb = ov::util::wstring_to_string(cache_path_w);
std::wstring model_xml_path_w =
- ov::util::string_to_wstring(cache_path_mb + ov::util::FileTraits<char>::file_separator + m_modelName);
+ ov::util::string_to_wstring(cache_path_mb + ov::test::utils::FileTraits<char>::file_separator + m_modelName);
std::wstring model_bin_path_w =
- ov::util::string_to_wstring(cache_path_mb + ov::util::FileTraits<char>::file_separator + m_weightsName);
+ ov::util::string_to_wstring(cache_path_mb + ov::test::utils::FileTraits<char>::file_separator + m_weightsName);
try {
ov::test::utils::createDirectory(cache_path_w);
diff --git a/src/tests/functional/plugin/conformance/op_conformance_utils/src/utils/file.cpp b/src/tests/functional/plugin/conformance/op_conformance_utils/src/utils/file.cpp
index 25f722e8426..3f1e84303dc 100644
--- a/src/tests/functional/plugin/conformance/op_conformance_utils/src/utils/file.cpp
+++ b/src/tests/functional/plugin/conformance/op_conformance_utils/src/utils/file.cpp
@@ -21,21 +21,18 @@ get_filelist_recursive(const std::vector<std::string>& dir_paths,
std::string msg = "Input directory (" + dir_path + ") doesn't not exist!";
throw std::runtime_error(msg);
}
- ov::util::iterate_files(
- dir_path,
- [&result, &patterns](const std::string& file_path, bool is_dir) {
- auto file = ov::util::get_file_name(file_path);
- if (ov::util::file_exists(file_path)) {
- for (const auto& pattern : patterns) {
- if (std::regex_match(file_path, pattern)) {
- result.push_back(file_path);
- break;
- }
- }
- }
- },
- true,
- false);
+ ov::util::recursive_iterate_files(ov::util::make_path(dir_path),
+ [&result, &patterns](const std::filesystem::path& file_path) {
+ if (ov::util::file_exists(file_path)) {
+ for (const auto& pattern : patterns) {
+ if (auto file_path_str = ov::util::path_to_string(file_path);
+ std::regex_match(file_path_str, pattern)) {
+ result.push_back(std::move(file_path_str));
+ break;
+ }
+ }
+ }
+ });
}
return result;
}
@@ -96,4 +93,4 @@ split_str(std::string paths, const char delimiter) {
}
} // namespace util
-} // namespace ov
\ No newline at end of file
+} // namespace ov
diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp
index 78a0a7bb961..c7e548a4b6d 100644
--- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp
+++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/main.cpp
@@ -25,9 +25,11 @@ int main(int argc, char *argv[]) {
if (!FLAGS_device.empty() && !FLAGS_plugin_lib_name.empty()) {
try {
- auto plugin_path = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), std::string(FLAGS_plugin_lib_name) + OV_BUILD_POSTFIX);
+ auto plugin_path = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(),
+ FLAGS_plugin_lib_name + OV_BUILD_POSTFIX);
if (!ov::util::file_exists(plugin_path)) {
- throw std::runtime_error("[ WARNING ][ GRAPH CACHE ] Plugin: " + plugin_path + " does not exists!");
+ throw std::runtime_error("[ WARNING ][ GRAPH CACHE ] Plugin: " + ov::util::path_to_string(plugin_path) +
+ " does not exist!");
}
ov::util::core->register_plugin(plugin_path, FLAGS_device);
std::cout << "[ INFO ] Device: " << FLAGS_device << " is registred in OV core with " << FLAGS_plugin_lib_name << " lib" << std::endl;
diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp
index 3ee4a254c6c..3096dfedefd 100644
--- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp
+++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp
@@ -19,9 +19,12 @@ void FusedNamesExtractor::set_target_device(const std::string& _device) {
auto available_devices = ov::util::core->get_available_devices();
if (_device == std::string("TEMPLATE") &&
std::find(available_devices.begin(), available_devices.end(), _device) == available_devices.end()) {
- auto plugin_path = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), std::string("openvino_template_plugin") + OV_BUILD_POSTFIX);
+ auto plugin_path =
+ ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(),
+ std::string("openvino_template_plugin") + OV_BUILD_POSTFIX);
if (!ov::util::file_exists(plugin_path)) {
- throw std::runtime_error("[ WARNING ][ GRAPH CACHE ] Plugin: " + plugin_path + " does not exists!");
+ throw std::runtime_error("[ WARNING ][ GRAPH CACHE ] Plugin: " + ov::util::path_to_string(plugin_path) +
+ " does not exist!");
}
ov::util::core->register_plugin(plugin_path, _device);
available_devices = ov::util::core->get_available_devices();
diff --git a/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp b/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp
index 6dc813f0664..30f6f077f08 100644
--- a/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp
+++ b/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp
@@ -22,8 +22,9 @@ void QuantizedModelsTests::SetUp() {
}
static std::string getModelFullPath(const char* path) {
- return ov::util::make_path<char>(ov::util::make_path<char>(ov::test::utils::getExecutableDirectory(), TEST_MODELS),
- path);
+ return ov::test::utils::makePath<char>(
+ ov::test::utils::makePath<char>(ov::test::utils::getExecutableDirectory(), TEST_MODELS),
+ path);
}
void QuantizedModelsTests::run_model(const char* model, const LayerInputTypes& expected_layer_input_types, float thr) {
diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp
index 3eb993434d8..5650fefcb36 100644
--- a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp
+++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp
@@ -14,6 +14,7 @@
#include <vector>
#include "common_test_utils/common_utils.hpp"
+#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/test_constants.hpp"
#include "common_test_utils/w_dirent.h"
#include "openvino/runtime/internal_properties.hpp"
@@ -28,9 +29,69 @@
# include <unistd.h>
#endif // _WIN32
-namespace ov {
-namespace test {
-namespace utils {
+namespace ov::test::utils {
+
+/// OS specific file traits
+template <class C>
+struct FileTraits;
+
+template <>
+struct FileTraits<char> {
+ static constexpr const auto file_separator =
+#ifdef _WIN32
+ '\\';
+#else
+ '/';
+#endif
+ static constexpr const auto dot_symbol = '.';
+ static std::string library_ext() {
+#ifdef _WIN32
+ return {"dll"};
+#else
+ return {"so"};
+#endif
+ }
+ static std::string library_prefix() {
+#ifdef _WIN32
+# if defined(__MINGW32__) || defined(__MINGW64__)
+ return {"lib"};
+# else
+ return {""};
+# endif
+#else
+ return {"lib"};
+#endif
+ }
+};
+
+template <>
+struct FileTraits<wchar_t> {
+ static constexpr const auto file_separator =
+#ifdef _WIN32
+ L'\\';
+#else
+ L'/';
+#endif
+ static constexpr const auto dot_symbol = L'.';
+ static std::wstring library_ext() {
+#ifdef _WIN32
+ return {L"dll"};
+#else
+ return {L"so"};
+#endif
+ }
+ static std::wstring library_prefix() {
+#ifdef _WIN32
+# if defined(__MINGW32__) || defined(__MINGW64__)
+ return {L"lib"};
+# else
+ return {L""};
+# endif
+#else
+ return {L"lib"};
+#endif
+ }
+};
template <class T>
inline std::string to_string_c_locale(T value) {
@@ -40,10 +101,9 @@ inline std::string to_string_c_locale(T value) {
return val_stream.str();
}
-inline std::string makePath(const std::string& folder, const std::string& file) {
- if (folder.empty())
- return file;
- return folder + FileSeparator + file;
+template <class C, std::enable_if_t<(std::is_same_v<C, char> || std::is_same_v<C, wchar_t>)>* = nullptr>
+inline std::basic_string<C> makePath(const std::basic_string<C>& folder, const std::basic_string<C>& file) {
+ return folder.empty() ? file : folder + FileTraits<C>::file_separator + file;
}
inline long long fileSize(const char* fileName) {
@@ -181,9 +241,9 @@ std::string getCurrentWorkingDir();
std::string getRelativePath(const std::string& from, const std::string& to);
namespace {
-inline std::string get_mock_engine_path() {
+inline std::filesystem::path get_mock_engine_path() {
std::string mockEngineName("mock_engine");
- return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
+ return ov::util::make_plugin_library_name(ov::util::make_path(ov::test::utils::getExecutableDirectory()),
mockEngineName + OV_BUILD_POSTFIX);
}
@@ -270,6 +330,4 @@ using StringPathVariant = std::variant<std::string, std::u16string, std::u32stri
std::filesystem::path to_fs_path(const StringPathVariant& param);
-} // namespace utils
-} // namespace test
-} // namespace ov
+} // namespace ov::test::utils
diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp
index b2f699137d3..9a1d8af766b 100644
--- a/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp
+++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp
@@ -10,6 +10,7 @@
#include <vector>
#include "common_test_utils/common_utils.hpp"
+#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/w_dirent.h"
#include "gtest/gtest.h"
#include "openvino/util/file_util.hpp"
@@ -96,7 +97,7 @@ inline int removeFilesWithExt(std::wstring path, std::wstring ext) {
_WDIR* dir = _wopendir(path.c_str());
if (dir != nullptr) {
while ((ent = _wreaddir(dir)) != NULL) {
- auto file = ov::util::make_path(path, std::wstring(ent->wd_name));
+ auto file = makePath(path, std::wstring(ent->wd_name));
struct _stat64i32 stat_path;
_wstat(file.c_str(), &stat_path);
if (!S_ISDIR(stat_path.st_mode) && endsWith(file, L"." + ext)) {
@@ -122,7 +123,7 @@ inline int removeFilesWithExt(std::wstring path, std::wstring ext) {
DIR* dir = opendir(path_mb.c_str());
if (dir != nullptr) {
while ((ent = readdir(dir)) != NULL) {
- std::string file = ov::util::make_path(path_mb, std::string(ent->d_name));
+ std::string file = makePath(path_mb, std::string(ent->d_name));
struct stat stat_path;
stat(file.c_str(), &stat_path);
if (!S_ISDIR(stat_path.st_mode) && endsWith(file, "." + ext_mb)) {
diff --git a/src/tests/test_utils/common_test_utils/src/file_utils.cpp b/src/tests/test_utils/common_test_utils/src/file_utils.cpp
index 273474c5ffa..883ac1943cc 100644
--- a/src/tests/test_utils/common_test_utils/src/file_utils.cpp
+++ b/src/tests/test_utils/common_test_utils/src/file_utils.cpp
@@ -22,16 +22,13 @@
#endif
#include "openvino/util/variant_visitor.hpp"
-namespace ov {
-namespace test {
-namespace utils {
-
+namespace ov::test::utils {
namespace {
template <typename C,
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
std::basic_string<C> get_path_name(const std::basic_string<C>& s) {
- size_t i = s.rfind(ov::util::FileTraits<C>::file_separator, s.length());
+ size_t i = s.rfind(FileTraits<C>::file_separator, s.length());
if (i != std::string::npos) {
return (s.substr(0, i));
}
@@ -60,7 +57,7 @@ std::string getOpenvinoLibDirectoryA() {
#elif defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
Dl_info info;
dladdr(reinterpret_cast<void*>(ov::get_openvino_version), &info);
- return get_path_name(ov::util::get_absolute_file_path(info.dli_fname)).c_str();
+ return ov::util::path_to_string(ov::util::get_absolute_file_path(info.dli_fname).parent_path());
#else
# error "Unsupported OS"
#endif // _WIN32
@@ -178,7 +175,7 @@ std::string getModelFromTestModelZoo(const std::string& relModelPath) {
std::string getRelativePath(const std::string& from, const std::string& to) {
auto split_path = [](const std::string& path) -> std::vector<std::string> {
- std::string sep{ov::util::FileTraits<char>::file_separator};
+ std::string sep{FileTraits<char>::file_separator};
std::vector<std::string> retvalue;
size_t start = 0;
size_t end = 0;
@@ -205,7 +202,7 @@ std::string getRelativePath(const std::string& from, const std::string& to) {
return {};
}
- std::string separator(1, ov::util::FileTraits<char>::file_separator);
+ std::string separator(1, FileTraits<char>::file_separator);
std::string output;
// generates path to the top common directory from the start directory
if (mismatch_it.first != from_vec.end()) {
@@ -250,6 +247,4 @@ std::filesystem::path to_fs_path(const StringPathVariant& param) {
}},
param);
}
-} // namespace utils
-} // namespace test
-} // namespace ov
+} // namespace ov::test::utils