Fixed mock_engine for proxy tests (#17431)

* Fixed mock_engine for proxy tests

* Fixed some caching tests

* FIxed build

* Fixed CoreThreading tests

* Try to fix crash in functional tests

* Fixed typo

* Fixed typo

* Small change

* Remove shared pointer from MockPluginWrapper

* Small fixes

* Do not throw an exception from device_supports_cache_dir
This commit is contained in:
Ilya Churaev 2023-05-17 11:15:28 +04:00 committed by GitHub
parent 96a80ffc3d
commit 92a0108f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 210 additions and 151 deletions

View File

@ -126,9 +126,6 @@ GetSupportedNodes(const std::shared_ptr<const ov::Model>& model,
*/ */
class INFERENCE_ENGINE_API_CLASS(IInferencePlugin) : public std::enable_shared_from_this<IInferencePlugin> { class INFERENCE_ENGINE_API_CLASS(IInferencePlugin) : public std::enable_shared_from_this<IInferencePlugin> {
class VersionStore : public Version { class VersionStore : public Version {
std::string _dsc;
std::string _buildNumber;
void copyFrom(const Version& v); void copyFrom(const Version& v);
public: public:

View File

@ -23,7 +23,7 @@ namespace ov {
* @brief Minimal ICore interface to allow plugin to get information from Core OpenVINO class. * @brief Minimal ICore interface to allow plugin to get information from Core OpenVINO class.
* @ingroup ov_dev_api_plugin_api * @ingroup ov_dev_api_plugin_api
*/ */
class ICore { class OPENVINO_RUNTIME_API ICore {
public: public:
/** /**
* @brief Reads IR xml and bin (with the same name) files * @brief Reads IR xml and bin (with the same name) files

View File

@ -86,10 +86,8 @@ OutputsDataMap copyInfo(const OutputsDataMap& networkOutputs) {
IInferencePlugin::IInferencePlugin() : _executorManager(InferenceEngine::executorManager()), _isNewAPI(true) {} IInferencePlugin::IInferencePlugin() : _executorManager(InferenceEngine::executorManager()), _isNewAPI(true) {}
void IInferencePlugin::VersionStore::copyFrom(const Version& v) { void IInferencePlugin::VersionStore::copyFrom(const Version& v) {
_dsc = v.description; description = v.description;
_buildNumber = v.buildNumber; buildNumber = v.buildNumber;
description = _dsc.c_str();
buildNumber = _buildNumber.c_str();
apiVersion = v.apiVersion; apiVersion = v.apiVersion;
} }

View File

@ -1126,7 +1126,13 @@ bool ov::CoreImpl::device_supports_model_caching(const ov::Plugin& plugin) const
} }
bool ov::CoreImpl::device_supports_cache_dir(const ov::Plugin& plugin) const { bool ov::CoreImpl::device_supports_cache_dir(const ov::Plugin& plugin) const {
return util::contains(plugin.get_property(ov::supported_properties), ov::cache_dir); try {
return util::contains(plugin.get_property(ov::supported_properties), ov::cache_dir);
} catch (const InferenceEngine::NotImplemented&) {
return false;
} catch (const ov::NotImplemented&) {
return false;
}
} }
ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model_and_cache(const std::shared_ptr<const ov::Model>& model, ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model_and_cache(const std::shared_ptr<const ov::Model>& model,

View File

@ -6,139 +6,212 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <memory>
#include <mutex>
#include <queue>
#include <string> #include <string>
#include <utility> #include <utility>
#include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "description_buffer.hpp" #include "description_buffer.hpp"
#include "ie_icore.hpp"
#include "openvino/core/except.hpp"
#include "openvino/runtime/common.hpp" #include "openvino/runtime/common.hpp"
#include "openvino/runtime/icore.hpp"
#include "openvino/runtime/iplugin.hpp"
using namespace std; class MockInternalPlugin : public ov::IPlugin {
using namespace InferenceEngine; ov::IPlugin* m_plugin;
std::shared_ptr<ov::IPlugin> m_converted_plugin;
InferenceEngine::IInferencePlugin* m_old_plugin;
ov::AnyMap config;
MockPlugin::MockPlugin(InferenceEngine::IInferencePlugin* target) { public:
_target = target; explicit MockInternalPlugin(InferenceEngine::IInferencePlugin* target) : m_old_plugin(target) {
} std::shared_ptr<InferenceEngine::IInferencePlugin> shared_target(target,
[](InferenceEngine::IInferencePlugin*) {});
m_converted_plugin = InferenceEngine::convert_plugin(shared_target);
m_plugin = m_converted_plugin.get();
}
explicit MockInternalPlugin(ov::IPlugin* target) : m_plugin(target) {}
explicit MockInternalPlugin() = default;
void MockPlugin::SetConfig(const std::map<std::string, std::string>& _config) { std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
this->config = _config; const ov::AnyMap& properties) const override {
if (_target) { if (m_plugin)
_target->SetConfig(config); return m_plugin->compile_model(model, properties);
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> compile_model(const std::string& model_path,
const ov::AnyMap& properties) const override {
if (m_plugin)
return m_plugin->compile_model(model_path, properties);
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties,
const ov::RemoteContext& context) const override {
if (m_plugin)
return m_plugin->compile_model(model, properties, context);
OPENVINO_NOT_IMPLEMENTED;
}
void set_property(const ov::AnyMap& properties) override {
config = properties;
if (m_plugin) {
m_plugin->set_property(config);
}
}
ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override {
if (m_plugin)
return m_plugin->get_property(name, arguments);
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override {
if (m_plugin)
return m_plugin->create_context(remote_properties);
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override {
if (m_plugin)
return m_plugin->get_default_context(remote_properties);
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model, const ov::AnyMap& properties) const override {
if (m_plugin)
return m_plugin->import_model(model, properties);
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::RemoteContext& context,
const ov::AnyMap& properties) const override {
if (m_plugin)
return m_plugin->import_model(model, context, properties);
OPENVINO_NOT_IMPLEMENTED;
}
ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override {
if (m_plugin)
return m_plugin->query_model(model, properties);
OPENVINO_NOT_IMPLEMENTED;
}
void set_parameters_if_need(const std::shared_ptr<ov::ICore>& core, const std::string& dev_name) const {
if (m_plugin) {
if (!m_plugin->get_core() && core) {
m_plugin->set_core(core);
}
if (m_plugin->get_device_name().empty()) {
m_plugin->set_device_name(dev_name);
}
}
if (m_old_plugin) {
if (!m_old_plugin->GetCore() && core) {
auto old_core = std::static_pointer_cast<InferenceEngine::ICore>(core);
m_old_plugin->SetCore(old_core);
}
if (m_old_plugin->GetName().empty()) {
m_old_plugin->SetName(dev_name);
}
}
}
};
void MockPlugin::set_parameters_if_need() const {
auto core = get_core();
if (auto internal_plugin = std::dynamic_pointer_cast<const MockInternalPlugin>(m_plugin)) {
internal_plugin->set_parameters_if_need(core, get_device_name());
} }
} }
Parameter MockPlugin::GetMetric(const std::string& name, MockPlugin::MockPlugin(const std::shared_ptr<ov::IPlugin>& target) : m_plugin(target) {
const std::map<std::string, InferenceEngine::Parameter>& options) const { OPENVINO_ASSERT(m_plugin);
if (_target) {
return _target->GetMetric(name, options);
} else {
IE_THROW(NotImplemented);
}
} }
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadNetwork( void MockPlugin::set_property(const ov::AnyMap& properties) {
const CNNNetwork& network, set_parameters_if_need();
const std::map<std::string, std::string>& config) { m_plugin->set_property(properties);
if (_target) {
return _target->LoadNetwork(network, config);
} else {
IE_THROW(NotImplemented);
}
} }
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadNetwork( ov::Any MockPlugin::get_property(const std::string& name, const ov::AnyMap& arguments) const {
const CNNNetwork& network, set_parameters_if_need();
const std::map<std::string, std::string>& config, return m_plugin->get_property(name, arguments);
const std::shared_ptr<RemoteContext>& context) {
if (_target) {
return _target->LoadNetwork(network, config, context);
} else {
IE_THROW(NotImplemented);
}
} }
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadNetwork( std::shared_ptr<ov::ICompiledModel> MockPlugin::compile_model(const std::shared_ptr<const ov::Model>& model,
const std::string& modelPath, const ov::AnyMap& properties) const {
const std::map<std::string, std::string>& config) { set_parameters_if_need();
if (_target) { return m_plugin->compile_model(model, properties);
return _target->LoadNetwork(modelPath, config);
} else {
return InferenceEngine::IInferencePlugin::LoadNetwork(modelPath, config);
}
} }
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadExeNetworkImpl( std::shared_ptr<ov::ICompiledModel> MockPlugin::compile_model(const std::string& model_path,
const CNNNetwork& network, const ov::AnyMap& properties) const {
const std::map<std::string, std::string>& config) { set_parameters_if_need();
return {}; return m_plugin->compile_model(model_path, properties);
} }
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::ImportNetwork( std::shared_ptr<ov::ICompiledModel> MockPlugin::compile_model(const std::shared_ptr<const ov::Model>& model,
std::istream& networkModel, const ov::AnyMap& properties,
const std::map<std::string, std::string>& config) { const ov::RemoteContext& context) const {
if (_target) { set_parameters_if_need();
return _target->ImportNetwork(networkModel, config); return m_plugin->compile_model(model, properties, context);
} else {
IE_THROW(NotImplemented);
}
} }
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::ImportNetwork( std::shared_ptr<ov::IRemoteContext> MockPlugin::create_context(const ov::AnyMap& remote_properties) const {
std::istream& networkModel, set_parameters_if_need();
const std::shared_ptr<InferenceEngine::RemoteContext>& context, return m_plugin->create_context(remote_properties);
const std::map<std::string, std::string>& config) {
if (_target) {
return _target->ImportNetwork(networkModel, context, config);
} else {
IE_THROW(NotImplemented);
}
} }
std::shared_ptr<InferenceEngine::RemoteContext> MockPlugin::GetDefaultContext(const InferenceEngine::ParamMap& params) { std::shared_ptr<ov::IRemoteContext> MockPlugin::get_default_context(const ov::AnyMap& remote_properties) const {
if (_target) { set_parameters_if_need();
return _target->GetDefaultContext(params); return m_plugin->get_default_context(remote_properties);
} else {
IE_THROW(NotImplemented);
}
} }
InferenceEngine::QueryNetworkResult MockPlugin::QueryNetwork(const InferenceEngine::CNNNetwork& network, std::shared_ptr<ov::ICompiledModel> MockPlugin::import_model(std::istream& model, const ov::AnyMap& properties) const {
const std::map<std::string, std::string>& config) const { set_parameters_if_need();
if (_target) { return m_plugin->import_model(model, properties);
return _target->QueryNetwork(network, config); }
} else { std::shared_ptr<ov::ICompiledModel> MockPlugin::import_model(std::istream& model,
IE_THROW(NotImplemented); const ov::RemoteContext& context,
} const ov::AnyMap& properties) const {
set_parameters_if_need();
return m_plugin->import_model(model, context, properties);
}
ov::SupportedOpsMap MockPlugin::query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const {
set_parameters_if_need();
return m_plugin->query_model(model, properties);
} }
void MockPlugin::SetCore(std::weak_ptr<InferenceEngine::ICore> core) noexcept { std::queue<std::shared_ptr<ov::IPlugin>> targets;
if (_target) { std::mutex targets_mutex;
_target->SetCore(core);
}
InferenceEngine::IInferencePlugin::SetCore(core);
}
void MockPlugin::SetName(const std::string& name) noexcept {
if (_target) {
_target->SetName(name);
}
InferenceEngine::IInferencePlugin::SetName(name);
}
std::string MockPlugin::GetName() const noexcept {
if (_target) {
return _target->GetName();
}
return InferenceEngine::IInferencePlugin::GetName();
}
InferenceEngine::IInferencePlugin* __target = nullptr;
OPENVINO_PLUGIN_API void CreatePluginEngine(std::shared_ptr<ov::IPlugin>& plugin) { OPENVINO_PLUGIN_API void CreatePluginEngine(std::shared_ptr<ov::IPlugin>& plugin) {
IInferencePlugin* p = nullptr; std::shared_ptr<ov::IPlugin> internal_plugin;
std::swap(__target, p); if (targets.empty()) {
plugin = convert_plugin(std::make_shared<MockPlugin>(p)); internal_plugin = std::make_shared<MockInternalPlugin>();
} else {
std::lock_guard<std::mutex> lock(targets_mutex);
internal_plugin = targets.front();
targets.pop();
}
plugin = std::make_shared<MockPlugin>(internal_plugin);
} }
OPENVINO_PLUGIN_API void InjectProxyEngine(InferenceEngine::IInferencePlugin* target) { OPENVINO_PLUGIN_API void InjectProxyEngine(InferenceEngine::IInferencePlugin* target) {
__target = target; std::lock_guard<std::mutex> lock(targets_mutex);
targets.push(std::make_shared<MockInternalPlugin>(target));
}
OPENVINO_PLUGIN_API void InjectPlugin(ov::IPlugin* target) {
std::lock_guard<std::mutex> lock(targets_mutex);
targets.push(std::make_shared<MockInternalPlugin>(target));
} }

View File

@ -7,56 +7,41 @@
#include <map> #include <map>
#include <string> #include <string>
#include <cpp_interfaces/interface/ie_iplugin_internal.hpp> #include "openvino/runtime/iplugin.hpp"
#include <ie_icore.hpp>
class MockPlugin : public InferenceEngine::IInferencePlugin { namespace InferenceEngine {
InferenceEngine::IInferencePlugin * _target = nullptr; class IInferencePlugin;
}
class MockPlugin : public ov::IPlugin {
std::shared_ptr<ov::IPlugin> m_plugin;
void set_parameters_if_need() const;
public: public:
explicit MockPlugin(InferenceEngine::IInferencePlugin*target); explicit MockPlugin(const std::shared_ptr<ov::IPlugin>& target);
void SetConfig(const std::map<std::string, std::string>& config) override; std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> std::shared_ptr<ov::ICompiledModel> compile_model(const std::string& model_path,
LoadNetwork(const InferenceEngine::CNNNetwork &network, const ov::AnyMap& properties) const override;
const std::map<std::string, std::string> &config) override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
LoadNetwork(const InferenceEngine::CNNNetwork& network, const ov::AnyMap& properties,
const std::map<std::string, std::string>& config, const ov::RemoteContext& context) const override;
const std::shared_ptr<InferenceEngine::RemoteContext>& context) override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> void set_property(const ov::AnyMap& properties) override;
LoadExeNetworkImpl(const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config) override;
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override;
LoadNetwork(const std::string &modelPath,
const std::map<std::string, std::string> &config) override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> std::shared_ptr<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override;
ImportNetwork(std::istream& networkModel,
const std::map<std::string, std::string>& config) override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> std::shared_ptr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override;
ImportNetwork(std::istream& networkModel,
const std::shared_ptr<InferenceEngine::RemoteContext>& context,
const std::map<std::string, std::string>& config) override;
InferenceEngine::Parameter GetMetric(const std::string& name, std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model, const ov::AnyMap& properties) const override;
const std::map<std::string, InferenceEngine::Parameter>& options) const override; std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::RemoteContext& context,
std::shared_ptr<InferenceEngine::RemoteContext> GetDefaultContext(const InferenceEngine::ParamMap& params) override; const ov::AnyMap& properties) const override;
ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>& model,
InferenceEngine::QueryNetworkResult QueryNetwork(const InferenceEngine::CNNNetwork& network, const ov::AnyMap& properties) const override;
const std::map<std::string, std::string>& config) const override;
void SetCore(std::weak_ptr<InferenceEngine::ICore> core) noexcept override;
void SetName(const std::string& name) noexcept override;
std::string GetName() const noexcept override;
std::map<std::string, std::string> config;
}; };