From 44bbfefacd4f12e144dc659bf47ac52c086dbc9f Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 20 Oct 2022 07:04:57 +0400 Subject: [PATCH] Fixed loading old extensions inside the OpenVINO (#13543) --- src/inference/src/ie_core.cpp | 28 ++++++++++++++++-- .../inference_engine/ov_extension_test.cpp | 29 +++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index cb0901f1a1a..51b3511b152 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -1995,11 +1995,35 @@ void Core::add_extension(const ie::IExtensionPtr& extension) { } void Core::add_extension(const std::string& library_path) { - add_extension(ov::detail::load_extensions(library_path)); + try { + add_extension(ov::detail::load_extensions(library_path)); + } catch (const std::runtime_error&) { + try { + // Try to load legacy extension + const auto extension_ptr = std::make_shared(library_path); + OPENVINO_SUPPRESS_DEPRECATED_START + add_extension(extension_ptr); + OPENVINO_SUPPRESS_DEPRECATED_END + } catch (const std::runtime_error&) { + throw ov::Exception("Cannot add extension. Cannot find entry point to the extension library"); + } + } } #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT void Core::add_extension(const std::wstring& library_path) { - add_extension(ov::detail::load_extensions(library_path)); + try { + add_extension(ov::detail::load_extensions(library_path)); + } catch (const std::runtime_error&) { + try { + // Try to load legacy extension + const auto extension_ptr = std::make_shared(library_path); + OPENVINO_SUPPRESS_DEPRECATED_START + add_extension(extension_ptr); + OPENVINO_SUPPRESS_DEPRECATED_END + } catch (const std::runtime_error&) { + throw ov::Exception("Cannot add extension. Cannot find entry point to the extension library"); + } + } } #endif diff --git a/src/tests/functional/inference_engine/ov_extension_test.cpp b/src/tests/functional/inference_engine/ov_extension_test.cpp index 3cac2f5c1c8..9b12c1996cf 100644 --- a/src/tests/functional/inference_engine/ov_extension_test.cpp +++ b/src/tests/functional/inference_engine/ov_extension_test.cpp @@ -10,13 +10,14 @@ #include #include -#include "common_test_utils/test_common.hpp" #include "common_test_utils/file_utils.hpp" -#include "openvino/util/file_util.hpp" +#include "common_test_utils/test_common.hpp" #include "ie_iextension.h" #include "ngraph/op/op.hpp" +#include "openvino/core/except.hpp" #include "openvino/core/op_extension.hpp" #include "openvino/runtime/core.hpp" +#include "openvino/util/file_util.hpp" using namespace testing; using namespace InferenceEngine; @@ -176,7 +177,17 @@ namespace { std::string getOVExtensionPath() { return ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - std::string("openvino_template_extension") + IE_BUILD_POSTFIX); + std::string("openvino_template_extension") + IE_BUILD_POSTFIX); +} + +std::string getOldExtensionPath() { + return ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("template_extension") + IE_BUILD_POSTFIX); +} + +std::string getIncorrectExtensionPath() { + return ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("incorrect") + IE_BUILD_POSTFIX); } } // namespace @@ -334,3 +345,15 @@ TEST_F(OVExtensionTests, ReshapeIRWithSeveralNewOps) { core.add_extension(); test_two_op(); } + +TEST_F(OVExtensionTests, load_new_extension) { + EXPECT_NO_THROW(core.add_extension(getOVExtensionPath())); +} + +TEST_F(OVExtensionTests, load_old_extension) { + EXPECT_NO_THROW(core.add_extension(getOldExtensionPath())); +} + +TEST_F(OVExtensionTests, load_incorrect_extension) { + EXPECT_THROW(core.add_extension(getIncorrectExtensionPath()), ov::Exception); +}