From 5857a22ac30981251a27e0b5542cb8b9319a53be Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 13 May 2021 19:12:36 +0300 Subject: [PATCH 01/20] Added LoadNetwork(filename) to AUTO --- .../src/auto_plugin/auto_plugin.cpp | 32 ++++++ .../src/auto_plugin/auto_plugin.hpp | 1 + .../src/gna_plugin/gna_plugin.hpp | 2 +- .../src/inference_engine/ie_plugin_cpp.hpp | 2 +- .../impl/ie_executable_network_2_internal.hpp | 107 ++++++++++++++++++ .../impl/ie_executable_network_internal.hpp | 3 +- .../impl/ie_infer_request_2_internal.hpp | 90 +++++++++++++++ .../impl/ie_plugin_internal.hpp | 9 +- .../impl/ie_variable_state_2_internal.hpp | 37 ++++++ .../interface/ie_iplugin_internal.hpp | 4 +- .../interface/mock_iinference_plugin.hpp | 2 +- 11 files changed, 278 insertions(+), 11 deletions(-) create mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp create mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp create mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp diff --git a/inference-engine/src/auto_plugin/auto_plugin.cpp b/inference-engine/src/auto_plugin/auto_plugin.cpp index 692d8955a09424..280a74e52acf13 100644 --- a/inference-engine/src/auto_plugin/auto_plugin.cpp +++ b/inference-engine/src/auto_plugin/auto_plugin.cpp @@ -38,6 +38,38 @@ AutoInferencePlugin::AutoInferencePlugin() { _pluginName = "AUTO"; } +IE::IExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadNetwork(const std::string& fileName, + const ConfigType& config) { + if (GetCore() == nullptr) { + IE_THROW() << "Please, work with AUTO device via InferencEngine::Core object"; + } + + auto fullConfig = mergeConfigs(_config, config); + auto metaDevices = GetDeviceChoice(fullConfig); + + // FIXME: always select CPU device now + DeviceInformation selectedDevice = SelectDevice(metaDevices); + IE::ExecutableNetwork executableNetwork; + try { + executableNetwork = GetCore()->LoadNetwork(fileName, selectedDevice.deviceName, selectedDevice.config); + } catch(const IE::Exception &iie) { + IE_THROW() << "Failed to load network to device named " << selectedDevice.deviceName + << " with exception " << iie.what(); + } + + bool enablePerfCounters = false; + try { + enablePerfCounters = + executableNetwork.GetConfig(IE::PluginConfigParams::KEY_PERF_COUNT).as() == + IE::PluginConfigParams::YES; + } catch (...) { + } + + return std::make_shared(executableNetwork, + selectedDevice, + enablePerfCounters); +} + IE::ExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadExeNetworkImpl(const IE::CNNNetwork& network, const ConfigType& config) { if (GetCore() == nullptr) { diff --git a/inference-engine/src/auto_plugin/auto_plugin.hpp b/inference-engine/src/auto_plugin/auto_plugin.hpp index a2a885d4f1fc51..6eefeec5e2ed26 100644 --- a/inference-engine/src/auto_plugin/auto_plugin.hpp +++ b/inference-engine/src/auto_plugin/auto_plugin.hpp @@ -22,6 +22,7 @@ class AutoInferencePlugin : public IE::InferencePluginInternal { AutoInferencePlugin(); ~AutoInferencePlugin() = default; IE::ExecutableNetworkInternal::Ptr LoadExeNetworkImpl(const IE::CNNNetwork& network, const ConfigType& config) override; + IE::IExecutableNetworkInternal::Ptr LoadNetwork(const std::string& fileName, const ConfigType& config) override; IE::QueryNetworkResult QueryNetwork(const IE::CNNNetwork& network, const ConfigType& config) const override; IE::Parameter GetMetric(const std::string& name, const std::map& options) const override; IE::Parameter GetConfig(const std::string& name, const std::map & options) const override; diff --git a/inference-engine/src/gna_plugin/gna_plugin.hpp b/inference-engine/src/gna_plugin/gna_plugin.hpp index 33df51710ba69e..7ea93642ba1bb6 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.hpp +++ b/inference-engine/src/gna_plugin/gna_plugin.hpp @@ -110,7 +110,7 @@ class GNAPlugin : public InferenceEngine::IInferencePlugin { InferenceEngine::IExecutableNetworkInternal::Ptr LoadNetwork(const InferenceEngine::CNNNetwork &network, const std::map &config_map, InferenceEngine::RemoteContext::Ptr context) override { THROW_GNA_EXCEPTION << "Not implemented"; } - InferenceEngine::ExecutableNetwork LoadNetwork(const std::string &modelPath, + InferenceEngine::IExecutableNetworkInternal::Ptr LoadNetwork(const std::string &modelPath, const std::map &config_map) override { THROW_GNA_EXCEPTION << "Not implemented"; } bool Infer(const InferenceEngine::Blob &input, InferenceEngine::Blob &result); void SetCore(InferenceEngine::ICore*) noexcept override {} diff --git a/inference-engine/src/inference_engine/ie_plugin_cpp.hpp b/inference-engine/src/inference_engine/ie_plugin_cpp.hpp index d40bdc478aae1b..8e76faceef2475 100644 --- a/inference-engine/src/inference_engine/ie_plugin_cpp.hpp +++ b/inference-engine/src/inference_engine/ie_plugin_cpp.hpp @@ -89,7 +89,7 @@ class InferencePlugin { } ExecutableNetwork LoadNetwork(const std::string& modelPath, const std::map& config) { - PLUGIN_CALL_STATEMENT(return actual->LoadNetwork(modelPath, config)); + PLUGIN_CALL_STATEMENT(return ExecutableNetwork(actual->LoadNetwork(modelPath, config), actual)); } QueryNetworkResult QueryNetwork(const CNNNetwork& network, diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp new file mode 100644 index 00000000000000..ad89a212512ba0 --- /dev/null +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp @@ -0,0 +1,107 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "cpp_interfaces/impl/ie_executable_network_internal.hpp" +#include "cpp_interfaces/impl/ie_infer_request_2_internal.hpp" +#include "cpp/ie_executable_network.hpp" + +namespace InferenceEngine { + +class ExecutableNetwork2Internal : public ExecutableNetworkInternal { + ExecutableNetwork actual; +public: + explicit ExecutableNetwork2Internal(const ExecutableNetwork & exec) : actual(exec) { + if (!actual) { + IE_THROW(NotAllocated); + } + } + + virtual void setNetworkInputs(const InferenceEngine::InputsDataMap networkInputs) { + // should call internal methods + IE_THROW(NotImplemented); + } + + virtual void setNetworkOutputs(const InferenceEngine::OutputsDataMap networkOutputs) { + // should call internal methods + IE_THROW(NotImplemented); + } + + ConstOutputsDataMap GetOutputsInfo() const override { + return actual.GetOutputsInfo(); + } + + ConstInputsDataMap GetInputsInfo() const override { + return actual.GetInputsInfo(); + } + + void Export(const std::string& modelFileName) override { + actual.Export(modelFileName); + } + + void Export(std::ostream& networkModel) override { + actual.Export(networkModel); + } + + CNNNetwork GetExecGraphInfo() override { + return actual.GetExecGraphInfo(); + } + + void SetPointerToPlugin(IInferencePlugin::Ptr plugin) override { + // should call internal methods + IE_THROW(NotImplemented); + } + + std::vector QueryState() override { + IE_SUPPRESS_DEPRECATED_START + std::vector states; + for (auto & state : actual.QueryState()) { + states.push_back(std::make_shared(state)); + } + return states; + IE_SUPPRESS_DEPRECATED_END + } + + void SetConfig(const std::map& config) override { + actual.SetConfig(config); + } + + Parameter GetConfig(const std::string& name) const override { + return actual.GetConfig(name); + } + + Parameter GetMetric(const std::string& name) const override { + return actual.GetConfig(name); + } + + RemoteContext::Ptr GetContext() const override { + return actual.GetContext(); + } + + IInferRequestInternal::Ptr CreateInferRequest() override { + return std::make_shared(actual.CreateInferRequest()); + } + +protected: + IInferRequestInternal::Ptr CreateInferRequestImpl(InputsDataMap networkInputs, + OutputsDataMap networkOutputs) override { + // should call internal methods + IE_THROW(NotImplemented); + } + + void ExportImpl(std::ostream& networkModel) override { + // should call internal methods + IE_THROW(NotImplemented); + } +}; + +} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp index d91d24e3e06ccf..d1cd185be9cc50 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_internal.hpp @@ -86,7 +86,7 @@ class ExecutableNetworkInternal : public IExecutableNetworkInternal { * @param[in] plugin The plugin * @note Needed to correctly handle ownership between objects. */ - void SetPointerToPlugin(IInferencePlugin::Ptr plugin) { + virtual void SetPointerToPlugin(IInferencePlugin::Ptr plugin) { _plugin = plugin; } @@ -116,7 +116,6 @@ class ExecutableNetworkInternal : public IExecutableNetworkInternal { IE_THROW(NotImplemented); } - /** * @brief Creates an inference request public implementation. * @return The request public implementation diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp new file mode 100644 index 00000000000000..046d476e4e3148 --- /dev/null +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp @@ -0,0 +1,90 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" +#include "cpp_interfaces/impl/ie_variable_state_2_internal.hpp" + +namespace InferenceEngine { + +class InferRequest2Internal : public IInferRequestInternal { + InferRequest actual; + +public: + explicit InferRequest2Internal(const InferRequest & request) : actual(request) { + if (!actual) { + IE_THROW(NotAllocated); + } + } + + void Infer() override { + actual.Infer(); + } + + virtual void InferImpl() { + // should call internal methods + IE_THROW(NotImplemented); + } + + void Cancel() override { + actual.Cancel(); + } + + std::map GetPerformanceCounts() const override { + return actual.GetPerformanceCounts(); + } + + void SetBlob(const std::string& name, const Blob::Ptr& data) override { + actual.SetBlob(name, data); + } + + Blob::Ptr GetBlob(const std::string& name) override { + return actual.GetBlob(name); + } + + void SetBlob(const std::string& name, const Blob::Ptr& data, const PreProcessInfo& info) override { + actual.SetBlob(name, data, info); + } + + const PreProcessInfo& GetPreProcess(const std::string& name) const override { + return actual.GetPreProcess(name); + } + + void SetBatch(int batch) override { + actual.SetBatch(batch); + } + + std::vector> QueryState() override { + std::vector states; + for (auto & state : actual.QueryState()) { + states.push_back(std::make_shared(state)); + } + return states; + } + + void StartAsync() override { + actual.StartAsync(); + } + + void StartAsyncImpl() override { + // should call internal methods + IE_THROW(NotImplemented); + } + + StatusCode Wait(int64_t millis_timeout) override { + return actual.Wait(millis_timeout); + } + + void SetCallback(Callback callback) override { + // TODO: + } + + void checkBlobs() override { + // should call internal methods + IE_THROW(NotImplemented); + } +}; + +} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp index dcaf4a1e529f65..270daa372d423c 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp @@ -16,7 +16,7 @@ #include #include -#include "cpp_interfaces/impl/ie_executable_network_internal.hpp" +#include "cpp_interfaces/impl/ie_executable_network_2_internal.hpp" #include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include "cpp_interfaces/plugin_itt.hpp" @@ -72,10 +72,11 @@ class InferencePluginInternal : public IInferencePlugin { return impl; } - ExecutableNetwork LoadNetwork(const std::string& modelPath, - const std::map& config) override { + IExecutableNetworkInternal::Ptr LoadNetwork(const std::string& modelPath, + const std::map& config) override { auto cnnNet = GetCore()->ReadNetwork(modelPath, std::string()); - return GetCore()->LoadNetwork(cnnNet, GetName(), config); + auto exec = GetCore()->LoadNetwork(cnnNet, GetName(), config); + return std::make_shared(exec); } IExecutableNetworkInternal::Ptr ImportNetwork(const std::string& modelFileName, diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp new file mode 100644 index 00000000000000..6cd4e8dd7c2c1a --- /dev/null +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include "cpp/ie_memory_state.hpp" + +namespace InferenceEngine { + +class VariableState2Internal : public VariableStateInternal { + VariableState actual; + +public: + explicit VariableState2Internal(const VariableState & variableState) : + VariableStateInternal(variableState.GetName()), actual(variableState) { + // TODO: added a check for emptyness + // if (!actual) { + // IE_THROW(NotAllocated); + // } + } + + void Reset() override { + actual.Reset(); + } + + void SetState(Blob::Ptr newState) override { + actual.SetState(newState); + } + + Blob::CPtr GetState() const override { + return actual.GetState(); + } +}; + +} // namespace InferenceEngine 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 18f4658d6a4cc4..6030e2f7ddb3db 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 @@ -173,8 +173,8 @@ class IInferencePlugin : public std::enable_shared_from_this { * @param config A string-string map of config parameters relevant only for this load operation * @return Created Executable Network object */ - virtual ExecutableNetwork LoadNetwork(const std::string& modelPath, - const std::map& config) = 0; + virtual std::shared_ptr LoadNetwork(const std::string& modelPath, + const std::map& config) = 0; /** * @brief Registers extension within plugin diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp index 7f450f660f37a6..083a529e121493 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp @@ -15,7 +15,7 @@ class MockIInferencePlugin : public InferenceEngine::IInferencePlugin { MOCK_METHOD1(AddExtension, void(InferenceEngine::IExtensionPtr)); MOCK_METHOD2(LoadNetwork, std::shared_ptr( const InferenceEngine::CNNNetwork&, const std::map&)); - MOCK_METHOD2(LoadNetwork, InferenceEngine::ExecutableNetwork( + MOCK_METHOD2(LoadNetwork, std::shared_ptr( const std::string&, const std::map&)); MOCK_METHOD2(ImportNetwork, std::shared_ptr( const std::string&, const std::map&)); From 73ecd115623946c3134e02ff5a27a1e6983bcd8d Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 13 May 2021 19:53:57 +0300 Subject: [PATCH 02/20] Added more files --- .../impl/ie_executable_network_2_internal.hpp | 19 +------------------ .../impl/ie_infer_request_2_internal.hpp | 16 +++++++++++++++- .../impl/ie_variable_state_2_internal.hpp | 8 ++++++-- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp index ad89a212512ba0..08e76565cccecc 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp @@ -17,7 +17,7 @@ namespace InferenceEngine { -class ExecutableNetwork2Internal : public ExecutableNetworkInternal { +class ExecutableNetwork2Internal : public IExecutableNetworkInternal { ExecutableNetwork actual; public: explicit ExecutableNetwork2Internal(const ExecutableNetwork & exec) : actual(exec) { @@ -56,11 +56,6 @@ class ExecutableNetwork2Internal : public ExecutableNetworkInternal { return actual.GetExecGraphInfo(); } - void SetPointerToPlugin(IInferencePlugin::Ptr plugin) override { - // should call internal methods - IE_THROW(NotImplemented); - } - std::vector QueryState() override { IE_SUPPRESS_DEPRECATED_START std::vector states; @@ -90,18 +85,6 @@ class ExecutableNetwork2Internal : public ExecutableNetworkInternal { IInferRequestInternal::Ptr CreateInferRequest() override { return std::make_shared(actual.CreateInferRequest()); } - -protected: - IInferRequestInternal::Ptr CreateInferRequestImpl(InputsDataMap networkInputs, - OutputsDataMap networkOutputs) override { - // should call internal methods - IE_THROW(NotImplemented); - } - - void ExportImpl(std::ostream& networkModel) override { - // should call internal methods - IE_THROW(NotImplemented); - } }; } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp index 046d476e4e3148..7189edc6b55107 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp @@ -78,7 +78,21 @@ class InferRequest2Internal : public IInferRequestInternal { } void SetCallback(Callback callback) override { - // TODO: + // actual.SetCallback([&] (std::exception_ptr exceptionPtr) { + // StatusCode statusCode = StatusCode::OK; + // if (exceptionPtr != nullptr) { + // statusCode = [&] { + // try { + // std::rethrow_exception(exceptionPtr); + // } CATCH_IE_EXCEPTIONS_RETURN catch (const std::exception& ex) { + // return GENERAL_ERROR; + // } catch (...) { + // return UNEXPECTED; + // } + // } (); + // } + // callback(weakThis, statusCode); + // }); } void checkBlobs() override { diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp index 6cd4e8dd7c2c1a..de9b580c7516b9 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp @@ -9,18 +9,22 @@ namespace InferenceEngine { -class VariableState2Internal : public VariableStateInternal { +class VariableState2Internal : public IVariableStateInternal { VariableState actual; public: explicit VariableState2Internal(const VariableState & variableState) : - VariableStateInternal(variableState.GetName()), actual(variableState) { + actual(variableState) { // TODO: added a check for emptyness // if (!actual) { // IE_THROW(NotAllocated); // } } + virtual std::string GetName() const override { + return actual.GetName(); + } + void Reset() override { actual.Reset(); } From 9c752b1e047d9741887a85132a467c9ca18ac198 Mon Sep 17 00:00:00 2001 From: apankratovantonp Date: Fri, 14 May 2021 23:32:17 +0300 Subject: [PATCH 03/20] So pointer can be used without loading --- .../include/cpp/ie_executable_network.hpp | 23 +--- .../include/cpp/ie_infer_request.hpp | 19 +-- .../include/cpp/ie_memory_state.hpp | 17 +-- .../include/details/ie_so_loader.h | 7 +- .../include/details/ie_so_pointer.hpp | 117 +++++++----------- .../cpp/ie_executable_network.cpp | 49 +++----- .../inference_engine/cpp/ie_infer_request.cpp | 57 ++++----- .../{ie_plugin_cpp.hpp => cpp/ie_plugin.hpp} | 72 ++++------- .../cpp/ie_variable_state.cpp | 17 +-- .../src/inference_engine/ie_core.cpp | 4 +- .../inference_engine/ie_network_reader.cpp | 2 +- .../src/inference_engine/ie_plugin_ptr.hpp | 41 ------ .../os/lin/lin_shared_object_loader.cpp | 1 + .../mkldnn_plugin/mkldnn_extension_mngr.cpp | 2 +- .../nodes/extract_image_patches.hpp | 1 + .../interface/ie_iplugin_internal.hpp | 8 ++ .../src/preprocessing/ie_preprocess_data.hpp | 2 +- .../inference_engine/caching_test.cpp | 3 +- .../shared_object_loader_test.cpp | 2 +- .../inference_engine/so_pointer_tests.cpp | 64 +--------- .../ie_infer_async_request_base_test.cpp | 10 +- .../ie_memory_state_internal_test.cpp | 7 +- .../cpp_interfaces/ie_plugin_test.cpp | 13 +- .../ie_executable_network_test.cpp | 9 +- .../unit/inference_engine/ie_plugin_ptr.cpp | 13 +- .../vpu/myriad_tests/vpu_watchdog_tests.cpp | 2 +- 26 files changed, 163 insertions(+), 399 deletions(-) rename inference-engine/src/inference_engine/{ie_plugin_cpp.hpp => cpp/ie_plugin.hpp} (59%) delete mode 100644 inference-engine/src/inference_engine/ie_plugin_ptr.hpp diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 1001e65903df0d..0430ce17d64192 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -21,36 +21,17 @@ namespace InferenceEngine { -namespace details { -class SharedObjectLoader; -} - class IExecutableNetworkInternal; class IExecutableNetwork; /** * @brief This is an interface of an executable network */ -class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) { - std::shared_ptr _impl; - std::shared_ptr _so; - - ExecutableNetwork(const std::shared_ptr& impl, - const std::shared_ptr& so); - +class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPointer { + using details::SOPointer::SOPointer; friend class InferencePlugin; public: - /** - * @brief Default constructor - */ - ExecutableNetwork() = default; - - /** - * @brief Default destructor - */ - ~ExecutableNetwork(); - /** * @brief Gets the Executable network output Data node information. * diff --git a/inference-engine/include/cpp/ie_infer_request.hpp b/inference-engine/include/cpp/ie_infer_request.hpp index 8ae8f1be3b948a..47dba4e9c5234a 100644 --- a/inference-engine/include/cpp/ie_infer_request.hpp +++ b/inference-engine/include/cpp/ie_infer_request.hpp @@ -32,13 +32,8 @@ class IInferRequestInternal; * Wraps IInferRequest * It can throw exceptions safely for the application, where it is properly handled. */ -class INFERENCE_ENGINE_API_CLASS(InferRequest) { - std::shared_ptr _impl; - std::shared_ptr _so; - - InferRequest(const std::shared_ptr& impl, - const std::shared_ptr& so); - +class INFERENCE_ENGINE_API_CLASS(InferRequest) : protected details::SOPointer { + using details::SOPointer::SOPointer; friend class ExecutableNetwork; public: @@ -58,16 +53,6 @@ class INFERENCE_ENGINE_API_CLASS(InferRequest) { */ using Ptr = std::shared_ptr; - /** - * @brief Default constructor - */ - InferRequest() = default; - - /** - * @brief Destructor - */ - ~InferRequest(); - /** * @brief Sets input/output data to infer * diff --git a/inference-engine/include/cpp/ie_memory_state.hpp b/inference-engine/include/cpp/ie_memory_state.hpp index 6907862efc1048..3ca2c910b268af 100644 --- a/inference-engine/include/cpp/ie_memory_state.hpp +++ b/inference-engine/include/cpp/ie_memory_state.hpp @@ -15,6 +15,7 @@ #include "ie_api.h" #include "ie_blob.h" +#include "details/ie_so_pointer.hpp" namespace InferenceEngine { @@ -27,18 +28,8 @@ class IVariableStateInternal; /** * @brief C++ exception based error reporting wrapper of API class IVariableState */ -class INFERENCE_ENGINE_API_CLASS(VariableState) { - std::shared_ptr _impl = nullptr; - std::shared_ptr _so = nullptr; - - /** - * @brief Constructs VariableState from the initialized std::shared_ptr - * @param impl Initialized shared pointer - * @param so Optional: Plugin to use. This is required to ensure that VariableState can work properly even if plugin object is destroyed. - */ - VariableState(const std::shared_ptr& impl, - const std::shared_ptr& so); - +class INFERENCE_ENGINE_API_CLASS(VariableState) : protected details::SOPointer { + using details::SOPointer::SOPointer; friend class InferRequest; friend class ExecutableNetwork; @@ -62,7 +53,7 @@ class INFERENCE_ENGINE_API_CLASS(VariableState) { * @copybrief IVariableState::GetState * * Wraps IVariableState::GetState - * @return A blob representing a state + * @return A blob representing a state */ Blob::CPtr GetState() const; diff --git a/inference-engine/include/details/ie_so_loader.h b/inference-engine/include/details/ie_so_loader.h index aa1a82a2281a6d..0a0762ce241fdd 100644 --- a/inference-engine/include/details/ie_so_loader.h +++ b/inference-engine/include/details/ie_so_loader.h @@ -4,7 +4,7 @@ /** * @brief A header file for definition of abstraction over platform specific shared objects - * + * * @file ie_so_loader.h */ #pragma once @@ -24,10 +24,7 @@ class INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) { std::shared_ptr _impl; public: - /** - * @brief A shared pointer to SharedObjectLoader - */ - using Ptr = std::shared_ptr; + SharedObjectLoader() = default; #ifdef ENABLE_UNICODE_PATH_SUPPORT /** diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index b2926ee44ecae7..4b240f90e19bb2 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -34,13 +34,12 @@ template using enableIfSupportedChar = typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; /** - * @brief This class instantiate object using shared library + * @brief This class instantiate object loaded from the shared library * @tparam T An type of object SOPointer can hold - * @tparam Loader A loader used to load a library */ -template +template class SOPointer { - template + template friend class SOPointer; IE_SUPPRESS_DEPRECATED_START struct HasRelease { @@ -57,73 +56,60 @@ IE_SUPPRESS_DEPRECATED_END SOPointer() = default; /** - * @brief The main constructor - * @param name Name of a shared library file - */ - template > - explicit SOPointer(const std::basic_string & name) - : _so_loader(new Loader(name.c_str())) { - Load(std::integral_constant{}); - } - - /** - * @brief The main constructor - * @param name Name of a shared library file + * @brief Constructs an object using name to load library + * @param name Existing pointer to a library loader */ - explicit SOPointer(const char * name) - : _so_loader(new Loader(name)) { - Load(std::integral_constant{}); - } - - /** - * @brief Constructs an object with existing reference - * @param pointedObj Existing reference to wrap - */ - explicit SOPointer(T* pointedObj): _so_loader(), _pointedObj(pointedObj) { - if (_pointedObj == nullptr) { - IE_THROW() << "Cannot create SOPointer from nullptr"; - } + template> + SOPointer(const std::basic_string& name) : + _so{name.c_str()} { + Load(std::integral_constant{}); } /** * @brief Constructs an object with existing loader - * @param so_loader Existing pointer to a library loader + * @param soLoader Existing pointer to a library loader */ - explicit SOPointer(const std::shared_ptr& so_loader) - : _so_loader(so_loader) { - Load(std::integral_constant{}); - } + SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) : _so{so}, _ptr{ptr} {} /** * @brief The copy-like constructor, can create So Pointer that dereferenced into child type if T is derived of U * @param that copied SOPointer object */ - template - SOPointer(const SOPointer& that) - : _so_loader(std::dynamic_pointer_cast(that._so_loader)), - _pointedObj(std::dynamic_pointer_cast(that._pointedObj)) { - IE_ASSERT(_pointedObj != nullptr); - } + template + SOPointer(const SOPointer& that) + : _so(that._so), + _ptr(std::dynamic_pointer_cast(that._ptr)) {} /** * @brief Standard pointer operator - * @return underlined interface with disabled Release method */ T* operator->() const noexcept { - return _pointedObj.get(); + return _ptr.get(); } /** * @brief Standard dereference operator - * @return underlined interface with disabled Release method */ const T* operator*() const noexcept { return this->operator->(); } + /** + * @return raw pointer + */ + T* get() noexcept { + return _ptr.get(); + } + + /** + * @return raw pointer + */ + const T* get() const noexcept { + return this->get(); + } + explicit operator bool() const noexcept { - return (nullptr != _pointedObj); + return _ptr != nullptr; } friend bool operator==(std::nullptr_t, const SOPointer& ptr) noexcept { @@ -139,14 +125,12 @@ IE_SUPPRESS_DEPRECATED_END return static_cast(ptr); } - SOPointer& operator=(const SOPointer& pointer) noexcept { - _pointedObj = pointer._pointedObj; - _so_loader = pointer._so_loader; - return *this; + operator const SharedObjectLoader&() const noexcept { + return _so; } - operator const std::shared_ptr&() const noexcept { - return _so_loader; + operator std::shared_ptr& () noexcept { + return _ptr; } protected: @@ -166,17 +150,14 @@ IE_SUPPRESS_DEPRECATED_END CATCH_IE_EXCEPTION(NetworkNotRead) \ CATCH_IE_EXCEPTION(InferCancelled) - /** - * @brief Implements load of object from library if Release method is presented - */ void Load(std::true_type) { try { void* create = nullptr; try { - create = _so_loader->get_symbol((SOCreatorTrait::name + std::string("Shared")).c_str()); + create = _so.get_symbol((SOCreatorTrait::name + std::string("Shared")).c_str()); } catch (const NotFound&) {} if (create == nullptr) { - create = _so_loader->get_symbol(SOCreatorTrait::name); + create = _so.get_symbol(SOCreatorTrait::name); using CreateF = StatusCode(T*&, ResponseDesc*); T* object = nullptr; ResponseDesc desc; @@ -186,11 +167,11 @@ IE_SUPPRESS_DEPRECATED_END InferenceEngine::details::ThrowNow{} <<= std::stringstream{} << IE_LOCATION << desc.msg) } IE_SUPPRESS_DEPRECATED_START - _pointedObj = std::shared_ptr(object, [] (T* ptr){ptr->Release();}); + _ptr = std::shared_ptr{object, [] (T* ptr){ptr->Release();}}; IE_SUPPRESS_DEPRECATED_END } else { using CreateF = void(std::shared_ptr&); - reinterpret_cast(create)(_pointedObj); + reinterpret_cast(create)(_ptr); } } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { IE_THROW() << ex.what(); @@ -199,31 +180,21 @@ IE_SUPPRESS_DEPRECATED_END } } - /** - * @brief Implements load of object from library - */ void Load(std::false_type) { try { using CreateF = void(std::shared_ptr&); - reinterpret_cast(_so_loader->get_symbol(SOCreatorTrait::name))(_pointedObj); + reinterpret_cast(_so.get_symbol(SOCreatorTrait::name))(_ptr); } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { IE_THROW() << ex.what(); } catch(...) { IE_THROW(Unexpected); } } - #undef CATCH_IE_EXCEPTION - #undef CATCH_IE_EXCEPTIONS +#undef CATCH_IE_EXCEPTION +#undef CATCH_IE_EXCEPTIONS - /** - * @brief Gets a smart pointer to the DLL - */ - std::shared_ptr _so_loader; - - /** - * @brief Gets a smart pointer to the custom object - */ - std::shared_ptr _pointedObj; + SharedObjectLoader _so; + std::shared_ptr _ptr; }; } // namespace details } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index cef73ed9347168..b1641c4531a5a1 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -11,7 +11,7 @@ namespace InferenceEngine { #define EXEC_NET_CALL_STATEMENT(...) \ - if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \ + if (_ptr == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \ try { \ __VA_ARGS__; \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -20,45 +20,35 @@ namespace InferenceEngine { IE_THROW(Unexpected); \ } -ExecutableNetwork::ExecutableNetwork(const IExecutableNetworkInternal::Ptr& impl, - const std::shared_ptr& so) - : _impl(impl), _so(so) { - IE_ASSERT(_impl != nullptr); -} - -ExecutableNetwork::~ExecutableNetwork() { - _impl = {}; -} - ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const { - EXEC_NET_CALL_STATEMENT(return _impl->GetOutputsInfo()); + EXEC_NET_CALL_STATEMENT(return _ptr->GetOutputsInfo()); } ConstInputsDataMap ExecutableNetwork::GetInputsInfo() const { - EXEC_NET_CALL_STATEMENT(return _impl->GetInputsInfo()); + EXEC_NET_CALL_STATEMENT(return _ptr->GetInputsInfo()); } IE_SUPPRESS_DEPRECATED_START void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) { - if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; + if (_ptr == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; if (newActual == nullptr) IE_THROW() << "ExecutableNetwork wrapper used for reset was not initialized."; auto newBase = std::dynamic_pointer_cast(newActual); IE_ASSERT(newBase != nullptr); auto newImpl = newBase->GetImpl(); IE_ASSERT(newImpl != nullptr); - this->_impl.swap(newImpl); + _ptr = details::SOPointer{_so, newImpl}; } ExecutableNetwork::operator IExecutableNetwork::Ptr() { - return std::make_shared(_impl); + return std::make_shared(_ptr); } std::vector ExecutableNetwork::QueryState() { std::vector controller; EXEC_NET_CALL_STATEMENT( - for (auto&& state : _impl->QueryState()) { - controller.emplace_back(VariableState(state, _so)); + for (auto&& state : _ptr->QueryState()) { + controller.emplace_back(_so, state); }); return controller; } @@ -66,47 +56,46 @@ std::vector ExecutableNetwork::QueryState() { IE_SUPPRESS_DEPRECATED_END InferRequest ExecutableNetwork::CreateInferRequest() { - EXEC_NET_CALL_STATEMENT(return InferRequest{_impl->CreateInferRequest(), _so}); + EXEC_NET_CALL_STATEMENT(return InferRequest{_so, _ptr->CreateInferRequest()}); } InferRequest::Ptr ExecutableNetwork::CreateInferRequestPtr() { - EXEC_NET_CALL_STATEMENT(return std::make_shared(InferRequest{_impl->CreateInferRequest(), _so})); + EXEC_NET_CALL_STATEMENT(return std::make_shared(_so, _ptr->CreateInferRequest())); } void ExecutableNetwork::Export(const std::string& modelFileName) { - EXEC_NET_CALL_STATEMENT(_impl->Export(modelFileName)); + EXEC_NET_CALL_STATEMENT(_ptr->Export(modelFileName)); } void ExecutableNetwork::Export(std::ostream& networkModel) { - EXEC_NET_CALL_STATEMENT(_impl->Export(networkModel)); + EXEC_NET_CALL_STATEMENT(_ptr->Export(networkModel)); } CNNNetwork ExecutableNetwork::GetExecGraphInfo() { - EXEC_NET_CALL_STATEMENT(return _impl->GetExecGraphInfo()); + EXEC_NET_CALL_STATEMENT(return _ptr->GetExecGraphInfo()); } void ExecutableNetwork::SetConfig(const std::map& config) { - EXEC_NET_CALL_STATEMENT(_impl->SetConfig(config)); + EXEC_NET_CALL_STATEMENT(_ptr->SetConfig(config)); } Parameter ExecutableNetwork::GetConfig(const std::string& name) const { - EXEC_NET_CALL_STATEMENT(return _impl->GetConfig(name)); + EXEC_NET_CALL_STATEMENT(return _ptr->GetConfig(name)); } Parameter ExecutableNetwork::GetMetric(const std::string& name) const { - EXEC_NET_CALL_STATEMENT(return _impl->GetMetric(name)); + EXEC_NET_CALL_STATEMENT(return _ptr->GetMetric(name)); } RemoteContext::Ptr ExecutableNetwork::GetContext() const { - EXEC_NET_CALL_STATEMENT(return _impl->GetContext()); + EXEC_NET_CALL_STATEMENT(return _ptr->GetContext()); } bool ExecutableNetwork::operator!() const noexcept { - return !_impl; + return !_ptr; } ExecutableNetwork::operator bool() const noexcept { - return !!_impl; + return !!_ptr; } - } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index a3052ecda78896..21e7e39e712439 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -32,7 +32,7 @@ namespace InferenceEngine { CATCH_IE_EXCEPTION(InferCancelled) #define INFER_REQ_CALL_STATEMENT(...) \ - if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \ + if (_ptr == nullptr) IE_THROW() << "Inference Request is not initialized"; \ try { \ __VA_ARGS__ \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -41,24 +41,13 @@ namespace InferenceEngine { IE_THROW(Unexpected); \ } -InferRequest::InferRequest(const std::shared_ptr& impl, - const std::shared_ptr& so) : - _impl{impl}, - _so{so} { - if (_impl == nullptr) IE_THROW() << "Inference Requst is not initialized"; -} - -InferRequest::~InferRequest() { - _impl = {}; -} - void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) { - INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data);) + INFER_REQ_CALL_STATEMENT(_ptr->SetBlob(name, data);) } Blob::Ptr InferRequest::GetBlob(const std::string& name) { Blob::Ptr blobPtr; - INFER_REQ_CALL_STATEMENT(blobPtr = _impl->GetBlob(name);) + INFER_REQ_CALL_STATEMENT(blobPtr = _ptr->GetBlob(name);) std::string error = "Internal error: blob with name `" + name + "` is not allocated!"; const bool remoteBlobPassed = blobPtr->is(); if (blobPtr == nullptr) IE_THROW() << error; @@ -67,29 +56,29 @@ Blob::Ptr InferRequest::GetBlob(const std::string& name) { } void InferRequest::SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info) { - INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data, info);) + INFER_REQ_CALL_STATEMENT(_ptr->SetBlob(name, data, info);) } const PreProcessInfo& InferRequest::GetPreProcess(const std::string& name) const { - INFER_REQ_CALL_STATEMENT(return _impl->GetPreProcess(name);) + INFER_REQ_CALL_STATEMENT(return _ptr->GetPreProcess(name);) } void InferRequest::Infer() { - INFER_REQ_CALL_STATEMENT(_impl->Infer();) + INFER_REQ_CALL_STATEMENT(_ptr->Infer();) } void InferRequest::Cancel() { - INFER_REQ_CALL_STATEMENT(_impl->Cancel();) + INFER_REQ_CALL_STATEMENT(_ptr->Cancel();) } std::map InferRequest::GetPerformanceCounts() const { - INFER_REQ_CALL_STATEMENT(return _impl->GetPerformanceCounts();) + INFER_REQ_CALL_STATEMENT(return _ptr->GetPerformanceCounts();) } void InferRequest::SetInput(const BlobMap& inputs) { INFER_REQ_CALL_STATEMENT( for (auto&& input : inputs) { - _impl->SetBlob(input.first, input.second); + _ptr->SetBlob(input.first, input.second); } ) } @@ -97,27 +86,27 @@ void InferRequest::SetInput(const BlobMap& inputs) { void InferRequest::SetOutput(const BlobMap& results) { INFER_REQ_CALL_STATEMENT( for (auto&& result : results) { - _impl->SetBlob(result.first, result.second); + _ptr->SetBlob(result.first, result.second); } ) } void InferRequest::SetBatch(const int batch) { - INFER_REQ_CALL_STATEMENT(_impl->SetBatch(batch);) + INFER_REQ_CALL_STATEMENT(_ptr->SetBatch(batch);) } void InferRequest::StartAsync() { - INFER_REQ_CALL_STATEMENT(_impl->StartAsync();) + INFER_REQ_CALL_STATEMENT(_ptr->StartAsync();) } StatusCode InferRequest::Wait(int64_t millis_timeout) { - INFER_REQ_CALL_STATEMENT(return _impl->Wait(millis_timeout);) + INFER_REQ_CALL_STATEMENT(return _ptr->Wait(millis_timeout);) } void InferRequest::SetCompletionCallbackImpl(std::function callback) { INFER_REQ_CALL_STATEMENT( - _impl->SetCallback([callback] (std::exception_ptr) { + _ptr->SetCallback([callback] (std::exception_ptr) { callback(); }); ) @@ -144,8 +133,8 @@ void InferRequest::SetCompletionCallbackImpl(std::function callback) { void InferRequest::SetCompletionCallbackImpl(std::function callback) { INFER_REQ_CALL_STATEMENT( - auto weakThis = InferRequest{std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}, _so}; - _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { + auto weakThis = InferRequest{_so, std::shared_ptr{_ptr.get(), [](IInferRequestInternal*){}}}; + _ptr->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { StatusCode statusCode = StatusCode::OK; if (exceptionPtr != nullptr) { statusCode = [&] { @@ -167,8 +156,8 @@ IE_SUPPRESS_DEPRECATED_START void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback callback) { INFER_REQ_CALL_STATEMENT( - IInferRequest::Ptr weakThis = InferRequest{std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}, _so}; - _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { + IInferRequest::Ptr weakThis = InferRequest{_so, std::shared_ptr{_ptr.get(), [](IInferRequestInternal*){}}}; + _ptr->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { StatusCode statusCode = StatusCode::OK; if (exceptionPtr != nullptr) { statusCode = [&] { @@ -188,7 +177,7 @@ void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback c InferRequest::operator IInferRequest::Ptr () { INFER_REQ_CALL_STATEMENT( - return std::make_shared(_impl); + return std::make_shared(_ptr); ) } @@ -197,18 +186,18 @@ IE_SUPPRESS_DEPRECATED_END std::vector InferRequest::QueryState() { std::vector controller; INFER_REQ_CALL_STATEMENT( - for (auto&& state : _impl->QueryState()) { - controller.emplace_back(VariableState(state, _so)); + for (auto&& state : _ptr->QueryState()) { + controller.emplace_back(_so, state); } ) return controller; } bool InferRequest::operator!() const noexcept { - return !_impl; + return !_ptr; } InferRequest::operator bool() const noexcept { - return !!_impl; + return !!_ptr; } } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/ie_plugin_cpp.hpp b/inference-engine/src/inference_engine/cpp/ie_plugin.hpp similarity index 59% rename from inference-engine/src/inference_engine/ie_plugin_cpp.hpp rename to inference-engine/src/inference_engine/cpp/ie_plugin.hpp index d40bdc478aae1b..9be0845484a95f 100644 --- a/inference-engine/src/inference_engine/ie_plugin_cpp.hpp +++ b/inference-engine/src/inference_engine/cpp/ie_plugin.hpp @@ -16,8 +16,8 @@ #include "file_utils.h" #include "cpp/ie_executable_network.hpp" #include "cpp/ie_cnn_network.h" -#include "ie_plugin_ptr.hpp" #include "cpp/exception2status.hpp" +#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #if defined __GNUC__ # pragma GCC diagnostic push @@ -25,7 +25,7 @@ #endif #define PLUGIN_CALL_STATEMENT(...) \ - if (!actual) IE_THROW() << "Wrapper used in the PLUGIN_CALL_STATEMENT was not initialized."; \ + if (!_ptr) IE_THROW() << "Wrapper used in the PLUGIN_CALL_STATEMENT was not initialized."; \ try { \ __VA_ARGS__; \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -35,117 +35,87 @@ } namespace InferenceEngine { - /** * @brief This class is a C++ API wrapper for IInferencePlugin. * * It can throw exceptions safely for the application, where it is properly handled. */ -class InferencePlugin { - InferenceEnginePluginPtr actual; +class InferencePlugin : protected details::SOPointer { + using details::SOPointer::SOPointer; + friend class ICore; public: - InferencePlugin() = default; - - explicit InferencePlugin(const InferenceEnginePluginPtr& pointer): actual(pointer) { - if (actual == nullptr) { - IE_THROW() << "InferencePlugin wrapper was not initialized."; - } - } - - explicit InferencePlugin(const FileUtils::FilePath & libraryLocation) : - actual(libraryLocation) { - if (actual == nullptr) { - IE_THROW() << "InferencePlugin wrapper was not initialized."; - } - } - void SetName(const std::string & deviceName) { - PLUGIN_CALL_STATEMENT(actual->SetName(deviceName)); + PLUGIN_CALL_STATEMENT(_ptr->SetName(deviceName)); } void SetCore(ICore* core) { - PLUGIN_CALL_STATEMENT(actual->SetCore(core)); + PLUGIN_CALL_STATEMENT(_ptr->SetCore(core)); } const Version GetVersion() const { - PLUGIN_CALL_STATEMENT(return actual->GetVersion()); + PLUGIN_CALL_STATEMENT(return _ptr->GetVersion()); } void AddExtension(InferenceEngine::IExtensionPtr extension) { - PLUGIN_CALL_STATEMENT(actual->AddExtension(extension)); + PLUGIN_CALL_STATEMENT(_ptr->AddExtension(extension)); } void SetConfig(const std::map& config) { - PLUGIN_CALL_STATEMENT(actual->SetConfig(config)); + PLUGIN_CALL_STATEMENT(_ptr->SetConfig(config)); } ExecutableNetwork LoadNetwork(const CNNNetwork& network, const std::map& config) { - PLUGIN_CALL_STATEMENT(return ExecutableNetwork(actual->LoadNetwork(network, config), actual)); + PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(network, config)}); } ExecutableNetwork LoadNetwork(const CNNNetwork& network, RemoteContext::Ptr context, const std::map& config) { - PLUGIN_CALL_STATEMENT(return ExecutableNetwork(actual->LoadNetwork(network, config, context), actual)); + PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(network, config, context)}); } ExecutableNetwork LoadNetwork(const std::string& modelPath, const std::map& config) { - PLUGIN_CALL_STATEMENT(return actual->LoadNetwork(modelPath, config)); + PLUGIN_CALL_STATEMENT(return _ptr->LoadNetwork(modelPath, config)); } QueryNetworkResult QueryNetwork(const CNNNetwork& network, const std::map& config) const { QueryNetworkResult res; - PLUGIN_CALL_STATEMENT(res = actual->QueryNetwork(network, config)); + PLUGIN_CALL_STATEMENT(res = _ptr->QueryNetwork(network, config)); if (res.rc != OK) IE_THROW() << res.resp.msg; return res; } ExecutableNetwork ImportNetwork(const std::string& modelFileName, const std::map& config) { - PLUGIN_CALL_STATEMENT(return ExecutableNetwork(actual->ImportNetwork(modelFileName, config), actual)); + PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(modelFileName, config)}); } ExecutableNetwork ImportNetwork(std::istream& networkModel, const std::map& config) { - PLUGIN_CALL_STATEMENT(return ExecutableNetwork(actual->ImportNetwork(networkModel, config), actual)); + PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(networkModel, config)}); } ExecutableNetwork ImportNetwork(std::istream& networkModel, const RemoteContext::Ptr& context, const std::map& config) { - PLUGIN_CALL_STATEMENT(return ExecutableNetwork(actual->ImportNetwork(networkModel, context, config), actual)); + PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(networkModel, context, config)}); } Parameter GetMetric(const std::string& name, const std::map& options) const { - PLUGIN_CALL_STATEMENT(return actual->GetMetric(name, options)); + PLUGIN_CALL_STATEMENT(return _ptr->GetMetric(name, options)); } RemoteContext::Ptr CreateContext(const ParamMap& params) { - PLUGIN_CALL_STATEMENT(return actual->CreateContext(params)); + PLUGIN_CALL_STATEMENT(return _ptr->CreateContext(params)); } RemoteContext::Ptr GetDefaultContext(const ParamMap& params) { - PLUGIN_CALL_STATEMENT(return actual->GetDefaultContext(params)); + PLUGIN_CALL_STATEMENT(return _ptr->GetDefaultContext(params)); } Parameter GetConfig(const std::string& name, const std::map& options) const { - PLUGIN_CALL_STATEMENT(return actual->GetConfig(name, options)); - } - - /** - * @brief Converts InferenceEngine to InferenceEnginePluginPtr pointer - * - * @return Wrapped object - */ - operator InferenceEngine::InferenceEnginePluginPtr() { - return actual; + PLUGIN_CALL_STATEMENT(return _ptr->GetConfig(name, options)); } - - /** - * @brief Shared pointer on InferencePlugin object - * - */ - using Ptr = std::shared_ptr; }; } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp index 5d4a09dcb5d03b..cc2dbd5deec4ff 100644 --- a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp @@ -8,7 +8,7 @@ #include "exception2status.hpp" #define VARIABLE_CALL_STATEMENT(...) \ - if (_impl == nullptr) IE_THROW() << "VariableState was not initialized."; \ + if (_ptr == nullptr) IE_THROW() << "VariableState was not initialized."; \ try { \ __VA_ARGS__; \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -19,13 +19,6 @@ namespace InferenceEngine { -VariableState::VariableState(const std::shared_ptr& impl, - const std::shared_ptr& so) : _impl(impl), _so(so) { - if (impl == nullptr) { - IE_THROW(NotAllocated) << "VariableState wrapper was not initialized."; - } -} - IE_SUPPRESS_DEPRECATED_START Blob::CPtr VariableState::GetLastState() const { @@ -35,19 +28,19 @@ Blob::CPtr VariableState::GetLastState() const { IE_SUPPRESS_DEPRECATED_END void VariableState::Reset() { - VARIABLE_CALL_STATEMENT(_impl->Reset()); + VARIABLE_CALL_STATEMENT(_ptr->Reset()); } std::string VariableState::GetName() const { - VARIABLE_CALL_STATEMENT(return _impl->GetName()); + VARIABLE_CALL_STATEMENT(return _ptr->GetName()); } Blob::CPtr VariableState::GetState() const { - VARIABLE_CALL_STATEMENT(return _impl->GetState()); + VARIABLE_CALL_STATEMENT(return _ptr->GetState()); } void VariableState::SetState(Blob::Ptr state) { - VARIABLE_CALL_STATEMENT(_impl->SetState(state)); + VARIABLE_CALL_STATEMENT(_ptr->SetState(state)); } } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/ie_core.cpp b/inference-engine/src/inference_engine/ie_core.cpp index 8d9a6bb475cb81..9f026ecf693364 100644 --- a/inference-engine/src/inference_engine/ie_core.cpp +++ b/inference-engine/src/inference_engine/ie_core.cpp @@ -17,7 +17,7 @@ #include #include "compilation_context.hpp" -#include "ie_plugin_cpp.hpp" +#include "cpp/ie_plugin.hpp" #include "ie_plugin_config.hpp" #include "ie_cache_manager.hpp" #include "ie_cache_guard.hpp" @@ -661,7 +661,7 @@ class Core::Impl : public ICore { PluginDescriptor desc = it->second; try { - InferencePlugin plugin(desc.libraryLocation); + InferencePlugin plugin{desc.libraryLocation}; { plugin.SetName(deviceName); diff --git a/inference-engine/src/inference_engine/ie_network_reader.cpp b/inference-engine/src/inference_engine/ie_network_reader.cpp index 6ffe494203e0fb..6043303712dc02 100644 --- a/inference-engine/src/inference_engine/ie_network_reader.cpp +++ b/inference-engine/src/inference_engine/ie_network_reader.cpp @@ -52,7 +52,7 @@ class Reader: public IReader { << FileUtils::fromFilePath(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in " << getIELibraryPath(); } - ptr = InferenceEngine::details::SOPointer(readersLibraryPath); + ptr = {readersLibraryPath}; }); return ptr; diff --git a/inference-engine/src/inference_engine/ie_plugin_ptr.hpp b/inference-engine/src/inference_engine/ie_plugin_ptr.hpp deleted file mode 100644 index e12b41fc1c9910..00000000000000 --- a/inference-engine/src/inference_engine/ie_plugin_ptr.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief A header file contains a wrapper class for handling plugin instantiation and releasing resources - * - * @file ie_plugin_ptr.hpp - */ -#pragma once - -#include - -#include "details/ie_so_pointer.hpp" -#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" - -namespace InferenceEngine { -namespace details { - -/** - * @brief This class defines the name of the fabric for creating an IInferencePlugin object in DLL - */ -template <> -class SOCreatorTrait { -public: - /** - * @brief A name of the fabric for creating IInferencePlugin object in DLL - */ - static constexpr auto name = "CreatePluginEngine"; -}; - -} // namespace details - -/** - * @brief A C++ helper to work with objects created by the plugin. - * - * Implements different interfaces. - */ -using InferenceEnginePluginPtr = InferenceEngine::details::SOPointer; - -} // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp b/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp index 297929aa4ae832..c8674911c499da 100644 --- a/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp @@ -7,6 +7,7 @@ #include "details/ie_so_loader.h" #include "file_utils.h" +#include namespace InferenceEngine { namespace details { diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_extension_mngr.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_extension_mngr.cpp index deb3fdff7d68f3..bd5fa6456ea06f 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_extension_mngr.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_extension_mngr.cpp @@ -37,7 +37,7 @@ std::shared_ptr MKLDNNExtensionManager::Crea ResponseDesc responseDesc; StatusCode rc = GENERAL_ERROR; ILayerImplFactory* factory_ptr = nullptr; - if (auto mkldnnExt = std::dynamic_pointer_cast(ext)) + if (auto mkldnnExt = dynamic_cast(ext.get())) rc = mkldnnExt->getFactoryFor(factory_ptr, op, &responseDesc); if (rc != OK) { factory = nullptr; diff --git a/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp b/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp index 8cbd9c4f6055a4..8ed62fbca89b0d 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp +++ b/inference-engine/src/mkldnn_plugin/nodes/extract_image_patches.hpp @@ -6,6 +6,7 @@ #include "base.hpp" #include #include +#include namespace InferenceEngine { namespace Extensions { 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 18f4658d6a4cc4..fc739612666823 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 @@ -275,6 +275,14 @@ class IInferencePlugin : public std::enable_shared_from_this { ~IInferencePlugin() = default; }; +namespace details { +template <> +class SOCreatorTrait { +public: + static constexpr auto name = "CreatePluginEngine"; +}; +} // namespace details + } // namespace InferenceEngine /** diff --git a/inference-engine/src/preprocessing/ie_preprocess_data.hpp b/inference-engine/src/preprocessing/ie_preprocess_data.hpp index fa097fca02554d..fab055000cac69 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_data.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_data.hpp @@ -96,7 +96,7 @@ inline PreProcessDataPtr CreatePreprocDataHelper() { << FileUtils::fromFilePath(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in " << getIELibraryPath(); } - return PreProcessDataPtr(preprocLibraryPath); + return {preprocLibraryPath}; } } // 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 947733c3f150f4..287aaedcd0d981 100644 --- a/inference-engine/tests/functional/inference_engine/caching_test.cpp +++ b/inference-engine/tests/functional/inference_engine/caching_test.cpp @@ -12,7 +12,6 @@ #include #include "ie_core.hpp" -#include "ie_plugin_ptr.hpp" #include "ngraph/function.hpp" #include "details/ie_so_loader.h" #include "ie_metric_helpers.hpp" @@ -30,7 +29,7 @@ #include "unit_test_utils/mocks/mock_iinfer_request.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" -#include "ie_plugin_cpp.hpp" +#include "cpp/ie_plugin.hpp" using namespace InferenceEngine; using namespace ::testing; 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 4821910d139110..ef2a2d72feed57 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 @@ -4,9 +4,9 @@ #include -#include #include #include "details/ie_so_loader.h" +#include using namespace std; using namespace InferenceEngine; diff --git a/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp b/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp index b18957ed5790e5..9050e72f750081 100644 --- a/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp @@ -12,70 +12,12 @@ #include #include
#include -#include using namespace InferenceEngine; using namespace InferenceEngine::details; using namespace ::testing; using ::testing::InSequence; -class PointedObjHelper { -public: - MOCK_METHOD0(obj_dtor, void()); - - virtual ~PointedObjHelper() { - obj_dtor(); - } -}; - -class SharedObjectLoaderHelper { -public: - MOCK_METHOD0(loader_dtor, void()); - - virtual ~SharedObjectLoaderHelper() { - loader_dtor(); - } -}; - -template -class SoPointerHelper : public SOPointer { -public: - SoPointerHelper(std::shared_ptr&& loader, std::shared_ptr&& object) - : SOPointer() { - SOPointer::_so_loader = std::move(loader); - SOPointer::_pointedObj = std::move(object); - } -}; - -class SoPointerTests : public ::testing::Test { -protected: - SharedObjectLoaderHelper *loader1 = nullptr, *loader2 = nullptr; - PointedObjHelper *obj1 = nullptr, *obj2 = nullptr; -}; - -TEST_F(SoPointerTests, assignObjThenLoader) { - auto loaderPtr1 = std::make_shared(); - auto objPtr1 = std::make_shared(); - auto loaderPtr2 = std::make_shared(); - auto objPtr2 = std::make_shared(); - loader1 = loaderPtr1.get(); - obj1 = objPtr1.get(); - loader2 = loaderPtr2.get(); - obj2 = objPtr2.get(); - SoPointerHelper<> soPointer1(std::move(loaderPtr1), std::move(objPtr1)); - SoPointerHelper<> soPointer2(std::move(loaderPtr2), std::move(objPtr2)); - - { - InSequence dummy; - EXPECT_CALL(*obj1, obj_dtor()); - EXPECT_CALL(*loader1, loader_dtor()); - EXPECT_CALL(*obj2, obj_dtor()); - EXPECT_CALL(*loader2, loader_dtor()); - } - - soPointer1 = soPointer2; -} - namespace InferenceEngine { namespace details { @@ -92,13 +34,15 @@ class SOCreatorTrait { } // namespace InferenceEngine +class SoPointerTests : public ::testing::Test {}; + TEST_F(SoPointerTests, UnknownPlugin) { - ASSERT_THROW(SOPointer("UnknownPlugin"), Exception); + ASSERT_THROW(SOPointer{std::string{"UnknownPlugin"}}, Exception); } TEST_F(SoPointerTests, UnknownPluginExceptionStr) { try { - SOPointer("UnknownPlugin"); + SOPointer(std::string{"UnknownPlugin"}); } catch (Exception &e) { ASSERT_STR_CONTAINS(e.what(), "Cannot load library 'UnknownPlugin':"); 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 73ecba07d82441..78a1e66cf54805 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 @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" @@ -198,9 +198,9 @@ class InferRequestTests : public ::testing::Test { mock_request = make_shared(); mockIExeNet = std::make_shared(); ON_CALL(*mockIExeNet, CreateInferRequest()).WillByDefault(Return(mock_request)); - std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); - plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); request = exeNetwork.CreateInferRequest(); _incorrectName = "incorrect_name"; @@ -222,9 +222,9 @@ class InferRequestTests : public ::testing::Test { mockInferRequestInternal = make_shared(inputsInfo, outputsInfo); auto mockIExeNet = std::make_shared(); ON_CALL(*mockIExeNet, CreateInferRequest()).WillByDefault(Return(mockInferRequestInternal)); - std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); - auto plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + auto plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; auto exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); return exeNetwork.CreateInferRequest(); } 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 0557ed203b1337..654fc9b4de2113 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 @@ -12,7 +12,7 @@ #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_ivariable_state_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" -#include "ie_plugin_cpp.hpp" +#include "cpp/ie_plugin.hpp" using namespace ::testing; using namespace std; @@ -35,9 +35,9 @@ class VariableStateTests : public ::testing::Test { mockInferRequestInternal = make_shared(); mockVariableStateInternal = make_shared(); ON_CALL(*mockExeNetworkInternal, CreateInferRequest()).WillByDefault(Return(mockInferRequestInternal)); - std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockExeNetworkInternal)); - plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; net = plugin.LoadNetwork(CNNNetwork{}, {}); req = net.CreateInferRequest(); } @@ -144,6 +144,7 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfOne) { std::string name; EXPECT_NO_THROW(name = pState.GetName()); EXPECT_EQ(name, "someName"); + EXPECT_EQ(name, ""); IE_SUPPRESS_DEPRECATED_END } diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp index a7dbba29a0670c..92625a5182e957 100644 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp +++ b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_test.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -169,12 +169,6 @@ TEST_F(InferenceEnginePluginInternalTest, pluginInternalEraseMagicAndNameWhenImp } -TEST(InferencePluginTests, throwsOnNullptrCreation) { - InferenceEnginePluginPtr nulptr; - InferencePlugin plugin; - ASSERT_THROW(plugin = InferencePlugin(nulptr), Exception); -} - TEST(InferencePluginTests, throwsOnUninitializedGetVersion) { InferencePlugin plg; ASSERT_THROW(plg.GetVersion(), Exception); @@ -199,8 +193,3 @@ TEST(InferencePluginTests, throwsOnUninitializedSetConfig) { InferencePlugin plg; ASSERT_THROW(plg.SetConfig({{}}), Exception); } - -TEST(InferencePluginTests, nothrowsUninitializedCast) { - InferencePlugin plg; - ASSERT_NO_THROW(auto plgPtr = static_cast(plg)); -} 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 1df88845775f3f..fa7256e3217caa 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 @@ -9,7 +9,7 @@ #include "cpp/ie_executable_network.hpp" #include "cpp/ie_executable_network_base.hpp" -#include "ie_plugin_cpp.hpp" +#include "cpp/ie_plugin.hpp" #include "unit_test_utils/mocks/mock_iexecutable_network.hpp" #include "unit_test_utils/mocks/mock_iinfer_request.hpp" @@ -43,7 +43,6 @@ class ExecutableNetworkTests : public ::testing::Test { MockIInferencePlugin* mockIPlugin; InferencePlugin plugin; - virtual void TearDown() { mockIExeNet.reset(); exeNetwork = {}; @@ -52,9 +51,9 @@ class ExecutableNetworkTests : public ::testing::Test { virtual void SetUp() { mockIExeNet = std::make_shared(); - std::unique_ptr mockIPluginPtr{new MockIInferencePlugin}; + auto mockIPluginPtr = std::make_shared(); ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); - plugin = InferenceEngine::InferencePlugin{InferenceEngine::details::SOPointer{mockIPluginPtr.release()}}; + plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); } }; @@ -70,8 +69,6 @@ TEST_F(ExecutableNetworkTests, GetOutputsInfoThrowsIfReturnErr) { TEST_F(ExecutableNetworkTests, GetOutputsInfo) { InferenceEngine::ConstOutputsDataMap data; EXPECT_CALL(*mockIExeNet.get(), GetOutputsInfo()).Times(1).WillRepeatedly(Return(InferenceEngine::ConstOutputsDataMap{})); - - ASSERT_NO_THROW(data = exeNetwork.GetOutputsInfo()); ASSERT_EQ(data, InferenceEngine::ConstOutputsDataMap{}); } diff --git a/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp b/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp index 0f66277141e4db..28e4245a6bce6b 100644 --- a/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include "details/ie_so_loader.h" @@ -19,7 +18,7 @@ class PluginTest: public ::testing::Test { protected: unique_ptr sharedObjectLoader; std::function createPluginEngineProxy; - InferenceEnginePluginPtr getPtr(); + InferenceEngine::details::SOPointer getPtr(); std::string get_mock_engine_name() { std::string mockEngineName("mock_engine"); @@ -41,20 +40,20 @@ class PluginTest: public ::testing::Test { }; TEST_F(PluginTest, canCreatePluginUsingSmartPtr) { - ASSERT_NO_THROW(InferenceEnginePluginPtr ptr(get_mock_engine_name())); + ASSERT_NO_THROW(InferenceEngine::details::SOPointer ptr(get_mock_engine_name())); } TEST_F(PluginTest, shouldThrowExceptionIfPluginNotExist) { - EXPECT_THROW(InferenceEnginePluginPtr("unknown_plugin"), Exception); + EXPECT_THROW(InferenceEngine::details::SOPointer(std::string{"unknown_plugin"}), Exception); } -InferenceEnginePluginPtr PluginTest::getPtr() { - InferenceEnginePluginPtr smart_ptr(get_mock_engine_name()); +InferenceEngine::details::SOPointer PluginTest::getPtr() { + InferenceEngine::details::SOPointer smart_ptr(get_mock_engine_name()); return smart_ptr; } TEST_F(PluginTest, canSetConfiguration) { - InferenceEnginePluginPtr ptr = getPtr(); + 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()); 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 764d0e72df2f08..537713ac6fef24 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 @@ -15,7 +15,7 @@ #include "helpers/myriad_devices.hpp" -#include +#include using namespace std; using namespace ::testing; From db5b669ff896a2c7db490bd25b08e59185595cbe Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 15 May 2021 13:51:36 +0300 Subject: [PATCH 04/20] Changed InferencePlugin, ICore to return internal interfaces --- .../include/cpp/ie_executable_network.hpp | 5 +- .../src/auto_plugin/auto_exec_network.cpp | 23 ++-- .../src/auto_plugin/auto_exec_network.hpp | 8 +- .../src/auto_plugin/auto_infer_request.cpp | 16 +-- .../src/auto_plugin/auto_infer_request.hpp | 8 +- .../src/auto_plugin/auto_plugin.cpp | 8 +- .../hetero_async_infer_request.cpp | 28 ++--- .../hetero_async_infer_request.hpp | 1 - .../hetero_executable_network.cpp | 56 ++++----- .../hetero_executable_network.hpp | 16 +-- .../hetero_plugin/hetero_infer_request.cpp | 28 ++--- .../hetero_plugin/hetero_infer_request.hpp | 6 +- .../src/inference_engine/cpp/ie_plugin.hpp | 12 +- .../src/inference_engine/ie_core.cpp | 58 ++++----- .../src/inference_engine/ie_system_conf.cpp | 5 - .../multi_device_async_infer_request.cpp | 15 +-- .../multi_device_exec_network.cpp | 20 +-- .../multi_device_exec_network.hpp | 10 +- .../multi_device_infer_request.cpp | 20 +-- .../multi_device_infer_request.hpp | 4 +- .../src/multi_device/multi_device_plugin.cpp | 4 +- .../impl/ie_executable_network_2_internal.hpp | 90 -------------- .../impl/ie_infer_request_2_internal.hpp | 104 ---------------- .../impl/ie_plugin_internal.hpp | 5 +- .../impl/ie_variable_state_2_internal.hpp | 41 ------- inference-engine/src/plugin_api/ie_icore.hpp | 15 ++- .../src/plugin_api/ie_system_conf.h | 6 - .../cpp_interfaces/interface/mock_icore.hpp | 10 +- .../ie_infer_async_request_base_test.cpp | 115 +++--------------- .../ie_memory_state_internal_test.cpp | 114 +++++------------ .../ie_executable_network_test.cpp | 54 ++------ 31 files changed, 248 insertions(+), 657 deletions(-) delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 0430ce17d64192..15c1ecbedd5e91 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -29,7 +29,10 @@ class IExecutableNetwork; */ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPointer { using details::SOPointer::SOPointer; - friend class InferencePlugin; + // TODO: remove? + ExecutableNetwork(const details::SOPointer & obj) : + details::SOPointer::SOPointer(obj) { } + friend class Core; public: /** diff --git a/inference-engine/src/auto_plugin/auto_exec_network.cpp b/inference-engine/src/auto_plugin/auto_exec_network.cpp index 0d691214835701..04b5253d7098d2 100644 --- a/inference-engine/src/auto_plugin/auto_exec_network.cpp +++ b/inference-engine/src/auto_plugin/auto_exec_network.cpp @@ -13,11 +13,12 @@ #include "auto_infer_request.hpp" namespace AutoPlugin { - using namespace InferenceEngine; -AutoExecutableNetwork::AutoExecutableNetwork(const ExecutableNetwork& network, - const DeviceInformation& deviceInfo, - const bool needPerfCounters) : +using namespace InferenceEngine; + +AutoExecutableNetwork::AutoExecutableNetwork(const SoExecutableNetworkInternal& network, + const DeviceInformation& deviceInfo, + const bool needPerfCounters) : _deviceInfo(deviceInfo), _network(network), _config(deviceInfo.config.begin(), deviceInfo.config.end()), @@ -28,32 +29,32 @@ AutoExecutableNetwork::~AutoExecutableNetwork() = default; IInferRequestInternal::Ptr AutoExecutableNetwork::CreateInferRequestImpl(InputsDataMap networkInputs, OutputsDataMap networkOutputs) { - auto inferRequest = _network.CreateInferRequest(); + auto inferRequest = _network->CreateInferRequest(); return std::make_shared(networkInputs, networkOutputs, inferRequest); } void AutoExecutableNetwork::Export(std::ostream& networkModel) { - _network.Export(networkModel); + _network->Export(networkModel); } RemoteContext::Ptr AutoExecutableNetwork::GetContext() const { - return _network.GetContext(); + return _network->GetContext(); } InferenceEngine::CNNNetwork AutoExecutableNetwork::GetExecGraphInfo() { - return _network.GetExecGraphInfo(); + return _network->GetExecGraphInfo(); } Parameter AutoExecutableNetwork::GetMetric(const std::string &name) const { - return _network.GetMetric(name); + return _network->GetMetric(name); } void AutoExecutableNetwork::SetConfig(const std::map& config) { - _network.SetConfig(config); + _network->SetConfig(config); } Parameter AutoExecutableNetwork::GetConfig(const std::string& name) const { - return _network.GetConfig(name); + return _network->GetConfig(name); } } // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_exec_network.hpp b/inference-engine/src/auto_plugin/auto_exec_network.hpp index 635d9573b9da66..0a99ba061336e9 100644 --- a/inference-engine/src/auto_plugin/auto_exec_network.hpp +++ b/inference-engine/src/auto_plugin/auto_exec_network.hpp @@ -28,9 +28,9 @@ class AutoExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSaf public: using Ptr = std::shared_ptr; - AutoExecutableNetwork(const InferenceEngine::ExecutableNetwork& network, - const DeviceInformation& deviceInfo, - const bool needPerfCounters = false); + AutoExecutableNetwork(const InferenceEngine::SoExecutableNetworkInternal& network, + const DeviceInformation& deviceInfo, + const bool needPerfCounters = false); void Export(std::ostream& networkModel) override; InferenceEngine::RemoteContext::Ptr GetContext() const override; @@ -43,7 +43,7 @@ class AutoExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSaf ~AutoExecutableNetwork() override; DeviceInformation _deviceInfo; - InferenceEngine::ExecutableNetwork _network; + InferenceEngine::SoExecutableNetworkInternal _network; std::unordered_map _config; bool _needPerfCounters = false; }; diff --git a/inference-engine/src/auto_plugin/auto_infer_request.cpp b/inference-engine/src/auto_plugin/auto_infer_request.cpp index 0adc4ba09388b3..33deef1892f9f5 100644 --- a/inference-engine/src/auto_plugin/auto_infer_request.cpp +++ b/inference-engine/src/auto_plugin/auto_infer_request.cpp @@ -9,31 +9,31 @@ namespace AutoPlugin { using namespace InferenceEngine; -AutoInferRequest::AutoInferRequest(const InputsDataMap& networkInputs, - const OutputsDataMap& networkOutputs, - const InferRequest& inferRequest) +AutoInferRequest::AutoInferRequest(const InputsDataMap& networkInputs, + const OutputsDataMap& networkOutputs, + const IInferRequestInternal::Ptr& inferRequest) : IInferRequestInternal(networkInputs, networkOutputs) , _inferRequest(inferRequest) { } std::map AutoInferRequest::GetPerformanceCounts() const { - return _inferRequest.GetPerformanceCounts(); + return _inferRequest->GetPerformanceCounts(); } void AutoInferRequest::InferImpl() { - _inferRequest.Infer(); + _inferRequest->Infer(); } void AutoInferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) { - _inferRequest.SetBlob(name, data); + _inferRequest->SetBlob(name, data); } Blob::Ptr AutoInferRequest::GetBlob(const std::string& name) { - return _inferRequest.GetBlob(name); + return _inferRequest->GetBlob(name); } void AutoInferRequest::Cancel() { - _inferRequest.Cancel(); + _inferRequest->Cancel(); } } // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_infer_request.hpp b/inference-engine/src/auto_plugin/auto_infer_request.hpp index 49da8a117e1779..473f93fb45a1c3 100644 --- a/inference-engine/src/auto_plugin/auto_infer_request.hpp +++ b/inference-engine/src/auto_plugin/auto_infer_request.hpp @@ -24,9 +24,9 @@ namespace AutoPlugin { class AutoInferRequest : public InferenceEngine::IInferRequestInternal { public: using Ptr = std::shared_ptr; - explicit AutoInferRequest(const InferenceEngine::InputsDataMap& networkInputs, - const InferenceEngine::OutputsDataMap& networkOutputs, - const InferenceEngine::InferRequest& inferRequest); + explicit AutoInferRequest(const InferenceEngine::InputsDataMap& networkInputs, + const InferenceEngine::OutputsDataMap& networkOutputs, + const InferenceEngine::IInferRequestInternal::Ptr& inferRequest); std::map GetPerformanceCounts() const override; void InferImpl() override; void SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) override; @@ -34,7 +34,7 @@ class AutoInferRequest : public InferenceEngine::IInferRequestInternal { void Cancel() override; private: - InferenceEngine::InferRequest _inferRequest; + InferenceEngine::IInferRequestInternal::Ptr _inferRequest; }; } // namespace AutoPlugin diff --git a/inference-engine/src/auto_plugin/auto_plugin.cpp b/inference-engine/src/auto_plugin/auto_plugin.cpp index 280a74e52acf13..79f89ecdf4b76c 100644 --- a/inference-engine/src/auto_plugin/auto_plugin.cpp +++ b/inference-engine/src/auto_plugin/auto_plugin.cpp @@ -49,7 +49,7 @@ IE::IExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadNetwork(const std:: // FIXME: always select CPU device now DeviceInformation selectedDevice = SelectDevice(metaDevices); - IE::ExecutableNetwork executableNetwork; + IE::SoExecutableNetworkInternal executableNetwork; try { executableNetwork = GetCore()->LoadNetwork(fileName, selectedDevice.deviceName, selectedDevice.config); } catch(const IE::Exception &iie) { @@ -60,7 +60,7 @@ IE::IExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadNetwork(const std:: bool enablePerfCounters = false; try { enablePerfCounters = - executableNetwork.GetConfig(IE::PluginConfigParams::KEY_PERF_COUNT).as() == + executableNetwork->GetConfig(IE::PluginConfigParams::KEY_PERF_COUNT).as() == IE::PluginConfigParams::YES; } catch (...) { } @@ -85,7 +85,7 @@ IE::ExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadExeNetworkImpl(const // FIXME: always select CPU device now DeviceInformation selectedDevice = SelectDevice(metaDevices); - IE::ExecutableNetwork executableNetwork; + IE::SoExecutableNetworkInternal executableNetwork; try { executableNetwork = GetCore()->LoadNetwork(network, selectedDevice.deviceName, selectedDevice.config); } catch(const IE::Exception &iie) { @@ -96,7 +96,7 @@ IE::ExecutableNetworkInternal::Ptr AutoInferencePlugin::LoadExeNetworkImpl(const bool enablePerfCounters = false; try { enablePerfCounters = - executableNetwork.GetConfig(IE::PluginConfigParams::KEY_PERF_COUNT).as() == + executableNetwork->GetConfig(IE::PluginConfigParams::KEY_PERF_COUNT).as() == IE::PluginConfigParams::YES; } catch (...) { } diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp index cdd3c54ae17fd4..7113e34abe301c 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp @@ -13,35 +13,31 @@ HeteroAsyncInferRequest::HeteroAsyncInferRequest(const IInferRequestInternal::Pt const ITaskExecutor::Ptr& taskExecutor, const ITaskExecutor::Ptr& callbackExecutor) : AsyncInferRequestThreadSafeDefault(request, taskExecutor, callbackExecutor), - _heteroInferRequest(std::static_pointer_cast(request)), - _statusCodes{_heteroInferRequest->_inferRequests.size(), StatusCode::OK} { + _heteroInferRequest(std::static_pointer_cast(request)) { _pipeline.clear(); for (std::size_t requestId = 0; requestId < _heteroInferRequest->_inferRequests.size(); ++requestId) { struct RequestExecutor : ITaskExecutor { - explicit RequestExecutor(InferRequest & inferRequest) : _inferRequest(inferRequest) { - _inferRequest.SetCompletionCallback>( - [this] (InferRequest, StatusCode sts) mutable { - _status = sts; + explicit RequestExecutor(IInferRequestInternal::Ptr & inferRequest) : _inferRequest(inferRequest) { + _inferRequest->SetCallback( + [this] (std::exception_ptr exceptionPtr) mutable { + _exceptionPtr = exceptionPtr; auto capturedTask = std::move(_task); capturedTask(); }); } void run(Task task) override { _task = std::move(task); - _inferRequest.StartAsync(); + _inferRequest->StartAsync(); }; - InferRequest & _inferRequest; - StatusCode _status = StatusCode::OK; - Task _task; + IInferRequestInternal::Ptr & _inferRequest; + std::exception_ptr _exceptionPtr; + Task _task; }; auto requestExecutor = std::make_shared(_heteroInferRequest->_inferRequests[requestId]._request); _pipeline.emplace_back(requestExecutor, [requestExecutor] { - if (StatusCode::OK != requestExecutor->_status) { - IE_EXCEPTION_SWITCH(requestExecutor->_status, ExceptionType, - InferenceEngine::details::ThrowNow{} - <<= std::stringstream{} << IE_LOCATION - << InferenceEngine::details::ExceptionTraits::string()); + if (nullptr != requestExecutor->_exceptionPtr) { + std::rethrow_exception(requestExecutor->_exceptionPtr); } }); } @@ -58,7 +54,7 @@ StatusCode HeteroAsyncInferRequest::Wait(int64_t millis_timeout) { waitStatus = AsyncInferRequestThreadSafeDefault::Wait(millis_timeout); } catch(...) { for (auto&& requestDesc : _heteroInferRequest->_inferRequests) { - requestDesc._request.Wait(InferRequest::RESULT_READY); + requestDesc._request->Wait(InferRequest::RESULT_READY); } throw; } diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp index 1a36f8724be416..22f8d065432287 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.hpp @@ -23,7 +23,6 @@ class HeteroAsyncInferRequest : public InferenceEngine::AsyncInferRequestThreadS private: HeteroInferRequest::Ptr _heteroInferRequest; - std::vector _statusCodes; }; } // namespace HeteroPlugin diff --git a/inference-engine/src/hetero_plugin/hetero_executable_network.cpp b/inference-engine/src/hetero_plugin/hetero_executable_network.cpp index 83f8a57156cded..bc5ace2160c514 100644 --- a/inference-engine/src/hetero_plugin/hetero_executable_network.cpp +++ b/inference-engine/src/hetero_plugin/hetero_executable_network.cpp @@ -368,17 +368,17 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(const InferenceEngine::CNNNetwo InputsDataMap externalInputsData = network.getInputsInfo(); OutputsDataMap externalOutputsData = network.getOutputsInfo(); - networks.resize(orderedSubgraphs.size()); + _networks.resize(orderedSubgraphs.size()); std::vector> subFunctions(orderedSubgraphs.size()); int id = 0; for (auto&& subgraph : orderedSubgraphs) { - networks[id]._device = subgraph._affinity; + _networks[id]._device = subgraph._affinity; subFunctions[id] = std::make_shared(subgraph._results, subgraph._parameters, _name + '_' + std::to_string(id)); - networks[id]._clonedNetwork = CNNNetwork{subFunctions[id]}; + _networks[id]._clonedNetwork = CNNNetwork{subFunctions[id]}; // update of pre-processing info - auto clonedInputs = networks[id]._clonedNetwork.getInputsInfo(); + auto clonedInputs = _networks[id]._clonedNetwork.getInputsInfo(); for (auto&& externalInput : externalInputsData) { auto itClonedInput = clonedInputs.find(externalInput.first); if (itClonedInput != clonedInputs.end() && nullptr != itClonedInput->second) { @@ -388,7 +388,7 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(const InferenceEngine::CNNNetwo } } // update output info - auto clonedOutputs = networks[id]._clonedNetwork.getOutputsInfo(); + auto clonedOutputs = _networks[id]._clonedNetwork.getOutputsInfo(); for (auto&& externalOutput : externalOutputsData) { auto itClonedOutput = clonedOutputs.find(externalOutput.first); if (itClonedOutput != clonedOutputs.end() && nullptr != itClonedOutput->second) { @@ -418,7 +418,7 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(const InferenceEngine::CNNNetwo } }}.run_on_function(ngraph::clone_function(*function)); } - for (auto&& network : networks) { + for (auto&& network : _networks) { auto metaDevices = _heteroPlugin->GetDevicePlugins(network._device, _config); metaDevices[network._device].emplace(CONFIG_KEY_INTERNAL(FORCE_DISABLE_CACHE), ""); network._network = _heteroPlugin->GetCore()->LoadNetwork(network._clonedNetwork, @@ -481,7 +481,7 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(std::istream& assert(metaDevices.size() == 1); auto& loadConfig = metaDevices[deviceName]; - InferenceEngine::ExecutableNetwork executableNetwork; + InferenceEngine::SoExecutableNetworkInternal executableNetwork; CNNNetwork cnnnetwork; bool loaded = false; if (ImportExportSupported(deviceName)) { @@ -526,13 +526,13 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(std::istream& } // restore network inputs and outputs - for (auto&& input : executableNetwork.GetInputsInfo()) { + for (auto&& input : executableNetwork->GetInputsInfo()) { if (networkInputs.end() != networkInputs.find(input.first)) { _networkInputs.emplace(input.first, std::make_shared(*input.second)); } } - for (auto&& output : executableNetwork.GetOutputsInfo()) { + for (auto&& output : executableNetwork->GetOutputsInfo()) { if (networkOutputs.end() != networkOutputs.find(output.first)) { _networkOutputs.emplace(output.first, std::make_shared(*output.second)); } @@ -547,7 +547,7 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(std::istream& // save state this->_config = importedConfigs; - this->networks = std::move(descs); + this->_networks = std::move(descs); this->SetPointerToPlugin(_heteroPlugin->shared_from_this()); } @@ -567,7 +567,7 @@ void HeteroExecutableNetwork::ExportImpl(std::ostream& heteroModel) { } auto subnetworksNode = heteroNode.append_child("subnetworks"); - for (auto&& subnetwork : networks) { + for (auto&& subnetwork : _networks) { auto subnet = subnetwork._clonedNetwork; IE_ASSERT(subnet.getFunction() != nullptr); @@ -611,9 +611,9 @@ void HeteroExecutableNetwork::ExportImpl(std::ostream& heteroModel) { doc.reset(); heteroModel << std::endl; - for (auto&& subnetwork : networks) { + for (auto&& subnetwork : _networks) { if (ImportExportSupported(subnetwork._device)) { - subnetwork._network.Export(heteroModel); + subnetwork._network->Export(heteroModel); } else { auto subnet = subnetwork._clonedNetwork; if (!subnet.getFunction()) { @@ -645,7 +645,7 @@ IInferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl( OutputsDataMap networkOutputs) { HeteroInferRequest::SubRequestsList inferRequests; int index = 0; - for (auto&& subnetwork : networks) { + for (auto&& subnetwork : _networks) { HeteroInferRequest::SubRequestDesc desc; desc._network = subnetwork._network; desc._profilingTask = openvino::itt::handle("Infer" + std::to_string(index++)); @@ -677,12 +677,12 @@ InferenceEngine::Parameter HeteroExecutableNetwork::GetConfig(const std::string result = it->second == YES ? true : false; } else { // find config key among plugin config keys - for (auto&& desc : networks) { + for (auto&& desc : _networks) { auto execNetwork = desc._network; - auto param = execNetwork.GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS)); + auto param = execNetwork->GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS)); for (auto && configKey : param.as>()) { if (configKey == name) { - return execNetwork.GetConfig(configKey); + return execNetwork->GetConfig(configKey); } } } @@ -741,12 +741,12 @@ InferenceEngine::Parameter HeteroExecutableNetwork::GetMetric(const std::string { std::vector<::Metrics> pluginMetrics; - for (auto&& desc : networks) { + for (auto&& desc : _networks) { auto execNetwork = desc._network; - auto param = execNetwork.GetMetric(METRIC_KEY(SUPPORTED_METRICS)); + auto param = execNetwork->GetMetric(METRIC_KEY(SUPPORTED_METRICS)); ::Metrics metrics; for (auto && metricName : param.as>()) { - metrics[metricName] = execNetwork.GetMetric(metricName); + metrics[metricName] = execNetwork->GetMetric(metricName); } pluginMetrics.push_back(std::move(metrics)); } @@ -764,12 +764,12 @@ InferenceEngine::Parameter HeteroExecutableNetwork::GetMetric(const std::string { std::vector<::Metrics> pluginConfigKeys; - for (auto&& desc : networks) { + for (auto&& desc : _networks) { auto execNetwork = desc._network; - auto param = execNetwork.GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS)); + auto param = execNetwork->GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS)); ::Metrics configKeys; for (auto && metricName : param.as>()) { - configKeys[metricName] = execNetwork.GetConfig(metricName); + configKeys[metricName] = execNetwork->GetConfig(metricName); } pluginConfigKeys.push_back(std::move(configKeys)); } @@ -782,18 +782,18 @@ InferenceEngine::Parameter HeteroExecutableNetwork::GetMetric(const std::string IE_SET_METRIC_RETURN(NETWORK_NAME, _name); } else if (EXEC_NETWORK_METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS) == name) { unsigned int value = 0u; - for (auto&& desc : networks) { - value = std::max(value, desc._network.GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)).as()); + for (auto&& desc : _networks) { + value = std::max(value, desc._network->GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)).as()); } IE_SET_METRIC_RETURN(OPTIMAL_NUMBER_OF_INFER_REQUESTS, value); } else { // find metric key among plugin metrics - for (auto&& desc : networks) { + for (auto&& desc : _networks) { auto execNetwork = desc._network; - auto param = execNetwork.GetMetric(METRIC_KEY(SUPPORTED_METRICS)); + auto param = execNetwork->GetMetric(METRIC_KEY(SUPPORTED_METRICS)); for (auto && metricKey : param.as>()) { if (metricKey == name) { - return execNetwork.GetMetric(metricKey); + return execNetwork->GetMetric(metricKey); } } } diff --git a/inference-engine/src/hetero_plugin/hetero_executable_network.hpp b/inference-engine/src/hetero_plugin/hetero_executable_network.hpp index 323cafbeb1eb39..9189d965a813af 100644 --- a/inference-engine/src/hetero_plugin/hetero_executable_network.hpp +++ b/inference-engine/src/hetero_plugin/hetero_executable_network.hpp @@ -50,7 +50,7 @@ class HeteroExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadS ~HeteroExecutableNetwork() override = default; InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, - InferenceEngine::OutputsDataMap networkOutputs) override; + InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; @@ -66,15 +66,15 @@ class HeteroExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadS bool ImportExportSupported(const std::string& deviceName) const; struct NetworkDesc { - std::string _device; - InferenceEngine::CNNNetwork _clonedNetwork; - InferenceEngine::ExecutableNetwork _network; + std::string _device; + InferenceEngine::CNNNetwork _clonedNetwork; + InferenceEngine::SoExecutableNetworkInternal _network; }; - std::vector networks; - Engine* _heteroPlugin; - std::string _name; - std::map _config; + std::vector _networks; + Engine* _heteroPlugin; + std::string _name; + std::map _config; std::unordered_map _blobNameMap; }; diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp index e6fb139daa1060..1c8a72e0a22ae8 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp @@ -26,7 +26,7 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp IE_THROW() << "Internal error: no information about network's output/input"; } - auto requestBlob([&](const std::string& blobName, InferenceEngine::InferRequest & r) { + auto requestBlob([&](const std::string& blobName, InferenceEngine::IInferRequestInternal::Ptr & r) { std::string intermediateBlobName = blobName; auto itName = subgraphInputToOutputBlobNames.find(blobName); if (itName != subgraphInputToOutputBlobNames.end()) { @@ -36,29 +36,29 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp bool emplaced = false; std::tie(itBlob, emplaced) = _blobs.emplace(intermediateBlobName, Blob::Ptr{}); if (emplaced) { - itBlob->second = r.GetBlob(blobName); + itBlob->second = r->GetBlob(blobName); if (InferenceEngine::details::contains(networkInputs, blobName)) { _inputs[blobName] = itBlob->second; } else if (InferenceEngine::details::contains(networkOutputs, blobName)) { _outputs[blobName] = itBlob->second; } } else { - r.SetBlob(blobName, itBlob->second); + r->SetBlob(blobName, itBlob->second); } }); // go over all subnet and create requests for (auto&& desc : _inferRequests) { - desc._request = desc._network.CreateInferRequest(); + desc._request = desc._network->CreateInferRequest(); // go over all inputs and get blobs from subnet infer requests - for (auto&& outputInfo : desc._network.GetOutputsInfo()) { + for (auto&& outputInfo : desc._network->GetOutputsInfo()) { requestBlob(outputInfo.first, desc._request); } } // go over all outputs and get blobs from subnet infer requests for (auto&& desc : _inferRequests) { - for (auto&& inputInfo : desc._network.GetInputsInfo()) { + for (auto&& inputInfo : desc._network->GetInputsInfo()) { requestBlob(inputInfo.first, desc._request); } } @@ -75,7 +75,7 @@ void HeteroInferRequest::SetBlob(const std::string& name, const InferenceEngine: try { // if `name` is input blob if (findInputAndOutputBlobByName(name, foundInput, foundOutput)) { - r.SetBlob(name, data, foundInput->getPreProcess()); + r->SetBlob(name, data, foundInput->getPreProcess()); } } catch (const InferenceEngine::NotFound& ex) {} } @@ -87,14 +87,14 @@ void HeteroInferRequest::InferImpl() { OV_ITT_SCOPED_TASK(itt::domains::HeteroPlugin, desc._profilingTask); auto &r = desc._request; assert(r); - r.Infer(); + r->Infer(); } } std::map HeteroInferRequest::GetPerformanceCounts() const { std::map perfMap; for (size_t i = 0; i < _inferRequests.size(); i++) { - auto perfMapRequest = _inferRequests[i]._request.GetPerformanceCounts(); + auto perfMapRequest = _inferRequests[i]._request->GetPerformanceCounts(); for (auto &&r : perfMapRequest) { perfMap[std::string("subgraph") + std::to_string(i) + ": " + r.first] = r.second; } @@ -108,30 +108,30 @@ void HeteroInferRequest::updateInOutIfNeeded() { for (auto &&desc : _inferRequests) { auto &r = desc._request; assert(r); - for (auto&& inputInfo : desc._network.GetInputsInfo()) { + for (auto&& inputInfo : desc._network->GetInputsInfo()) { auto& ioname = inputInfo.first; auto iti = _inputs.find(ioname); if (iti != _inputs.end()) { auto it = _preProcData.find(ioname); if (it != _preProcData.end()) { if (it->second->getRoiBlob() != _blobs[ioname]) { - r.SetBlob(ioname.c_str(), it->second->getRoiBlob()); + r->SetBlob(ioname.c_str(), it->second->getRoiBlob()); _blobs[ioname] = iti->second; } } else { if (iti->second != _blobs[ioname]) { - r.SetBlob(ioname.c_str(), iti->second); + r->SetBlob(ioname.c_str(), iti->second); _blobs[ioname] = iti->second; } } } } - for (auto&& outputInfo : desc._network.GetOutputsInfo()) { + for (auto&& outputInfo : desc._network->GetOutputsInfo()) { auto& ioname = outputInfo.first; auto ito = _outputs.find(ioname); if (ito != _outputs.end()) { if (ito->second != _blobs[ioname]) { - r.SetBlob(ioname.c_str(), ito->second); + r->SetBlob(ioname.c_str(), ito->second); _blobs[ioname] = ito->second; } } diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp index 9f13e57a817eb4..b6cb02c6dd04e7 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp @@ -23,9 +23,9 @@ class HeteroInferRequest : public InferenceEngine::IInferRequestInternal { typedef std::shared_ptr Ptr; struct SubRequestDesc { - InferenceEngine::ExecutableNetwork _network; - InferenceEngine::InferRequest _request; - openvino::itt::handle_t _profilingTask; + InferenceEngine::SoExecutableNetworkInternal _network; + InferenceEngine::IInferRequestInternal::Ptr _request; + openvino::itt::handle_t _profilingTask; }; using SubRequestsList = std::vector; diff --git a/inference-engine/src/inference_engine/cpp/ie_plugin.hpp b/inference-engine/src/inference_engine/cpp/ie_plugin.hpp index 0df92057607136..d9802e6c59f5aa 100644 --- a/inference-engine/src/inference_engine/cpp/ie_plugin.hpp +++ b/inference-engine/src/inference_engine/cpp/ie_plugin.hpp @@ -65,15 +65,15 @@ class InferencePlugin : protected details::SOPointer { PLUGIN_CALL_STATEMENT(_ptr->SetConfig(config)); } - ExecutableNetwork LoadNetwork(const CNNNetwork& network, const std::map& config) { + details::SOPointer LoadNetwork(const CNNNetwork& network, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(network, config)}); } - ExecutableNetwork LoadNetwork(const CNNNetwork& network, RemoteContext::Ptr context, const std::map& config) { + details::SOPointer LoadNetwork(const CNNNetwork& network, RemoteContext::Ptr context, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(network, config, context)}); } - ExecutableNetwork LoadNetwork(const std::string& modelPath, const std::map& config) { + details::SOPointer LoadNetwork(const std::string& modelPath, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->LoadNetwork(modelPath, config)}); } @@ -85,17 +85,17 @@ class InferencePlugin : protected details::SOPointer { return res; } - ExecutableNetwork ImportNetwork(const std::string& modelFileName, + details::SOPointer ImportNetwork(const std::string& modelFileName, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(modelFileName, config)}); } - ExecutableNetwork ImportNetwork(std::istream& networkModel, + details::SOPointer ImportNetwork(std::istream& networkModel, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(networkModel, config)}); } - ExecutableNetwork ImportNetwork(std::istream& networkModel, + details::SOPointer ImportNetwork(std::istream& networkModel, const RemoteContext::Ptr& context, const std::map& config) { PLUGIN_CALL_STATEMENT(return {_so, _ptr->ImportNetwork(networkModel, context, config)}); diff --git a/inference-engine/src/inference_engine/ie_core.cpp b/inference-engine/src/inference_engine/ie_core.cpp index 9f026ecf693364..fa2fa8a6422dfd 100644 --- a/inference-engine/src/inference_engine/ie_core.cpp +++ b/inference-engine/src/inference_engine/ie_core.cpp @@ -26,6 +26,7 @@ #include "ie_network_reader.hpp" #include "xml_parse_utils.h" #include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" +#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" using namespace InferenceEngine::PluginConfigParams; using namespace std::placeholders; @@ -223,15 +224,15 @@ class Core::Impl : public ICore { return supported; } - ExecutableNetwork LoadNetworkImpl(const CNNNetwork& network, - InferencePlugin& plugin, - const std::map& parsedConfig, - const RemoteContext::Ptr& context, - const std::string& blobID, - const std::string& modelPath = std::string(), - bool forceDisableCache = false) { + SoExecutableNetworkInternal LoadNetworkImpl(const CNNNetwork& network, + InferencePlugin& plugin, + const std::map& parsedConfig, + const RemoteContext::Ptr& context, + const std::string& blobID, + const std::string& modelPath = std::string(), + bool forceDisableCache = false) { OV_ITT_SCOPED_TASK(itt::domains::IE, "Core::Impl::LoadNetworkImpl"); - ExecutableNetwork execNetwork; + SoExecutableNetworkInternal execNetwork; execNetwork = context ? plugin.LoadNetwork(network, context, parsedConfig) : plugin.LoadNetwork(network, parsedConfig); auto cacheManager = coreConfig.getCacheConfig()._cacheManager; @@ -242,7 +243,7 @@ class Core::Impl : public ICore { cacheManager->writeCacheEntry(blobID, [&](std::ostream& networkStream) { networkStream << CompiledBlobHeader(GetInferenceEngineVersion()->buildNumber, NetworkCompilationContext::calculateFileInfo(modelPath)); - execNetwork.Export(networkStream); + execNetwork->Export(networkStream); }); } catch (...) { cacheManager->removeCacheEntry(blobID); @@ -252,14 +253,14 @@ class Core::Impl : public ICore { return execNetwork; } - ExecutableNetwork LoadNetworkFromCache(const std::shared_ptr& cacheManager, - const std::string& blobId, - InferencePlugin& plugin, - const std::map& config, - const RemoteContext::Ptr& context, - bool& networkIsImported, - const std::string& modelPath = std::string()) { - ExecutableNetwork execNetwork; + SoExecutableNetworkInternal LoadNetworkFromCache(const std::shared_ptr& cacheManager, + const std::string& blobId, + InferencePlugin& plugin, + const std::map& config, + const RemoteContext::Ptr& context, + bool& networkIsImported, + const std::string& modelPath = std::string()) { + SoExecutableNetworkInternal execNetwork; struct HeaderException {}; IE_ASSERT(cacheManager != nullptr); @@ -446,15 +447,15 @@ class Core::Impl : public ICore { } // TODO: In future this method can be added to ICore interface - ExecutableNetwork LoadNetwork(const CNNNetwork& network, const RemoteContext::Ptr& context, - const std::map& config) { + SoExecutableNetworkInternal LoadNetwork(const CNNNetwork& network, const RemoteContext::Ptr& context, + const std::map& config) { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::IE_LT, "Core::LoadNetwork::RemoteContext"); if (context == nullptr) { IE_THROW() << "Remote context is null"; } auto parsed = parseDeviceNameIntoConfig(context->getDeviceName(), config); auto plugin = GetCPPPluginByName(parsed._deviceName); - ExecutableNetwork res; + SoExecutableNetworkInternal res; auto cacheManager = coreConfig.getCacheConfig()._cacheManager; if (cacheManager && DeviceSupportsImportExport(plugin)) { auto hash = CalculateNetworkHash(network, parsed._deviceName, plugin, parsed._config); @@ -470,8 +471,8 @@ class Core::Impl : public ICore { return res; } - ExecutableNetwork LoadNetwork(const CNNNetwork& network, const std::string& deviceName, - const std::map& config) override { + SoExecutableNetworkInternal LoadNetwork(const CNNNetwork& network, const std::string& deviceName, + const std::map& config) override { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::IE_LT, "Core::LoadNetwork::CNN"); bool forceDisableCache = config.count(CONFIG_KEY_INTERNAL(FORCE_DISABLE_CACHE)) > 0; auto parsed = parseDeviceNameIntoConfig(deviceName, config); @@ -480,7 +481,7 @@ class Core::Impl : public ICore { parsed._config.erase(CONFIG_KEY_INTERNAL(FORCE_DISABLE_CACHE)); } auto plugin = GetCPPPluginByName(parsed._deviceName); - ExecutableNetwork res; + SoExecutableNetworkInternal res; auto cacheManager = coreConfig.getCacheConfig()._cacheManager; if (!forceDisableCache && cacheManager && DeviceSupportsImportExport(plugin)) { auto hash = CalculateNetworkHash(network, parsed._deviceName, plugin, parsed._config); @@ -496,12 +497,12 @@ class Core::Impl : public ICore { return res; } - ExecutableNetwork LoadNetwork(const std::string& modelPath, const std::string& deviceName, - const std::map& config) override { + SoExecutableNetworkInternal LoadNetwork(const std::string& modelPath, const std::string& deviceName, + const std::map& config) override { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::IE_LT, "Core::LoadNetwork::Path"); auto parsed = parseDeviceNameIntoConfig(deviceName, config); auto plugin = GetCPPPluginByName(parsed._deviceName); - ExecutableNetwork res; + SoExecutableNetworkInternal res; auto cacheManager = coreConfig.getCacheConfig()._cacheManager; if (cacheManager && DeviceSupportsImportExport(plugin)) { bool loadedFromCache = false; @@ -522,8 +523,8 @@ class Core::Impl : public ICore { return res; } - ExecutableNetwork ImportNetwork(std::istream& networkModel, const std::string& deviceName, - const std::map& config) override { + SoExecutableNetworkInternal ImportNetwork(std::istream& networkModel, const std::string& deviceName, + const std::map& config) override { auto parsed = parseDeviceNameIntoConfig(deviceName, config); if (parsed._deviceName.empty()) { @@ -925,7 +926,6 @@ RemoteContext::Ptr Core::CreateContext(const std::string& deviceName, const Para IE_THROW() << "AUTO device does not support remote context"; } - auto parsed = parseDeviceNameIntoConfig(deviceName, params); return _impl->GetCPPPluginByName(parsed._deviceName).CreateContext(parsed._config); } diff --git a/inference-engine/src/inference_engine/ie_system_conf.cpp b/inference-engine/src/inference_engine/ie_system_conf.cpp index d9219597a93799..2626ad7e424407 100644 --- a/inference-engine/src/inference_engine/ie_system_conf.cpp +++ b/inference-engine/src/inference_engine/ie_system_conf.cpp @@ -111,9 +111,4 @@ std::vector getAvailableCoresTypes() { } #endif -std::exception_ptr& CurrentException() { - static thread_local std::exception_ptr currentException = nullptr; - return currentException; -} - } // namespace InferenceEngine diff --git a/inference-engine/src/multi_device/multi_device_async_infer_request.cpp b/inference-engine/src/multi_device/multi_device_async_infer_request.cpp index ca1c98976a2aea..9f845586a55330 100644 --- a/inference-engine/src/multi_device/multi_device_async_infer_request.cpp +++ b/inference-engine/src/multi_device/multi_device_async_infer_request.cpp @@ -28,7 +28,7 @@ MultiDeviceAsyncInferRequest::MultiDeviceAsyncInferRequest( void run(Task task) override { auto workerInferRequest = _this->_workerInferRequest; workerInferRequest->_task = std::move(task); - workerInferRequest->_inferRequest.StartAsync(); + workerInferRequest->_inferRequest->StartAsync(); }; MultiDeviceAsyncInferRequest* _this = nullptr; }; @@ -69,18 +69,11 @@ MultiDeviceAsyncInferRequest::MultiDeviceAsyncInferRequest( }}, // final task in the pipeline: { /*TaskExecutor*/std::make_shared(this), /*task*/ [this] { - auto status = _workerInferRequest->_status; - if (InferenceEngine::StatusCode::OK != status) { - if (nullptr != InferenceEngine::CurrentException()) - std::rethrow_exception(InferenceEngine::CurrentException()); - else - IE_EXCEPTION_SWITCH(status, ExceptionType, - InferenceEngine::details::ThrowNow{} - <<= std::stringstream{} << IE_LOCATION - << InferenceEngine::details::ExceptionTraits::string()); + if (nullptr != _workerInferRequest->_exceptionPtr) { + std::rethrow_exception(_workerInferRequest->_exceptionPtr); } if (_needPerfCounters) - _perfMap = _workerInferRequest->_inferRequest.GetPerformanceCounts(); + _perfMap = _workerInferRequest->_inferRequest->GetPerformanceCounts(); }} }; } diff --git a/inference-engine/src/multi_device/multi_device_exec_network.cpp b/inference-engine/src/multi_device/multi_device_exec_network.cpp index 9e42cbe080919d..5265e233cfd0a0 100644 --- a/inference-engine/src/multi_device/multi_device_exec_network.cpp +++ b/inference-engine/src/multi_device/multi_device_exec_network.cpp @@ -47,7 +47,7 @@ struct IdleGuard { MultiDeviceExecutableNetwork::NotBusyWorkerRequests* _notBusyWorkerRequests = nullptr; }; -MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMap& networksPerDevice, +MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMap& networksPerDevice, const std::vector& networkDevices, const std::unordered_map& config, const bool needPerfCounters) : @@ -66,7 +66,7 @@ MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMap(); + optimalNum = network->GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)).as(); } catch (const InferenceEngine::Exception &iie) { IE_THROW() << "Every device used with the Multi-Device should " @@ -82,13 +82,13 @@ MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMapCreateInferRequest(); auto* workerRequestPtr = &workerRequest; IE_ASSERT(idleWorkerRequests.try_push(workerRequestPtr) == true); - workerRequest._inferRequest.SetCompletionCallback>( - [workerRequestPtr, this, device, idleWorkerRequestsPtr] (InferRequest , StatusCode status) mutable { + workerRequest._inferRequest->SetCallback( + [workerRequestPtr, this, device, idleWorkerRequestsPtr] (std::exception_ptr exceptionPtr) mutable { IdleGuard idleGuard{workerRequestPtr, *idleWorkerRequestsPtr}; - workerRequestPtr->_status = status; + workerRequestPtr->_exceptionPtr = exceptionPtr; { auto capturedTask = std::move(workerRequestPtr->_task); capturedTask(); @@ -166,7 +166,7 @@ RemoteContext::Ptr MultiDeviceExecutableNetwork::GetContext() const { devices_names += device.deviceName + " "; const auto& n = _networksPerDevice.at(device.deviceName); try { - return n.GetContext(); + return n->GetContext(); } catch (const NotImplemented&) {} } IE_THROW(NotImplemented) << "None of the devices in the MULTI has an associated remote context." @@ -177,7 +177,7 @@ InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::Create InferenceEngine::OutputsDataMap networkOutputs) { auto num = _numRequestsCreated++; size_t sum = 0; - InferenceEngine::InferRequest request_to_share_blobs_with; + InferenceEngine::IInferRequestInternal::Ptr request_to_share_blobs_with; // borrowing device-specific blobs from the underlying requests for the device-agnostic, user-facing requests // this allows to potentially save on the data-copy later (if the requests are scheduled in the same order) for (const auto& device : _devicePrioritiesInitial) { @@ -248,7 +248,7 @@ InferenceEngine::Parameter MultiDeviceExecutableNetwork::GetMetric(const std::st unsigned int res = 0u; for (auto n : _networksPerDevice) { try { - res += n.second.GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)).as(); + res += n.second->GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)).as(); } catch (const InferenceEngine::Exception &iie) { IE_THROW() << "Every device used with the Multi-Device should " @@ -260,7 +260,7 @@ InferenceEngine::Parameter MultiDeviceExecutableNetwork::GetMetric(const std::st } else if (name == METRIC_KEY(NETWORK_NAME)) { auto it = _networksPerDevice.begin(); IE_ASSERT(it != _networksPerDevice.end()); - IE_SET_METRIC_RETURN(NETWORK_NAME, it->second.GetMetric( + IE_SET_METRIC_RETURN(NETWORK_NAME, it->second->GetMetric( METRIC_KEY(NETWORK_NAME)).as()); } else if (name == METRIC_KEY(SUPPORTED_METRICS)) { IE_SET_METRIC_RETURN(SUPPORTED_METRICS, { diff --git a/inference-engine/src/multi_device/multi_device_exec_network.hpp b/inference-engine/src/multi_device/multi_device_exec_network.hpp index dce26006b0502b..39dd6e999c1f47 100644 --- a/inference-engine/src/multi_device/multi_device_exec_network.hpp +++ b/inference-engine/src/multi_device/multi_device_exec_network.hpp @@ -99,13 +99,13 @@ class MultiDeviceExecutableNetwork : public InferenceEngine::ExecutableNetworkTh public: using Ptr = std::shared_ptr; struct WorkerInferRequest { - InferenceEngine::InferRequest _inferRequest; - InferenceEngine::Task _task; - InferenceEngine::StatusCode _status = InferenceEngine::StatusCode::OK; + InferenceEngine::IInferRequestInternal::Ptr _inferRequest; + InferenceEngine::Task _task; + std::exception_ptr _exceptionPtr = nullptr; }; using NotBusyWorkerRequests = ThreadSafeBoundedQueue; - explicit MultiDeviceExecutableNetwork(const DeviceMap& networksPerDevice, + explicit MultiDeviceExecutableNetwork(const DeviceMap& networksPerDevice, const std::vector& networkDevices, const std::unordered_map& config, const bool needPerfCounters = false); @@ -130,7 +130,7 @@ class MultiDeviceExecutableNetwork : public InferenceEngine::ExecutableNetworkTh mutable std::mutex _mutex; std::vector _devicePriorities; const std::vector _devicePrioritiesInitial; - DeviceMap _networksPerDevice; + DeviceMap _networksPerDevice; ThreadSafeQueue _inferPipelineTasks; DeviceMap>> _inferPipelineTasksDeviceSpecific; DeviceMap _idleWorkerRequests; diff --git a/inference-engine/src/multi_device/multi_device_infer_request.cpp b/inference-engine/src/multi_device/multi_device_infer_request.cpp index bebf27ec662191..5913a0b39d728f 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.cpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.cpp @@ -10,18 +10,20 @@ #include namespace MultiDevicePlugin { - using namespace InferenceEngine; + +using namespace InferenceEngine; + // ------------------------------MultiDeviceInferRequest---------------------------- MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs, - InferRequest request_to_share_blobs_with) + const IInferRequestInternal::Ptr & request_to_share_blobs_with) : IInferRequestInternal(networkInputs, networkOutputs) { if (request_to_share_blobs_with) { // borrow device-friendly blobs from the request for (const auto &it : _networkInputs) - _inputs[it.first] = request_to_share_blobs_with.GetBlob(it.first); + _inputs[it.first] = request_to_share_blobs_with->GetBlob(it.first); for (const auto &it : _networkOutputs) - _outputs[it.first] = request_to_share_blobs_with.GetBlob(it.first); + _outputs[it.first] = request_to_share_blobs_with->GetBlob(it.first); return; } // Allocate all input blobs @@ -46,20 +48,20 @@ MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkI } } -void MultiDeviceInferRequest::SetBlobsToAnotherRequest(InferRequest& req) { +void MultiDeviceInferRequest::SetBlobsToAnotherRequest(const IInferRequestInternal::Ptr& req) { for (const auto &it : _networkInputs) { auto &name = it.first; // this request is already in BUSY state, so using the internal functions safely auto blob = GetBlob(name); - if (req.GetBlob(name) != blob) - req.SetBlob(name, blob); + if (req->GetBlob(name) != blob) + req->SetBlob(name, blob); } for (const auto &it : _networkOutputs) { auto &name = it.first; // this request is already in BUSY state, so using the internal functions safely auto blob = GetBlob(name); - if (req.GetBlob(name) != blob) - req.SetBlob(name, blob); + if (req->GetBlob(name) != blob) + req->SetBlob(name, blob); } } diff --git a/inference-engine/src/multi_device/multi_device_infer_request.hpp b/inference-engine/src/multi_device/multi_device_infer_request.hpp index 3284b985054fe5..80f81c37e9c210 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.hpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.hpp @@ -25,11 +25,11 @@ class MultiDeviceInferRequest : public InferenceEngine::IInferRequestInternal { using Ptr = std::shared_ptr; explicit MultiDeviceInferRequest(const InferenceEngine::InputsDataMap& networkInputs, const InferenceEngine::OutputsDataMap& networkOutputs, - InferenceEngine::InferRequest request_to_share_blobs_with); + const InferenceEngine::IInferRequestInternal::Ptr & request_to_share_blobs_with); std::map GetPerformanceCounts() const override; void InferImpl() override; // Multi-Device impl specific: sets the data (blobs from the device-less requests to the specific device request) - void SetBlobsToAnotherRequest(InferenceEngine::InferRequest& req); + void SetBlobsToAnotherRequest(const InferenceEngine::IInferRequestInternal::Ptr& req); }; } // namespace MultiDevicePlugin diff --git a/inference-engine/src/multi_device/multi_device_plugin.cpp b/inference-engine/src/multi_device/multi_device_plugin.cpp index 15b25b59ad08d1..f15db83651ec05 100644 --- a/inference-engine/src/multi_device/multi_device_plugin.cpp +++ b/inference-engine/src/multi_device/multi_device_plugin.cpp @@ -164,7 +164,7 @@ ExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(co std::unordered_map multiNetworkConfig; multiNetworkConfig.insert(*priorities); - DeviceMap executableNetworkPerDevice; + DeviceMap executableNetworkPerDevice; std::mutex load_mutex; std::vector loads; for (auto& p : metaDevices) { @@ -192,7 +192,7 @@ ExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(co for (auto n : executableNetworkPerDevice) { try { num_plugins_supporting_perf_counters += - n.second.GetConfig(PluginConfigParams::KEY_PERF_COUNT).as() == + n.second->GetConfig(PluginConfigParams::KEY_PERF_COUNT).as() == PluginConfigParams::YES; } catch (...) { } diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp deleted file mode 100644 index 08e76565cccecc..00000000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_executable_network_2_internal.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "cpp_interfaces/impl/ie_executable_network_internal.hpp" -#include "cpp_interfaces/impl/ie_infer_request_2_internal.hpp" -#include "cpp/ie_executable_network.hpp" - -namespace InferenceEngine { - -class ExecutableNetwork2Internal : public IExecutableNetworkInternal { - ExecutableNetwork actual; -public: - explicit ExecutableNetwork2Internal(const ExecutableNetwork & exec) : actual(exec) { - if (!actual) { - IE_THROW(NotAllocated); - } - } - - virtual void setNetworkInputs(const InferenceEngine::InputsDataMap networkInputs) { - // should call internal methods - IE_THROW(NotImplemented); - } - - virtual void setNetworkOutputs(const InferenceEngine::OutputsDataMap networkOutputs) { - // should call internal methods - IE_THROW(NotImplemented); - } - - ConstOutputsDataMap GetOutputsInfo() const override { - return actual.GetOutputsInfo(); - } - - ConstInputsDataMap GetInputsInfo() const override { - return actual.GetInputsInfo(); - } - - void Export(const std::string& modelFileName) override { - actual.Export(modelFileName); - } - - void Export(std::ostream& networkModel) override { - actual.Export(networkModel); - } - - CNNNetwork GetExecGraphInfo() override { - return actual.GetExecGraphInfo(); - } - - std::vector QueryState() override { - IE_SUPPRESS_DEPRECATED_START - std::vector states; - for (auto & state : actual.QueryState()) { - states.push_back(std::make_shared(state)); - } - return states; - IE_SUPPRESS_DEPRECATED_END - } - - void SetConfig(const std::map& config) override { - actual.SetConfig(config); - } - - Parameter GetConfig(const std::string& name) const override { - return actual.GetConfig(name); - } - - Parameter GetMetric(const std::string& name) const override { - return actual.GetConfig(name); - } - - RemoteContext::Ptr GetContext() const override { - return actual.GetContext(); - } - - IInferRequestInternal::Ptr CreateInferRequest() override { - return std::make_shared(actual.CreateInferRequest()); - } -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp deleted file mode 100644 index 7189edc6b55107..00000000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_request_2_internal.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" -#include "cpp_interfaces/impl/ie_variable_state_2_internal.hpp" - -namespace InferenceEngine { - -class InferRequest2Internal : public IInferRequestInternal { - InferRequest actual; - -public: - explicit InferRequest2Internal(const InferRequest & request) : actual(request) { - if (!actual) { - IE_THROW(NotAllocated); - } - } - - void Infer() override { - actual.Infer(); - } - - virtual void InferImpl() { - // should call internal methods - IE_THROW(NotImplemented); - } - - void Cancel() override { - actual.Cancel(); - } - - std::map GetPerformanceCounts() const override { - return actual.GetPerformanceCounts(); - } - - void SetBlob(const std::string& name, const Blob::Ptr& data) override { - actual.SetBlob(name, data); - } - - Blob::Ptr GetBlob(const std::string& name) override { - return actual.GetBlob(name); - } - - void SetBlob(const std::string& name, const Blob::Ptr& data, const PreProcessInfo& info) override { - actual.SetBlob(name, data, info); - } - - const PreProcessInfo& GetPreProcess(const std::string& name) const override { - return actual.GetPreProcess(name); - } - - void SetBatch(int batch) override { - actual.SetBatch(batch); - } - - std::vector> QueryState() override { - std::vector states; - for (auto & state : actual.QueryState()) { - states.push_back(std::make_shared(state)); - } - return states; - } - - void StartAsync() override { - actual.StartAsync(); - } - - void StartAsyncImpl() override { - // should call internal methods - IE_THROW(NotImplemented); - } - - StatusCode Wait(int64_t millis_timeout) override { - return actual.Wait(millis_timeout); - } - - void SetCallback(Callback callback) override { - // actual.SetCallback([&] (std::exception_ptr exceptionPtr) { - // StatusCode statusCode = StatusCode::OK; - // if (exceptionPtr != nullptr) { - // statusCode = [&] { - // try { - // std::rethrow_exception(exceptionPtr); - // } CATCH_IE_EXCEPTIONS_RETURN catch (const std::exception& ex) { - // return GENERAL_ERROR; - // } catch (...) { - // return UNEXPECTED; - // } - // } (); - // } - // callback(weakThis, statusCode); - // }); - } - - void checkBlobs() override { - // should call internal methods - IE_THROW(NotImplemented); - } -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp index 270daa372d423c..2afb5f066f6509 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_plugin_internal.hpp @@ -16,7 +16,7 @@ #include #include -#include "cpp_interfaces/impl/ie_executable_network_2_internal.hpp" +#include "cpp_interfaces/impl/ie_executable_network_internal.hpp" #include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include "cpp_interfaces/plugin_itt.hpp" @@ -75,8 +75,7 @@ class InferencePluginInternal : public IInferencePlugin { IExecutableNetworkInternal::Ptr LoadNetwork(const std::string& modelPath, const std::map& config) override { auto cnnNet = GetCore()->ReadNetwork(modelPath, std::string()); - auto exec = GetCore()->LoadNetwork(cnnNet, GetName(), config); - return std::make_shared(exec); + return GetCore()->LoadNetwork(cnnNet, GetName(), config); } IExecutableNetworkInternal::Ptr ImportNetwork(const std::string& modelFileName, diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp deleted file mode 100644 index de9b580c7516b9..00000000000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_variable_state_2_internal.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include "cpp/ie_memory_state.hpp" - -namespace InferenceEngine { - -class VariableState2Internal : public IVariableStateInternal { - VariableState actual; - -public: - explicit VariableState2Internal(const VariableState & variableState) : - actual(variableState) { - // TODO: added a check for emptyness - // if (!actual) { - // IE_THROW(NotAllocated); - // } - } - - virtual std::string GetName() const override { - return actual.GetName(); - } - - void Reset() override { - actual.Reset(); - } - - void SetState(Blob::Ptr newState) override { - actual.SetState(newState); - } - - Blob::CPtr GetState() const override { - return actual.GetState(); - } -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/ie_icore.hpp b/inference-engine/src/plugin_api/ie_icore.hpp index 6c35277726f386..7f3ed86ee384b5 100644 --- a/inference-engine/src/plugin_api/ie_icore.hpp +++ b/inference-engine/src/plugin_api/ie_icore.hpp @@ -16,11 +16,14 @@ #include #include #include +#include
#include "threading/ie_itask_executor.hpp" namespace InferenceEngine { +using SoExecutableNetworkInternal = details::SOPointer; + /** * @interface ICore * @brief Minimal ICore interface to allow plugin to get information from Core Inference Engine class. @@ -63,8 +66,8 @@ class ICore { * operation * @return An executable network reference */ - virtual ExecutableNetwork LoadNetwork(const CNNNetwork& network, const std::string& deviceName, - const std::map& config = {}) = 0; + virtual SoExecutableNetworkInternal LoadNetwork(const CNNNetwork& network, const std::string& deviceName, + const std::map& config = {}) = 0; /** * @brief Creates an executable network from a model file. @@ -78,8 +81,8 @@ class ICore { * operation * @return An executable network reference */ - virtual ExecutableNetwork LoadNetwork(const std::string& modelPath, const std::string& deviceName, - const std::map& config) = 0; + virtual SoExecutableNetworkInternal LoadNetwork(const std::string& modelPath, const std::string& deviceName, + const std::map& config) = 0; /** * @brief Creates an executable network from a previously exported network @@ -89,8 +92,8 @@ class ICore { * operation* * @return An executable network reference */ - virtual ExecutableNetwork ImportNetwork(std::istream& networkModel, const std::string& deviceName = {}, - const std::map& config = {}) = 0; + virtual SoExecutableNetworkInternal ImportNetwork(std::istream& networkModel, const std::string& deviceName = {}, + const std::map& config = {}) = 0; /** * @brief Query device if it supports specified network with specified configuration diff --git a/inference-engine/src/plugin_api/ie_system_conf.h b/inference-engine/src/plugin_api/ie_system_conf.h index 28c1e155e87fa8..2e4481bf09e204 100644 --- a/inference-engine/src/plugin_api/ie_system_conf.h +++ b/inference-engine/src/plugin_api/ie_system_conf.h @@ -15,12 +15,6 @@ namespace InferenceEngine { -/** - * @brief Provides the reference to static thread_local std::exception_ptr - * @return A an exception pointer - */ -INFERENCE_ENGINE_API_CPP(std::exception_ptr&) CurrentException(); - /** * @brief Checks whether OpenMP environment variables are defined * @ingroup ie_dev_api_system_conf diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp index 7e264217bf999f..7832894a91390e 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp @@ -14,16 +14,16 @@ class MockICore : public InferenceEngine::ICore { MOCK_QUALIFIED_METHOD2(ReadNetwork, const, InferenceEngine::CNNNetwork(const std::string&, const InferenceEngine::Blob::CPtr&)); MOCK_QUALIFIED_METHOD2(ReadNetwork, const, InferenceEngine::CNNNetwork(const std::string&, const std::string&)); - MOCK_METHOD3(LoadNetwork, InferenceEngine::ExecutableNetwork( + MOCK_METHOD3(LoadNetwork, InferenceEngine::SoExecutableNetworkInternal( const InferenceEngine::CNNNetwork&, const std::string&, const std::map&)); - MOCK_METHOD3(LoadNetwork, InferenceEngine::ExecutableNetwork( + MOCK_METHOD3(LoadNetwork, InferenceEngine::SoExecutableNetworkInternal( const InferenceEngine::CNNNetwork&, const InferenceEngine::RemoteContext::Ptr &, const std::map&)); - MOCK_METHOD3(LoadNetwork, InferenceEngine::ExecutableNetwork( + MOCK_METHOD3(LoadNetwork, InferenceEngine::SoExecutableNetworkInternal( const std::string &, const std::string &, const std::map&)); - MOCK_METHOD3(ImportNetwork, InferenceEngine::ExecutableNetwork( + MOCK_METHOD3(ImportNetwork, InferenceEngine::SoExecutableNetworkInternal( std::istream&, const std::string&, const std::map&)); - MOCK_METHOD3(ImportNetwork, InferenceEngine::ExecutableNetwork( + MOCK_METHOD3(ImportNetwork, InferenceEngine::SoExecutableNetworkInternal( std::istream&, const InferenceEngine::RemoteContext::Ptr&, const std::map&)); MOCK_QUALIFIED_METHOD3(QueryNetwork, const, InferenceEngine::QueryNetworkResult( 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 78a1e66cf54805..d0cde74580cb1b 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 @@ -173,11 +173,11 @@ TEST_F(InferRequestBaseTests, canReportErrorInSetCompletionCallback) { class InferRequestTests : public ::testing::Test { protected: std::shared_ptr mock_request; - InferRequest request; + IInferRequestInternal::Ptr request; ResponseDesc dsc; std::shared_ptr mockIExeNet; - InferenceEngine::ExecutableNetwork exeNetwork; + InferenceEngine::SoExecutableNetworkInternal exeNetwork; MockIInferencePlugin* mockIPlugin; InferencePlugin plugin; shared_ptr mockInferRequestInternal; @@ -202,7 +202,7 @@ class InferRequestTests : public ::testing::Test { ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); - request = exeNetwork.CreateInferRequest(); + request = exeNetwork->CreateInferRequest(); _incorrectName = "incorrect_name"; _inputName = MockNotEmptyICNNNetwork::INPUT_BLOB_NAME; _failedToFindInOutError = @@ -213,7 +213,7 @@ class InferRequestTests : public ::testing::Test { + _inputName + "\'"; } - InferRequest getInferRequestWithMockImplInside() { + IInferRequestInternal::Ptr getInferRequestWithMockImplInside() { IInferRequest::Ptr inferRequest; InputsDataMap inputsInfo; mockNotEmptyNet.getInputsInfo(inputsInfo); @@ -226,7 +226,7 @@ class InferRequestTests : public ::testing::Test { ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockIExeNet)); auto plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; auto exeNetwork = plugin.LoadNetwork(CNNNetwork{}, {}); - return exeNetwork.CreateInferRequest(); + return exeNetwork->CreateInferRequest(); } std::string getExceptionMessage(std::function function) { @@ -238,71 +238,54 @@ class InferRequestTests : public ::testing::Test { } return actualError; } - - BlobMap getBlobMapWithIncorrectName() const { - Blob::Ptr Blob = make_shared_blob({ Precision::FP32, {1, 1, 1, 1}, NCHW }); - Blob->allocate(); - return BlobMap{{_incorrectName, Blob}}; - } - - BlobMap getBlobMapWithNotAllocatedInput() const { - Blob::Ptr Blob = make_shared_blob({ Precision::FP32, {1, 1, 1, 1}, NCHW }); - return BlobMap{{_inputName, Blob}}; - } - - BlobMap getBlobMapWithEmptyDimensions() const { - Blob::Ptr Blob = make_shared_blob({ Precision::FP32, {}, NCHW }); - Blob->allocate(); - return BlobMap{{_inputName, Blob}}; - } }; // StartAsync TEST_F(InferRequestTests, canForwardStartAsync) { EXPECT_CALL(*mock_request.get(), StartAsync()); - ASSERT_NO_THROW(request.StartAsync()); + ASSERT_NO_THROW(request->StartAsync()); } TEST_F(InferRequestTests, throwsIfStartAsyncReturnNotOK) { EXPECT_CALL(*mock_request.get(), StartAsync()).WillOnce(Throw(GeneralError{""})); - ASSERT_THROW(request.StartAsync(), Exception); + ASSERT_THROW(request->StartAsync(), Exception); } // Wait TEST_F(InferRequestTests, canForwardWait) { int64_t ms = 0; EXPECT_CALL(*mock_request.get(), Wait(_)).WillOnce(Return(OK)); - ASSERT_TRUE(OK == request.Wait(ms)); + ASSERT_TRUE(OK == request->Wait(ms)); } TEST_F(InferRequestTests, canForwardStatusFromWait) { EXPECT_CALL(*mock_request.get(), Wait(_)).WillOnce(Return(RESULT_NOT_READY)); - ASSERT_EQ(request.Wait(0), RESULT_NOT_READY); + ASSERT_EQ(request->Wait(0), RESULT_NOT_READY); } // Infer TEST_F(InferRequestTests, canForwardInfer) { EXPECT_CALL(*mock_request.get(), Infer()); - ASSERT_NO_THROW(request.Infer()); + ASSERT_NO_THROW(request->Infer()); } TEST_F(InferRequestTests, throwsIfInferReturnNotOK) { EXPECT_CALL(*mock_request.get(), Infer()).WillOnce(Throw(GeneralError{""})); - ASSERT_THROW(request.Infer(), Exception); + ASSERT_THROW(request->Infer(), Exception); } // GetPerformanceCounts TEST_F(InferRequestTests, canForwardGetPerformanceCounts) { std::map info; EXPECT_CALL(*mock_request.get(), GetPerformanceCounts()).WillOnce(Return(info)); - ASSERT_NO_THROW(info = request.GetPerformanceCounts()); + ASSERT_NO_THROW(info = request->GetPerformanceCounts()); } TEST_F(InferRequestTests, throwsIfGetPerformanceCountsReturnNotOK) { std::map info; EXPECT_CALL(*mock_request.get(), GetPerformanceCounts()).WillOnce(Throw(GeneralError{""})); - ASSERT_THROW(info = request.GetPerformanceCounts(), Exception); + ASSERT_THROW(info = request->GetPerformanceCounts(), Exception); } MATCHER_P(blob_in_map_pointer_is_same, ref_blob, "") { @@ -310,38 +293,6 @@ MATCHER_P(blob_in_map_pointer_is_same, ref_blob, "") { return reinterpret_cast(arg.begin()->second->buffer()) == reinterpret_cast(ref_blob->buffer()); } -// SetInput -TEST_F(InferRequestTests, getInputCallsSetBlob) { - Blob::Ptr inblob; - std::string blobName1 = "blob1"; - std::string blobName2 = "blob2"; - BlobMap blobMap{{blobName1, inblob}, - {blobName2, inblob}}; - - EXPECT_CALL(*mock_request.get(), SetBlob(blobName1, inblob)); - EXPECT_CALL(*mock_request.get(), SetBlob(blobName2, inblob)); - ASSERT_NO_THROW(request.SetInput(blobMap)); -} - -TEST_F(InferRequestTests, throwsIfSetInputReturnNotOK) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); - BlobMap blobMap{{{}, {}}}; - ASSERT_THROW(request.SetInput(blobMap), Exception); -} - -// SetOutput -TEST_F(InferRequestTests, getOutputCallsSetBlob) { - Blob::Ptr inblob; - std::string blobName1 = "blob1"; - std::string blobName2 = "blob2"; - BlobMap blobMap{{blobName1, inblob}, - {blobName2, inblob}}; - - EXPECT_CALL(*mock_request.get(), SetBlob(blobName1, inblob)); - EXPECT_CALL(*mock_request.get(), SetBlob(blobName2, inblob)); - ASSERT_NO_THROW(request.SetOutput(blobMap)); -} - // GetBlob TEST_F(InferRequestTests, canForwardGetBlob) { Blob::Ptr blob = make_shared_blob({ Precision::FP32, {}, NCHW }); @@ -349,7 +300,7 @@ TEST_F(InferRequestTests, canForwardGetBlob) { std::string name = "blob1"; EXPECT_CALL(*mock_request.get(), GetBlob(_)).WillOnce(Return(blob)); - ASSERT_NO_THROW(request.GetBlob(name)); + ASSERT_NO_THROW(request->GetBlob(name)); } TEST_F(InferRequestTests, throwsIfGetBlobReturnNotOK) { @@ -357,7 +308,7 @@ TEST_F(InferRequestTests, throwsIfGetBlobReturnNotOK) { std::string name = "blob1"; EXPECT_CALL(*mock_request.get(), GetBlob(_)).WillOnce(Throw(GeneralError{""})); - ASSERT_THROW(blob = request.GetBlob(name), Exception); + ASSERT_THROW(blob = request->GetBlob(name), Exception); } // SetBlob @@ -366,7 +317,7 @@ TEST_F(InferRequestTests, canForwardSetBlob) { std::string name = "blob1"; EXPECT_CALL(*mock_request.get(), SetBlob(name, blob)); - ASSERT_NO_THROW(request.SetBlob(name, blob)); + ASSERT_NO_THROW(request->SetBlob(name, blob)); } TEST_F(InferRequestTests, throwsIfSetBlobReturnNotOK) { @@ -374,40 +325,10 @@ TEST_F(InferRequestTests, throwsIfSetBlobReturnNotOK) { std::string name = "blob1"; EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); - ASSERT_THROW(request.SetBlob(name, blob), Exception); -} - -TEST_F(InferRequestTests, throwsIfSetOutputReturnNotOK) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); - BlobMap blobMap{{{}, {}}}; - ASSERT_THROW(request.SetOutput(blobMap), Exception); + ASSERT_THROW(request->SetBlob(name, blob), Exception); } TEST_F(InferRequestTests, canForwardAnyCallback) { EXPECT_CALL(*mock_request.get(), SetCallback(_)); - ASSERT_NO_THROW(request.SetCompletionCallback([] {})); -} - -TEST_F(InferRequestTests, failToSetInputWithInCorrectName) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(NotFound{""})); - auto blobMap = getBlobMapWithIncorrectName(); - ASSERT_THROW(request.SetInput(blobMap), NotFound); -} - -TEST_F(InferRequestTests, failToSetOutputWithInCorrectName) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(NotFound{""})); - auto blobMap = getBlobMapWithIncorrectName(); - ASSERT_THROW(request.SetOutput(blobMap), NotFound); -} - -TEST_F(InferRequestTests, failToSetInputWithNotAllocatedInput) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(NotAllocated{""})); - auto blobMap = getBlobMapWithNotAllocatedInput(); - ASSERT_THROW(request.SetInput(blobMap), NotAllocated); -} - -TEST_F(InferRequestTests, failToSetInputWithEmptyDimensions) { - EXPECT_CALL(*mock_request.get(), SetBlob(_, _)).WillOnce(Throw(GeneralError{""})); - auto blobMap = getBlobMapWithEmptyDimensions(); - ASSERT_THROW(request.SetInput(blobMap), GeneralError); + ASSERT_NO_THROW(request->SetCallback([] (std::exception_ptr) {})); } 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 654fc9b4de2113..6867cb92b26cce 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 @@ -27,8 +27,8 @@ class VariableStateTests : public ::testing::Test { shared_ptr mockVariableStateInternal; MockIInferencePlugin* mockIPlugin; InferencePlugin plugin; - ExecutableNetwork net; - InferRequest req; + SoExecutableNetworkInternal net; + IInferRequestInternal::Ptr req; virtual void SetUp() { mockExeNetworkInternal = make_shared(); @@ -39,7 +39,7 @@ class VariableStateTests : public ::testing::Test { ON_CALL(*mockIPluginPtr, LoadNetwork(MatcherCast(_), _)).WillByDefault(Return(mockExeNetworkInternal)); plugin = InferenceEngine::InferencePlugin{{}, mockIPluginPtr}; net = plugin.LoadNetwork(CNNNetwork{}, {}); - req = net.CreateInferRequest(); + req = net->CreateInferRequest(); } }; @@ -50,7 +50,7 @@ TEST_F(VariableStateTests, ExecutableNetworkCanConvertOneVariableStateFromCppToA EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - auto state = net.QueryState(); + auto state = net->QueryState(); ASSERT_EQ(state.size(), 1); IE_SUPPRESS_DEPRECATED_END } @@ -61,7 +61,7 @@ TEST_F(VariableStateTests, ExecutableNetworkCanConvertZeroVariableStateFromCppTo EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).WillOnce(Return(toReturn)); - auto state = net.QueryState(); + auto state = net->QueryState(); ASSERT_EQ(state.size(), 0); IE_SUPPRESS_DEPRECATED_END } @@ -74,7 +74,7 @@ TEST_F(VariableStateTests, ExecutableNetworkCanConvert2VariableStatesFromCPPtoAP EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - auto state = net.QueryState(); + auto state = net->QueryState(); ASSERT_EQ(state.size(), 2); IE_SUPPRESS_DEPRECATED_END } @@ -87,8 +87,8 @@ TEST_F(VariableStateTests, VariableStatePropagatesReset) { EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), Reset()).Times(1); - auto state = net.QueryState(); - state.front().Reset(); + auto state = net->QueryState(); + state.front()->Reset(); IE_SUPPRESS_DEPRECATED_END } @@ -100,8 +100,8 @@ TEST_F(VariableStateTests, VariableStatePropagatesExceptionsFromReset) { EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), Reset()).WillOnce(Throw(std::logic_error("some error"))); - auto state = net.QueryState(); - EXPECT_ANY_THROW(state.front().Reset()); + auto state = net->QueryState(); + EXPECT_ANY_THROW(state.front()->Reset()); IE_SUPPRESS_DEPRECATED_END } @@ -113,8 +113,8 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetName) { EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - auto state = net.QueryState(); - EXPECT_STREQ(state.front().GetName().c_str(), "someName"); + auto state = net->QueryState(); + EXPECT_STREQ(state.front()->GetName().c_str(), "someName"); IE_SUPPRESS_DEPRECATED_END } @@ -126,8 +126,8 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithZeroLen) { EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - auto pState = net.QueryState().front(); - EXPECT_NO_THROW(pState.GetName()); + auto pState = net->QueryState().front(); + EXPECT_NO_THROW(pState->GetName()); IE_SUPPRESS_DEPRECATED_END } @@ -140,11 +140,10 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfOne) { EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - auto pState = net.QueryState().front(); + auto pState = net->QueryState().front(); std::string name; - EXPECT_NO_THROW(name = pState.GetName()); + EXPECT_NO_THROW(name = pState->GetName()); EXPECT_EQ(name, "someName"); - EXPECT_EQ(name, ""); IE_SUPPRESS_DEPRECATED_END } @@ -156,9 +155,9 @@ TEST_F(VariableStateTests, VariableStatePropagatesGetNameWithLenOfTwo) { EXPECT_CALL(*mockExeNetworkInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - auto pState = net.QueryState().front(); + auto pState = net->QueryState().front(); std::string name; - EXPECT_NO_THROW(name = pState.GetName()); + EXPECT_NO_THROW(name = pState->GetName()); EXPECT_EQ(name, "someName"); IE_SUPPRESS_DEPRECATED_END } @@ -175,7 +174,7 @@ TEST_F(VariableStateTests, VariableStateCanPropagateSetState) { float data[] = {123, 124, 125}; auto stateBlob = make_shared_blob({ Precision::FP32, {3}, C }, data, sizeof(data) / sizeof(*data)); - EXPECT_NO_THROW(net.QueryState().front().SetState(stateBlob)); + EXPECT_NO_THROW(net->QueryState().front()->SetState(stateBlob)); ASSERT_FLOAT_EQ(saver->buffer().as()[0], 123); ASSERT_FLOAT_EQ(saver->buffer().as()[1], 124); ASSERT_FLOAT_EQ(saver->buffer().as()[2], 125); @@ -196,7 +195,7 @@ TEST_F(VariableStateTests, VariableStateCanPropagateGetLastState) { EXPECT_CALL(*mockVariableStateInternal.get(), GetState()).WillOnce(Return(stateBlob)); - auto saver = net.QueryState().front().GetState(); + auto saver = net->QueryState().front()->GetState(); ASSERT_FLOAT_EQ(saver->cbuffer().as()[0], 123); ASSERT_FLOAT_EQ(saver->cbuffer().as()[1], 124); ASSERT_FLOAT_EQ(saver->cbuffer().as()[2], 125); @@ -214,7 +213,6 @@ TEST_F(VariableStateTests, VariableStateInternalCanSaveName) { ASSERT_STREQ(pState->GetName().c_str(), "name"); } - TEST_F(VariableStateTests, VariableStateInternalCanSaveState) { IVariableStateInternal::Ptr pState(new VariableStateInternalMockImpl("name")); float data[] = {123, 124, 125}; @@ -253,7 +251,7 @@ TEST_F(VariableStateTests, InferRequestCanConvertOneVariableStateFromCppToAPI) { EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - auto state = req.QueryState(); + auto state = req->QueryState(); ASSERT_EQ(state.size(), 1); } @@ -262,7 +260,7 @@ TEST_F(VariableStateTests, InferRequestCanConvertZeroVariableStateFromCppToAPI) EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).WillOnce(Return(toReturn)); - auto state = req.QueryState(); + auto state = req->QueryState(); ASSERT_EQ(state.size(), 0); } @@ -273,7 +271,7 @@ TEST_F(VariableStateTests, InferRequestCanConvert2VariableStatesFromCPPtoAPI) { EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - auto state = req.QueryState(); + auto state = req->QueryState(); ASSERT_EQ(state.size(), 2); } @@ -284,8 +282,8 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesReset) { EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), Reset()).Times(1); - auto state = req.QueryState(); - state.front().Reset(); + auto state = req->QueryState(); + state.front()->Reset(); } TEST_F(VariableStateTests, InfReqVariableStatePropagatesExceptionsFromReset) { @@ -295,8 +293,8 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesExceptionsFromReset) { EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), Reset()).WillOnce(Throw(std::logic_error("some error"))); - auto state = req.QueryState(); - EXPECT_ANY_THROW(state.front().Reset()); + auto state = req->QueryState(); + EXPECT_ANY_THROW(state.front()->Reset()); } TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetName) { @@ -306,58 +304,8 @@ TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetName) { EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - auto state = req.QueryState(); - EXPECT_STREQ(state.front().GetName().c_str(), "someName"); -} - -TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithZeroLen) { - IE_SUPPRESS_DEPRECATED_START - std::vector toReturn; - toReturn.push_back(mockVariableStateInternal); - - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - - IVariableState::Ptr pState; - - static_cast(req)->QueryState(pState, 0, nullptr); - char *name = reinterpret_cast(1); - EXPECT_NO_THROW(pState->GetName(name, 0, nullptr)); - IE_SUPPRESS_DEPRECATED_END -} - -TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithLenOfOne) { - IE_SUPPRESS_DEPRECATED_START - std::vector toReturn; - toReturn.push_back(mockVariableStateInternal); - - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - - IVariableState::Ptr pState; - - static_cast(req)->QueryState(pState, 0, nullptr); - char name[1]; - EXPECT_NO_THROW(pState->GetName(name, 1, nullptr)); - EXPECT_STREQ(name, ""); - IE_SUPPRESS_DEPRECATED_END -} - -TEST_F(VariableStateTests, InfReqVariableStatePropagatesGetNameWithLenOfTwo) { - IE_SUPPRESS_DEPRECATED_START - std::vector toReturn; - toReturn.push_back(mockVariableStateInternal); - - EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).Times(1).WillRepeatedly(Return(toReturn)); - EXPECT_CALL(*mockVariableStateInternal.get(), GetName()).WillOnce(Return("someName")); - - IVariableState::Ptr pState; - - static_cast(req)->QueryState(pState, 0, nullptr); - char name[2]; - EXPECT_NO_THROW(pState->GetName(name, 2, nullptr)); - EXPECT_STREQ(name, "s"); - IE_SUPPRESS_DEPRECATED_END + auto state = req->QueryState(); + EXPECT_STREQ(state.front()->GetName().c_str(), "someName"); } TEST_F(VariableStateTests, InfReqVariableStateCanPropagateSetState) { @@ -371,7 +319,7 @@ TEST_F(VariableStateTests, InfReqVariableStateCanPropagateSetState) { float data[] = {123, 124, 125}; auto stateBlob = make_shared_blob({ Precision::FP32, {3}, C }, data, sizeof(data) / sizeof(*data)); - EXPECT_NO_THROW(req.QueryState().front().SetState(stateBlob)); + EXPECT_NO_THROW(req->QueryState().front()->SetState(stateBlob)); ASSERT_FLOAT_EQ(saver->buffer().as()[0], 123); ASSERT_FLOAT_EQ(saver->buffer().as()[1], 124); ASSERT_FLOAT_EQ(saver->buffer().as()[2], 125); @@ -388,7 +336,7 @@ TEST_F(VariableStateTests, InfReqVariableStateCanPropagateGetLastState) { EXPECT_CALL(*mockInferRequestInternal.get(), QueryState()).WillRepeatedly(Return(toReturn)); EXPECT_CALL(*mockVariableStateInternal.get(), GetState()).WillOnce(Return(stateBlob)); - auto saver = req.QueryState().front().GetState(); + auto saver = req->QueryState().front()->GetState(); ASSERT_FLOAT_EQ(saver->cbuffer().as()[0], 123); ASSERT_FLOAT_EQ(saver->cbuffer().as()[1], 124); ASSERT_FLOAT_EQ(saver->cbuffer().as()[2], 125); 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 fa7256e3217caa..2c35e8652dfcc0 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 @@ -39,9 +39,9 @@ using testing::SetArgReferee; class ExecutableNetworkTests : public ::testing::Test { protected: std::shared_ptr mockIExeNet; - InferenceEngine::ExecutableNetwork exeNetwork; - MockIInferencePlugin* mockIPlugin; - InferencePlugin plugin; + InferenceEngine::SoExecutableNetworkInternal exeNetwork; + MockIInferencePlugin* mockIPlugin; + InferencePlugin plugin; virtual void TearDown() { mockIExeNet.reset(); @@ -63,12 +63,13 @@ TEST_F(ExecutableNetworkTests, GetOutputsInfoThrowsIfReturnErr) { .Times(1) .WillOnce(Throw(InferenceEngine::GeneralError{""})); - ASSERT_THROW(exeNetwork.GetOutputsInfo(), InferenceEngine::Exception); + ASSERT_THROW(exeNetwork->GetOutputsInfo(), InferenceEngine::Exception); } TEST_F(ExecutableNetworkTests, GetOutputsInfo) { InferenceEngine::ConstOutputsDataMap data; EXPECT_CALL(*mockIExeNet.get(), GetOutputsInfo()).Times(1).WillRepeatedly(Return(InferenceEngine::ConstOutputsDataMap{})); + ASSERT_NO_THROW(data = exeNetwork->GetOutputsInfo()); ASSERT_EQ(data, InferenceEngine::ConstOutputsDataMap{}); } @@ -77,29 +78,24 @@ TEST_F(ExecutableNetworkTests, GetInputsInfoThrowsIfReturnErr) { .Times(1) .WillOnce(Throw(InferenceEngine::GeneralError{""})); - ASSERT_THROW(exeNetwork.GetInputsInfo(), InferenceEngine::Exception); + ASSERT_THROW(exeNetwork->GetInputsInfo(), InferenceEngine::Exception); } TEST_F(ExecutableNetworkTests, GetInputsInfo) { EXPECT_CALL(*mockIExeNet.get(), GetInputsInfo()).Times(1).WillRepeatedly(Return(InferenceEngine::ConstInputsDataMap{})); InferenceEngine::ConstInputsDataMap info; - ASSERT_NO_THROW(info = exeNetwork.GetInputsInfo()); + ASSERT_NO_THROW(info = exeNetwork->GetInputsInfo()); ASSERT_EQ(info, InferenceEngine::ConstInputsDataMap{}); } IE_SUPPRESS_DEPRECATED_START -TEST_F(ExecutableNetworkTests, resetThrowsIfResetToNullptr) { - InferenceEngine::IExecutableNetwork::Ptr mockIExeNet_2{}; - ASSERT_THROW(exeNetwork.reset(mockIExeNet_2), InferenceEngine::Exception); -} - TEST_F(ExecutableNetworkTests, QueryStateThrowsIfReturnErr) { EXPECT_CALL(*mockIExeNet.get(), QueryState()) .Times(1) .WillOnce(Throw(InferenceEngine::GeneralError{""})); - EXPECT_THROW(exeNetwork.QueryState(), InferenceEngine::Exception); + EXPECT_THROW(exeNetwork->QueryState(), InferenceEngine::Exception); } TEST_F(ExecutableNetworkTests, QueryState) { @@ -107,8 +103,8 @@ TEST_F(ExecutableNetworkTests, QueryState) { EXPECT_CALL(*mockIExeNet.get(), QueryState()) .Times(1) .WillOnce(Return(std::vector>(1, mockIMemState_p))); - std::vector MemState_v; - EXPECT_NO_THROW(MemState_v = exeNetwork.QueryState()); + std::vector MemState_v; + EXPECT_NO_THROW(MemState_v = exeNetwork->QueryState()); EXPECT_EQ(MemState_v.size(), 1); } @@ -131,39 +127,17 @@ class ExecutableNetworkWithIInferReqTests : public ExecutableNetworkTests { TEST_F(ExecutableNetworkWithIInferReqTests, CanCreateInferRequest) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(mockIInferReq_p)); - InferRequest actualInferReq; - ASSERT_NO_THROW(actualInferReq = exeNetwork.CreateInferRequest()); + IInferRequestInternal::Ptr actualInferReq; + ASSERT_NO_THROW(actualInferReq = exeNetwork->CreateInferRequest()); } TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestThrowsIfReturnNotOK) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Throw(InferenceEngine::GeneralError{""})); - ASSERT_THROW(exeNetwork.CreateInferRequest(), InferenceEngine::Exception); -} - -TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestThrowsIfSetRequestToNullptr) { - EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()) - .WillOnce(Return(std::shared_ptr{})); - ASSERT_THROW(exeNetwork.CreateInferRequest(), InferenceEngine::Exception); + ASSERT_THROW(exeNetwork->CreateInferRequest(), InferenceEngine::Exception); } IE_SUPPRESS_DEPRECATED_START -// CreateInferRequestPtr -TEST_F(ExecutableNetworkWithIInferReqTests, CanCreateInferRequestPtr) { - EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(mockIInferReq_p)); - ASSERT_NO_THROW(exeNetwork.CreateInferRequestPtr()); -} - -TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfReturnNotOK) { - EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Throw(InferenceEngine::GeneralError{""})); - ASSERT_THROW(exeNetwork.CreateInferRequestPtr(), InferenceEngine::Exception); -} - -TEST_F(ExecutableNetworkWithIInferReqTests, CreateInferRequestPtrThrowsIfSetRequestToNullptr) { - EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(std::shared_ptr{})); - ASSERT_THROW(exeNetwork.CreateInferRequestPtr(), InferenceEngine::Exception); -} - class ExecutableNetworkBaseTests : public ::testing::Test { protected: std::shared_ptr mock_impl; @@ -217,5 +191,3 @@ TEST_F(ExecutableNetworkBaseTests, canCatchUnknownErrorInExport) { EXPECT_CALL(*mock_impl.get(), Export(_)).WillOnce(Throw(5)); ASSERT_EQ(UNEXPECTED, exeNetwork->Export({}, nullptr)); } - - From 3bfa602974334920f72ebb40478bffcb7d6ddf61 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 15 May 2021 14:13:00 +0300 Subject: [PATCH 05/20] Added SoPointers for InferRequest, ExecutableNetwork --- inference-engine/include/cpp/ie_executable_network.hpp | 2 ++ inference-engine/src/auto_plugin/auto_exec_network.cpp | 2 +- inference-engine/src/auto_plugin/auto_infer_request.cpp | 6 +++--- inference-engine/src/auto_plugin/auto_infer_request.hpp | 8 ++++---- .../src/hetero_plugin/hetero_async_infer_request.cpp | 8 ++++---- .../src/hetero_plugin/hetero_infer_request.cpp | 4 ++-- .../src/hetero_plugin/hetero_infer_request.hpp | 2 +- .../src/multi_device/multi_device_exec_network.cpp | 4 ++-- .../src/multi_device/multi_device_exec_network.hpp | 6 +++--- .../src/multi_device/multi_device_infer_request.cpp | 4 ++-- .../src/multi_device/multi_device_infer_request.hpp | 4 ++-- .../interface/ie_iexecutable_network_internal.hpp | 8 ++++++++ .../interface/ie_iinfer_request_internal.hpp | 9 ++++++++- .../interface/ie_ivariable_state_internal.hpp | 6 ++++++ inference-engine/src/plugin_api/ie_icore.hpp | 5 +---- 15 files changed, 49 insertions(+), 29 deletions(-) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 15c1ecbedd5e91..a1f5fb44cfaec8 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -35,6 +35,8 @@ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPoint friend class Core; public: + ExecutableNetwork() = default; + /** * @brief Gets the Executable network output Data node information. * diff --git a/inference-engine/src/auto_plugin/auto_exec_network.cpp b/inference-engine/src/auto_plugin/auto_exec_network.cpp index 04b5253d7098d2..d6b42a1a8eca05 100644 --- a/inference-engine/src/auto_plugin/auto_exec_network.cpp +++ b/inference-engine/src/auto_plugin/auto_exec_network.cpp @@ -29,7 +29,7 @@ AutoExecutableNetwork::~AutoExecutableNetwork() = default; IInferRequestInternal::Ptr AutoExecutableNetwork::CreateInferRequestImpl(InputsDataMap networkInputs, OutputsDataMap networkOutputs) { - auto inferRequest = _network->CreateInferRequest(); + SoIInferRequestInternal inferRequest = { _network, _network->CreateInferRequest() }; return std::make_shared(networkInputs, networkOutputs, inferRequest); } diff --git a/inference-engine/src/auto_plugin/auto_infer_request.cpp b/inference-engine/src/auto_plugin/auto_infer_request.cpp index 33deef1892f9f5..bcaf9b2aa5c4c0 100644 --- a/inference-engine/src/auto_plugin/auto_infer_request.cpp +++ b/inference-engine/src/auto_plugin/auto_infer_request.cpp @@ -9,9 +9,9 @@ namespace AutoPlugin { using namespace InferenceEngine; -AutoInferRequest::AutoInferRequest(const InputsDataMap& networkInputs, - const OutputsDataMap& networkOutputs, - const IInferRequestInternal::Ptr& inferRequest) +AutoInferRequest::AutoInferRequest(const InputsDataMap& networkInputs, + const OutputsDataMap& networkOutputs, + const SoIInferRequestInternal& inferRequest) : IInferRequestInternal(networkInputs, networkOutputs) , _inferRequest(inferRequest) { } diff --git a/inference-engine/src/auto_plugin/auto_infer_request.hpp b/inference-engine/src/auto_plugin/auto_infer_request.hpp index 473f93fb45a1c3..c1b2a87b6e0be3 100644 --- a/inference-engine/src/auto_plugin/auto_infer_request.hpp +++ b/inference-engine/src/auto_plugin/auto_infer_request.hpp @@ -24,9 +24,9 @@ namespace AutoPlugin { class AutoInferRequest : public InferenceEngine::IInferRequestInternal { public: using Ptr = std::shared_ptr; - explicit AutoInferRequest(const InferenceEngine::InputsDataMap& networkInputs, - const InferenceEngine::OutputsDataMap& networkOutputs, - const InferenceEngine::IInferRequestInternal::Ptr& inferRequest); + explicit AutoInferRequest(const InferenceEngine::InputsDataMap& networkInputs, + const InferenceEngine::OutputsDataMap& networkOutputs, + const InferenceEngine::SoIInferRequestInternal& inferRequest); std::map GetPerformanceCounts() const override; void InferImpl() override; void SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) override; @@ -34,7 +34,7 @@ class AutoInferRequest : public InferenceEngine::IInferRequestInternal { void Cancel() override; private: - InferenceEngine::IInferRequestInternal::Ptr _inferRequest; + InferenceEngine::SoIInferRequestInternal _inferRequest; }; } // namespace AutoPlugin diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp index 7113e34abe301c..ee770c12ed2292 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp @@ -17,7 +17,7 @@ HeteroAsyncInferRequest::HeteroAsyncInferRequest(const IInferRequestInternal::Pt _pipeline.clear(); for (std::size_t requestId = 0; requestId < _heteroInferRequest->_inferRequests.size(); ++requestId) { struct RequestExecutor : ITaskExecutor { - explicit RequestExecutor(IInferRequestInternal::Ptr & inferRequest) : _inferRequest(inferRequest) { + explicit RequestExecutor(SoIInferRequestInternal & inferRequest) : _inferRequest(inferRequest) { _inferRequest->SetCallback( [this] (std::exception_ptr exceptionPtr) mutable { _exceptionPtr = exceptionPtr; @@ -29,9 +29,9 @@ HeteroAsyncInferRequest::HeteroAsyncInferRequest(const IInferRequestInternal::Pt _task = std::move(task); _inferRequest->StartAsync(); }; - IInferRequestInternal::Ptr & _inferRequest; - std::exception_ptr _exceptionPtr; - Task _task; + SoIInferRequestInternal & _inferRequest; + std::exception_ptr _exceptionPtr; + Task _task; }; auto requestExecutor = std::make_shared(_heteroInferRequest->_inferRequests[requestId]._request); diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp index 1c8a72e0a22ae8..7171363e7830f2 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.cpp @@ -26,7 +26,7 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp IE_THROW() << "Internal error: no information about network's output/input"; } - auto requestBlob([&](const std::string& blobName, InferenceEngine::IInferRequestInternal::Ptr & r) { + auto requestBlob([&](const std::string& blobName, InferenceEngine::SoIInferRequestInternal& r) { std::string intermediateBlobName = blobName; auto itName = subgraphInputToOutputBlobNames.find(blobName); if (itName != subgraphInputToOutputBlobNames.end()) { @@ -49,7 +49,7 @@ HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInp // go over all subnet and create requests for (auto&& desc : _inferRequests) { - desc._request = desc._network->CreateInferRequest(); + desc._request = { desc._network, desc._network->CreateInferRequest() }; // go over all inputs and get blobs from subnet infer requests for (auto&& outputInfo : desc._network->GetOutputsInfo()) { requestBlob(outputInfo.first, desc._request); diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp index b6cb02c6dd04e7..db16c3e2bf5fa5 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp @@ -24,7 +24,7 @@ class HeteroInferRequest : public InferenceEngine::IInferRequestInternal { struct SubRequestDesc { InferenceEngine::SoExecutableNetworkInternal _network; - InferenceEngine::IInferRequestInternal::Ptr _request; + InferenceEngine::SoIInferRequestInternal _request; openvino::itt::handle_t _profilingTask; }; using SubRequestsList = std::vector; diff --git a/inference-engine/src/multi_device/multi_device_exec_network.cpp b/inference-engine/src/multi_device/multi_device_exec_network.cpp index 5265e233cfd0a0..56def8e98fe48e 100644 --- a/inference-engine/src/multi_device/multi_device_exec_network.cpp +++ b/inference-engine/src/multi_device/multi_device_exec_network.cpp @@ -82,7 +82,7 @@ MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMapCreateInferRequest(); + workerRequest._inferRequest = { network, network->CreateInferRequest() }; auto* workerRequestPtr = &workerRequest; IE_ASSERT(idleWorkerRequests.try_push(workerRequestPtr) == true); workerRequest._inferRequest->SetCallback( @@ -177,7 +177,7 @@ InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::Create InferenceEngine::OutputsDataMap networkOutputs) { auto num = _numRequestsCreated++; size_t sum = 0; - InferenceEngine::IInferRequestInternal::Ptr request_to_share_blobs_with; + InferenceEngine::SoIInferRequestInternal request_to_share_blobs_with; // borrowing device-specific blobs from the underlying requests for the device-agnostic, user-facing requests // this allows to potentially save on the data-copy later (if the requests are scheduled in the same order) for (const auto& device : _devicePrioritiesInitial) { diff --git a/inference-engine/src/multi_device/multi_device_exec_network.hpp b/inference-engine/src/multi_device/multi_device_exec_network.hpp index 39dd6e999c1f47..3a9516d6c3b039 100644 --- a/inference-engine/src/multi_device/multi_device_exec_network.hpp +++ b/inference-engine/src/multi_device/multi_device_exec_network.hpp @@ -99,9 +99,9 @@ class MultiDeviceExecutableNetwork : public InferenceEngine::ExecutableNetworkTh public: using Ptr = std::shared_ptr; struct WorkerInferRequest { - InferenceEngine::IInferRequestInternal::Ptr _inferRequest; - InferenceEngine::Task _task; - std::exception_ptr _exceptionPtr = nullptr; + InferenceEngine::SoIInferRequestInternal _inferRequest; + InferenceEngine::Task _task; + std::exception_ptr _exceptionPtr = nullptr; }; using NotBusyWorkerRequests = ThreadSafeBoundedQueue; diff --git a/inference-engine/src/multi_device/multi_device_infer_request.cpp b/inference-engine/src/multi_device/multi_device_infer_request.cpp index 5913a0b39d728f..de6540b88f0fc8 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.cpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.cpp @@ -16,7 +16,7 @@ using namespace InferenceEngine; // ------------------------------MultiDeviceInferRequest---------------------------- MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs, - const IInferRequestInternal::Ptr & request_to_share_blobs_with) + const SoIInferRequestInternal & request_to_share_blobs_with) : IInferRequestInternal(networkInputs, networkOutputs) { if (request_to_share_blobs_with) { // borrow device-friendly blobs from the request @@ -48,7 +48,7 @@ MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkI } } -void MultiDeviceInferRequest::SetBlobsToAnotherRequest(const IInferRequestInternal::Ptr& req) { +void MultiDeviceInferRequest::SetBlobsToAnotherRequest(const SoIInferRequestInternal& req) { for (const auto &it : _networkInputs) { auto &name = it.first; // this request is already in BUSY state, so using the internal functions safely diff --git a/inference-engine/src/multi_device/multi_device_infer_request.hpp b/inference-engine/src/multi_device/multi_device_infer_request.hpp index 80f81c37e9c210..88dc0a07ae188e 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.hpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.hpp @@ -25,11 +25,11 @@ class MultiDeviceInferRequest : public InferenceEngine::IInferRequestInternal { using Ptr = std::shared_ptr; explicit MultiDeviceInferRequest(const InferenceEngine::InputsDataMap& networkInputs, const InferenceEngine::OutputsDataMap& networkOutputs, - const InferenceEngine::IInferRequestInternal::Ptr & request_to_share_blobs_with); + const InferenceEngine::SoIInferRequestInternal & request_to_share_blobs_with); std::map GetPerformanceCounts() const override; void InferImpl() override; // Multi-Device impl specific: sets the data (blobs from the device-less requests to the specific device request) - void SetBlobsToAnotherRequest(const InferenceEngine::IInferRequestInternal::Ptr& req); + void SetBlobsToAnotherRequest(const InferenceEngine::SoIInferRequestInternal& req); }; } // namespace MultiDevicePlugin diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp index fb1b961109d110..da55b2896c24e8 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp @@ -13,9 +13,12 @@ #include #include #include +#include
namespace InferenceEngine { + class IInferRequestInternal; + /** * @interface IExecutableNetworkInternal * @brief An internal API of executable network to be implemented by plugin, @@ -109,4 +112,9 @@ class IExecutableNetworkInternal : public std::enable_shared_from_this; + } // namespace InferenceEngine 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 bd43eab73d0a3f..864cd4dc6936e7 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 @@ -15,8 +15,10 @@ #include namespace InferenceEngine { + class IExecutableNetworkInternal; class IVariableStateInternal; + /** * @interface IInferRequestInternal * @brief An internal API of synchronous inference request to be implemented by plugin, @@ -212,7 +214,7 @@ class INFERENCE_ENGINE_API_CLASS(IInferRequestInternal) : public std::enable_sha int m_curBatch = -1; //!< Current batch value used in dynamic batching /** - * @brief A shared pointer to ExecutableNetworkInternal interface + * @brief A shared pointer to IInferRequestInternal * @note Needed to correctly handle ownership between objects. */ std::shared_ptr _exeNetwork; @@ -224,4 +226,9 @@ class INFERENCE_ENGINE_API_CLASS(IInferRequestInternal) : public std::enable_sha ~IInferRequestInternal(); }; +/** + * @brief SOPointer to IInferRequestInternal. + */ +using SoIInferRequestInternal = details::SOPointer; + } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_ivariable_state_internal.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_ivariable_state_internal.hpp index 4f31b57958275f..279ae854f73828 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_ivariable_state_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_ivariable_state_internal.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include
#include #include @@ -68,4 +69,9 @@ class IVariableStateInternal { */ using IMemoryStateInternal = IVariableStateInternal; +/** + * @brief SOPointer to IVariableStateInternal. + */ +using SoIVariableStateInternal = details::SOPointer; + } // namespace InferenceEngine diff --git a/inference-engine/src/plugin_api/ie_icore.hpp b/inference-engine/src/plugin_api/ie_icore.hpp index 7f3ed86ee384b5..1662b966de86e5 100644 --- a/inference-engine/src/plugin_api/ie_icore.hpp +++ b/inference-engine/src/plugin_api/ie_icore.hpp @@ -15,15 +15,12 @@ #include #include -#include -#include
+#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" #include "threading/ie_itask_executor.hpp" namespace InferenceEngine { -using SoExecutableNetworkInternal = details::SOPointer; - /** * @interface ICore * @brief Minimal ICore interface to allow plugin to get information from Core Inference Engine class. From 9f27ea0a67adf3871fc54aa7339e2706fdc4af7c Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 15 May 2021 14:50:28 +0300 Subject: [PATCH 06/20] Fixed Windows --- inference-engine/include/details/ie_so_pointer.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 4b240f90e19bb2..675e144c2b41ef 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -24,7 +24,13 @@ namespace details { * parameter */ template -class SOCreatorTrait {}; +class SOCreatorTrait { +public: + /** + * @brief A dummy name for fabric + */ + static constexpr auto name = ""; +}; /** * @brief Enables only `char` or `wchar_t` template specializations From a783cf6fbf5b3a52d1e0aac90a5e00dc049defca Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 15 May 2021 17:19:53 +0300 Subject: [PATCH 07/20] Fixed KMB --- .../src/transformations/preprocessing/preprocessing.cpp | 1 + inference-engine/include/details/ie_so_loader.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs/template_plugin/src/transformations/preprocessing/preprocessing.cpp b/docs/template_plugin/src/transformations/preprocessing/preprocessing.cpp index a7e6d8bc718202..4f68deb3f93cd8 100644 --- a/docs/template_plugin/src/transformations/preprocessing/preprocessing.cpp +++ b/docs/template_plugin/src/transformations/preprocessing/preprocessing.cpp @@ -42,6 +42,7 @@ bool ngraph::pass::AddPreprocessing::run_on_function(std::shared_ptrgetTensorDesc().getPrecision() == InferenceEngine::Precision::FP32, "Only InferenceEngine::Precision::FP32 precision is supported for PreProcessChannel::meanData"); } else { + NGRAPH_CHECK(pInfo[c]->meanData != nullptr, "pInfo[c]->meanData is nullptr"); NGRAPH_CHECK(meanImage->getTensorDesc() == pInfo[c]->meanData->getTensorDesc(), "TensorDesc for PreProcessChannel::meanData must be equal"); } diff --git a/inference-engine/include/details/ie_so_loader.h b/inference-engine/include/details/ie_so_loader.h index 0a0762ce241fdd..1b8e3e85fd143f 100644 --- a/inference-engine/include/details/ie_so_loader.h +++ b/inference-engine/include/details/ie_so_loader.h @@ -24,6 +24,11 @@ class INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) { std::shared_ptr _impl; public: + /** + * @brief A shared pointer to SharedObjectLoader + */ + using Ptr = std::shared_ptr; + SharedObjectLoader() = default; #ifdef ENABLE_UNICODE_PATH_SUPPORT From 85c8809d13eb21aa8bb40a84be6440b270cf78d5 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 15 May 2021 17:43:23 +0300 Subject: [PATCH 08/20] Fixes for KMB --- .../include/details/ie_so_loader.h | 4 +--- .../include/details/ie_so_pointer.hpp | 21 +++++++++++++++---- .../os/lin/lin_shared_object_loader.cpp | 3 +++ .../os/win/win_shared_object_loader.cpp | 3 +++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/inference-engine/include/details/ie_so_loader.h b/inference-engine/include/details/ie_so_loader.h index 1b8e3e85fd143f..dc03b31655a866 100644 --- a/inference-engine/include/details/ie_so_loader.h +++ b/inference-engine/include/details/ie_so_loader.h @@ -25,10 +25,8 @@ class INFERENCE_ENGINE_API_CLASS(SharedObjectLoader) { public: /** - * @brief A shared pointer to SharedObjectLoader + * @brief Default constructor */ - using Ptr = std::shared_ptr; - SharedObjectLoader() = default; #ifdef ENABLE_UNICODE_PATH_SUPPORT diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 675e144c2b41ef..15dcb9af9645dc 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -47,13 +47,14 @@ template class SOPointer { template friend class SOPointer; -IE_SUPPRESS_DEPRECATED_START + + IE_SUPPRESS_DEPRECATED_START struct HasRelease { template static char test(decltype(&C::Release)); template static long test(...); constexpr static const bool value = sizeof(test(nullptr)) == sizeof(char); }; -IE_SUPPRESS_DEPRECATED_END + IE_SUPPRESS_DEPRECATED_END public: /** @@ -65,15 +66,27 @@ IE_SUPPRESS_DEPRECATED_END * @brief Constructs an object using name to load library * @param name Existing pointer to a library loader */ - template> + template > SOPointer(const std::basic_string& name) : _so{name.c_str()} { Load(std::integral_constant{}); } + /** + * @deprecated Use SOPointer::SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) + * @brief Constructs an object with existing loader + * @param so_loader Existing pointer to a library loader + */ + INFERENCE_ENGINE_DEPRECATED("SOPointer::SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr)") + explicit SOPointer(const SharedObjectLoader& so_loader) + : _so{so_loader} { + Load(std::integral_constant{}); + } + /** * @brief Constructs an object with existing loader - * @param soLoader Existing pointer to a library loader + * @param so Existing pointer to a library loader + * @param ptr A shared pointer to the object */ SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) : _so{so}, _ptr{ptr} {} diff --git a/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp b/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp index c8674911c499da..be02992304d143 100644 --- a/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp @@ -65,6 +65,9 @@ SharedObjectLoader::SharedObjectLoader(const char * pluginName) { SharedObjectLoader::~SharedObjectLoader() {} void* SharedObjectLoader::get_symbol(const char* symbolName) const { + if (_impl == nullptr) { + IE_THROW() << "SharedObjectLoader is"; + } return _impl->get_symbol(symbolName); } diff --git a/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp b/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp index 43f72b4a6fa0a3..ec0d5c1526a21f 100644 --- a/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp @@ -266,6 +266,9 @@ SharedObjectLoader::SharedObjectLoader(const wchar_t* pluginName) { #endif void* SharedObjectLoader::get_symbol(const char* symbolName) const { + if (_impl == nullptr) { + IE_THROW(NotAllocated) << "SharedObjectLoader is not initialized"; + } return _impl->get_symbol(symbolName); } From 132da7afd4957dd35bc99b25c1980eef45bc7cc0 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 15 May 2021 18:14:26 +0300 Subject: [PATCH 09/20] Removed dereference operator --- inference-engine/include/details/ie_so_pointer.hpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 15dcb9af9645dc..4f21805130fb6f 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -73,12 +73,12 @@ class SOPointer { } /** - * @deprecated Use SOPointer::SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) + * @deprecated Use SOPointer::SOPointer(const std::basic_string& name) * @brief Constructs an object with existing loader * @param so_loader Existing pointer to a library loader */ - INFERENCE_ENGINE_DEPRECATED("SOPointer::SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr)") - explicit SOPointer(const SharedObjectLoader& so_loader) + INFERENCE_ENGINE_DEPRECATED("Use SOPointer(const std::basic_string& name)") + SOPointer(const SharedObjectLoader& so_loader) : _so{so_loader} { Load(std::integral_constant{}); } @@ -106,13 +106,6 @@ class SOPointer { return _ptr.get(); } - /** - * @brief Standard dereference operator - */ - const T* operator*() const noexcept { - return this->operator->(); - } - /** * @return raw pointer */ From da48c9e1ba14a0674d85aaa51153a5e5c18066e3 Mon Sep 17 00:00:00 2001 From: apankratovantonp Date: Mon, 17 May 2021 20:09:42 +0300 Subject: [PATCH 10/20] Fixed win build --- .../include/details/ie_so_pointer.hpp | 229 +++++++++++++----- 1 file changed, 169 insertions(+), 60 deletions(-) diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 4b240f90e19bb2..4af70da06f81c6 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -24,7 +24,13 @@ namespace details { * parameter */ template -class SOCreatorTrait {}; +class SOCreatorTrait { +public: + /** + * @brief A dummy name for fabric + */ + static constexpr auto name = ""; +}; /** * @brief Enables only `char` or `wchar_t` template specializations @@ -33,21 +39,48 @@ class SOCreatorTrait {}; template using enableIfSupportedChar = typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; +/// @cond +IE_SUPPRESS_DEPRECATED_START +template +struct HasRelease { + template static char test(decltype(&C::Release)); + template static long test(...); + constexpr static const bool value = sizeof(test(nullptr)) == sizeof(char); +}; +IE_SUPPRESS_DEPRECATED_END +/// @endcond + /** * @brief This class instantiate object loaded from the shared library * @tparam T An type of object SOPointer can hold */ +template ::value> +class SOPointer; + +#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;} +#define CATCH_IE_EXCEPTIONS \ + CATCH_IE_EXCEPTION(GeneralError) \ + CATCH_IE_EXCEPTION(NotImplemented) \ + CATCH_IE_EXCEPTION(NetworkNotLoaded) \ + CATCH_IE_EXCEPTION(ParameterMismatch) \ + CATCH_IE_EXCEPTION(NotFound) \ + CATCH_IE_EXCEPTION(OutOfBounds) \ + CATCH_IE_EXCEPTION(Unexpected) \ + CATCH_IE_EXCEPTION(RequestBusy) \ + CATCH_IE_EXCEPTION(ResultNotReady) \ + CATCH_IE_EXCEPTION(NotAllocated) \ + CATCH_IE_EXCEPTION(InferNotStarted) \ + CATCH_IE_EXCEPTION(NetworkNotRead) \ + CATCH_IE_EXCEPTION(InferCancelled) + +/** + * @brief This class instantiate object loaded from the shared library and use Release method to destroy the object + * @tparam T An type of object SOPointer can hold + */ template -class SOPointer { - template +class SOPointer { + template friend class SOPointer; -IE_SUPPRESS_DEPRECATED_START - struct HasRelease { - template static char test(decltype(&C::Release)); - template static long test(...); - constexpr static const bool value = sizeof(test(nullptr)) == sizeof(char); - }; -IE_SUPPRESS_DEPRECATED_END public: /** @@ -59,10 +92,36 @@ IE_SUPPRESS_DEPRECATED_END * @brief Constructs an object using name to load library * @param name Existing pointer to a library loader */ - template> + template SOPointer(const std::basic_string& name) : _so{name.c_str()} { - Load(std::integral_constant{}); + try { + void* create = nullptr; + try { + create = _so.get_symbol((SOCreatorTrait::name + std::string("Shared")).c_str()); + } catch (const NotFound&) {} + if (create == nullptr) { + create = _so.get_symbol(SOCreatorTrait::name); + 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, + InferenceEngine::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_IE_EXCEPTIONS catch (const std::exception& ex) { + IE_THROW() << ex.what(); + } catch(...) { + IE_THROW(Unexpected); + } } /** @@ -76,7 +135,7 @@ IE_SUPPRESS_DEPRECATED_END * @param that copied SOPointer object */ template - SOPointer(const SOPointer& that) + SOPointer(const SOPointer& that) : _so(that._so), _ptr(std::dynamic_pointer_cast(that._ptr)) {} @@ -134,53 +193,32 @@ IE_SUPPRESS_DEPRECATED_END } protected: -#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;} -#define CATCH_IE_EXCEPTIONS \ - CATCH_IE_EXCEPTION(GeneralError) \ - CATCH_IE_EXCEPTION(NotImplemented) \ - CATCH_IE_EXCEPTION(NetworkNotLoaded) \ - CATCH_IE_EXCEPTION(ParameterMismatch) \ - CATCH_IE_EXCEPTION(NotFound) \ - CATCH_IE_EXCEPTION(OutOfBounds) \ - CATCH_IE_EXCEPTION(Unexpected) \ - CATCH_IE_EXCEPTION(RequestBusy) \ - CATCH_IE_EXCEPTION(ResultNotReady) \ - CATCH_IE_EXCEPTION(NotAllocated) \ - CATCH_IE_EXCEPTION(InferNotStarted) \ - CATCH_IE_EXCEPTION(NetworkNotRead) \ - CATCH_IE_EXCEPTION(InferCancelled) + SharedObjectLoader _so; + std::shared_ptr _ptr; +}; - void Load(std::true_type) { - try { - void* create = nullptr; - try { - create = _so.get_symbol((SOCreatorTrait::name + std::string("Shared")).c_str()); - } catch (const NotFound&) {} - if (create == nullptr) { - create = _so.get_symbol(SOCreatorTrait::name); - 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, - InferenceEngine::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_IE_EXCEPTIONS catch (const std::exception& ex) { - IE_THROW() << ex.what(); - } catch(...) { - IE_THROW(Unexpected); - } - } +/** + * @brief This class instantiate object loaded from the shared library + * @tparam T An type of object SOPointer can hold + */ +template +class SOPointer { + template + friend class SOPointer; - void Load(std::false_type) { +public: + /** + * @brief Default constructor + */ + SOPointer() = default; + + /** + * @brief Constructs an object using name to load library + * @param name Existing pointer to a library loader + */ + template> + SOPointer(const std::basic_string& name) : + _so{name.c_str()} { try { using CreateF = void(std::shared_ptr&); reinterpret_cast(_so.get_symbol(SOCreatorTrait::name))(_ptr); @@ -190,11 +228,82 @@ IE_SUPPRESS_DEPRECATED_END IE_THROW(Unexpected); } } -#undef CATCH_IE_EXCEPTION -#undef CATCH_IE_EXCEPTIONS + /** + * @brief Constructs an object with existing loader + * @param soLoader Existing pointer to a library loader + */ + SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) : _so{so}, _ptr{ptr} {} + + /** + * @brief The copy-like constructor, can create So Pointer that dereferenced into child type if T is derived of U + * @param that copied SOPointer object + */ + template + SOPointer(const SOPointer& that) + : _so(that._so), + _ptr(std::dynamic_pointer_cast(that._ptr)) {} + + /** + * @brief Standard pointer operator + */ + T* operator->() const noexcept { + return _ptr.get(); + } + + /** + * @brief Standard dereference operator + */ + const T* operator*() const noexcept { + return this->operator->(); + } + + /** + * @return raw pointer + */ + T* get() noexcept { + return _ptr.get(); + } + + /** + * @return raw pointer + */ + const T* get() const noexcept { + return this->get(); + } + + explicit operator bool() const noexcept { + return _ptr != nullptr; + } + + friend bool operator==(std::nullptr_t, const SOPointer& ptr) noexcept { + return !ptr; + } + friend bool operator==(const SOPointer& ptr, std::nullptr_t) noexcept { + return !ptr; + } + friend bool operator!=(std::nullptr_t, const SOPointer& ptr) noexcept { + return static_cast(ptr); + } + friend bool operator!=(const SOPointer& ptr, std::nullptr_t) noexcept { + return static_cast(ptr); + } + + operator const SharedObjectLoader&() const noexcept { + return _so; + } + + operator std::shared_ptr& () noexcept { + return _ptr; + } + +protected: SharedObjectLoader _so; std::shared_ptr _ptr; }; + +#undef CATCH_IE_EXCEPTION +#undef CATCH_IE_EXCEPTIONS + } // namespace details } // namespace InferenceEngine From 83f8c580172608444c094b24769ed48b933ded89 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 17 May 2021 17:39:14 +0300 Subject: [PATCH 11/20] Play with include files --- inference-engine/include/cpp/ie_executable_network.hpp | 3 --- inference-engine/include/details/ie_so_pointer.hpp | 4 ++-- inference-engine/src/auto_plugin/auto_infer_request.hpp | 2 -- inference-engine/src/gna_plugin/gna_infer_request.hpp | 1 + inference-engine/src/hetero_plugin/hetero_infer_request.hpp | 4 +--- .../src/inference_engine/cpp/ie_executable_network_base.hpp | 1 - inference-engine/src/inference_engine/cpp/ie_plugin.hpp | 1 - .../src/multi_device/multi_device_infer_request.hpp | 2 -- .../impl/ie_infer_async_request_thread_safe_default.hpp | 1 + .../cpp_interfaces/interface/ie_iinfer_request_internal.hpp | 1 - 10 files changed, 5 insertions(+), 15 deletions(-) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index a1f5fb44cfaec8..0567715e125884 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -29,14 +29,11 @@ class IExecutableNetwork; */ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPointer { using details::SOPointer::SOPointer; - // TODO: remove? ExecutableNetwork(const details::SOPointer & obj) : details::SOPointer::SOPointer(obj) { } friend class Core; public: - ExecutableNetwork() = default; - /** * @brief Gets the Executable network output Data node information. * diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 8303eb1b59df52..13f31344b98f78 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -166,7 +166,7 @@ class SOPointer { * @return raw pointer */ const T* get() const noexcept { - return this->get(); + return _ptr.get(); } explicit operator bool() const noexcept { @@ -275,7 +275,7 @@ class SOPointer { * @return raw pointer */ const T* get() const noexcept { - return this->get(); + return _ptr.get(); } explicit operator bool() const noexcept { diff --git a/inference-engine/src/auto_plugin/auto_infer_request.hpp b/inference-engine/src/auto_plugin/auto_infer_request.hpp index c1b2a87b6e0be3..400a18bf7c6167 100644 --- a/inference-engine/src/auto_plugin/auto_infer_request.hpp +++ b/inference-engine/src/auto_plugin/auto_infer_request.hpp @@ -5,8 +5,6 @@ #pragma once #include -#include -#include #include #include #include diff --git a/inference-engine/src/gna_plugin/gna_infer_request.hpp b/inference-engine/src/gna_plugin/gna_infer_request.hpp index e0256b32f2b641..2aaf21341c398e 100644 --- a/inference-engine/src/gna_plugin/gna_infer_request.hpp +++ b/inference-engine/src/gna_plugin/gna_infer_request.hpp @@ -9,6 +9,7 @@ #include #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" +#include "cpp/ie_infer_request.hpp" #include "gna_plugin.hpp" namespace GNAPluginNS { diff --git a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp index db16c3e2bf5fa5..9327d2c410d908 100644 --- a/inference-engine/src/hetero_plugin/hetero_infer_request.hpp +++ b/inference-engine/src/hetero_plugin/hetero_infer_request.hpp @@ -11,9 +11,7 @@ #include #include #include -#include -#include -#include +#include #include namespace HeteroPlugin { diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network_base.hpp b/inference-engine/src/inference_engine/cpp/ie_executable_network_base.hpp index cb3edc1e23eeac..ffb3a3df69e3ea 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network_base.hpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network_base.hpp @@ -15,7 +15,6 @@ #include #include -#include #include #include #include "cpp/exception2status.hpp" diff --git a/inference-engine/src/inference_engine/cpp/ie_plugin.hpp b/inference-engine/src/inference_engine/cpp/ie_plugin.hpp index d9802e6c59f5aa..3c7d4afc000ef5 100644 --- a/inference-engine/src/inference_engine/cpp/ie_plugin.hpp +++ b/inference-engine/src/inference_engine/cpp/ie_plugin.hpp @@ -14,7 +14,6 @@ #include #include "file_utils.h" -#include "cpp/ie_executable_network.hpp" #include "cpp/ie_cnn_network.h" #include "cpp/exception2status.hpp" #include "cpp_interfaces/interface/ie_iplugin_internal.hpp" diff --git a/inference-engine/src/multi_device/multi_device_infer_request.hpp b/inference-engine/src/multi_device/multi_device_infer_request.hpp index 88dc0a07ae188e..9ec23eda91833e 100644 --- a/inference-engine/src/multi_device/multi_device_infer_request.hpp +++ b/inference-engine/src/multi_device/multi_device_infer_request.hpp @@ -15,8 +15,6 @@ #include #include #include -#include -#include namespace MultiDevicePlugin { diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp index 5d98772a65a504..470dc646b8f3f0 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include 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 864cd4dc6936e7..12addfe14aa980 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 @@ -8,7 +8,6 @@ #include #include #include -#include #include #include From 8ea736196ad485384a0fdf1fc3a856b6ba98e1df Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 17 May 2021 19:29:01 +0300 Subject: [PATCH 12/20] Fixed compilation with older compilers --- inference-engine/include/cpp/ie_executable_network.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 0567715e125884..8131531893434c 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -34,6 +34,11 @@ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPoint friend class Core; public: + /** + * @brief A default constructor. + */ + ExecutableNetwork() = default; + /** * @brief Gets the Executable network output Data node information. * From e94f0e93f4bdb7d1f602f47deec93c91f9bd8a9e Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 17 May 2021 19:52:48 +0300 Subject: [PATCH 13/20] Fixed comments --- .../src/inference_engine/os/lin/lin_shared_object_loader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp b/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp index be02992304d143..7ce910b158cc0c 100644 --- a/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/os/lin/lin_shared_object_loader.cpp @@ -66,7 +66,7 @@ SharedObjectLoader::~SharedObjectLoader() {} void* SharedObjectLoader::get_symbol(const char* symbolName) const { if (_impl == nullptr) { - IE_THROW() << "SharedObjectLoader is"; + IE_THROW(NotAllocated) << "SharedObjectLoader is not initialized"; } return _impl->get_symbol(symbolName); } From d11311c6469d763ce6d3441137f152de0013d455 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 17 May 2021 20:30:58 +0300 Subject: [PATCH 14/20] Try to fix Windows --- inference-engine/include/details/ie_so_pointer.hpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 13f31344b98f78..75fca43c21d0a3 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -151,7 +151,7 @@ class SOPointer { /** * @brief Standard pointer operator */ - T* operator->() const noexcept { + T* operator->() noexcept { return _ptr.get(); } @@ -253,17 +253,10 @@ class SOPointer { /** * @brief Standard pointer operator */ - T* operator->() const noexcept { + T* operator->() noexcept { return _ptr.get(); } - /** - * @brief Standard dereference operator - */ - const T* operator*() const noexcept { - return this->operator->(); - } - /** * @return raw pointer */ From 1310d1a65f115a081f907157c751d49f1fea43e9 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 17 May 2021 20:31:24 +0300 Subject: [PATCH 15/20] Try to fix Windows 2 --- inference-engine/include/details/ie_so_pointer.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index 75fca43c21d0a3..f95710822df036 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -151,7 +151,7 @@ class SOPointer { /** * @brief Standard pointer operator */ - T* operator->() noexcept { + T* operator->() const noexcept { return _ptr.get(); } @@ -253,7 +253,7 @@ class SOPointer { /** * @brief Standard pointer operator */ - T* operator->() noexcept { + T* operator->() const noexcept { return _ptr.get(); } From 79d452eaf172a28d0e11419e2508bfbda23395b8 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 18 May 2021 01:04:03 +0300 Subject: [PATCH 16/20] Fixed windows --- .../include/cpp/ie_executable_network.hpp | 7 ++++--- inference-engine/src/auto_plugin/auto_plugin.cpp | 1 - .../src/hetero_plugin/hetero_async_infer_request.cpp | 2 +- .../inference_engine/cpp/ie_executable_network.cpp | 6 ++++++ .../ie_infer_async_request_thread_safe_default.hpp | 12 +++++------- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 8131531893434c..c18d57abae996b 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -29,15 +29,14 @@ class IExecutableNetwork; */ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPointer { using details::SOPointer::SOPointer; - ExecutableNetwork(const details::SOPointer & obj) : - details::SOPointer::SOPointer(obj) { } + ExecutableNetwork(const details::SOPointer & obj); friend class Core; public: /** * @brief A default constructor. */ - ExecutableNetwork() = default; + ExecutableNetwork(); /** * @brief Gets the Executable network output Data node information. @@ -187,6 +186,8 @@ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPoint INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead") std::vector QueryState(); IE_SUPPRESS_DEPRECATED_END + + ~ExecutableNetwork(); }; } // namespace InferenceEngine diff --git a/inference-engine/src/auto_plugin/auto_plugin.cpp b/inference-engine/src/auto_plugin/auto_plugin.cpp index 79f89ecdf4b76c..8035cc74ccfc0a 100644 --- a/inference-engine/src/auto_plugin/auto_plugin.cpp +++ b/inference-engine/src/auto_plugin/auto_plugin.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp index ee770c12ed2292..ce99b0958c9cfc 100644 --- a/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp +++ b/inference-engine/src/hetero_plugin/hetero_async_infer_request.cpp @@ -54,7 +54,7 @@ StatusCode HeteroAsyncInferRequest::Wait(int64_t millis_timeout) { waitStatus = AsyncInferRequestThreadSafeDefault::Wait(millis_timeout); } catch(...) { for (auto&& requestDesc : _heteroInferRequest->_inferRequests) { - requestDesc._request->Wait(InferRequest::RESULT_READY); + requestDesc._request->Wait(-1); } throw; } diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index b1641c4531a5a1..5f57fc6f7b78fc 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -20,6 +20,12 @@ namespace InferenceEngine { IE_THROW(Unexpected); \ } +ExecutableNetwork::ExecutableNetwork() : + details::SOPointer() { } + +ExecutableNetwork::ExecutableNetwork(const details::SOPointer & obj) : + details::SOPointer::SOPointer(obj) { } + ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const { EXEC_NET_CALL_STATEMENT(return _ptr->GetOutputsInfo()); } diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp index 470dc646b8f3f0..90a9575ecbbea0 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp @@ -8,9 +8,7 @@ #include #include -#include #include -#include #include #include @@ -167,10 +165,10 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { * @return A status code */ StatusCode Wait(int64_t millis_timeout) override { - if (millis_timeout < InferRequest::WaitMode::RESULT_READY) { + if (millis_timeout < -1) { IE_THROW(ParameterMismatch) << " Timeout can't be less " - << InferRequest::WaitMode::RESULT_READY << " for InferRequest::Wait\n"; + << -1 << " for InferRequest::Wait\n"; } auto status = std::future_status::deferred; @@ -185,11 +183,11 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { } switch (millis_timeout) { - case InferRequest::WaitMode::RESULT_READY: { + case -1: { future.wait(); status = std::future_status::ready; } break; - case InferRequest::WaitMode::STATUS_ONLY: { + case 0: { status = future.wait_for(std::chrono::milliseconds {0}); } break; default: { @@ -212,7 +210,7 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { void Infer() override { DisableCallbackGuard disableCallbackGuard{this}; InferImpl([&] {Infer_ThreadUnsafe();}); - Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY); + Wait(-1); } std::map GetPerformanceCounts() const override { From 5e9a93039fab2b734469faf8c7bc172126105050 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 18 May 2021 01:21:49 +0300 Subject: [PATCH 17/20] Fixed windows --- .../src/inference_engine/cpp/ie_executable_network.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index 5f57fc6f7b78fc..f366c52bb5e0da 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -26,6 +26,8 @@ ExecutableNetwork::ExecutableNetwork() : ExecutableNetwork::ExecutableNetwork(const details::SOPointer & obj) : details::SOPointer::SOPointer(obj) { } +ExecutableNetwork::~ExecutableNetwork() { } + ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const { EXEC_NET_CALL_STATEMENT(return _ptr->GetOutputsInfo()); } From 13fbf85bd069fabf45b07d05908876824061921d Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 18 May 2021 14:46:06 +0300 Subject: [PATCH 18/20] Removed SOPointer as a base class --- .../include/cpp/ie_executable_network.hpp | 22 +++++--- .../include/cpp/ie_infer_request.hpp | 24 ++++++--- .../include/cpp/ie_memory_state.hpp | 24 ++++++--- .../cpp/ie_executable_network.cpp | 50 +++++++++-------- .../inference_engine/cpp/ie_infer_request.cpp | 53 +++++++++++-------- .../cpp/ie_variable_state.cpp | 16 ++++-- .../src/inference_engine/ie_core.cpp | 24 ++++++--- ...nfer_async_request_thread_safe_default.hpp | 10 ++-- .../interface/ie_iinfer_request_internal.hpp | 1 + 9 files changed, 138 insertions(+), 86 deletions(-) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index c18d57abae996b..9e5e7158e6736a 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -16,27 +16,37 @@ #include #include +#include "ie_parameter.hpp" +#include "ie_remote_context.hpp" #include "cpp/ie_cnn_network.h" #include "cpp/ie_infer_request.hpp" +#include "details/ie_so_loader.h" namespace InferenceEngine { - class IExecutableNetworkInternal; class IExecutableNetwork; /** * @brief This is an interface of an executable network */ -class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPointer { - using details::SOPointer::SOPointer; - ExecutableNetwork(const details::SOPointer & obj); +class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) { + std::shared_ptr _impl; + details::SharedObjectLoader _so; + + /** + * @brief Constructs ExecutableNetwork from the initialized std::shared_ptr + * @param so Plugin to use. This is required to ensure that ExecutableNetwork can work properly even if plugin object is destroyed. + * @param impl Initialized shared pointer + */ + ExecutableNetwork(const details::SharedObjectLoader& so, + const std::shared_ptr& impl); friend class Core; public: /** * @brief A default constructor. */ - ExecutableNetwork(); + ExecutableNetwork() = default; /** * @brief Gets the Executable network output Data node information. @@ -186,8 +196,6 @@ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) : protected details::SOPoint INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead") std::vector QueryState(); IE_SUPPRESS_DEPRECATED_END - - ~ExecutableNetwork(); }; } // namespace InferenceEngine diff --git a/inference-engine/include/cpp/ie_infer_request.hpp b/inference-engine/include/cpp/ie_infer_request.hpp index 47dba4e9c5234a..392c0abaa0568e 100644 --- a/inference-engine/include/cpp/ie_infer_request.hpp +++ b/inference-engine/include/cpp/ie_infer_request.hpp @@ -13,17 +13,13 @@ #include #include +#include "ie_blob.h" #include "cpp/ie_memory_state.hpp" -#include "ie_remote_context.hpp" #include "ie_iinfer_request.hpp" #include "details/ie_so_loader.h" -#include "ie_blob.h" namespace InferenceEngine { -namespace details { -class SharedObjectLoader; -} class IInferRequestInternal; /** @@ -32,8 +28,17 @@ class IInferRequestInternal; * Wraps IInferRequest * It can throw exceptions safely for the application, where it is properly handled. */ -class INFERENCE_ENGINE_API_CLASS(InferRequest) : protected details::SOPointer { - using details::SOPointer::SOPointer; +class INFERENCE_ENGINE_API_CLASS(InferRequest) { + std::shared_ptr _impl; + details::SharedObjectLoader _so; + + /** + * @brief Constructs InferRequest from the initialized std::shared_ptr + * @param so Plugin to use. This is required to ensure that InferRequest can work properly even if plugin object is destroyed. + * @param impl Initialized shared pointer + */ + InferRequest(const details::SharedObjectLoader& so, + const std::shared_ptr& impl); friend class ExecutableNetwork; public: @@ -53,6 +58,11 @@ class INFERENCE_ENGINE_API_CLASS(InferRequest) : protected details::SOPointer; + /** + * @brief Default constructor + */ + InferRequest() = default; + /** * @brief Sets input/output data to infer * diff --git a/inference-engine/include/cpp/ie_memory_state.hpp b/inference-engine/include/cpp/ie_memory_state.hpp index 3ca2c910b268af..8014c8fa3a34a3 100644 --- a/inference-engine/include/cpp/ie_memory_state.hpp +++ b/inference-engine/include/cpp/ie_memory_state.hpp @@ -15,25 +15,35 @@ #include "ie_api.h" #include "ie_blob.h" -#include "details/ie_so_pointer.hpp" +#include "details/ie_so_loader.h" namespace InferenceEngine { -namespace details { -class SharedObjectLoader; -} - class IVariableStateInternal; /** * @brief C++ exception based error reporting wrapper of API class IVariableState */ -class INFERENCE_ENGINE_API_CLASS(VariableState) : protected details::SOPointer { - using details::SOPointer::SOPointer; +class INFERENCE_ENGINE_API_CLASS(VariableState) { + std::shared_ptr _impl; + details::SharedObjectLoader _so; + + /** + * @brief Constructs VariableState from the initialized std::shared_ptr + * @param impl Initialized shared pointer + * @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); friend class InferRequest; friend class ExecutableNetwork; public: + /** + * @brief Default constructor + */ + VariableState() = default; + /** * @copybrief IVariableState::Reset * diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index f366c52bb5e0da..f096c56fb0bad9 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -11,7 +11,7 @@ namespace InferenceEngine { #define EXEC_NET_CALL_STATEMENT(...) \ - if (_ptr == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \ + if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \ try { \ __VA_ARGS__; \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -20,43 +20,41 @@ namespace InferenceEngine { IE_THROW(Unexpected); \ } -ExecutableNetwork::ExecutableNetwork() : - details::SOPointer() { } - -ExecutableNetwork::ExecutableNetwork(const details::SOPointer & obj) : - details::SOPointer::SOPointer(obj) { } - -ExecutableNetwork::~ExecutableNetwork() { } +ExecutableNetwork::ExecutableNetwork(const details::SharedObjectLoader& so, + const IExecutableNetworkInternal::Ptr& impl) + : _impl(impl), _so(so) { + IE_ASSERT(_impl != nullptr); +} ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const { - EXEC_NET_CALL_STATEMENT(return _ptr->GetOutputsInfo()); + EXEC_NET_CALL_STATEMENT(return _impl->GetOutputsInfo()); } ConstInputsDataMap ExecutableNetwork::GetInputsInfo() const { - EXEC_NET_CALL_STATEMENT(return _ptr->GetInputsInfo()); + EXEC_NET_CALL_STATEMENT(return _impl->GetInputsInfo()); } IE_SUPPRESS_DEPRECATED_START void ExecutableNetwork::reset(IExecutableNetwork::Ptr newActual) { - if (_ptr == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; + if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; if (newActual == nullptr) IE_THROW() << "ExecutableNetwork wrapper used for reset was not initialized."; auto newBase = std::dynamic_pointer_cast(newActual); IE_ASSERT(newBase != nullptr); auto newImpl = newBase->GetImpl(); IE_ASSERT(newImpl != nullptr); - _ptr = details::SOPointer{_so, newImpl}; + _impl = newImpl; } ExecutableNetwork::operator IExecutableNetwork::Ptr() { - return std::make_shared(_ptr); + return std::make_shared(_impl); } std::vector ExecutableNetwork::QueryState() { std::vector controller; EXEC_NET_CALL_STATEMENT( - for (auto&& state : _ptr->QueryState()) { - controller.emplace_back(_so, state); + for (auto&& state : _impl->QueryState()) { + controller.emplace_back(VariableState { _so, static_cast>(state) }); }); return controller; } @@ -64,46 +62,46 @@ std::vector ExecutableNetwork::QueryState() { IE_SUPPRESS_DEPRECATED_END InferRequest ExecutableNetwork::CreateInferRequest() { - EXEC_NET_CALL_STATEMENT(return InferRequest{_so, _ptr->CreateInferRequest()}); + EXEC_NET_CALL_STATEMENT(return {_so, _impl->CreateInferRequest()}); } InferRequest::Ptr ExecutableNetwork::CreateInferRequestPtr() { - EXEC_NET_CALL_STATEMENT(return std::make_shared(_so, _ptr->CreateInferRequest())); + EXEC_NET_CALL_STATEMENT(return std::make_shared(CreateInferRequest())); } void ExecutableNetwork::Export(const std::string& modelFileName) { - EXEC_NET_CALL_STATEMENT(_ptr->Export(modelFileName)); + EXEC_NET_CALL_STATEMENT(_impl->Export(modelFileName)); } void ExecutableNetwork::Export(std::ostream& networkModel) { - EXEC_NET_CALL_STATEMENT(_ptr->Export(networkModel)); + EXEC_NET_CALL_STATEMENT(_impl->Export(networkModel)); } CNNNetwork ExecutableNetwork::GetExecGraphInfo() { - EXEC_NET_CALL_STATEMENT(return _ptr->GetExecGraphInfo()); + EXEC_NET_CALL_STATEMENT(return _impl->GetExecGraphInfo()); } void ExecutableNetwork::SetConfig(const std::map& config) { - EXEC_NET_CALL_STATEMENT(_ptr->SetConfig(config)); + EXEC_NET_CALL_STATEMENT(_impl->SetConfig(config)); } Parameter ExecutableNetwork::GetConfig(const std::string& name) const { - EXEC_NET_CALL_STATEMENT(return _ptr->GetConfig(name)); + EXEC_NET_CALL_STATEMENT(return _impl->GetConfig(name)); } Parameter ExecutableNetwork::GetMetric(const std::string& name) const { - EXEC_NET_CALL_STATEMENT(return _ptr->GetMetric(name)); + EXEC_NET_CALL_STATEMENT(return _impl->GetMetric(name)); } RemoteContext::Ptr ExecutableNetwork::GetContext() const { - EXEC_NET_CALL_STATEMENT(return _ptr->GetContext()); + EXEC_NET_CALL_STATEMENT(return _impl->GetContext()); } bool ExecutableNetwork::operator!() const noexcept { - return !_ptr; + return !_impl; } ExecutableNetwork::operator bool() const noexcept { - return !!_ptr; + return !!_impl; } } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index 21e7e39e712439..af2cad1c816abe 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -32,7 +32,7 @@ namespace InferenceEngine { CATCH_IE_EXCEPTION(InferCancelled) #define INFER_REQ_CALL_STATEMENT(...) \ - if (_ptr == nullptr) IE_THROW() << "Inference Request is not initialized"; \ + if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \ try { \ __VA_ARGS__ \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -41,13 +41,19 @@ namespace InferenceEngine { IE_THROW(Unexpected); \ } +InferRequest::InferRequest(const details::SharedObjectLoader& so, + const IInferRequestInternal::Ptr& impl) + : _impl(impl), _so(so) { + IE_ASSERT(_impl != nullptr); +} + void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) { - INFER_REQ_CALL_STATEMENT(_ptr->SetBlob(name, data);) + INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data);) } Blob::Ptr InferRequest::GetBlob(const std::string& name) { Blob::Ptr blobPtr; - INFER_REQ_CALL_STATEMENT(blobPtr = _ptr->GetBlob(name);) + INFER_REQ_CALL_STATEMENT(blobPtr = _impl->GetBlob(name);) std::string error = "Internal error: blob with name `" + name + "` is not allocated!"; const bool remoteBlobPassed = blobPtr->is(); if (blobPtr == nullptr) IE_THROW() << error; @@ -56,29 +62,29 @@ Blob::Ptr InferRequest::GetBlob(const std::string& name) { } void InferRequest::SetBlob(const std::string &name, const Blob::Ptr &data, const PreProcessInfo& info) { - INFER_REQ_CALL_STATEMENT(_ptr->SetBlob(name, data, info);) + INFER_REQ_CALL_STATEMENT(_impl->SetBlob(name, data, info);) } const PreProcessInfo& InferRequest::GetPreProcess(const std::string& name) const { - INFER_REQ_CALL_STATEMENT(return _ptr->GetPreProcess(name);) + INFER_REQ_CALL_STATEMENT(return _impl->GetPreProcess(name);) } void InferRequest::Infer() { - INFER_REQ_CALL_STATEMENT(_ptr->Infer();) + INFER_REQ_CALL_STATEMENT(_impl->Infer();) } void InferRequest::Cancel() { - INFER_REQ_CALL_STATEMENT(_ptr->Cancel();) + INFER_REQ_CALL_STATEMENT(_impl->Cancel();) } std::map InferRequest::GetPerformanceCounts() const { - INFER_REQ_CALL_STATEMENT(return _ptr->GetPerformanceCounts();) + INFER_REQ_CALL_STATEMENT(return _impl->GetPerformanceCounts();) } void InferRequest::SetInput(const BlobMap& inputs) { INFER_REQ_CALL_STATEMENT( for (auto&& input : inputs) { - _ptr->SetBlob(input.first, input.second); + _impl->SetBlob(input.first, input.second); } ) } @@ -86,27 +92,27 @@ void InferRequest::SetInput(const BlobMap& inputs) { void InferRequest::SetOutput(const BlobMap& results) { INFER_REQ_CALL_STATEMENT( for (auto&& result : results) { - _ptr->SetBlob(result.first, result.second); + _impl->SetBlob(result.first, result.second); } ) } void InferRequest::SetBatch(const int batch) { - INFER_REQ_CALL_STATEMENT(_ptr->SetBatch(batch);) + INFER_REQ_CALL_STATEMENT(_impl->SetBatch(batch);) } void InferRequest::StartAsync() { - INFER_REQ_CALL_STATEMENT(_ptr->StartAsync();) + INFER_REQ_CALL_STATEMENT(_impl->StartAsync();) } StatusCode InferRequest::Wait(int64_t millis_timeout) { - INFER_REQ_CALL_STATEMENT(return _ptr->Wait(millis_timeout);) + INFER_REQ_CALL_STATEMENT(return _impl->Wait(millis_timeout);) } void InferRequest::SetCompletionCallbackImpl(std::function callback) { INFER_REQ_CALL_STATEMENT( - _ptr->SetCallback([callback] (std::exception_ptr) { + _impl->SetCallback([callback] (std::exception_ptr) { callback(); }); ) @@ -133,8 +139,8 @@ void InferRequest::SetCompletionCallbackImpl(std::function callback) { void InferRequest::SetCompletionCallbackImpl(std::function callback) { INFER_REQ_CALL_STATEMENT( - auto weakThis = InferRequest{_so, std::shared_ptr{_ptr.get(), [](IInferRequestInternal*){}}}; - _ptr->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { + auto weakThis = InferRequest{_so, std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}}; + _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { StatusCode statusCode = StatusCode::OK; if (exceptionPtr != nullptr) { statusCode = [&] { @@ -156,8 +162,8 @@ IE_SUPPRESS_DEPRECATED_START void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback callback) { INFER_REQ_CALL_STATEMENT( - IInferRequest::Ptr weakThis = InferRequest{_so, std::shared_ptr{_ptr.get(), [](IInferRequestInternal*){}}}; - _ptr->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { + IInferRequest::Ptr weakThis = InferRequest{_so, std::shared_ptr{_impl.get(), [](IInferRequestInternal*){}}}; + _impl->SetCallback([callback, weakThis] (std::exception_ptr exceptionPtr) { StatusCode statusCode = StatusCode::OK; if (exceptionPtr != nullptr) { statusCode = [&] { @@ -177,7 +183,7 @@ void InferRequest::SetCompletionCallbackImpl(IInferRequest::CompletionCallback c InferRequest::operator IInferRequest::Ptr () { INFER_REQ_CALL_STATEMENT( - return std::make_shared(_ptr); + return std::make_shared(_impl); ) } @@ -186,18 +192,19 @@ IE_SUPPRESS_DEPRECATED_END std::vector InferRequest::QueryState() { std::vector controller; INFER_REQ_CALL_STATEMENT( - for (auto&& state : _ptr->QueryState()) { - controller.emplace_back(_so, state); + for (auto&& _state : _impl->QueryState()) { + VariableState state{_so, static_cast>(_state)}; + controller.emplace_back(state); } ) return controller; } bool InferRequest::operator!() const noexcept { - return !_ptr; + return !_impl; } InferRequest::operator bool() const noexcept { - return !!_ptr; + return !!_impl; } } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp index cc2dbd5deec4ff..d74ccaace6d094 100644 --- a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp @@ -8,7 +8,7 @@ #include "exception2status.hpp" #define VARIABLE_CALL_STATEMENT(...) \ - if (_ptr == nullptr) IE_THROW() << "VariableState was not initialized."; \ + if (_impl == nullptr) IE_THROW() << "VariableState was not initialized."; \ try { \ __VA_ARGS__; \ } CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \ @@ -19,6 +19,12 @@ namespace InferenceEngine { +VariableState::VariableState(const details::SharedObjectLoader& so, + const IVariableStateInternal::Ptr& impl) + : _impl(impl), _so(so) { + IE_ASSERT(_impl != nullptr); +} + IE_SUPPRESS_DEPRECATED_START Blob::CPtr VariableState::GetLastState() const { @@ -28,19 +34,19 @@ Blob::CPtr VariableState::GetLastState() const { IE_SUPPRESS_DEPRECATED_END void VariableState::Reset() { - VARIABLE_CALL_STATEMENT(_ptr->Reset()); + VARIABLE_CALL_STATEMENT(_impl->Reset()); } std::string VariableState::GetName() const { - VARIABLE_CALL_STATEMENT(return _ptr->GetName()); + VARIABLE_CALL_STATEMENT(return _impl->GetName()); } Blob::CPtr VariableState::GetState() const { - VARIABLE_CALL_STATEMENT(return _ptr->GetState()); + VARIABLE_CALL_STATEMENT(return _impl->GetState()); } void VariableState::SetState(Blob::Ptr state) { - VARIABLE_CALL_STATEMENT(_ptr->SetState(state)); + VARIABLE_CALL_STATEMENT(_impl->SetState(state)); } } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/ie_core.cpp b/inference-engine/src/inference_engine/ie_core.cpp index fa2fa8a6422dfd..6273bf3f30380f 100644 --- a/inference-engine/src/inference_engine/ie_core.cpp +++ b/inference-engine/src/inference_engine/ie_core.cpp @@ -902,17 +902,23 @@ CNNNetwork Core::ReadNetwork(const std::string& model, const Blob::CPtr& weights ExecutableNetwork Core::LoadNetwork(const CNNNetwork& network, const std::string& deviceName, const std::map& config) { - return _impl->LoadNetwork(network, deviceName, config); + auto exec = _impl->LoadNetwork(network, deviceName, config); + return { static_cast(exec), + static_cast>(exec) }; } ExecutableNetwork Core::LoadNetwork(const CNNNetwork& network, RemoteContext::Ptr context, const std::map& config) { - return _impl->LoadNetwork(network, context, config); + auto exec = _impl->LoadNetwork(network, context, config); + return { static_cast(exec), + static_cast>(exec) }; } ExecutableNetwork Core::LoadNetwork(const std::string& modelPath, const std::string& deviceName, const std::map& config) { - return _impl->LoadNetwork(modelPath, deviceName, config); + auto exec = _impl->LoadNetwork(modelPath, deviceName, config); + return { static_cast(exec), + static_cast>(exec) }; } RemoteContext::Ptr Core::CreateContext(const std::string& deviceName, const ParamMap& params) { @@ -982,12 +988,16 @@ ExecutableNetwork Core::ImportNetwork(const std::string& modelFileName, const st } auto parsed = parseDeviceNameIntoConfig(deviceName, config); - return _impl->GetCPPPluginByName(parsed._deviceName).ImportNetwork(modelFileName, parsed._config); + auto exec = _impl->GetCPPPluginByName(parsed._deviceName).ImportNetwork(modelFileName, parsed._config); + return { static_cast(exec), + static_cast>(exec) }; } ExecutableNetwork Core::ImportNetwork(std::istream& networkModel, const std::string& deviceName, const std::map& config) { - return _impl->ImportNetwork(networkModel, deviceName, config); + auto exec = _impl->ImportNetwork(networkModel, deviceName, config); + return { static_cast(exec), + static_cast>(exec) }; } ExecutableNetwork Core::ImportNetwork(std::istream& networkModel, @@ -1004,7 +1014,9 @@ ExecutableNetwork Core::ImportNetwork(std::istream& networkModel, std::string deviceName = device.getDeviceName(); auto parsed = parseDeviceNameIntoConfig(deviceName, config); - return _impl->GetCPPPluginByName(deviceName).ImportNetwork(networkModel, context, parsed._config); + auto exec = _impl->GetCPPPluginByName(deviceName).ImportNetwork(networkModel, context, parsed._config); + return { static_cast(exec), + static_cast>(exec) }; } QueryNetworkResult Core::QueryNetwork(const CNNNetwork& network, const std::string& deviceName, diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp index 90a9575ecbbea0..3f5c8b26de20cd 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp @@ -165,10 +165,10 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { * @return A status code */ StatusCode Wait(int64_t millis_timeout) override { - if (millis_timeout < -1) { + if (millis_timeout < InferRequest::WaitMode::RESULT_READY) { IE_THROW(ParameterMismatch) << " Timeout can't be less " - << -1 << " for InferRequest::Wait\n"; + << InferRequest::WaitMode::RESULT_READY << " for InferRequest::Wait\n"; } auto status = std::future_status::deferred; @@ -183,11 +183,11 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { } switch (millis_timeout) { - case -1: { + case InferRequest::WaitMode::RESULT_READY: { future.wait(); status = std::future_status::ready; } break; - case 0: { + case InferRequest::WaitMode::STATUS_ONLY: { status = future.wait_for(std::chrono::milliseconds {0}); } break; default: { @@ -210,7 +210,7 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal { void Infer() override { DisableCallbackGuard disableCallbackGuard{this}; InferImpl([&] {Infer_ThreadUnsafe();}); - Wait(-1); + Wait(InferRequest::WaitMode::RESULT_READY); } std::map GetPerformanceCounts() const override { 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 12addfe14aa980..864cd4dc6936e7 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 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include From 8e1fed68f414fab8436c5b8fc5c04e226627adcf Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 18 May 2021 15:05:42 +0300 Subject: [PATCH 19/20] Reverted back SOPointer split --- .../include/details/ie_so_pointer.hpp | 269 ++++++------------ .../cpp/ie_executable_network.cpp | 2 +- .../inference_engine/cpp/ie_infer_request.cpp | 5 +- .../src/inference_engine/ie_core.cpp | 18 +- 4 files changed, 93 insertions(+), 201 deletions(-) diff --git a/inference-engine/include/details/ie_so_pointer.hpp b/inference-engine/include/details/ie_so_pointer.hpp index f95710822df036..62abb7bb10e497 100644 --- a/inference-engine/include/details/ie_so_pointer.hpp +++ b/inference-engine/include/details/ie_so_pointer.hpp @@ -24,13 +24,7 @@ namespace details { * parameter */ template -class SOCreatorTrait { -public: - /** - * @brief A dummy name for fabric - */ - static constexpr auto name = ""; -}; +class SOCreatorTrait {}; /** * @brief Enables only `char` or `wchar_t` template specializations @@ -39,49 +33,23 @@ class SOCreatorTrait { template using enableIfSupportedChar = typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; -/// @cond -IE_SUPPRESS_DEPRECATED_START -template -struct HasRelease { - template static char test(decltype(&C::Release)); - template static long test(...); - constexpr static const bool value = sizeof(test(nullptr)) == sizeof(char); -}; -IE_SUPPRESS_DEPRECATED_END -/// @endcond - -/** - * @brief This class instantiate object loaded from the shared library - * @tparam T An type of object SOPointer can hold - */ -template ::value> -class SOPointer; - -#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;} -#define CATCH_IE_EXCEPTIONS \ - CATCH_IE_EXCEPTION(GeneralError) \ - CATCH_IE_EXCEPTION(NotImplemented) \ - CATCH_IE_EXCEPTION(NetworkNotLoaded) \ - CATCH_IE_EXCEPTION(ParameterMismatch) \ - CATCH_IE_EXCEPTION(NotFound) \ - CATCH_IE_EXCEPTION(OutOfBounds) \ - CATCH_IE_EXCEPTION(Unexpected) \ - CATCH_IE_EXCEPTION(RequestBusy) \ - CATCH_IE_EXCEPTION(ResultNotReady) \ - CATCH_IE_EXCEPTION(NotAllocated) \ - CATCH_IE_EXCEPTION(InferNotStarted) \ - CATCH_IE_EXCEPTION(NetworkNotRead) \ - CATCH_IE_EXCEPTION(InferCancelled) - /** - * @brief This class instantiate object loaded from the shared library and use Release method to destroy the object + * @brief This class instantiate object using shared library * @tparam T An type of object SOPointer can hold */ template -class SOPointer { - template +class SOPointer { + template friend class SOPointer; + IE_SUPPRESS_DEPRECATED_START + struct HasRelease { + template static char test(decltype(&C::Release)); + template static long test(...); + constexpr static const bool value = sizeof(test(nullptr)) == sizeof(char); + }; + IE_SUPPRESS_DEPRECATED_END + public: /** * @brief Default constructor @@ -89,86 +57,51 @@ class SOPointer { SOPointer() = default; /** - * @brief Constructs an object using name to load library - * @param name Existing pointer to a library loader + * @brief The main constructor + * @param name Name of a shared library file */ - template - SOPointer(const std::basic_string& name) : - SOPointer(details::SharedObjectLoader(name.c_str())) { + template > + SOPointer(const std::basic_string & name) + : _so(name.c_str()) { + Load(std::integral_constant{}); } /** + * @brief Constructs an object with existing reference * @brief Constructs an object with existing loader - * @param so_loader Existing pointer to a library loader + * @param soLoader Existing pointer to a library loader */ - SOPointer(const SharedObjectLoader& so_loader) - : _so{so_loader} { - try { - void* create = nullptr; - try { - create = _so.get_symbol((SOCreatorTrait::name + std::string("Shared")).c_str()); - } catch (const NotFound&) {} - if (create == nullptr) { - create = _so.get_symbol(SOCreatorTrait::name); - 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, - InferenceEngine::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_IE_EXCEPTIONS catch (const std::exception& ex) { - IE_THROW() << ex.what(); - } catch(...) { - IE_THROW(Unexpected); - } - } + SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) : _so{so}, _ptr{ptr} {} /** * @brief Constructs an object with existing loader * @param so Existing pointer to a library loader - * @param ptr A shared pointer to the object */ - SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) : _so{so}, _ptr{ptr} {} + explicit SOPointer(const SharedObjectLoader& so) + : _so(so) { + Load(std::integral_constant{}); + } /** * @brief The copy-like constructor, can create So Pointer that dereferenced into child type if T is derived of U * @param that copied SOPointer object */ - template - SOPointer(const SOPointer& that) + template + SOPointer(const SOPointer& that) : _so(that._so), - _ptr(std::dynamic_pointer_cast(that._ptr)) {} + _ptr(std::dynamic_pointer_cast(that._ptr)) { + IE_ASSERT(_ptr != nullptr); + } /** * @brief Standard pointer operator + * @return underlined interface with disabled Release method */ T* operator->() const noexcept { return _ptr.get(); } - /** - * @return raw pointer - */ - T* get() noexcept { - return _ptr.get(); - } - - /** - * @return raw pointer - */ - const T* get() const noexcept { - return _ptr.get(); - } - explicit operator bool() const noexcept { return _ptr != nullptr; } @@ -195,36 +128,59 @@ class SOPointer { } protected: - SharedObjectLoader _so; - std::shared_ptr _ptr; -}; - -/** - * @brief This class instantiate object loaded from the shared library - * @tparam T An type of object SOPointer can hold - */ -template -class SOPointer { - template - friend class SOPointer; +#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;} +#define CATCH_IE_EXCEPTIONS \ + CATCH_IE_EXCEPTION(GeneralError) \ + CATCH_IE_EXCEPTION(NotImplemented) \ + CATCH_IE_EXCEPTION(NetworkNotLoaded) \ + CATCH_IE_EXCEPTION(ParameterMismatch) \ + CATCH_IE_EXCEPTION(NotFound) \ + CATCH_IE_EXCEPTION(OutOfBounds) \ + CATCH_IE_EXCEPTION(Unexpected) \ + CATCH_IE_EXCEPTION(RequestBusy) \ + CATCH_IE_EXCEPTION(ResultNotReady) \ + CATCH_IE_EXCEPTION(NotAllocated) \ + CATCH_IE_EXCEPTION(InferNotStarted) \ + CATCH_IE_EXCEPTION(NetworkNotRead) \ + CATCH_IE_EXCEPTION(InferCancelled) -public: /** - * @brief Default constructor + * @brief Implements load of object from library if Release method is presented */ - SOPointer() = default; + void Load(std::true_type) { + try { + void* create = nullptr; + try { + create = _so.get_symbol((SOCreatorTrait::name + std::string("Shared")).c_str()); + } catch (const NotFound&) {} + if (create == nullptr) { + create = _so.get_symbol(SOCreatorTrait::name); + 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, + InferenceEngine::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_IE_EXCEPTIONS catch (const std::exception& ex) { + IE_THROW() << ex.what(); + } catch(...) { + IE_THROW(Unexpected); + } + } /** - * @brief Constructs an object using name to load library - * @param name Existing pointer to a library loader + * @brief Implements load of object from library */ - template > - SOPointer(const std::basic_string& name) : - SOPointer(details::SharedObjectLoader(name.c_str())) { - } - - SOPointer(const SharedObjectLoader& so_loader) - : _so{so_loader} { + void Load(std::false_type) { try { using CreateF = void(std::shared_ptr&); reinterpret_cast(_so.get_symbol(SOCreatorTrait::name))(_ptr); @@ -234,75 +190,18 @@ class SOPointer { IE_THROW(Unexpected); } } + #undef CATCH_IE_EXCEPTION + #undef CATCH_IE_EXCEPTIONS /** - * @brief Constructs an object with existing loader - * @param soLoader Existing pointer to a library loader + * @brief The DLL */ - SOPointer(const SharedObjectLoader& so, const std::shared_ptr& ptr) : _so{so}, _ptr{ptr} {} - - /** - * @brief The copy-like constructor, can create So Pointer that dereferenced into child type if T is derived of U - * @param that copied SOPointer object - */ - template - SOPointer(const SOPointer& that) - : _so(that._so), - _ptr(std::dynamic_pointer_cast(that._ptr)) {} - - /** - * @brief Standard pointer operator - */ - T* operator->() const noexcept { - return _ptr.get(); - } - - /** - * @return raw pointer - */ - T* get() noexcept { - return _ptr.get(); - } + SharedObjectLoader _so; /** - * @return raw pointer + * @brief Gets a smart pointer to the custom object */ - const T* get() const noexcept { - return _ptr.get(); - } - - explicit operator bool() const noexcept { - return _ptr != nullptr; - } - - friend bool operator==(std::nullptr_t, const SOPointer& ptr) noexcept { - return !ptr; - } - friend bool operator==(const SOPointer& ptr, std::nullptr_t) noexcept { - return !ptr; - } - friend bool operator!=(std::nullptr_t, const SOPointer& ptr) noexcept { - return static_cast(ptr); - } - friend bool operator!=(const SOPointer& ptr, std::nullptr_t) noexcept { - return static_cast(ptr); - } - - operator const SharedObjectLoader&() const noexcept { - return _so; - } - - operator std::shared_ptr& () noexcept { - return _ptr; - } - -protected: - SharedObjectLoader _so; std::shared_ptr _ptr; }; - -#undef CATCH_IE_EXCEPTION -#undef CATCH_IE_EXCEPTIONS - } // namespace details } // namespace InferenceEngine diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index f096c56fb0bad9..c792af606a7fa3 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -54,7 +54,7 @@ std::vector ExecutableNetwork::QueryState() { std::vector controller; EXEC_NET_CALL_STATEMENT( for (auto&& state : _impl->QueryState()) { - controller.emplace_back(VariableState { _so, static_cast>(state) }); + controller.emplace_back(VariableState{ _so, state }); }); return controller; } diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index af2cad1c816abe..7d9e57bba1e9f7 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -192,9 +192,8 @@ IE_SUPPRESS_DEPRECATED_END std::vector InferRequest::QueryState() { std::vector controller; INFER_REQ_CALL_STATEMENT( - for (auto&& _state : _impl->QueryState()) { - VariableState state{_so, static_cast>(_state)}; - controller.emplace_back(state); + for (auto&& state : _impl->QueryState()) { + controller.emplace_back(VariableState{_so, state}); } ) return controller; diff --git a/inference-engine/src/inference_engine/ie_core.cpp b/inference-engine/src/inference_engine/ie_core.cpp index 6273bf3f30380f..39052af8badd66 100644 --- a/inference-engine/src/inference_engine/ie_core.cpp +++ b/inference-engine/src/inference_engine/ie_core.cpp @@ -903,22 +903,19 @@ CNNNetwork Core::ReadNetwork(const std::string& model, const Blob::CPtr& weights ExecutableNetwork Core::LoadNetwork(const CNNNetwork& network, const std::string& deviceName, const std::map& config) { auto exec = _impl->LoadNetwork(network, deviceName, config); - return { static_cast(exec), - static_cast>(exec) }; + return { exec, exec }; } ExecutableNetwork Core::LoadNetwork(const CNNNetwork& network, RemoteContext::Ptr context, const std::map& config) { auto exec = _impl->LoadNetwork(network, context, config); - return { static_cast(exec), - static_cast>(exec) }; + return { exec, exec }; } ExecutableNetwork Core::LoadNetwork(const std::string& modelPath, const std::string& deviceName, const std::map& config) { auto exec = _impl->LoadNetwork(modelPath, deviceName, config); - return { static_cast(exec), - static_cast>(exec) }; + return { exec, exec }; } RemoteContext::Ptr Core::CreateContext(const std::string& deviceName, const ParamMap& params) { @@ -989,15 +986,13 @@ ExecutableNetwork Core::ImportNetwork(const std::string& modelFileName, const st auto parsed = parseDeviceNameIntoConfig(deviceName, config); auto exec = _impl->GetCPPPluginByName(parsed._deviceName).ImportNetwork(modelFileName, parsed._config); - return { static_cast(exec), - static_cast>(exec) }; + return { exec, exec }; } ExecutableNetwork Core::ImportNetwork(std::istream& networkModel, const std::string& deviceName, const std::map& config) { auto exec = _impl->ImportNetwork(networkModel, deviceName, config); - return { static_cast(exec), - static_cast>(exec) }; + return { exec, exec }; } ExecutableNetwork Core::ImportNetwork(std::istream& networkModel, @@ -1015,8 +1010,7 @@ ExecutableNetwork Core::ImportNetwork(std::istream& networkModel, auto parsed = parseDeviceNameIntoConfig(deviceName, config); auto exec = _impl->GetCPPPluginByName(deviceName).ImportNetwork(networkModel, context, parsed._config); - return { static_cast(exec), - static_cast>(exec) }; + return { exec, exec }; } QueryNetworkResult Core::QueryNetwork(const CNNNetwork& network, const std::string& deviceName, From c494012cd7beba45a5bb3cd275f25386cbd4ec7f Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 18 May 2021 16:35:46 +0300 Subject: [PATCH 20/20] Code review --- inference-engine/include/cpp/ie_executable_network.hpp | 2 +- inference-engine/include/cpp/ie_infer_request.hpp | 2 +- inference-engine/include/cpp/ie_memory_state.hpp | 2 +- .../src/inference_engine/cpp/ie_executable_network.cpp | 2 +- inference-engine/src/inference_engine/cpp/ie_infer_request.cpp | 2 +- inference-engine/src/inference_engine/cpp/ie_variable_state.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/inference-engine/include/cpp/ie_executable_network.hpp b/inference-engine/include/cpp/ie_executable_network.hpp index 9e5e7158e6736a..4200d160c5d94c 100644 --- a/inference-engine/include/cpp/ie_executable_network.hpp +++ b/inference-engine/include/cpp/ie_executable_network.hpp @@ -30,8 +30,8 @@ class IExecutableNetwork; * @brief This is an interface of an executable network */ class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) { - std::shared_ptr _impl; details::SharedObjectLoader _so; + std::shared_ptr _impl; /** * @brief Constructs ExecutableNetwork from the initialized std::shared_ptr diff --git a/inference-engine/include/cpp/ie_infer_request.hpp b/inference-engine/include/cpp/ie_infer_request.hpp index 392c0abaa0568e..54c71c410fd7d8 100644 --- a/inference-engine/include/cpp/ie_infer_request.hpp +++ b/inference-engine/include/cpp/ie_infer_request.hpp @@ -29,8 +29,8 @@ class IInferRequestInternal; * It can throw exceptions safely for the application, where it is properly handled. */ class INFERENCE_ENGINE_API_CLASS(InferRequest) { - std::shared_ptr _impl; details::SharedObjectLoader _so; + std::shared_ptr _impl; /** * @brief Constructs InferRequest from the initialized std::shared_ptr diff --git a/inference-engine/include/cpp/ie_memory_state.hpp b/inference-engine/include/cpp/ie_memory_state.hpp index 8014c8fa3a34a3..7e135abcb4721d 100644 --- a/inference-engine/include/cpp/ie_memory_state.hpp +++ b/inference-engine/include/cpp/ie_memory_state.hpp @@ -25,8 +25,8 @@ class IVariableStateInternal; * @brief C++ exception based error reporting wrapper of API class IVariableState */ class INFERENCE_ENGINE_API_CLASS(VariableState) { - std::shared_ptr _impl; details::SharedObjectLoader _so; + std::shared_ptr _impl; /** * @brief Constructs VariableState from the initialized std::shared_ptr diff --git a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp index c792af606a7fa3..de7a0371718d59 100644 --- a/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_executable_network.cpp @@ -22,7 +22,7 @@ namespace InferenceEngine { ExecutableNetwork::ExecutableNetwork(const details::SharedObjectLoader& so, const IExecutableNetworkInternal::Ptr& impl) - : _impl(impl), _so(so) { + : _so(so), _impl(impl) { IE_ASSERT(_impl != nullptr); } diff --git a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp index 7d9e57bba1e9f7..39ded89d237bec 100644 --- a/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_infer_request.cpp @@ -43,7 +43,7 @@ namespace InferenceEngine { InferRequest::InferRequest(const details::SharedObjectLoader& so, const IInferRequestInternal::Ptr& impl) - : _impl(impl), _so(so) { + : _so(so), _impl(impl) { IE_ASSERT(_impl != nullptr); } diff --git a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp index d74ccaace6d094..2490b9fe1ad694 100644 --- a/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp +++ b/inference-engine/src/inference_engine/cpp/ie_variable_state.cpp @@ -21,7 +21,7 @@ namespace InferenceEngine { VariableState::VariableState(const details::SharedObjectLoader& so, const IVariableStateInternal::Ptr& impl) - : _impl(impl), _so(so) { + : _so(so), _impl(impl) { IE_ASSERT(_impl != nullptr); }