OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core] Update core add extension overloads (#32884)
Pawel Raaszeafc3aadf8d7
diff --git a/src/bindings/c/src/ov_core.cpp b/src/bindings/c/src/ov_core.cppindex 2b6580a9e1b..709fd676499 100644--- a/src/bindings/c/src/ov_core.cpp+++ b/src/bindings/c/src/ov_core.cpp@@ -209,7 +209,7 @@ ov_status_e ov_core_add_extension(const ov_core_t* core, const char* path) {return ov_status_e::INVALID_C_PARAM;}try {- core->object->add_extension(path);+ core->object->add_extension(ov::util::make_path(path));}CATCH_OV_EXCEPTIONSreturn ov_status_e::OK;diff --git a/src/core/dev_api/openvino/core/so_extension.hpp b/src/core/dev_api/openvino/core/so_extension.hppindex 5b8c65e58af..90f29c1e833 100644--- a/src/core/dev_api/openvino/core/so_extension.hpp+++ b/src/core/dev_api/openvino/core/so_extension.hpp@@ -26,19 +26,17 @@ private:std::shared_ptr<void> m_so;};-inline std::string resolve_extension_path(const std::string& path) {- std::string retvalue;+inline std::filesystem::path resolve_extension_path(const std::filesystem::path& path) {try {- const std::string absolute_path = ov::util::get_absolute_file_path(path);- retvalue = ov::util::file_exists(absolute_path) ? absolute_path : path;+ auto absolute_path = std::filesystem::absolute(std::filesystem::weakly_canonical(path));+ return ov::util::file_exists(absolute_path) ? absolute_path : path;} catch (const std::runtime_error&) {- retvalue = path;+ return path;}- return retvalue;}-inline std::vector<Extension::Ptr> load_extensions(const std::string& path) {- const std::string resolved_path = resolve_extension_path(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());using CreateFunction = void(std::vector<Extension::Ptr>&);std::vector<Extension::Ptr> extensions;@@ -53,11 +51,9 @@ inline std::vector<Extension::Ptr> load_extensions(const std::string& path) {return so_extensions;}-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT-inline std::vector<Extension::Ptr> load_extensions(const std::wstring& path) {- return load_extensions(ov::util::wstring_to_string(path).c_str());+template <class T>+inline std::vector<Extension::Ptr> load_extensions(const std::basic_string<T>& path) {+ return load_extensions(ov::util::make_path(path));}-#endif-} // namespace detail} // namespace ovdiff --git a/src/inference/include/openvino/runtime/core.hpp b/src/inference/include/openvino/runtime/core.hppindex c7bdff8634c..d49234ba854 100644--- a/src/inference/include/openvino/runtime/core.hpp+++ b/src/inference/include/openvino/runtime/core.hpp@@ -449,24 +449,24 @@ public:* @param library_path Path to the library with ov::Extension.* @{*/+ void add_extension(const std::filesystem::path& library_path);+void add_extension(const std::string& library_path);- template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>- void add_extension(const Path& model_path) {- if constexpr (std::is_same_v<typename Path::value_type, wchar_t>)- return add_extension(model_path.wstring());- else- return add_extension(model_path.string());+ template <class TPath, std::enable_if_t<std::is_constructible_v<std::string, TPath>>* = nullptr>+ void add_extension(const TPath& library_path) {+ add_extension(std::string(library_path));}- /// @}#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT- /**- * @brief Registers an extension to a Core object.- * @param library_path Unicode path to the library with ov::Extension.- */void add_extension(const std::wstring& library_path);++ template <class TPath, std::enable_if_t<std::is_constructible_v<std::wstring, TPath>>* = nullptr>+ void add_extension(const TPath& library_path) {+ add_extension(std::wstring(library_path));+ }#endif+ /// @}/*** @brief Registers an extension to a Core object.diff --git a/src/inference/src/cpp/core.cpp b/src/inference/src/cpp/core.cppindex b9e9c182578..533b9f22301 100644--- a/src/inference/src/cpp/core.cpp+++ b/src/inference/src/cpp/core.cpp@@ -167,7 +167,7 @@ CompiledModel Core::compile_model(const std::shared_ptr<const ov::Model>& model,});}-void Core::add_extension(const std::string& library_path) {+void Core::add_extension(const std::filesystem::path& library_path) {try {add_extension(ov::detail::load_extensions(library_path));} catch (const std::runtime_error& e) {@@ -178,13 +178,13 @@ void Core::add_extension(const std::string& library_path) {}}+void Core::add_extension(const std::string& library_path) {+ add_extension(ov::util::make_path(library_path));+}+#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORTvoid Core::add_extension(const std::wstring& library_path) {- try {- add_extension(ov::detail::load_extensions(library_path));- } catch (const std::runtime_error&) {- OPENVINO_THROW("Cannot add extension. Cannot find entry point to the extension library");- }+ add_extension(ov::util::make_path(library_path));}#endifdiff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cppindex 3764fbad152..28e94cf73ac 100644--- a/src/inference/src/dev/core_impl.cpp+++ b/src/inference/src/dev/core_impl.cpp@@ -277,7 +277,7 @@ std::filesystem::path get_cache_model_path(const ov::AnyMap& config) {std::vector<ov::Extension::Ptr> try_get_extensions(const std::filesystem::path& path) {try {- return ov::detail::load_extensions(path.native());+ return ov::detail::load_extensions(path);} catch (const std::runtime_error&) {return {};}diff --git a/src/inference/tests/functional/ov_core_threading.cpp b/src/inference/tests/functional/ov_core_threading.cppindex aba791f6594..c010f1f250c 100644--- a/src/inference/tests/functional/ov_core_threading.cpp+++ b/src/inference/tests/functional/ov_core_threading.cpp@@ -62,9 +62,9 @@ public:void safeAddExtension(ov::Core& core) {try {- auto extension = ov::detail::load_extensions(+ auto extension = ov::detail::load_extensions(ov::util::make_path(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),- std::string("openvino_template_extension") + OV_BUILD_POSTFIX));+ std::string("openvino_template_extension") + OV_BUILD_POSTFIX)));core.add_extension(extension);} catch (const ov::Exception& ex) {ASSERT_STR_CONTAINS(ex.what(), "name: custom_opset. Opset");