From a4dcfed1a9c67e8fe611684711a38af6236afc35 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 14 Aug 2020 12:11:54 +0300 Subject: [PATCH] Simplified plugin interfaces (#1745) * Simplified plugin interface * Allow not implemented * Fixes * Fixed CPU plugin tests * Fixed tests dependencies * Fixes * Fixed GPU plugin compilation * Renamed plugin * Fixes * Removed tests for plugin base * Fix2 * Fix 2 * Define a macro to define plugin creation function * Clean-up * Fixed OSX build * Fixed CentOS * Fixed exception catch / throw * Fixed clang issue * Fixed python tests on macOsx --- cmake/os_flags.cmake | 1 + docs/template_plugin/src/template_plugin.cpp | 1 - .../include/details/ie_exception_conversion.hpp | 2 +- inference-engine/src/cldnn_engine/cldnn_engine.cpp | 1 - .../src/cldnn_engine/cldnn_remote_context.cpp | 2 +- .../src/cldnn_engine/cldnn_remote_context.h | 8 +- .../src/gna_plugin/gna_graph_compiler.hpp | 1 - inference-engine/src/gna_plugin/gna_plugin.cpp | 1 + inference-engine/src/gna_plugin/gna_plugin.hpp | 2 +- .../src/gna_plugin/gna_plugin_entry_points.cpp | 1 - .../src/gna_plugin/layers/gna_split_layer.hpp | 3 +- .../src/hetero_plugin/hetero_plugin.cpp | 1 - inference-engine/src/inference_engine/ie_core.cpp | 55 +++--- .../src/inference_engine/ie_plugin_cpp.hpp | 139 ++++++--------- .../src/inference_engine/ie_plugin_ptr.hpp | 3 +- inference-engine/src/mkldnn_plugin/config.cpp | 8 +- .../src/mkldnn_plugin/mkldnn_plugin.cpp | 1 - inference-engine/src/multi_device/multi_device.cpp | 1 - .../cpp_interfaces/base/ie_plugin_base.hpp | 148 ---------------- .../impl/ie_executable_network_internal.hpp | 6 +- .../cpp_interfaces/impl/ie_plugin_internal.hpp | 85 ++++----- .../interface/ie_iplugin_internal.hpp | 88 +++++++--- .../cpp_interfaces/interface/ie_plugin.hpp | 190 --------------------- .../src/vpu/myriad_plugin/api/myriad_api.cpp | 1 - .../src/vpu/myriad_plugin/myriad_plugin.cpp | 1 - .../inference_engine/executable_network.cpp | 2 +- .../inference_engine/so_pointer_tests.cpp | 5 +- .../tests/ie_test_utils/unit_test_utils/empty.cpp | 3 +- .../interface}/mock_iinference_plugin.hpp | 30 +--- .../mocks/cpp_interfaces/mock_plugin_impl.hpp | 52 ------ .../mocks/mock_engine/mock_plugin.cpp | 82 ++------- .../mocks/mock_engine/mock_plugin.hpp | 48 +----- .../cpp_interfaces/ie_plugin_base_test.cpp | 123 ------------- .../cpp_interfaces/ie_plugin_test.cpp | 50 ++++-- .../tests/unit/inference_engine/ie_plugin_ptr.cpp | 16 +- .../vpu/myriad_tests/vpu_watchdog_tests.cpp | 1 - .../mkldnn/extensions_tests/extensions_test.cpp | 21 +-- .../unit/engines/gna/gna_matcher.cpp | 10 +- .../unit/engines/gna/gna_matcher.hpp | 2 +- .../engines/vpu/mvnc/pthread_semaphore_tests.cpp | 2 +- 40 files changed, 312 insertions(+), 885 deletions(-) delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/base/ie_plugin_base.hpp delete mode 100644 inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp rename inference-engine/tests/ie_test_utils/unit_test_utils/mocks/{ => cpp_interfaces/interface}/mock_iinference_plugin.hpp (50%) delete mode 100644 inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp delete mode 100644 inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_base_test.cpp diff --git a/cmake/os_flags.cmake b/cmake/os_flags.cmake index ae8c8c2..9eae83f 100644 --- a/cmake/os_flags.cmake +++ b/cmake/os_flags.cmake @@ -265,6 +265,7 @@ else() ie_add_compiler_flags(-ffunction-sections -fdata-sections) ie_add_compiler_flags(-fdiagnostics-show-option) ie_add_compiler_flags(-Wundef) + ie_add_compiler_flags(-Wreturn-type) # Disable noisy warnings diff --git a/docs/template_plugin/src/template_plugin.cpp b/docs/template_plugin/src/template_plugin.cpp index 21ae573..264960f 100644 --- a/docs/template_plugin/src/template_plugin.cpp +++ b/docs/template_plugin/src/template_plugin.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/inference-engine/include/details/ie_exception_conversion.hpp b/inference-engine/include/details/ie_exception_conversion.hpp index 3a39275..ffc28b6 100644 --- a/inference-engine/include/details/ie_exception_conversion.hpp +++ b/inference-engine/include/details/ie_exception_conversion.hpp @@ -36,7 +36,7 @@ namespace InferenceEngine { namespace details { -inline void extract_exception(StatusCode status, char* msg) { +inline void extract_exception(StatusCode status, const char* msg) { switch (status) { case NOT_IMPLEMENTED: throw NotImplemented(msg); diff --git a/inference-engine/src/cldnn_engine/cldnn_engine.cpp b/inference-engine/src/cldnn_engine/cldnn_engine.cpp index 640cb8b..12bd170 100644 --- a/inference-engine/src/cldnn_engine/cldnn_engine.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_engine.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "ie_plugin_config.hpp" #include "caseless.hpp" #include diff --git a/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp b/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp index 2b1cb8a..3ff5289 100644 --- a/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_remote_context.cpp @@ -217,7 +217,7 @@ void CLDNNRemoteAllocator::unlock(void* handle) noexcept { release_lock(); } -CLDNNExecutionContextImpl::CLDNNExecutionContextImpl(const std::shared_ptr plugin, +CLDNNExecutionContextImpl::CLDNNExecutionContextImpl(const std::shared_ptr plugin, const ParamMap& params, const Config& config) : m_plugin(plugin), diff --git a/inference-engine/src/cldnn_engine/cldnn_remote_context.h b/inference-engine/src/cldnn_engine/cldnn_remote_context.h index 31b82dd..b5ff081 100644 --- a/inference-engine/src/cldnn_engine/cldnn_remote_context.h +++ b/inference-engine/src/cldnn_engine/cldnn_remote_context.h @@ -213,7 +213,7 @@ public: using Ptr = std::shared_ptr; using CPtr = std::shared_ptr; - explicit CLDNNExecutionContextImpl(std::shared_ptr plugin, + explicit CLDNNExecutionContextImpl(std::shared_ptr plugin, const ParamMap& params, const Config& config = {}); @@ -223,7 +223,7 @@ public: std::shared_ptr GetEngine() const { return m_engine; } Config& GetConfig() { return m_config; } ContextType GetType() const { return m_type; } - const std::weak_ptr GetPlugin() const { return m_plugin; } + const std::weak_ptr GetPlugin() const { return m_plugin; } void acquire_lock() { while (lock.test_and_set(std::memory_order_acquire)) {} @@ -239,7 +239,7 @@ protected: Config m_config; ContextType m_type; - std::weak_ptr m_plugin; + std::weak_ptr m_plugin; std::atomic_flag lock; }; @@ -374,7 +374,7 @@ public: using Ptr = std::shared_ptr; using CPtr = std::shared_ptr; - explicit typedCLDNNExecutionContext(std::shared_ptr plugin, + explicit typedCLDNNExecutionContext(std::shared_ptr plugin, const ParamMap& params, const Config& config = {}) : _impl(plugin, params, config) {} diff --git a/inference-engine/src/gna_plugin/gna_graph_compiler.hpp b/inference-engine/src/gna_plugin/gna_graph_compiler.hpp index 6e05c6e..22a2ada 100644 --- a/inference-engine/src/gna_plugin/gna_graph_compiler.hpp +++ b/inference-engine/src/gna_plugin/gna_graph_compiler.hpp @@ -16,7 +16,6 @@ #include #include "descriptions/gna_input_desc.hpp" #include "descriptions/gna_flags.hpp" -#include "cpp_interfaces/base/ie_plugin_base.hpp" #include "connection_details.hpp" #include "backend/dnn.hpp" #include "memory/polymorph_allocator.hpp" diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index 4bd8645..06835b4 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include diff --git a/inference-engine/src/gna_plugin/gna_plugin.hpp b/inference-engine/src/gna_plugin/gna_plugin.hpp index 0d6af64..8dcb804 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.hpp +++ b/inference-engine/src/gna_plugin/gna_plugin.hpp @@ -29,7 +29,7 @@ #endif namespace GNAPluginNS { -class GNAPlugin : public InferenceEngine::IInferencePluginInternal, public std::enable_shared_from_this { +class GNAPlugin : public InferenceEngine::IInferencePlugin { protected: std::string _pluginName = "GNA"; diff --git a/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp b/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp index f405963..87994ac 100644 --- a/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin_entry_points.cpp @@ -3,7 +3,6 @@ // #include -#include #include "gna_plugin_internal.hpp" using namespace InferenceEngine; diff --git a/inference-engine/src/gna_plugin/layers/gna_split_layer.hpp b/inference-engine/src/gna_plugin/layers/gna_split_layer.hpp index a971fda..1063274 100644 --- a/inference-engine/src/gna_plugin/layers/gna_split_layer.hpp +++ b/inference-engine/src/gna_plugin/layers/gna_split_layer.hpp @@ -6,8 +6,7 @@ #include -#include "ie_layers.h" -#include "cpp_interfaces/base/ie_plugin_base.hpp" +#include namespace GNAPluginNS { // Split, Slice diff --git a/inference-engine/src/hetero_plugin/hetero_plugin.cpp b/inference-engine/src/hetero_plugin/hetero_plugin.cpp index c726339..b4b1854 100644 --- a/inference-engine/src/hetero_plugin/hetero_plugin.cpp +++ b/inference-engine/src/hetero_plugin/hetero_plugin.cpp @@ -13,7 +13,6 @@ #include #include "ie_plugin_config.hpp" #include "hetero/hetero_plugin_config.hpp" -#include #include "hetero_executable_network.hpp" using namespace InferenceEngine; diff --git a/inference-engine/src/inference_engine/ie_core.cpp b/inference-engine/src/inference_engine/ie_core.cpp index 5595d0c..89e8805 100644 --- a/inference-engine/src/inference_engine/ie_core.cpp +++ b/inference-engine/src/inference_engine/ie_core.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "ie_plugin_cpp.hpp" #include "ie_plugin_config.hpp" #include "ie_itt.hpp" @@ -24,8 +25,6 @@ using namespace InferenceEngine::PluginConfigParams; namespace InferenceEngine { -IInferencePlugin::~IInferencePlugin() {} - namespace { template @@ -84,6 +83,18 @@ Parameter copyParameterValue(const Parameter & value) { return std::move(value); } +template +void allowNotImplemented(F && f) { + try { + f(); + } catch (const details::InferenceEngineException & ex) { + std::string message = ex.what(); + if (message.find(NOT_IMPLEMENTED_str) == std::string::npos) { + throw ex; + } + } +} + } // namespace DeviceIDParser::DeviceIDParser(const std::string& deviceNameWithID) { @@ -333,33 +344,37 @@ public: PluginDescriptor desc = it->second; try { - InferenceEnginePluginPtr plugin(desc.libraryLocation); + InferencePlugin plugin(desc.libraryLocation); { - plugin->SetName(deviceName); + plugin.SetName(deviceName); // Set Inference Engine class reference to plugins ICore* mutableCore = const_cast(static_cast(this)); - plugin->SetCore(mutableCore); + plugin.SetCore(mutableCore); } // Add registered extensions to new plugin - for (const auto& ext : extensions) { - plugin->AddExtension(ext, nullptr); - } - - InferencePlugin cppPlugin(plugin); + allowNotImplemented([&](){ + for (const auto& ext : extensions) { + plugin.AddExtension(ext); + } + }); // configuring { - cppPlugin.SetConfig(desc.defaultConfig); - - for (auto&& extensionLocation : desc.listOfExtentions) { - cppPlugin.AddExtension(make_so_pointer(extensionLocation)); - } + allowNotImplemented([&]() { + plugin.SetConfig(desc.defaultConfig); + }); + + allowNotImplemented([&]() { + for (auto&& extensionLocation : desc.listOfExtentions) { + plugin.AddExtension(make_so_pointer(extensionLocation)); + } + }); } - plugins[deviceName] = cppPlugin; + plugins[deviceName] = plugin; } catch (const details::InferenceEngineException& ex) { THROW_IE_EXCEPTION << "Failed to create plugin " << FileUtils::fromFilePath(desc.libraryLocation) << " for device " << deviceName << "\n" @@ -455,7 +470,9 @@ public: // set config for already created plugins for (auto& plugin : plugins) { if (deviceName.empty() || deviceName == plugin.first) { - plugin.second.SetConfig(config); + allowNotImplemented([&]() { + plugin.second.SetConfig(config); + }); } } } @@ -542,8 +559,8 @@ std::map Core::GetVersions(const std::string& deviceName) std::string deviceNameLocal = parser.getDeviceName(); InferenceEngine::InferencePlugin cppPlugin = _impl->GetCPPPluginByName(deviceNameLocal); - const Version * version = cppPlugin.GetVersion(); - versions[deviceNameLocal] = *version; + const Version version = cppPlugin.GetVersion(); + versions[deviceNameLocal] = version; } return versions; diff --git a/inference-engine/src/inference_engine/ie_plugin_cpp.hpp b/inference-engine/src/inference_engine/ie_plugin_cpp.hpp index 19bbe9b..662f73a 100644 --- a/inference-engine/src/inference_engine/ie_plugin_cpp.hpp +++ b/inference-engine/src/inference_engine/ie_plugin_cpp.hpp @@ -13,14 +13,29 @@ #include #include +#include "file_utils.h" #include "cpp/ie_executable_network.hpp" #include "cpp/ie_cnn_network.h" #include "details/ie_exception_conversion.hpp" #include "ie_plugin_ptr.hpp" -#define CALL_RETURN_FNC_NO_ARGS(function, ...) \ - if (!actual) THROW_IE_EXCEPTION << "Wrapper used in the CALL_RETURN_FNC_NO_ARGS was not initialized."; \ - return actual->function(__VA_ARGS__); +#if defined __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wreturn-type" +#endif + +#define CALL_STATEMENT(...) \ + if (!actual) THROW_IE_EXCEPTION << "Wrapper used in the CALL_STATEMENT was not initialized."; \ + try { \ + __VA_ARGS__; \ + } catch (const InferenceEngine::details::InferenceEngineException& iex) { \ + InferenceEngine::details::extract_exception(iex.hasStatus() ? \ + iex.getStatus() : GENERAL_ERROR, iex.what()); \ + } catch (const std::exception& ex) { \ + InferenceEngine::details::extract_exception(GENERAL_ERROR, ex.what()); \ + } catch (...) { \ + InferenceEngine::details::extract_exception(UNEXPECTED, ""); \ + } namespace InferenceEngine { @@ -33,148 +48,88 @@ class InferencePlugin { InferenceEnginePluginPtr actual; public: - /** @brief A default constructor */ InferencePlugin() = default; - /** - * @brief Constructs a plugin instance from the given pointer. - * - * @param pointer Initialized Plugin pointer - */ explicit InferencePlugin(const InferenceEnginePluginPtr& pointer): actual(pointer) { if (actual == nullptr) { THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized."; } } - /** - * @copybrief IInferencePlugin::GetVersion - * - * Wraps IInferencePlugin::GetVersion - * @return A plugin version - */ - const Version* GetVersion() { - const Version* versionInfo = nullptr; - if (actual == nullptr) THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized"; - actual->GetVersion(versionInfo); - if (versionInfo == nullptr) { - THROW_IE_EXCEPTION << "Unknown device is used"; + explicit InferencePlugin(const FileUtils::FilePath & libraryLocation) : + actual(libraryLocation) { + if (actual == nullptr) { + THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized."; } - return versionInfo; } - /** - * @copybrief IInferencePlugin::LoadNetwork - * - * Wraps IInferencePlugin::LoadNetwork - * - * @param network A network object to load - * @param config A map of configuration options - * @return Created Executable Network object - */ - ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map& config) { - IExecutableNetwork::Ptr ret; - CALL_STATUS_FNC(LoadNetwork, ret, network, config); - return ExecutableNetwork(ret, actual); + void SetName(const std::string & deviceName) { + CALL_STATEMENT(actual->SetName(deviceName)); + } + + void SetCore(ICore* core) { + CALL_STATEMENT(actual->SetCore(core)); + } + + const Version GetVersion() const { + CALL_STATEMENT(return actual->GetVersion()); } - /** - * @copybrief InferencePlugin::LoadNetwork - * - * Wraps IInferencePlugin::LoadNetwork - * @param network A network object to load - * @param config A map of configuration options - * @return Created Executable Network object - */ ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map& config) { IExecutableNetwork::Ptr ret; - CALL_STATUS_FNC(LoadNetwork, ret, network, config); - if (ret.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to executable network is null"; + CALL_STATEMENT(actual->LoadNetwork(ret, network, config)); return ExecutableNetwork(ret, actual); } - /** - * @copybrief IInferencePlugin::AddExtension - * - * Wraps IInferencePlugin::AddExtension - * - * @param extension Pointer to loaded Extension - */ void AddExtension(InferenceEngine::IExtensionPtr extension) { - CALL_STATUS_FNC(AddExtension, extension); + CALL_STATEMENT(actual->AddExtension(extension)); } - /** - * @copybrief IInferencePlugin::SetConfig - * - * Wraps IInferencePlugin::SetConfig - * @param config A configuration map - */ void SetConfig(const std::map& config) { - CALL_STATUS_FNC(SetConfig, config); + CALL_STATEMENT(actual->SetConfig(config)); } - /** - * @copybrief IInferencePlugin::ImportNetwork - * - * Wraps IInferencePlugin::ImportNetwork - * @param modelFileName A path to the imported network - * @param config A configuration map - * @return Created Executable Network object - */ ExecutableNetwork ImportNetwork(const std::string& modelFileName, const std::map& config) { - IExecutableNetwork::Ptr ret; - CALL_STATUS_FNC(ImportNetwork, ret, modelFileName, config); - return ExecutableNetwork(ret, actual); + CALL_STATEMENT(return ExecutableNetwork(actual->ImportNetwork(modelFileName, config), actual)); } - /** - * @copybrief IInferencePlugin::QueryNetwork - * - * Wraps IInferencePlugin::QueryNetwork - * - * @param network A network object to query - * @param config A configuration map - * @param res Query results - */ void QueryNetwork(const ICNNNetwork& network, const std::map& config, QueryNetworkResult& res) const { - if (actual == nullptr) THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized"; - actual->QueryNetwork(network, config, res); + CALL_STATEMENT(actual->QueryNetwork(network, config, res)); if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg; } ExecutableNetwork ImportNetwork(std::istream& networkModel, const std::map &config) { - CALL_RETURN_FNC_NO_ARGS(ImportNetwork, networkModel, config); + CALL_STATEMENT(return actual->ImportNetwork(networkModel, config)); } Parameter GetMetric(const std::string& name, const std::map& options) const { - CALL_RETURN_FNC_NO_ARGS(GetMetric, name, options); + CALL_STATEMENT(return actual->GetMetric(name, options)); } ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map& config, RemoteContext::Ptr context) { - CALL_RETURN_FNC_NO_ARGS(LoadNetwork, network, config, context); + CALL_STATEMENT(return actual->LoadNetwork(network, config, context)); } RemoteContext::Ptr CreateContext(const ParamMap& params) { - CALL_RETURN_FNC_NO_ARGS(CreateContext, params); + CALL_STATEMENT(return actual->CreateContext(params)); } RemoteContext::Ptr GetDefaultContext() { - CALL_RETURN_FNC_NO_ARGS(GetDefaultContext); + CALL_STATEMENT(return actual->GetDefaultContext()); } ExecutableNetwork ImportNetwork(std::istream& networkModel, const RemoteContext::Ptr& context, const std::map& config) { - CALL_RETURN_FNC_NO_ARGS(ImportNetwork, networkModel, context, config); + CALL_STATEMENT(return actual->ImportNetwork(networkModel, context, config)); } Parameter GetConfig(const std::string& name, const std::map& options) const { - CALL_RETURN_FNC_NO_ARGS(GetConfig, name, options); + CALL_STATEMENT(return actual->GetConfig(name, options)); } /** @@ -193,3 +148,9 @@ public: using Ptr = std::shared_ptr; }; } // namespace InferenceEngine + +#undef CALL_STATEMENT + +#if defined __GNUC__ +# pragma GCC diagnostic pop +#endif diff --git a/inference-engine/src/inference_engine/ie_plugin_ptr.hpp b/inference-engine/src/inference_engine/ie_plugin_ptr.hpp index 3aebd5b..fb31846 100644 --- a/inference-engine/src/inference_engine/ie_plugin_ptr.hpp +++ b/inference-engine/src/inference_engine/ie_plugin_ptr.hpp @@ -12,8 +12,7 @@ #include #include "details/ie_so_pointer.hpp" -#include "ie_extension.h" -#include "cpp_interfaces/interface/ie_plugin.hpp" +#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" namespace InferenceEngine { namespace details { diff --git a/inference-engine/src/mkldnn_plugin/config.cpp b/inference-engine/src/mkldnn_plugin/config.cpp index 44d8a9c..c095b93 100644 --- a/inference-engine/src/mkldnn_plugin/config.cpp +++ b/inference-engine/src/mkldnn_plugin/config.cpp @@ -47,7 +47,13 @@ void Config::readProperties(const std::map &prop) { std::find(std::begin(streamExecutorConfigKeys), std::end(streamExecutorConfigKeys), key)) { streamExecutorConfig.SetConfig(key, val); } else if (key == PluginConfigParams::KEY_DYN_BATCH_LIMIT) { - int val_i = std::stoi(val); + int val_i = -1; + try { + val_i = std::stoi(val); + } catch (const std::exception&) { + THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_DYN_BATCH_LIMIT + << ". Expected only integer numbers"; + } // zero and any negative value will be treated // as default batch size batchLimit = std::max(val_i, 0); diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index d783081..0219c83 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -9,7 +9,6 @@ #include "mkldnn_itt.h" #include -#include #include #include #include diff --git a/inference-engine/src/multi_device/multi_device.cpp b/inference-engine/src/multi_device/multi_device.cpp index face87a..d2bcf82 100644 --- a/inference-engine/src/multi_device/multi_device.cpp +++ b/inference-engine/src/multi_device/multi_device.cpp @@ -14,7 +14,6 @@ #include "ie_metric_helpers.hpp" #include -#include #include #include #include diff --git a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_plugin_base.hpp b/inference-engine/src/plugin_api/cpp_interfaces/base/ie_plugin_base.hpp deleted file mode 100644 index 1aa21b0..0000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/base/ie_plugin_base.hpp +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * \brief inference engine plugin API wrapper, to be used by particular implementors - * \file ie_plugin_base.hpp - */ - -#pragma once - -#include -#include -#include - -#include "cpp_interfaces/interface/ie_plugin.hpp" -#include "cpp_interfaces/exception2status.hpp" -#include "description_buffer.hpp" - -namespace InferenceEngine { - -/** - * @brief Plugin `noexcept` wrapper which accepts IInferencePluginInternal derived instance which can throw exceptions - * @ingroup ie_dev_api_plugin_api - * @tparam T Minimal CPP implementation of IInferencePluginInternal (e.g. InferencePluginInternal) - */ -template -class PluginBase : public IInferencePlugin { - class VersionStore : public Version { - std::string _dsc; - std::string _buildNumber; - - public: - explicit VersionStore(const Version& v) { - _dsc = v.description; - _buildNumber = v.buildNumber; - description = _dsc.c_str(); - buildNumber = _buildNumber.c_str(); - apiVersion = v.apiVersion; - } - } _version; - - std::shared_ptr _impl; - -public: - /** - * @brief Constructor with plugin version and actual underlying implementation. - * @param actualReported version that are to be reported - * @param impl Underplying implementation of type IInferencePluginInternal - */ - PluginBase(const Version& actualReported, std::shared_ptr impl): _version(actualReported) { - if (impl.get() == nullptr) { - THROW_IE_EXCEPTION << "implementation not defined"; - } - _impl = impl; - } - - void SetName(const std::string& pluginName) noexcept override { - _impl->SetName(pluginName); - } - - std::string GetName() const noexcept override { - return _impl->GetName(); - } - - void GetVersion(const Version*& versionInfo) noexcept override { - versionInfo = &_version; - } - - StatusCode LoadNetwork(IExecutableNetwork::Ptr& executableNetwork, const ICNNNetwork& network, - const std::map& config, ResponseDesc* resp) noexcept override { - TO_STATUS(_impl->LoadNetwork(executableNetwork, network, config)); - } - - StatusCode AddExtension(InferenceEngine::IExtensionPtr extension, - InferenceEngine::ResponseDesc* resp) noexcept override { - TO_STATUS(_impl->AddExtension(extension)); - } - - StatusCode SetConfig(const std::map& config, ResponseDesc* resp) noexcept override { - TO_STATUS(_impl->SetConfig(config)); - } - - StatusCode ImportNetwork(IExecutableNetwork::Ptr& ret, const std::string& modelFileName, - const std::map& config, ResponseDesc* resp) noexcept override { - TO_STATUS(ret = _impl->ImportNetwork(modelFileName, config)); - } - - ExecutableNetwork ImportNetwork(std::istream& networkModel, - const std::map& config) override { - return _impl->ImportNetwork(networkModel, config); - } - - void Release() noexcept override { - delete this; - } - - void QueryNetwork(const ICNNNetwork& network, const std::map& config, - QueryNetworkResult& res) const noexcept override { - TO_STATUSVAR(_impl->QueryNetwork(network, config, res), res.rc, &res.resp); - } - - void SetCore(ICore* core) noexcept override { - _impl->SetCore(core); - } - - const ICore& GetCore() const override { - IE_ASSERT(nullptr != _impl->GetCore()); - return *_impl->GetCore(); - } - - Parameter GetConfig(const std::string& name, const std::map& options) const override { - return _impl->GetConfig(name, options); - } - - Parameter GetMetric(const std::string& name, const std::map& options) const override { - return _impl->GetMetric(name, options); - } - - RemoteContext::Ptr CreateContext(const ParamMap& params) override { - return _impl->CreateContext(params); - } - - RemoteContext::Ptr GetDefaultContext() override { - return _impl->GetDefaultContext(); - } - - ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map& config, - RemoteContext::Ptr context) override { - return _impl->LoadNetwork(network, config, context); - } - - ExecutableNetwork ImportNetwork(std::istream& networkModel, - const RemoteContext::Ptr& context, - const std::map& config) override { - return _impl->ImportNetwork(networkModel, context, config); - } - -private: - ~PluginBase() override {} -}; - -template -inline IInferencePlugin* make_ie_compatible_plugin(const Version& reported, std::shared_ptr impl) { - return new PluginBase(reported, impl); -} - -} // 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 debecc0..f432b63 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 @@ -85,7 +85,7 @@ public: * @param[in] plugin The plugin * @note Needed to correctly handle ownership between objects. */ - void SetPointerToPluginInternal(IInferencePluginInternal::Ptr plugin) { + void SetPointerToPlugin(IInferencePlugin::Ptr plugin) { _plugin = plugin; } @@ -130,10 +130,10 @@ protected: InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data /** - * @brief A pointer to a IInferencePluginInternal interface. + * @brief A pointer to a IInferencePlugin interface. * @note Needed to correctly handle ownership between objects. */ - IInferencePluginInternal::Ptr _plugin; + IInferencePlugin::Ptr _plugin; }; } // 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 a456629..1a0e7b2 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 @@ -45,26 +45,26 @@ static inline void parsePluginName(std::istream& networkModel) { } // namespace /** - * @brief Optimal implementation of IInferencePluginInternal interface to avoid duplication in all plugins + * @brief Optimal implementation of IInferencePlugin interface to avoid duplication in all plugins * @ingroup ie_dev_api_plugin_api */ -class InferencePluginInternal : public IInferencePluginInternal, - public std::enable_shared_from_this { -public: +class InferencePluginInternal : public IInferencePlugin { +protected: /** * @brief Destroys the object. */ ~InferencePluginInternal() override = default; +public: void LoadNetwork(IExecutableNetwork::Ptr& executableNetwork, const ICNNNetwork& network, const std::map& config) override { - cloneAndCreateExecutableNetwork(executableNetwork, network, config); + LoadNetworkImplPrivate(executableNetwork, network, config); } ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map& config, RemoteContext::Ptr context) override { IExecutableNetwork::Ptr executableNetworkPtr; - cloneAndCreateExecutableNetwork(executableNetworkPtr, network, config, context); + LoadNetworkImplPrivate(executableNetworkPtr, network, config, context); return ExecutableNetwork(executableNetworkPtr); } @@ -137,9 +137,43 @@ public: THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str; } +private: + /** + * @brief A helper method which clones a ICNNNetwork object, keeps InputsDataMap and OutputsDataMap data maps, + * and creates an IExecutableNetwork object + * @param executableNetwork An output executable network object + * @param network An input ICNNNetwork object used to create an executable network object + * @param config A map of string -> string configuration options. + * @param context An optional pointer to RemoteContext + */ + void LoadNetworkImplPrivate(IExecutableNetwork::Ptr& executableNetwork, const ICNNNetwork& network, + const std::map& config, + RemoteContext::Ptr context = nullptr) { + InputsDataMap networkInputs, networkInputsCloned; + OutputsDataMap networkOutputs, networkOutputsCloned; + network.getInputsInfo(networkInputs); + network.getOutputsInfo(networkOutputs); + copyInputOutputInfo(networkInputs, networkOutputs, networkInputsCloned, networkOutputsCloned); + + ExecutableNetworkInternal::Ptr impl; + if (nullptr == context) { + impl = LoadExeNetworkImpl(network, config); + } else { + impl = LoadExeNetworkImpl(network, context, config); + } + + impl->setNetworkInputs(networkInputsCloned); + impl->setNetworkOutputs(networkOutputsCloned); + impl->SetPointerToPlugin(shared_from_this()); + + executableNetwork.reset(new ExecutableNetworkBase(impl), [](details::IRelease* p) { + p->Release(); + }); + } + protected: /** - * @brief Creates an executable network from an pares network object, users can create as many networks as they need + * @brief Creates an executable network from a parsed network object, users can create as many networks as they need * and use them simultaneously (up to the limitation of the HW resources) * @note The function is used in * InferencePluginInternal::LoadNetwork(IExecutableNetwork::Ptr&, const ICNNNetwork&, const std::map&) @@ -152,7 +186,7 @@ protected: const std::map& config) = 0; /** - * @brief Creates an executable network using remove context from an pares network object, + * @brief Creates an executable network using remote context from a parsed network object, * users can create as many networks as they need and use them simultaneously (up to the limitation of the HW resources) * @note The function is used in * InferencePluginInternal::LoadNetwork(const ICNNNetwork&, const std::map&, RemoteContext::Ptr) @@ -171,42 +205,9 @@ protected: } /** - * @brief A helper method which clones a ICNNNetwork object, keeps InputsDataMap and OutputsDataMap data maps, - * and creates an IExecutableNetwork object - * @param executableNetwork An output executable network object - * @param network An input ICNNNetwork object used to create an executable network object - * @param config A map of string -> string configuration options. - * @param context An optional pointer to RemoteContext - */ - void cloneAndCreateExecutableNetwork(IExecutableNetwork::Ptr& executableNetwork, const ICNNNetwork& network, - const std::map& config, - RemoteContext::Ptr context = nullptr) { - InputsDataMap networkInputs, networkInputsCloned; - OutputsDataMap networkOutputs, networkOutputsCloned; - network.getInputsInfo(networkInputs); - network.getOutputsInfo(networkOutputs); - copyInputOutputInfo(networkInputs, networkOutputs, networkInputsCloned, networkOutputsCloned); - - ExecutableNetworkInternal::Ptr impl; - if (nullptr == context) { - impl = LoadExeNetworkImpl(network, config); - } else { - impl = LoadExeNetworkImpl(network, context, config); - } - - impl->setNetworkInputs(networkInputsCloned); - impl->setNetworkOutputs(networkOutputsCloned); - impl->SetPointerToPluginInternal(shared_from_this()); - - executableNetwork.reset(new ExecutableNetworkBase(impl), [](details::IRelease* p) { - p->Release(); - }); - } - - /** * @brief Creates an executable network from an previously exported network * @note The function is called from - * IInferencePluginInternal::ImportNetwork(std::istream&, const RemoteContext::Ptr&, const std::map&) + * IInferencePlugin::ImportNetwork(std::istream&, const RemoteContext::Ptr&, const std::map&) * performs common steps first and calls this plugin-dependent implementation after. * @param networkModel Reference to network model output stream * @param config A string -> string map of parameters 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 cf9ccf9..73be14f 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_iplugin_internal.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include @@ -84,21 +83,70 @@ static void copyInputOutputInfo(const InputsDataMap & networkInputs, const Outpu } /** - * @interface IInferencePluginInternal - * @brief An internal API of plugin to be implemented by a plugin, which is used in PluginBase forwarding mechanism + * @interface IInferencePlugin + * @brief An API of plugin to be implemented by a plugin * @ingroup ie_dev_api_plugin_api */ -class IInferencePluginInternal { +class IInferencePlugin : public details::IRelease, + public std::enable_shared_from_this { + class VersionStore : public Version { + std::string _dsc; + std::string _buildNumber; + + void copyFrom(const Version & v) { + _dsc = v.description; + _buildNumber = v.buildNumber; + description = _dsc.c_str(); + buildNumber = _buildNumber.c_str(); + apiVersion = v.apiVersion; + } + + public: + VersionStore() = default; + + explicit VersionStore(const Version& v) { + copyFrom(v); + } + + VersionStore & operator = (const VersionStore & v) { + if (&v != this) { + copyFrom(v); + } + return *this; + } + } _version; + +protected: + /** + * @brief Destroys the object. + */ + ~IInferencePlugin() override = default; + public: /** - * @brief A shared pointer to IInferencePluginInternal interface + * @brief A shared pointer to IInferencePlugin interface */ - using Ptr = std::shared_ptr; + using Ptr = std::shared_ptr; /** - * @brief Destroys the object. + * @brief Sets a plugin version + * @param version A version to set + */ + void SetVersion(const Version & version) { + _version = VersionStore(version); + } + + /** + * @brief Gets a plugin version + * @return A const InferenceEngine::Version object */ - virtual ~IInferencePluginInternal() = default; + Version GetVersion() const { + return _version; + } + + void Release() noexcept override { + delete this; + } /** * @brief Provides a name of a plugin @@ -218,7 +266,7 @@ public: virtual ICore* GetCore() const noexcept = 0; /** - * @brief Queries a plugin about support layers in network + * @brief Queries a plugin about supported layers in network * @param[in] network The network object to query * @param[in] config The map of configuration parameters * @param res The result of query operator containing supported layers map @@ -234,16 +282,16 @@ public: * @brief Defines the exported `CreatePluginEngine` function which is used to create a plugin instance * @ingroup ie_dev_api_plugin_api */ -#define IE_DEFINE_PLUGIN_CREATE_FUNCTION(PluginType, version, ...) \ - INFERENCE_PLUGIN_API(InferenceEngine::StatusCode) CreatePluginEngine( \ - InferenceEngine::IInferencePlugin *&plugin, \ - InferenceEngine::ResponseDesc *resp) noexcept { \ - try { \ - InferenceEngine::Version _version = version; \ - plugin = make_ie_compatible_plugin(_version, std::make_shared(__VA_ARGS__)); \ - return OK; \ - } \ - catch (std::exception &ex) { \ +#define IE_DEFINE_PLUGIN_CREATE_FUNCTION(PluginType, version, ...) \ + INFERENCE_PLUGIN_API(InferenceEngine::StatusCode) CreatePluginEngine( \ + InferenceEngine::IInferencePlugin *&plugin, \ + InferenceEngine::ResponseDesc *resp) noexcept { \ + try { \ + plugin = new PluginType(__VA_ARGS__); \ + plugin->SetVersion(version); \ + return OK; \ + } \ + catch (std::exception &ex) { \ return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what(); \ - } \ + } \ } diff --git a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp b/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp deleted file mode 100644 index 982cb90..0000000 --- a/inference-engine/src/plugin_api/cpp_interfaces/interface/ie_plugin.hpp +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief A header file for Main Inference Engine API - * - * @file ie_plugin.hpp - */ -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace InferenceEngine { - -/** - * @brief This class is a main plugin interface - */ -class INFERENCE_ENGINE_API_CLASS(IInferencePlugin) - : public details::IRelease { -public: - /** - * @brief Returns plugin version information - * - * @param versionInfo Pointer to version info. Is set by plugin - */ - virtual void GetVersion(const Version*& versionInfo) noexcept = 0; - - /** - * @brief Creates an executable network from a network object. User can create as many networks as they need and use - * them simultaneously (up to the limitation of the hardware resources) - * - * @param ret Reference to a shared ptr of the returned network interface - * @param network Network object acquired from Core::ReadNetwork - * @param config Map of pairs: (config parameter name, config parameter value) relevant only for this load operation - * @param resp Pointer to the response message that holds a description of an error if any occurred - * @return Status code of the operation. InferenceEngine::OK if succeeded - */ - virtual StatusCode LoadNetwork(IExecutableNetwork::Ptr& ret, const ICNNNetwork& network, - const std::map& config, ResponseDesc* resp) noexcept = 0; - - /** - * @brief Creates an executable network from a previously exported network - * - * @param ret Reference to a shared ptr of the returned network interface - * @param modelFileName Path to the location of the exported file - * @param config Map of pairs: (config parameter name, config parameter value) relevant only for this load - * operation* - * @param resp Pointer to the response message that holds a description of an error if any occurred - * @return Status code of the operation. InferenceEngine::OK if succeeded - */ - virtual StatusCode ImportNetwork(IExecutableNetwork::Ptr& ret, const std::string& modelFileName, - const std::map& config, ResponseDesc* resp) noexcept = 0; - - /** - * @brief Registers extension within the plugin - * - * @param extension Pointer to already loaded extension - * @param resp Pointer to the response message that holds a description of an error if any occurred - * @return Status code of the operation. InferenceEngine::OK if succeeded - */ - virtual StatusCode AddExtension(InferenceEngine::IExtensionPtr extension, - InferenceEngine::ResponseDesc* resp) noexcept = 0; - - /** - * @brief Sets configuration for plugin, acceptable keys can be found in ie_plugin_config.hpp - * - * @param config Map of pairs: (config parameter name, config parameter value) - * @param resp Pointer to the response message that holds a description of an error if any occurred - * @return Status code of the operation. InferenceEngine::OK if succeeded - */ - virtual StatusCode SetConfig(const std::map& config, ResponseDesc* resp) noexcept = 0; - - /** - * @brief Query plugin if it supports specified network with specified configuration - * - * @param network Network object to query - * @param config Map of pairs: (config parameter name, config parameter value) - * @param res Reference to query network result - */ - virtual void QueryNetwork(const ICNNNetwork& network, const std::map& config, - QueryNetworkResult& res) const noexcept { - (void)network; - (void)config; - res.rc = InferenceEngine::NOT_IMPLEMENTED; - } - - /** - * @brief Sets plugin name - * @param pluginName Plugin name to set - */ - virtual void SetName(const std::string& pluginName) noexcept = 0; - - /** - * @brief Returns plugin name - * @return Plugin name - */ - virtual std::string GetName() const noexcept = 0; - - /** - * @brief Sets pointer to ICore interface - * @param core Pointer to Core interface - */ - virtual void SetCore(ICore* core) noexcept = 0; - - /** - * @brief Gets refernce to ICore interface - * @return Reference to core interface - */ - virtual const ICore& GetCore() const = 0; - - /** - * @brief Gets configuration dedicated to plugin behaviour - * @param name - value of config corresponding to config key - * @param options - configuration details for config - * @return Value of config corresponding to config key - */ - virtual Parameter GetConfig(const std::string& name, const std::map& options) const = 0; - - /** - * @brief Gets general runtime metric for dedicated hardware - * @param name - metric name to request - * @param options - configuration details for metric - * @return Metric value corresponding to metric key - */ - virtual Parameter GetMetric(const std::string& name, const std::map& options) const = 0; - - /** - * @brief Creates a remote context instance based on a map of parameters - * @param[in] params The map of parameters - * @return A remote context object - */ - virtual RemoteContext::Ptr CreateContext(const ParamMap& params) = 0; - - /** - * @brief Provides a default remote context instance if supported by a plugin - * @return The default context. - */ - virtual RemoteContext::Ptr GetDefaultContext() = 0; - - /** - * @brief Wraps original method - * IInferencePlugin::LoadNetwork - * @param network - a network object acquired from InferenceEngine::Core::ReadNetwork - * @param config string-string map of config parameters relevant only for this load operation - * @param context - a pointer to plugin context derived from RemoteContext class used to - * execute the network - * @return Created Executable Network object - */ - virtual ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map& config, - RemoteContext::Ptr context) = 0; - - /** - * @brief Creates an executable network from an previously exported network using plugin implementation - * and removes Inference Engine magic and plugin name - * @param networkModel Reference to network model output stream - * @param config A string -> string map of parameters - * @return An Executable network - */ - virtual ExecutableNetwork ImportNetwork(std::istream& networkModel, - const std::map& config) = 0; - - /** - * @brief Creates an executable network from an previously exported network using plugin implementation - * and removes Inference Engine magic and plugin name - * @param networkModel Reference to network model output stream - * @param context - a pointer to plugin context derived from RemoteContext class used to - * execute the network - * @param config A string -> string map of parameters - * @return An Executable network - */ - virtual ExecutableNetwork ImportNetwork(std::istream& networkModel, - const RemoteContext::Ptr& context, - const std::map& config) = 0; - - /** - * @brief A default virtual destructor - */ - ~IInferencePlugin() override; -}; - -} // namespace InferenceEngine diff --git a/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp b/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp index 8c722db..9a67718 100644 --- a/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp +++ b/inference-engine/src/vpu/myriad_plugin/api/myriad_api.cpp @@ -3,7 +3,6 @@ // #include -#include #include "myriad_plugin.h" #include "myriad_mvnc_wraper.h" diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp index a150647..28e838b 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/inference-engine/tests/functional/inference_engine/executable_network.cpp b/inference-engine/tests/functional/inference_engine/executable_network.cpp index 405b6e4..f449c4c 100644 --- a/inference-engine/tests/functional/inference_engine/executable_network.cpp +++ b/inference-engine/tests/functional/inference_engine/executable_network.cpp @@ -3,7 +3,7 @@ // #include -#include "cpp_interfaces/base/ie_plugin_base.hpp" +#include using namespace ::testing; using namespace std; 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 4d8142f..d7432c0 100644 --- a/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/so_pointer_tests.cpp @@ -12,7 +12,7 @@ #include #include
#include
-#include +#include #include using namespace InferenceEngine; @@ -118,6 +118,7 @@ TEST_F(SymbolLoaderTests, instantiateSymbol) { std::shared_ptr sharedLoader(new SharedObjectLoader(name.c_str())); SymbolLoader loader(sharedLoader); IInferencePlugin * value = nullptr; - ASSERT_NE(nullptr, value = loader.instantiateSymbol(SOCreatorTrait::name)); + ASSERT_NE(nullptr, value = loader.instantiateSymbol( + SOCreatorTrait::name)); value->Release(); } diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp b/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp index c374af7..f1c54ae 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/empty.cpp @@ -7,10 +7,8 @@ #include "unit_test_utils/mocks/mock_ie_imemory_state.hpp" #include "unit_test_utils/mocks/mock_iexecutable_network.hpp" #include "unit_test_utils/mocks/mock_iinfer_request.hpp" -#include "unit_test_utils/mocks/mock_iinference_plugin.hpp" #include "unit_test_utils/mocks/mock_not_empty_icnn_network.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp" #include "unit_test_utils/mocks/cpp_interfaces/mock_task_executor.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_async_infer_request_default.hpp" @@ -26,6 +24,7 @@ #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_imemory_state_internal.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" #include "unit_test_utils/mocks/shape_infer/mock_input_controller.hpp" #include "unit_test_utils/mocks/shape_infer/mock_ishape_infer_impl.hpp" diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_iinference_plugin.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp similarity index 50% rename from inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_iinference_plugin.hpp rename to inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp index 0890ba7..36bc0e3 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_iinference_plugin.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp @@ -7,34 +7,22 @@ #include #include -#include "cpp_interfaces/interface/ie_plugin.hpp" +#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include -class MockIInferencePlugin : public InferenceEngine :: IInferencePlugin { +class MockIInferencePlugin : public InferenceEngine::IInferencePlugin { public: - MOCK_QUALIFIED_METHOD2(AddExtension, noexcept, InferenceEngine::StatusCode(InferenceEngine::IExtensionPtr, - InferenceEngine::ResponseDesc *resp)); - MOCK_QUALIFIED_METHOD1(GetVersion, noexcept, void(const InferenceEngine::Version *&)); - MOCK_QUALIFIED_METHOD0(Release, noexcept, void()); - MOCK_QUALIFIED_METHOD2(LoadNetwork, noexcept, InferenceEngine::StatusCode( - const InferenceEngine::ICNNNetwork &, InferenceEngine::ResponseDesc *resp)); - MOCK_QUALIFIED_METHOD4(LoadNetwork, noexcept, InferenceEngine::StatusCode( - InferenceEngine::IExecutableNetwork::Ptr &, - const InferenceEngine::ICNNNetwork &, - const std::map &, - InferenceEngine::ResponseDesc *)); - MOCK_QUALIFIED_METHOD4(ImportNetwork, noexcept, InferenceEngine::StatusCode( - InferenceEngine::IExecutableNetwork::Ptr &, - const std::string &, - const std::map &, - InferenceEngine::ResponseDesc *)); - MOCK_QUALIFIED_METHOD2(SetConfig, noexcept, InferenceEngine::StatusCode( - const std::map &, InferenceEngine::ResponseDesc *resp)); + MOCK_METHOD1(AddExtension, void(InferenceEngine::IExtensionPtr)); + MOCK_METHOD3(LoadNetwork, void(IExecutableNetwork::Ptr&, + const ICNNNetwork&, const std::map&)); + MOCK_METHOD2(ImportNetwork, IExecutableNetwork::Ptr( + const std::string&, const std::map&)); + MOCK_METHOD1(SetConfig, void(const std::map &)); MOCK_QUALIFIED_METHOD1(SetName, noexcept, void(const std::string&)); MOCK_QUALIFIED_METHOD0(GetName, const noexcept, std::string(void)); MOCK_QUALIFIED_METHOD1(SetCore, noexcept, void(InferenceEngine::ICore*)); - MOCK_QUALIFIED_METHOD0(GetCore, const, const InferenceEngine::ICore&(void)); + MOCK_QUALIFIED_METHOD0(GetCore, const noexcept, InferenceEngine::ICore *(void)); MOCK_QUALIFIED_METHOD2(GetConfig, const, InferenceEngine::Parameter( const std::string&, const std::map&)); MOCK_QUALIFIED_METHOD2(GetMetric, const, InferenceEngine::Parameter( diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp deleted file mode 100644 index be2f2ab..0000000 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include -#include -#include - -#include "ie_iexecutable_network.hpp" -#include "ie_icore.hpp" -#include "cpp/ie_executable_network.hpp" - - -class MockPluginImpl { - public: - MOCK_METHOD3(LoadExeNetwork, void(InferenceEngine::IExecutableNetwork::Ptr &, - const InferenceEngine::ICNNNetwork &, - const std::map &)); - - void LoadNetwork(InferenceEngine::IExecutableNetwork::Ptr &exeNetwork, - const InferenceEngine::ICNNNetwork &cnnNetwork, - const std::map &config) { - LoadExeNetwork(exeNetwork, cnnNetwork, config); - } - MOCK_METHOD1(AddExtension, void(InferenceEngine::IExtensionPtr ext_ptr)); - MOCK_METHOD1(SetConfig, void(const std::map &)); - MOCK_METHOD2(ImportNetwork, InferenceEngine::IExecutableNetwork::Ptr(const std::string &, const std::map &)); - InferenceEngine::ExecutableNetwork ImportNetwork(const std::istream&, const std::map &) {return {};} - MOCK_QUALIFIED_METHOD0(GetName, const noexcept, std::string(void)); - MOCK_QUALIFIED_METHOD1(SetName, noexcept, void(const std::string &)); - MOCK_QUALIFIED_METHOD0(GetCore, const noexcept, InferenceEngine::ICore*(void)); - MOCK_QUALIFIED_METHOD1(SetCore, noexcept, void(InferenceEngine::ICore*)); - - MOCK_CONST_METHOD2(GetConfig, InferenceEngine::Parameter(const std::string& name, - const std::map & options)); - MOCK_CONST_METHOD2(GetMetric, InferenceEngine::Parameter(const std::string& name, - const std::map & options)); - void QueryNetwork(const InferenceEngine::ICNNNetwork &network, - const std::map& config, InferenceEngine::QueryNetworkResult &res) const { } - - MOCK_METHOD1(CreateContext, InferenceEngine::RemoteContext::Ptr(const std::map & options)); - MOCK_METHOD0(GetDefaultContext, InferenceEngine::RemoteContext::Ptr(void)); - InferenceEngine::ExecutableNetwork LoadNetwork(const InferenceEngine::ICNNNetwork &, const std::map &, - InferenceEngine::RemoteContext::Ptr) { return{}; } - InferenceEngine::ExecutableNetwork ImportNetwork(const std::istream &networkModel, - const InferenceEngine::RemoteContext::Ptr &context, - const std::map &config = {}) { return{}; } -}; diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.cpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.cpp index a22f7c8..0b80070 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.cpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.cpp @@ -8,88 +8,32 @@ #include #include "mock_plugin.hpp" +#include #include "description_buffer.hpp" using namespace std; using namespace InferenceEngine; -#define ACTION_IF_NOT_NULL(action) (nullptr == _target) ? NOT_IMPLEMENTED : _target->action - MockPlugin::MockPlugin(InferenceEngine::IInferencePlugin *target) { _target = target; } -StatusCode MockPlugin::LoadNetwork(IExecutableNetwork::Ptr &ret, const ICNNNetwork &network, - const std::map &config, ResponseDesc *resp) noexcept { - return ACTION_IF_NOT_NULL(LoadNetwork(ret, network, config, resp)); -} - -void MockPlugin::Release() noexcept { - if (nullptr != _target) _target->Release(); - delete this; -} - -void MockPlugin::GetVersion(const Version *&versionInfo) noexcept { - versionInfo = &version; -} - -StatusCode MockPlugin::AddExtension(IExtensionPtr extension, InferenceEngine::ResponseDesc *resp) noexcept { - return NOT_IMPLEMENTED; -} - -StatusCode MockPlugin::SetConfig(const std::map &_config, ResponseDesc *resp) noexcept { - config = _config; - return InferenceEngine::OK; -} - -StatusCode -MockPlugin::ImportNetwork(IExecutableNetwork::Ptr &ret, const std::string &modelFileName, - const std::map &config, ResponseDesc *resp) noexcept { - return NOT_IMPLEMENTED; -} - -void MockPlugin::SetName(const std::string& pluginName) noexcept { -} - -std::string MockPlugin::GetName() const noexcept { - return {}; -} - -void MockPlugin::SetCore(ICore* core) noexcept { +void MockPlugin::SetConfig(const std::map& config) { + this->config = config; } -const ICore& MockPlugin::GetCore() const { - static ICore * core = nullptr; - return *core; -} - -Parameter MockPlugin::GetConfig(const std::string& name, const std::map& options) const { - return {}; -} - -Parameter MockPlugin::GetMetric(const std::string& name, const std::map& options) const { - return {}; -} - -RemoteContext::Ptr MockPlugin::CreateContext(const ParamMap& params) { - return {}; -} -RemoteContext::Ptr MockPlugin::GetDefaultContext() { - return {}; -} -ExecutableNetwork MockPlugin::LoadNetwork(const ICNNNetwork& network, const std::map& config, - RemoteContext::Ptr context) { - return {}; -} - -ExecutableNetwork MockPlugin::ImportNetwork(std::istream& networkModel, - const std::map& config) { - return {}; +void MockPlugin::LoadNetwork(IExecutableNetwork::Ptr &ret, const ICNNNetwork &network, + const std::map &config) { + if (_target) { + _target->LoadNetwork(ret, network, config); + } else { + THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str; + } } -ExecutableNetwork MockPlugin::ImportNetwork(std::istream& networkModel, - const RemoteContext::Ptr& context, - const std::map& config) { +ExecutableNetworkInternal::Ptr +MockPlugin::LoadExeNetworkImpl(const InferenceEngine::ICNNNetwork& network, + const std::map& config) { return {}; } diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.hpp index 6c3cda8..fc4c99b 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/mock_engine/mock_plugin.hpp @@ -7,53 +7,21 @@ #include #include -#include +#include #include -class MockPlugin : public InferenceEngine::IInferencePlugin { +class MockPlugin : public InferenceEngine::InferencePluginInternal { InferenceEngine::IInferencePlugin * _target = nullptr; - InferenceEngine::Version version; public: explicit MockPlugin(InferenceEngine::IInferencePlugin*target); - void GetVersion(const InferenceEngine::Version *& versionInfo) noexcept override; - - InferenceEngine::StatusCode AddExtension(InferenceEngine::IExtensionPtr extension, InferenceEngine::ResponseDesc *resp) noexcept override; - - InferenceEngine::StatusCode SetConfig(const std::map& config, - InferenceEngine::ResponseDesc* resp) noexcept override; - - - InferenceEngine::StatusCode - LoadNetwork(InferenceEngine::IExecutableNetwork::Ptr &ret, const InferenceEngine::ICNNNetwork &network, - const std::map &config, InferenceEngine::ResponseDesc *resp) noexcept override; - - InferenceEngine::StatusCode - ImportNetwork(InferenceEngine::IExecutableNetwork::Ptr &ret, const std::string &modelFileName, - const std::map &config, InferenceEngine::ResponseDesc *resp) noexcept override; - - void Release() noexcept override; - - void SetName(const std::string& pluginName) noexcept override; - std::string GetName() const noexcept override; - void SetCore(InferenceEngine::ICore* core) noexcept override; - const InferenceEngine::ICore& GetCore() const override; - InferenceEngine::Parameter - GetConfig(const std::string& name, const std::map& options) const override; - InferenceEngine::Parameter - GetMetric(const std::string& name, const std::map& options) const override; - InferenceEngine::RemoteContext::Ptr - CreateContext(const InferenceEngine::ParamMap& params) override; - InferenceEngine::RemoteContext::Ptr GetDefaultContext() override; - InferenceEngine::ExecutableNetwork - LoadNetwork(const InferenceEngine::ICNNNetwork& network, const std::map& config, - InferenceEngine::RemoteContext::Ptr context) override; - InferenceEngine::ExecutableNetwork - ImportNetwork(std::istream& networkModel, const std::map& config) override; - InferenceEngine::ExecutableNetwork - ImportNetwork(std::istream& networkModel, const InferenceEngine::RemoteContext::Ptr& context, - const std::map& config) override; + void SetConfig(const std::map& config) override; + void LoadNetwork(InferenceEngine::IExecutableNetwork::Ptr &ret, const InferenceEngine::ICNNNetwork &network, + const std::map &config) override; + ExecutableNetworkInternal::Ptr + LoadExeNetworkImpl(const InferenceEngine::ICNNNetwork& network, + const std::map& config) override; std::map config; }; diff --git a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_base_test.cpp b/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_base_test.cpp deleted file mode 100644 index a46b50b..0000000 --- a/inference-engine/tests/unit/inference_engine/cpp_interfaces/ie_plugin_base_test.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -#include -#include -#include - -#include "unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp" - -using namespace ::testing; -using namespace std; -using namespace InferenceEngine; -using namespace InferenceEngine::details; - -IE_SUPPRESS_DEPRECATED_START -class PluginBaseTests: public ::testing::Test { -protected: - std::shared_ptr mock_impl; - shared_ptr plugin; - ResponseDesc dsc; - virtual void TearDown() { - } - virtual void SetUp() { - mock_impl.reset(new MockPluginImpl()); - plugin = details::shared_from_irelease(make_ie_compatible_plugin({{2, 1}, "test", "version"}, mock_impl)); - } -}; - -TEST_F(PluginBaseTests, canReportVersion) { - const Version *V; - plugin->GetVersion(V); - - EXPECT_STREQ(V->buildNumber, "test"); - EXPECT_STREQ(V->description, "version"); - EXPECT_EQ(V->apiVersion.major, 2); - EXPECT_EQ(V->apiVersion.minor, 1); -} - -TEST_F(PluginBaseTests, canForwardLoadExeNetwork) { - EXPECT_CALL(*mock_impl.get(), LoadExeNetwork(_, _, _)).Times(1); - ICNNNetwork * network = nullptr; - IExecutableNetwork::Ptr exeNetwork = nullptr; - ASSERT_EQ(OK, plugin->LoadNetwork(exeNetwork, *network, {}, &dsc)); -} - - -TEST_F(PluginBaseTests, canReportErrorInLoadExeNetwork) { - EXPECT_CALL(*mock_impl.get(), LoadExeNetwork(_, _, _)).WillOnce(Throw(std::runtime_error("compare"))); - - ICNNNetwork * network = nullptr; - IExecutableNetwork::Ptr exeNetwork = nullptr; - ASSERT_NE(plugin->LoadNetwork(exeNetwork, *network, {}, &dsc), OK); - ASSERT_STREQ(dsc.msg, "compare"); -} - -TEST_F(PluginBaseTests, canCatchUnknownErrorInLoadExeNetwork) { - EXPECT_CALL(*mock_impl.get(), LoadExeNetwork(_, _, _)).WillOnce(Throw(5)); - ICNNNetwork * network = nullptr; - IExecutableNetwork::Ptr exeNetwork = nullptr; - ASSERT_EQ(UNEXPECTED, plugin->LoadNetwork(exeNetwork, *network, {}, nullptr)); -} - -TEST_F(PluginBaseTests, canForwarSetConfig) { - const std::map config; - EXPECT_CALL(*mock_impl.get(), SetConfig(Ref(config))).Times(1); - ASSERT_EQ(OK, plugin->SetConfig(config, &dsc)); -} - -TEST_F(PluginBaseTests, canReportErrorInSetConfig) { - const std::map config; - EXPECT_CALL(*mock_impl.get(), SetConfig(_)).WillOnce(Throw(std::runtime_error("error"))); - - ASSERT_NE(OK, plugin->SetConfig(config, &dsc)); - ASSERT_STREQ(dsc.msg, "error"); -} - -TEST_F(PluginBaseTests, canCatchUnknownErrorInSetConfig) { - EXPECT_CALL(*mock_impl.get(), SetConfig(_)).WillOnce(Throw(5)); - const std::map config; - ASSERT_EQ(UNEXPECTED, plugin->SetConfig(config, nullptr)); -} - -TEST(InferencePluginTests, throwsOnNullptrCreation) { - InferenceEnginePluginPtr nulptr; - InferencePlugin plugin; - ASSERT_THROW(plugin = InferencePlugin(nulptr), details::InferenceEngineException); -} - -TEST(InferencePluginTests, throwsOnUninitializedGetVersion) { - InferencePlugin plg; - ASSERT_THROW(plg.GetVersion(), details::InferenceEngineException); -} - -TEST(InferencePluginTests, throwsOnUninitializedLoadNetwork) { - InferencePlugin plg; - QueryNetworkResult r; - ASSERT_THROW(plg.LoadNetwork(CNNNetwork(), {}), details::InferenceEngineException); -} - -TEST(InferencePluginTests, throwsOnUninitializedImportNetwork) { - InferencePlugin plg; - ASSERT_THROW(plg.ImportNetwork({}, {}), details::InferenceEngineException); -} - -TEST(InferencePluginTests, throwsOnUninitializedAddExtension) { - InferencePlugin plg; - ASSERT_THROW(plg.AddExtension(IExtensionPtr()), details::InferenceEngineException); -} - -TEST(InferencePluginTests, throwsOnUninitializedSetConfig) { - InferencePlugin plg; - ASSERT_THROW(plg.SetConfig({{}}), details::InferenceEngineException); -} - -TEST(InferencePluginTests, nothrowsUninitializedCast) { - InferencePlugin plg; - ASSERT_NO_THROW(auto plgPtr = static_cast(plg)); -} -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 de0097b..ee05fa1 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,10 +6,9 @@ #include #include -#include +#include #include "unit_test_utils/mocks/mock_not_empty_icnn_network.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/mock_plugin_impl.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_executable_thread_safe_default.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinfer_request_internal.hpp" @@ -21,9 +20,7 @@ using namespace InferenceEngine::details; class InferenceEnginePluginInternalTest : public ::testing::Test { protected: - IE_SUPPRESS_DEPRECATED_START shared_ptr plugin; - IE_SUPPRESS_DEPRECATED_END shared_ptr mock_plugin_impl; shared_ptr mockExeNetworkInternal; shared_ptr mockExeNetworkTS; @@ -45,9 +42,9 @@ protected: pluginId = "TEST"; mock_plugin_impl.reset(new MockInferencePluginInternal()); mock_plugin_impl->SetName(pluginId); - plugin = details::shared_from_irelease(make_ie_compatible_plugin({{2, 1}, "test", "version"}, mock_plugin_impl)); + plugin = std::static_pointer_cast(mock_plugin_impl); mockExeNetworkInternal = make_shared(); - mockExeNetworkInternal->SetPointerToPluginInternal(mock_plugin_impl); + mockExeNetworkInternal->SetPointerToPlugin(mock_plugin_impl); } void getInferRequestWithMockImplInside(IInferRequest::Ptr &request) { @@ -60,10 +57,7 @@ protected: mockExeNetworkTS = make_shared(); EXPECT_CALL(*mock_plugin_impl.get(), LoadExeNetworkImpl(_, _)).WillOnce(Return(mockExeNetworkTS)); EXPECT_CALL(*mockExeNetworkTS.get(), CreateInferRequestImpl(_, _)).WillOnce(Return(mockInferRequestInternal)); - IE_SUPPRESS_DEPRECATED_START - sts = plugin->LoadNetwork(exeNetwork, mockNotEmptyNet, {}, &dsc); - IE_SUPPRESS_DEPRECATED_END - ASSERT_EQ((int) StatusCode::OK, sts) << dsc.msg; + plugin->LoadNetwork(exeNetwork, mockNotEmptyNet, {}); ASSERT_NE(exeNetwork, nullptr) << dsc.msg; sts = exeNetwork->CreateInferRequest(request, &dsc); ASSERT_EQ((int) StatusCode::OK, sts) << dsc.msg; @@ -163,3 +157,39 @@ TEST_F(InferenceEnginePluginInternalTest, pluginInternalEraseMagicAndNameWhenImp mock_plugin_impl->importedString = {}; } + +TEST(InferencePluginTests, throwsOnNullptrCreation) { + InferenceEnginePluginPtr nulptr; + InferencePlugin plugin; + ASSERT_THROW(plugin = InferencePlugin(nulptr), details::InferenceEngineException); +} + +TEST(InferencePluginTests, throwsOnUninitializedGetVersion) { + InferencePlugin plg; + ASSERT_THROW(plg.GetVersion(), details::InferenceEngineException); +} + +TEST(InferencePluginTests, throwsOnUninitializedLoadNetwork) { + InferencePlugin plg; + ASSERT_THROW(plg.LoadNetwork(CNNNetwork(), {}), details::InferenceEngineException); +} + +TEST(InferencePluginTests, throwsOnUninitializedImportNetwork) { + InferencePlugin plg; + ASSERT_THROW(plg.ImportNetwork({}, {}), details::InferenceEngineException); +} + +TEST(InferencePluginTests, throwsOnUninitializedAddExtension) { + InferencePlugin plg; + ASSERT_THROW(plg.AddExtension(IExtensionPtr()), details::InferenceEngineException); +} + +TEST(InferencePluginTests, throwsOnUninitializedSetConfig) { + InferencePlugin plg; + ASSERT_THROW(plg.SetConfig({{}}), details::InferenceEngineException); +} + +TEST(InferencePluginTests, nothrowsUninitializedCast) { + InferencePlugin plg; + ASSERT_NO_THROW(auto plgPtr = static_cast(plg)); +} 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 4845bc6..fe612fb 100644 --- a/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp +++ b/inference-engine/tests/unit/inference_engine/ie_plugin_ptr.cpp @@ -7,7 +7,7 @@ #include "details/ie_so_loader.h" #include "unit_test_utils/mocks/mock_engine/mock_plugin.hpp" -#include "unit_test_utils/mocks/mock_iinference_plugin.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp" using namespace std; @@ -15,8 +15,6 @@ using namespace InferenceEngine; using namespace ::testing; using namespace InferenceEngine::details; -IE_SUPPRESS_DEPRECATED_START - class PluginTest: public ::testing::Test { protected: unique_ptr sharedObjectLoader; @@ -39,11 +37,12 @@ protected: return ptr; } - MockIInferencePlugin engine; + MockInferencePluginInternal2 engine; }; TEST_F(PluginTest, canCreatePlugin) { - auto ptr = make_std_function("CreatePluginEngineProxy"); + auto ptr = make_std_function("CreatePluginEngineProxy"); unique_ptr> smart_ptr(ptr(nullptr), [](IInferencePlugin *p) { p->Release(); @@ -65,16 +64,13 @@ InferenceEnginePluginPtr PluginTest::getPtr() { TEST_F(PluginTest, canSetConfiguration) { InferenceEnginePluginPtr ptr = getPtr(); - // TODO: dynamic->reinterpret because of calng/gcc cannot + // TODO: dynamic->reinterpret because of clang/gcc cannot // dynamically cast this MOCK object ASSERT_TRUE(reinterpret_cast(*ptr)->config.empty()); - ResponseDesc resp; std::map config = { { "key", "value" } }; - ASSERT_EQ(ptr->SetConfig(config, &resp), OK); + ASSERT_NO_THROW(ptr->SetConfig(config)); config.clear(); ASSERT_STREQ(reinterpret_cast(*ptr)->config["key"].c_str(), "value"); } - -IE_SUPPRESS_DEPRECATED_END \ No newline at end of file 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 152c7b5..f480493 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 @@ -16,7 +16,6 @@ #include "helpers/myriad_devices.hpp" #include
-#include #include using namespace std; diff --git a/inference-engine/tests_deprecated/functional/mkldnn/extensions_tests/extensions_test.cpp b/inference-engine/tests_deprecated/functional/mkldnn/extensions_tests/extensions_test.cpp index 3ced259..2c456ef 100644 --- a/inference-engine/tests_deprecated/functional/mkldnn/extensions_tests/extensions_test.cpp +++ b/inference-engine/tests_deprecated/functional/mkldnn/extensions_tests/extensions_test.cpp @@ -193,16 +193,12 @@ class smoke_ExtensionTest : public TestsCommon, protected: void checkExtensionRemoved(extension_params p) { try { - StatusCode sts; - ResponseDesc resp; std::unique_ptr score_engine; score_engine.reset(new InferenceEnginePluginPtr(make_plugin_name(p.plugin()).c_str())); - sts = (*score_engine)->SetConfig(p.config, &resp); - ASSERT_TRUE(sts == OK) << resp.msg; + (*score_engine)->SetConfig(p.config); ASSERT_EQ(p.extension.use_count(), 2); - sts = (*score_engine)->AddExtension(p.extension, &resp); - ASSERT_TRUE(sts == OK) << resp.msg; + (*score_engine)->AddExtension(p.extension); // multi-device holds additional reference of the extension ptr ASSERT_EQ(p.extension.use_count(), p.pluginName.find("Multi")==std::string::npos ? 3 : 4); score_engine.reset(); @@ -214,21 +210,16 @@ protected: } void checkExtensionNotRemovedFromAnotherEngineObject(extension_params p) { try { - StatusCode sts; - ResponseDesc resp; std::unique_ptr score_engine1; score_engine1.reset(new InferenceEnginePluginPtr(make_plugin_name(p.plugin()).c_str())); - sts = (*score_engine1)->SetConfig(p.config, &resp); - ASSERT_TRUE(sts == OK) << resp.msg; - + (*score_engine1)->SetConfig(p.config); + std::unique_ptr score_engine2; score_engine2.reset(new InferenceEnginePluginPtr(make_plugin_name(p.plugin()).c_str())); - sts = (*score_engine2)->SetConfig(p.config, &resp); - ASSERT_TRUE(sts == OK) << resp.msg; + (*score_engine2)->SetConfig(p.config); ASSERT_EQ(p.extension.use_count(), 2); - sts = (*score_engine1)->AddExtension(p.extension, &resp); - ASSERT_TRUE(sts == OK) << resp.msg; + (*score_engine1)->AddExtension(p.extension); // multi-device holds additional reference of the extension ptr ASSERT_EQ(p.extension.use_count(), p.pluginName.find("Multi")==std::string::npos ? 3 : 4); score_engine2.reset(); diff --git a/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp b/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp index 59c5565..f9af555 100644 --- a/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp +++ b/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.cpp @@ -480,10 +480,10 @@ void GNAPluginAOTMatcher :: match() { } -void GNADumpXNNMatcher::load(GNAPlugin & plugin) { +void GNADumpXNNMatcher::load(std::shared_ptr & plugin) { // matching gna DumpXNN forward call. - plugin = GNAPlugin(_env.config); + plugin = std::make_shared(_env.config); auto loadNetworkFromIR = [&]() { MockICNNNetwork net; @@ -501,11 +501,11 @@ void GNADumpXNNMatcher::load(GNAPlugin & plugin) { _env.cb(network); } - plugin.LoadNetwork(network); + plugin->LoadNetwork(network); }; auto loadNetworkFromAOT = [&]() { - plugin.ImportNetwork(_env.importedModelFileName); + plugin->ImportNetwork(_env.importedModelFileName); }; auto loadNetwork = [&]() { @@ -537,7 +537,7 @@ void GNADumpXNNMatcher::match() { try { // matching gna DumpXNN forward call. - GNAPluginNS::GNAPlugin plugin; + auto plugin = std::make_shared(); load(plugin); } catch(std::exception &ex) { diff --git a/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.hpp b/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.hpp index 190f331..0470a61 100644 --- a/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.hpp +++ b/inference-engine/tests_deprecated/unit/engines/gna/gna_matcher.hpp @@ -484,7 +484,7 @@ class GNADumpXNNMatcher : public GNATestConfigurability { protected: bool match_in_dctor = true; - void load(GNAPluginNS::GNAPlugin & plugin); + void load(std::shared_ptr & plugin); void match(); }; diff --git a/inference-engine/tests_deprecated/unit/engines/vpu/mvnc/pthread_semaphore_tests.cpp b/inference-engine/tests_deprecated/unit/engines/vpu/mvnc/pthread_semaphore_tests.cpp index 8404cd9..78aa84f 100644 --- a/inference-engine/tests_deprecated/unit/engines/vpu/mvnc/pthread_semaphore_tests.cpp +++ b/inference-engine/tests_deprecated/unit/engines/vpu/mvnc/pthread_semaphore_tests.cpp @@ -248,7 +248,7 @@ TEST_P(PThreadBinSemaphoreTest, WillBlockWhenAcquiringSemaTwice2) { th.join(); } -TEST_P(PThreadBinSemaphoreTest, DestroyAcquireadSemaResultedInError) { +TEST_P(PThreadBinSemaphoreTest, DestroyAcquiredSemaResultedInError) { ASSERT_EQ(0, invoke_wait()); // semaphore deleted - since not blocked, even if counter is 0 -- 2.7.4