From a1e95f4d69ddfe931ebfc6174c231fc2900b04e0 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 20 Nov 2021 18:13:10 +0300 Subject: [PATCH] Deprecated SOPointer (#8711) * Removed SOPointer * Updates * Fixed tests, compilation --- .../ie_bridges/c/src/ie_c_api.cpp | 1 + .../include/ie/cpp/ie_executable_network.hpp | 5 +- .../include/ie/cpp/ie_infer_request.hpp | 5 +- .../include/ie/cpp/ie_memory_state.hpp | 5 +- .../include/ie/details/ie_so_loader.h | 4 +- .../include/ie/details/ie_so_pointer.hpp | 3 +- .../include/ie/ie_extension.h | 46 +++++------ .../src/cpp/ie_executable_network.cpp | 2 +- .../inference_engine/src/cpp/ie_extension.cpp | 77 +++++++++++++++++++ .../src/cpp/ie_infer_request.cpp | 2 +- .../inference_engine/src/cpp/ie_plugin.hpp | 16 ++-- .../src/cpp/ie_variable_state.cpp | 2 +- .../src/inference_engine/src/file_utils.cpp | 2 +- .../src/inference_engine/src/ie_common.cpp | 6 -- .../src/inference_engine/src/ie_core.cpp | 2 +- .../src/ie_network_reader.cpp | 28 +++---- .../src/shared_object_loader.cpp | 4 + .../interface/ie_iinfer_request_internal.hpp | 2 +- .../interface/ie_iplugin_internal.hpp | 8 -- inference-engine/src/plugin_api/file_utils.h | 21 +++-- .../src/preprocessing/ie_preprocess_data.hpp | 2 - .../inference_engine/caching_test.cpp | 8 +- .../shared_object_loader_test.cpp | 9 ++- .../inference_engine/so_pointer_tests.cpp | 41 ---------- .../ie_infer_async_request_base_test.cpp | 2 +- .../ie_memory_state_internal_test.cpp | 2 +- .../ie_executable_network_test.cpp | 2 +- .../unit/inference_engine/ie_plugin_ptr.cpp | 71 ----------------- .../behavior/vpu/CMakeLists.txt | 3 +- .../vpu/myriad_tests/vpu_watchdog_tests.cpp | 9 ++- .../hello_nv12_input_classification/main.cpp | 1 + 31 files changed, 171 insertions(+), 220 deletions(-) create mode 100644 inference-engine/src/inference_engine/src/cpp/ie_extension.cpp delete mode 100644 inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp delete mode 100644 inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp diff --git a/inference-engine/ie_bridges/c/src/ie_c_api.cpp b/inference-engine/ie_bridges/c/src/ie_c_api.cpp index 4eaf8539e81..c7a9577f2ed 100644 --- a/inference-engine/ie_bridges/c/src/ie_c_api.cpp +++ b/inference-engine/ie_bridges/c/src/ie_c_api.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/inference-engine/src/inference_engine/include/ie/cpp/ie_executable_network.hpp b/inference-engine/src/inference_engine/include/ie/cpp/ie_executable_network.hpp index fc205e966f6..614d1eced26 100644 --- a/inference-engine/src/inference_engine/include/ie/cpp/ie_executable_network.hpp +++ b/inference-engine/src/inference_engine/include/ie/cpp/ie_executable_network.hpp @@ -18,7 +18,6 @@ #include "cpp/ie_cnn_network.h" #include "cpp/ie_infer_request.hpp" -#include "details/ie_so_loader.h" #include "ie_iexecutable_network.hpp" #include "ie_parameter.hpp" #include "ie_remote_context.hpp" @@ -36,7 +35,7 @@ class IExecutableNetworkInternal; * @brief This is an interface of an executable network */ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) { - details::SharedObjectLoader _so; + std::shared_ptr _so; std::shared_ptr _impl; /** @@ -45,7 +44,7 @@ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) { * object is destroyed. * @param impl Initialized shared pointer */ - ExecutableNetwork(const details::SharedObjectLoader& so, const std::shared_ptr& impl); + ExecutableNetwork(const std::shared_ptr& so, const std::shared_ptr& impl); friend class Core; friend class ov::runtime::Core; diff --git a/inference-engine/src/inference_engine/include/ie/cpp/ie_infer_request.hpp b/inference-engine/src/inference_engine/include/ie/cpp/ie_infer_request.hpp index 7e57123f78a..658aaf4b493 100644 --- a/inference-engine/src/inference_engine/include/ie/cpp/ie_infer_request.hpp +++ b/inference-engine/src/inference_engine/include/ie/cpp/ie_infer_request.hpp @@ -14,7 +14,6 @@ #include #include "cpp/ie_memory_state.hpp" -#include "details/ie_so_loader.h" #include "ie_blob.h" #include "ie_iinfer_request.hpp" @@ -33,7 +32,7 @@ class ICompletionCallbackWrapper; * It can throw exceptions safely for the application, where it is properly handled. */ class INFERENCE_ENGINE_API_CLASS(InferRequest) { - details::SharedObjectLoader _so; + std::shared_ptr _so; std::shared_ptr _impl; /** @@ -42,7 +41,7 @@ class INFERENCE_ENGINE_API_CLASS(InferRequest) { * destroyed. * @param impl Initialized shared pointer */ - InferRequest(const details::SharedObjectLoader& so, const std::shared_ptr& impl); + InferRequest(const std::shared_ptr& so, const std::shared_ptr& impl); friend class ExecutableNetwork; public: diff --git a/inference-engine/src/inference_engine/include/ie/cpp/ie_memory_state.hpp b/inference-engine/src/inference_engine/include/ie/cpp/ie_memory_state.hpp index ab1807dac4b..7ef8437b95d 100644 --- a/inference-engine/src/inference_engine/include/ie/cpp/ie_memory_state.hpp +++ b/inference-engine/src/inference_engine/include/ie/cpp/ie_memory_state.hpp @@ -13,7 +13,6 @@ #include #include -#include "details/ie_so_loader.h" #include "ie_api.h" #include "ie_blob.h" @@ -25,7 +24,7 @@ class IVariableStateInternal; * @brief VariableState class */ class INFERENCE_ENGINE_API_CLASS(VariableState) { - details::SharedObjectLoader _so; + std::shared_ptr _so; std::shared_ptr _impl; /** @@ -34,7 +33,7 @@ class INFERENCE_ENGINE_API_CLASS(VariableState) { * @param so Optional: Plugin to use. This is required to ensure that VariableState can work properly even if plugin * object is destroyed. */ - VariableState(const details::SharedObjectLoader& so, const std::shared_ptr& impl); + VariableState(const std::shared_ptr& so, const std::shared_ptr& impl); friend class InferRequest; friend class ExecutableNetwork; diff --git a/inference-engine/src/inference_engine/include/ie/details/ie_so_loader.h b/inference-engine/src/inference_engine/include/ie/details/ie_so_loader.h index c0135cfc698..81659053b3e 100644 --- a/inference-engine/src/inference_engine/include/ie/details/ie_so_loader.h +++ b/inference-engine/src/inference_engine/include/ie/details/ie_so_loader.h @@ -17,9 +17,11 @@ namespace InferenceEngine { namespace details { /** + * @deprecated This is internal stuff. Use Inference Engine Plugin API * @brief This class provides an OS shared module abstraction */ -class INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) { +class INFERENCE_ENGINE_DEPRECATED("This is internal stuff. Use Inference Engine Plugin API") + INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) { std::shared_ptr _so; public: diff --git a/inference-engine/src/inference_engine/include/ie/details/ie_so_pointer.hpp b/inference-engine/src/inference_engine/include/ie/details/ie_so_pointer.hpp index 9158d6f02cd..3807f6e5636 100644 --- a/inference-engine/src/inference_engine/include/ie/details/ie_so_pointer.hpp +++ b/inference-engine/src/inference_engine/include/ie/details/ie_so_pointer.hpp @@ -35,11 +35,12 @@ using enableIfSupportedChar = typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; /** + * @deprecated This is internal stuff. Use Inference Engine Plugin API * @brief This class instantiate object using shared library * @tparam T An type of object SOPointer can hold */ template -class SOPointer { +class INFERENCE_ENGINE_DEPRECATED("This is internal stuff. Use Inference Engine Plugin API") SOPointer { template friend class SOPointer; diff --git a/inference-engine/src/inference_engine/include/ie/ie_extension.h b/inference-engine/src/inference_engine/include/ie/ie_extension.h index 79491761043..7b92358e36a 100644 --- a/inference-engine/src/inference_engine/include/ie/ie_extension.h +++ b/inference-engine/src/inference_engine/include/ie/ie_extension.h @@ -14,27 +14,10 @@ #include #include -#include "details/ie_so_pointer.hpp" #include "ie_iextension.h" #include "ngraph/opsets/opset.hpp" namespace InferenceEngine { -namespace details { - -/** - * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for - * creating IExtension object in DLL - */ -template <> -class SOCreatorTrait { -public: - /** - * @brief A name of the fabric method for creating an IExtension object in DLL - */ - static constexpr auto name = "CreateExtension"; -}; - -} // namespace details /** * @brief This class is a C++ helper to work with objects created using extensions. @@ -46,8 +29,16 @@ public: * * @param name Full or relative path to extension library */ - template > - explicit Extension(const std::basic_string& name) : actual(name) {} + explicit Extension(const std::string& name); + +#ifdef ENABLE_UNICODE_PATH_SUPPORT + /** + * @brief Loads extension from a shared library + * + * @param name Full or relative path to extension library + */ + explicit Extension(const std::wstring& name); +#endif // ENABLE_UNICODE_PATH_SUPPORT /** * @brief Gets the extension version information @@ -55,14 +46,14 @@ public: * @param versionInfo A pointer to version info, set by the plugin */ void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override { - actual->GetVersion(versionInfo); + _actual->GetVersion(versionInfo); } /** * @brief Cleans the resources up */ void Unload() noexcept override { - actual->Unload(); + _actual->Unload(); } /** @@ -80,7 +71,7 @@ public: std::vector getImplTypes(const std::shared_ptr& node) override { if (node == nullptr) IE_THROW() << "Provided ngraph::Node pointer is nullptr."; - return actual->getImplTypes(node); + return _actual->getImplTypes(node); } /** @@ -92,14 +83,19 @@ public: ILayerImpl::Ptr getImplementation(const std::shared_ptr& node, const std::string& implType) override { if (node == nullptr) IE_THROW() << "Provided ngraph::Node pointer is nullptr."; - return actual->getImplementation(node, implType); + return _actual->getImplementation(node, implType); } protected: /** - * @brief A SOPointer instance to the loaded templated object + * @brief A shared library */ - details::SOPointer actual; + std::shared_ptr _so; + + /** + * @brief A instance to the loaded templated object + */ + std::shared_ptr _actual; }; /** diff --git a/inference-engine/src/inference_engine/src/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/src/cpp/ie_executable_network.cpp index 24a6af02d64..9c0d444acd1 100644 --- a/inference-engine/src/inference_engine/src/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/src/cpp/ie_executable_network.cpp @@ -33,7 +33,7 @@ namespace InferenceEngine { OPENVINO_ASSERT(false, "Unexpected exception"); \ } -ExecutableNetwork::ExecutableNetwork(const details::SharedObjectLoader& so, const IExecutableNetworkInternal::Ptr& impl) +ExecutableNetwork::ExecutableNetwork(const std::shared_ptr& so, const IExecutableNetworkInternal::Ptr& impl) : _so(so), _impl(impl) { IE_ASSERT(_impl != nullptr); diff --git a/inference-engine/src/inference_engine/src/cpp/ie_extension.cpp b/inference-engine/src/inference_engine/src/cpp/ie_extension.cpp new file mode 100644 index 00000000000..0554a983885 --- /dev/null +++ b/inference-engine/src/inference_engine/src/cpp/ie_extension.cpp @@ -0,0 +1,77 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ie_extension.h" + +#include "openvino/util/shared_object.hpp" + +using namespace InferenceEngine; + +namespace { + +template +std::shared_ptr CreateExtensionFromLibrary(std::shared_ptr _so) { + std::shared_ptr _ptr = nullptr; + constexpr char createFuncName[] = "CreateExtension"; + + try { + void* create = nullptr; + try { + create = ov::util::get_symbol(_so, (createFuncName + std::string("Shared")).c_str()); + } catch (const std::runtime_error&) { + } + + if (create == nullptr) { + create = ov::util::get_symbol(_so, createFuncName); + using CreateF = StatusCode(T*&, ResponseDesc*); + T* object = nullptr; + ResponseDesc desc; + StatusCode sts = reinterpret_cast(create)(object, &desc); + if (sts != OK) { + IE_EXCEPTION_SWITCH( + sts, + ExceptionType, + details::ThrowNow{} <<= std::stringstream{} << IE_LOCATION << desc.msg) + } + IE_SUPPRESS_DEPRECATED_START + _ptr = std::shared_ptr(object, [](T* ptr) { + ptr->Release(); + }); + IE_SUPPRESS_DEPRECATED_END + } else { + using CreateF = void(std::shared_ptr&); + reinterpret_cast(create)(_ptr); + } + } catch (...) { + details::Rethrow(); + } + + return _ptr; +} + +} // namespace + +Extension::Extension(const std::string& name) { + try { + _so = ov::util::load_shared_object(name.c_str()); + } catch (const std::runtime_error&) { + details::Rethrow(); + } + _actual = CreateExtensionFromLibrary(_so); +} + +#ifdef ENABLE_UNICODE_PATH_SUPPORT +Extension::Extension(const std::wstring& name) { + try { + _so = ov::util::load_shared_object(name.c_str()); + } catch (const std::runtime_error&) { + details::Rethrow(); + } + _actual = CreateExtensionFromLibrary(_so); +} +#endif // ENABLE_UNICODE_PATH_SUPPORT + +std::map Extension::getOpSets() { + return _actual->getOpSets(); +} diff --git a/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp index 01d2adb4b1f..5f9fbe6e283 100644 --- a/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/src/cpp/ie_infer_request.cpp @@ -58,7 +58,7 @@ namespace InferenceEngine { OPENVINO_ASSERT(false, "Unexpected exception"); \ } -InferRequest::InferRequest(const details::SharedObjectLoader& so, const IInferRequestInternal::Ptr& impl) +InferRequest::InferRequest(const std::shared_ptr& so, const IInferRequestInternal::Ptr& impl) : _so(so), _impl(impl) { IE_ASSERT(_impl != nullptr); diff --git a/inference-engine/src/inference_engine/src/cpp/ie_plugin.hpp b/inference-engine/src/inference_engine/src/cpp/ie_plugin.hpp index bd1718d55d9..e525103c06c 100644 --- a/inference-engine/src/inference_engine/src/cpp/ie_plugin.hpp +++ b/inference-engine/src/inference_engine/src/cpp/ie_plugin.hpp @@ -61,17 +61,17 @@ struct InferencePlugin { PLUGIN_CALL_STATEMENT(_ptr->SetConfig(config)); } - details::SOPointer LoadNetwork(const CNNNetwork& network, const std::map& config) { + ov::runtime::SoPtr LoadNetwork(const CNNNetwork& network, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(network, config)}); } - details::SOPointer LoadNetwork(const CNNNetwork& network, + ov::runtime::SoPtr LoadNetwork(const CNNNetwork& network, const std::shared_ptr& context, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(network, config, context)}); } - details::SOPointer LoadNetwork(const std::string& modelPath, const std::map& config) { + ov::runtime::SoPtr LoadNetwork(const std::string& modelPath, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(modelPath, config)}); } @@ -83,17 +83,17 @@ struct InferencePlugin { return res; } - details::SOPointer ImportNetwork(const std::string& modelFileName, + ov::runtime::SoPtr ImportNetwork(const std::string& modelFileName, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(modelFileName, config)}); } - details::SOPointer ImportNetwork(std::istream& networkModel, + ov::runtime::SoPtr ImportNetwork(std::istream& networkModel, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(networkModel, config)}); } - details::SOPointer ImportNetwork(std::istream& networkModel, + ov::runtime::SoPtr ImportNetwork(std::istream& networkModel, const std::shared_ptr& context, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(networkModel, context, config)}); @@ -103,11 +103,11 @@ struct InferencePlugin { PLUGIN_CALL_STATEMENT(return _ptr->GetMetric(name, options)); } - details::SOPointer CreateContext(const ParamMap& params) { + ov::runtime::SoPtr CreateContext(const ParamMap& params) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->CreateContext(params)}); } - details::SOPointer GetDefaultContext(const ParamMap& params) { + ov::runtime::SoPtr GetDefaultContext(const ParamMap& params) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->GetDefaultContext(params)}); } diff --git a/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp b/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp index a1f81768e32..e26d6df9409 100644 --- a/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp +++ b/inference-engine/src/inference_engine/src/cpp/ie_variable_state.cpp @@ -28,7 +28,7 @@ namespace InferenceEngine { -VariableState::VariableState(const details::SharedObjectLoader& so, const IVariableStateInternal::Ptr& impl) +VariableState::VariableState(const std::shared_ptr& so, const IVariableStateInternal::Ptr& impl) : _so(so), _impl(impl) { if (_impl == nullptr) diff --git a/inference-engine/src/inference_engine/src/file_utils.cpp b/inference-engine/src/inference_engine/src/file_utils.cpp index ea962e2b679..a150e1346d7 100644 --- a/inference-engine/src/inference_engine/src/file_utils.cpp +++ b/inference-engine/src/inference_engine/src/file_utils.cpp @@ -52,7 +52,7 @@ namespace InferenceEngine { namespace { -template > +template > std::basic_string getPathName(const std::basic_string& s) { size_t i = s.rfind(ov::util::FileTraits::file_separator, s.length()); if (i != std::string::npos) { diff --git a/inference-engine/src/inference_engine/src/ie_common.cpp b/inference-engine/src/inference_engine/src/ie_common.cpp index ce194f1bc6c..1a269837baf 100644 --- a/inference-engine/src/inference_engine/src/ie_common.cpp +++ b/inference-engine/src/inference_engine/src/ie_common.cpp @@ -40,12 +40,6 @@ std::map IExtension::getOpSets() { return {}; } -// -// ie_extension.h -// -std::map Extension::getOpSets() { - return actual->getOpSets(); -} namespace details { void Rethrow() { diff --git a/inference-engine/src/inference_engine/src/ie_core.cpp b/inference-engine/src/inference_engine/src/ie_core.cpp index 0004c48e462..5ef2839618d 100644 --- a/inference-engine/src/inference_engine/src/ie_core.cpp +++ b/inference-engine/src/inference_engine/src/ie_core.cpp @@ -1084,7 +1084,7 @@ private: extensions.emplace_back(extension); } - template > + template > void TryToRegisterLibraryAsExtensionUnsafe(const std::basic_string& path) const { try { const auto extension_ptr = std::make_shared(path); diff --git a/inference-engine/src/inference_engine/src/ie_network_reader.cpp b/inference-engine/src/inference_engine/src/ie_network_reader.cpp index 176b2685af8..3dbb0962dfb 100644 --- a/inference-engine/src/inference_engine/src/ie_network_reader.cpp +++ b/inference-engine/src/inference_engine/src/ie_network_reader.cpp @@ -13,7 +13,6 @@ #include "cnn_network_ngraph_impl.hpp" #include "cpp/ie_cnn_network.h" -#include "details/ie_so_pointer.hpp" #include "file_utils.h" #include "frontend_manager/frontend_manager.hpp" #include "ie_api.h" @@ -34,6 +33,8 @@ #include "openvino/core/preprocess/input_tensor_info.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" #include "openvino/core/type/element_type.hpp" +#include "openvino/util/shared_object.hpp" +#include "so_ptr.hpp" #include "transformations/rt_info/old_api_map_order_attribute.hpp" #include "transformations/utils/utils.hpp" @@ -77,22 +78,6 @@ namespace InferenceEngine { #ifdef ENABLE_IR_V7_READER -namespace details { - -/** - * @brief This class defines the name of the fabric for creating an IReader object in DLL - */ -template <> -class SOCreatorTrait { -public: - /** - * @brief A name of the fabric for creating IReader object in DLL - */ - static constexpr auto name = "CreateReader"; -}; - -} // namespace details - /** * @brief This class is a wrapper for reader interfaces */ @@ -100,7 +85,7 @@ class Reader : public IReader { # ifdef OPENVINO_STATIC_LIBRARY using ReaderPtr = std::shared_ptr; # else - using ReaderPtr = InferenceEngine::details::SOPointer; + using ReaderPtr = ov::runtime::SoPtr; # endif ReaderPtr ptr; std::once_flag readFlag; @@ -123,7 +108,12 @@ class Reader : public IReader { << ov::util::from_file_path(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in " << getIELibraryPath(); } - ptr = {readersLibraryPath}; + + auto so = ov::util::load_shared_object(readersLibraryPath.c_str()); + std::shared_ptr plugin_impl; + using createFunc = void(std::shared_ptr&); + reinterpret_cast(ov::util::get_symbol(so, "CreateReader"))(plugin_impl); + ptr = {so, plugin_impl}; # endif // OPENVINO_STATIC_LIBRARY }); diff --git a/inference-engine/src/inference_engine/src/shared_object_loader.cpp b/inference-engine/src/inference_engine/src/shared_object_loader.cpp index 85fbbb63618..24a90064273 100644 --- a/inference-engine/src/inference_engine/src/shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/src/shared_object_loader.cpp @@ -7,6 +7,8 @@ #include "openvino/util/file_util.hpp" #include "openvino/util/shared_object.hpp" +IE_SUPPRESS_DEPRECATED_START + namespace InferenceEngine { namespace details { @@ -41,3 +43,5 @@ std::shared_ptr SharedObjectLoader::get() const { } // namespace details } // namespace InferenceEngine + +IE_SUPPRESS_DEPRECATED_END diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp index 7cfa757ee72..9200c31920b 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iinfer_request_internal.hpp @@ -261,7 +261,7 @@ private: }; /** - * @brief SOPointer to IInferRequestInternal. + * @brief SoPtr to IInferRequestInternal. */ using SoIInferRequestInternal = ov::runtime::SoPtr; diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp index 09383330e22..e9799495680 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp @@ -16,7 +16,6 @@ #include "blob_factory.hpp" #include "cpp/ie_cnn_network.h" -#include "details/ie_so_pointer.hpp" #include "ie_iextension.h" #include "ie_input_info.hpp" #include "ie_parameter.hpp" @@ -346,13 +345,6 @@ using CreateExtensionFunc = void(std::shared_ptr&); */ constexpr static const auto create_plugin_function = OV_PP_TOSTRING(IE_CREATE_PLUGIN); -namespace details { -template <> -class SOCreatorTrait { -public: - static constexpr auto name = create_plugin_function; -}; -} // namespace details } // namespace InferenceEngine /** diff --git a/inference-engine/src/plugin_api/file_utils.h b/inference-engine/src/plugin_api/file_utils.h index cbde9d156d6..c1bf5bbab77 100644 --- a/inference-engine/src/plugin_api/file_utils.h +++ b/inference-engine/src/plugin_api/file_utils.h @@ -14,11 +14,18 @@ #include #include "ie_api.h" -#include "details/ie_so_pointer.hpp" #include "openvino/util/file_util.hpp" namespace FileUtils { +/** + * @brief Enables only `char` or `wchar_t` template specializations + * @tparam C A char type + */ +template +using enableIfSupportedChar = + typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; + /** * @brief Interface function to get absolute path of file * @ingroup ie_dev_api_file_utils @@ -74,7 +81,7 @@ inline long long fileSize(const wchar_t* fileName) { * @param f - string name of the file * @return size of the file */ -template > +template > inline long long fileSize(const std::basic_string &f) { return fileSize(f.c_str()); } @@ -85,7 +92,7 @@ inline long long fileSize(const std::basic_string &f) { * @param fileName - given filename * @return true is exists */ -template > +template > inline bool fileExist(const C * fileName) { return fileSize(fileName) >= 0; } @@ -96,7 +103,7 @@ inline bool fileExist(const C * fileName) { * @param fileName - string with a given filename * @return true is exists */ -template > +template > inline bool fileExist(const std::basic_string &fileName) { return fileExist(fileName.c_str()); } @@ -109,7 +116,7 @@ inline bool fileExist(const std::basic_string &fileName) { * @return string with combination of the path and the filename divided by file separator */ -template > +template > inline std::basic_string makePath(const std::basic_string &folder, const std::basic_string &file) { if (folder.empty()) return file; @@ -122,7 +129,7 @@ inline std::basic_string makePath(const std::basic_string &folder, const s * @param filename - string with the name of the file which extension should be extracted * @return string with extracted file extension */ -template > +template > inline std::basic_string fileExt(const std::basic_string &filename) { auto pos = filename.rfind(ov::util::FileTraits::dot_symbol); if (pos == std::string::npos) @@ -130,7 +137,7 @@ inline std::basic_string fileExt(const std::basic_string &filename) { return filename.substr(pos + 1); } -template > +template > inline std::basic_string makePluginLibraryName(const std::basic_string &path, const std::basic_string &input) { std::basic_string separator(1, ov::util::FileTraits::file_separator); if (path.empty()) diff --git a/inference-engine/src/preprocessing/ie_preprocess_data.hpp b/inference-engine/src/preprocessing/ie_preprocess_data.hpp index 3c99f0f23e8..745f4171688 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_data.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_data.hpp @@ -16,8 +16,6 @@ #include #include -#include
- namespace InferenceEngine { /** diff --git a/inference-engine/tests/functional/inference_engine/caching_test.cpp b/inference-engine/tests/functional/inference_engine/caching_test.cpp index 24ee87761d8..b6065d928c0 100644 --- a/inference-engine/tests/functional/inference_engine/caching_test.cpp +++ b/inference-engine/tests/functional/inference_engine/caching_test.cpp @@ -14,7 +14,6 @@ #include "ie_core.hpp" #include "ngraph/function.hpp" -#include "details/ie_so_loader.h" #include "ie_metric_helpers.hpp" #include "openvino/op/logical_not.hpp" @@ -168,7 +167,7 @@ public: class CachingTest : public ::testing::TestWithParam> { public: - std::unique_ptr sharedObjectLoader; + std::shared_ptr sharedObjectLoader; std::function injectProxyEngine; std::string modelName = "Caching_test.xml"; std::string weightsName = "Caching_test.bin"; @@ -270,7 +269,7 @@ public: mockPlugin = std::make_shared(); setupMock(*mockPlugin); std::string libraryName = get_mock_engine_name(); - sharedObjectLoader.reset(new SharedObjectLoader(libraryName.c_str())); + sharedObjectLoader = ov::util::load_shared_object(libraryName.c_str()); injectProxyEngine = make_std_function("InjectProxyEngine"); FuncTestUtils::TestModel::generateTestModel(modelName, weightsName); @@ -337,7 +336,8 @@ public: private: template std::function make_std_function(const std::string& functionName) { - std::function ptr(reinterpret_cast(sharedObjectLoader->get_symbol(functionName.c_str()))); + std::function ptr(reinterpret_cast( + ov::util::get_symbol(sharedObjectLoader, functionName.c_str()))); return ptr; } diff --git a/inference-engine/tests/functional/inference_engine/shared_object_loader_test.cpp b/inference-engine/tests/functional/inference_engine/shared_object_loader_test.cpp index fb1ab852c27..bb4e02927bc 100644 --- a/inference-engine/tests/functional/inference_engine/shared_object_loader_test.cpp +++ b/inference-engine/tests/functional/inference_engine/shared_object_loader_test.cpp @@ -5,7 +5,7 @@ #include #include -#include "details/ie_so_loader.h" +#include "openvino/util/shared_object.hpp" #include using namespace std; @@ -20,14 +20,15 @@ protected: } void loadDll(const string &libraryName) { - sharedObjectLoader.reset(new details::SharedObjectLoader(libraryName.c_str())); + sharedObjectLoader = ov::util::load_shared_object(libraryName.c_str()); } - unique_ptr sharedObjectLoader; + std::shared_ptr sharedObjectLoader; using CreateF = void(std::shared_ptr&); std::function make_std_function(const std::string& functionName) { - std::function ptr(reinterpret_cast(sharedObjectLoader->get_symbol(functionName.c_str()))); + std::function ptr(reinterpret_cast( + ov::util::get_symbol(sharedObjectLoader, functionName.c_str()))); return ptr; } }; diff --git a/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp b/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp deleted file mode 100644 index 066e8be24e1..00000000000 --- a/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include - -#include - -#include -#include -#include
-#include - -using namespace InferenceEngine; -using namespace InferenceEngine::details; -using namespace ::testing; -using ::testing::InSequence; - -namespace InferenceEngine { - -namespace details { - -struct UnknownPlugin : std::enable_shared_from_this {}; - -template<> -class SOCreatorTrait { -public: - static constexpr auto name = "CreateUnknownPlugin"; -}; - -} // namespace details - -} // namespace InferenceEngine - -class SoPointerTests : public ::testing::Test {}; - -TEST_F(SoPointerTests, UnknownPlugin) { - ASSERT_THROW(SOPointer{std::string{"UnknownPlugin"}}, Exception); -} diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp index 8f9d2d83301..bfb768f8b90 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_infer_async_request_base_test.cpp @@ -197,7 +197,7 @@ protected: auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; - exeNetwork = {{}, plugin.LoadNetwork(CNNNetwork{}, {})}; + exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); request = exeNetwork->CreateInferRequest(); _incorrectName = "incorrect_name"; _inputName = MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp index 8d7d39b92a3..4460de98ac4 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_memory_state_internal_test.cpp @@ -38,7 +38,7 @@ class InferRequestVariableStateTests : public ::testing::Test { auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockExeNetworkInternal)); plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; - net = {{}, plugin.LoadNetwork(CNNNetwork{}, {})}; + net = plugin.LoadNetwork(CNNNetwork{}, {}); req = net->CreateInferRequest(); } }; diff --git a/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp b/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp index 8b502109394..3595c5194f4 100644 --- a/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_executable_network_test.cpp @@ -53,7 +53,7 @@ protected: auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; - exeNetwork = {{}, plugin.LoadNetwork(CNNNetwork{}, {})}; + exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); } }; diff --git a/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp b/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp deleted file mode 100644 index ec7682130c1..00000000000 --- a/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include "details/ie_so_loader.h" -#include "details/ie_so_pointer.hpp" - -#include "unit_test_utils/mocks/mock_engine/mock_plugin.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp" - - -using namespace std; -using namespace InferenceEngine; -using namespace ::testing; -using namespace InferenceEngine::details; - -class PluginTest: public ::testing::Test { -protected: - unique_ptr sharedObjectLoader; - std::function createPluginEngineProxy; - InferenceEngine::details::SOPointer getPtr(); - - std::string get_mock_engine_name() { - std::string mockEngineName("mock_engine"); - return CommonTestUtils::pre + mockEngineName + IE_BUILD_POSTFIX + CommonTestUtils::ext; - } - - void SetUp() override { - std::string libraryName = get_mock_engine_name(); - sharedObjectLoader.reset(new SharedObjectLoader(libraryName.c_str())); - createPluginEngineProxy = make_std_function("CreatePluginEngineProxy"); - } - template - std::function make_std_function(const std::string& functionName) { - std::function ptr(reinterpret_cast(sharedObjectLoader->get_symbol(functionName.c_str()))); - return ptr; - } - - MockInferencePluginInternal2 engine; -}; - -#ifndef OPENVINO_STATIC_LIBRARY - -TEST_F(PluginTest, canCreatePluginUsingSmartPtr) { - ASSERT_NO_THROW(InferenceEngine::details::SOPointer ptr(get_mock_engine_name())); -} - -TEST_F(PluginTest, shouldThrowExceptionIfPluginNotExist) { - EXPECT_THROW(InferenceEngine::details::SOPointer(std::string{"unknown_plugin"}), Exception); -} - -InferenceEngine::details::SOPointer PluginTest::getPtr() { - InferenceEngine::details::SOPointer smart_ptr(get_mock_engine_name()); - return smart_ptr; -} - -TEST_F(PluginTest, canSetConfiguration) { - InferenceEngine::details::SOPointer ptr = getPtr(); - // TODO: dynamic->reinterpret because of clang/gcc cannot - // dynamically cast this MOCK object - ASSERT_TRUE(dynamic_cast(ptr.operator->())->config.empty()); - - std::map config = { { "key", "value" } }; - ASSERT_NO_THROW(ptr->SetConfig(config)); - config.clear(); - - ASSERT_STREQ(dynamic_cast(ptr.operator->())->config["key"].c_str(), "value"); -} - -#endif // OPENVINO_STATIC_LIBRARY diff --git a/inference-engine/tests_deprecated/behavior/vpu/CMakeLists.txt b/inference-engine/tests_deprecated/behavior/vpu/CMakeLists.txt index 72c1b13436b..8bdadeb99c8 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/CMakeLists.txt +++ b/inference-engine/tests_deprecated/behavior/vpu/CMakeLists.txt @@ -44,7 +44,8 @@ function(enable_vpu TARGET_NAME FLAG_NAME PLUGIN_NAME) ${FLAG_NAME}=1) target_link_libraries(${TARGET_NAME} PRIVATE - IEBehaviorSharedTests) + IEBehaviorSharedTests + openvino::util) target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instances/plugin_tests) diff --git a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp index dcf9f687ce6..3a7628bc9fb 100644 --- a/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp +++ b/inference-engine/tests_deprecated/behavior/vpu/myriad_tests/vpu_watchdog_tests.cpp @@ -11,6 +11,7 @@ #include #include #include "vpu_test_data.hpp" +#include "openvino/util/shared_object.hpp" #include "helpers/myriad_devices.hpp" @@ -126,8 +127,8 @@ TEST_P(MYRIADWatchdog, canDisableWatchdog) { ASSERT_GE(startup_devices.unbooted, 1); auto ctime = Time::now(); - SharedObjectLoader myriadPlg (make_plugin_name("myriadPlugin").c_str()); - void *p = myriadPlg.get_symbol(create_plugin_function); + std::shared_ptr myriadPlg = ov::util::load_shared_object(make_plugin_name("myriadPlugin").c_str()); + void *p = ov::util::get_symbol(myriadPlg, create_plugin_function); bootOneDevice(0, p); @@ -159,8 +160,8 @@ TEST_P(MYRIADWatchdog, canDetectWhenHostSiteStalled) { auto ctime = Time::now(); - SharedObjectLoader myriadPlg (make_plugin_name("myriadPlugin").c_str()); - void *p = myriadPlg.get_symbol(create_plugin_function); + std::shared_ptr myriadPlg = ov::util::load_shared_object(make_plugin_name("myriadPlugin").c_str()); + void *p = ov::util::get_symbol(myriadPlg, create_plugin_function); bootOneDevice(20000, p); diff --git a/samples/cpp/hello_nv12_input_classification/main.cpp b/samples/cpp/hello_nv12_input_classification/main.cpp index 9de3fa2bd68..8a6563e6900 100644 --- a/samples/cpp/hello_nv12_input_classification/main.cpp +++ b/samples/cpp/hello_nv12_input_classification/main.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include