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 VersionStore : public Version {
std::string _dsc;
std::string _buildNumber;
void copyFrom(const Version& v);
public:

View File

@ -23,7 +23,7 @@ namespace ov {
* @brief Minimal ICore interface to allow plugin to get information from Core OpenVINO class.
* @ingroup ov_dev_api_plugin_api
*/
class ICore {
class OPENVINO_RUNTIME_API ICore {
public:
/**
* @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) {}
void IInferencePlugin::VersionStore::copyFrom(const Version& v) {
_dsc = v.description;
_buildNumber = v.buildNumber;
description = _dsc.c_str();
buildNumber = _buildNumber.c_str();
description = v.description;
buildNumber = v.buildNumber;
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 {
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,

View File

@ -6,139 +6,212 @@
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <utility>
#include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "description_buffer.hpp"
#include "ie_icore.hpp"
#include "openvino/core/except.hpp"
#include "openvino/runtime/common.hpp"
#include "openvino/runtime/icore.hpp"
#include "openvino/runtime/iplugin.hpp"
using namespace std;
using namespace InferenceEngine;
class MockInternalPlugin : public ov::IPlugin {
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) {
_target = target;
}
public:
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) {
this->config = _config;
if (_target) {
_target->SetConfig(config);
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override {
if (m_plugin)
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,
const std::map<std::string, InferenceEngine::Parameter>& options) const {
if (_target) {
return _target->GetMetric(name, options);
} else {
IE_THROW(NotImplemented);
}
MockPlugin::MockPlugin(const std::shared_ptr<ov::IPlugin>& target) : m_plugin(target) {
OPENVINO_ASSERT(m_plugin);
}
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadNetwork(
const CNNNetwork& network,
const std::map<std::string, std::string>& config) {
if (_target) {
return _target->LoadNetwork(network, config);
} else {
IE_THROW(NotImplemented);
}
void MockPlugin::set_property(const ov::AnyMap& properties) {
set_parameters_if_need();
m_plugin->set_property(properties);
}
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadNetwork(
const CNNNetwork& network,
const std::map<std::string, std::string>& config,
const std::shared_ptr<RemoteContext>& context) {
if (_target) {
return _target->LoadNetwork(network, config, context);
} else {
IE_THROW(NotImplemented);
}
ov::Any MockPlugin::get_property(const std::string& name, const ov::AnyMap& arguments) const {
set_parameters_if_need();
return m_plugin->get_property(name, arguments);
}
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadNetwork(
const std::string& modelPath,
const std::map<std::string, std::string>& config) {
if (_target) {
return _target->LoadNetwork(modelPath, config);
} else {
return InferenceEngine::IInferencePlugin::LoadNetwork(modelPath, config);
}
std::shared_ptr<ov::ICompiledModel> MockPlugin::compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const {
set_parameters_if_need();
return m_plugin->compile_model(model, properties);
}
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::LoadExeNetworkImpl(
const CNNNetwork& network,
const std::map<std::string, std::string>& config) {
return {};
std::shared_ptr<ov::ICompiledModel> MockPlugin::compile_model(const std::string& model_path,
const ov::AnyMap& properties) const {
set_parameters_if_need();
return m_plugin->compile_model(model_path, properties);
}
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::ImportNetwork(
std::istream& networkModel,
const std::map<std::string, std::string>& config) {
if (_target) {
return _target->ImportNetwork(networkModel, config);
} else {
IE_THROW(NotImplemented);
}
std::shared_ptr<ov::ICompiledModel> MockPlugin::compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties,
const ov::RemoteContext& context) const {
set_parameters_if_need();
return m_plugin->compile_model(model, properties, context);
}
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> MockPlugin::ImportNetwork(
std::istream& networkModel,
const std::shared_ptr<InferenceEngine::RemoteContext>& context,
const std::map<std::string, std::string>& config) {
if (_target) {
return _target->ImportNetwork(networkModel, context, config);
} else {
IE_THROW(NotImplemented);
}
std::shared_ptr<ov::IRemoteContext> MockPlugin::create_context(const ov::AnyMap& remote_properties) const {
set_parameters_if_need();
return m_plugin->create_context(remote_properties);
}
std::shared_ptr<InferenceEngine::RemoteContext> MockPlugin::GetDefaultContext(const InferenceEngine::ParamMap& params) {
if (_target) {
return _target->GetDefaultContext(params);
} else {
IE_THROW(NotImplemented);
}
std::shared_ptr<ov::IRemoteContext> MockPlugin::get_default_context(const ov::AnyMap& remote_properties) const {
set_parameters_if_need();
return m_plugin->get_default_context(remote_properties);
}
InferenceEngine::QueryNetworkResult MockPlugin::QueryNetwork(const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config) const {
if (_target) {
return _target->QueryNetwork(network, config);
} else {
IE_THROW(NotImplemented);
}
std::shared_ptr<ov::ICompiledModel> MockPlugin::import_model(std::istream& model, const ov::AnyMap& properties) const {
set_parameters_if_need();
return m_plugin->import_model(model, properties);
}
std::shared_ptr<ov::ICompiledModel> MockPlugin::import_model(std::istream& model,
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 {
if (_target) {
_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;
std::queue<std::shared_ptr<ov::IPlugin>> targets;
std::mutex targets_mutex;
OPENVINO_PLUGIN_API void CreatePluginEngine(std::shared_ptr<ov::IPlugin>& plugin) {
IInferencePlugin* p = nullptr;
std::swap(__target, p);
plugin = convert_plugin(std::make_shared<MockPlugin>(p));
std::shared_ptr<ov::IPlugin> internal_plugin;
if (targets.empty()) {
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) {
__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 <string>
#include <cpp_interfaces/interface/ie_iplugin_internal.hpp>
#include <ie_icore.hpp>
#include "openvino/runtime/iplugin.hpp"
class MockPlugin : public InferenceEngine::IInferencePlugin {
InferenceEngine::IInferencePlugin * _target = nullptr;
namespace InferenceEngine {
class IInferencePlugin;
}
class MockPlugin : public ov::IPlugin {
std::shared_ptr<ov::IPlugin> m_plugin;
void set_parameters_if_need() const;
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>
LoadNetwork(const InferenceEngine::CNNNetwork &network,
const std::map<std::string, std::string> &config) override;
std::shared_ptr<ov::ICompiledModel> compile_model(const std::string& model_path,
const ov::AnyMap& properties) const override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>
LoadNetwork(const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config,
const std::shared_ptr<InferenceEngine::RemoteContext>& context) override;
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;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>
LoadExeNetworkImpl(const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config) override;
void set_property(const ov::AnyMap& properties) override;
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal>
LoadNetwork(const std::string &modelPath,
const std::map<std::string, std::string> &config) override;
ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>
ImportNetwork(std::istream& networkModel,
const std::map<std::string, std::string>& config) override;
std::shared_ptr<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override;
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal>
ImportNetwork(std::istream& networkModel,
const std::shared_ptr<InferenceEngine::RemoteContext>& context,
const std::map<std::string, std::string>& config) override;
std::shared_ptr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override;
InferenceEngine::Parameter GetMetric(const std::string& name,
const std::map<std::string, InferenceEngine::Parameter>& options) const override;
std::shared_ptr<InferenceEngine::RemoteContext> GetDefaultContext(const InferenceEngine::ParamMap& params) override;
InferenceEngine::QueryNetworkResult QueryNetwork(const InferenceEngine::CNNNetwork& network,
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;
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model, const ov::AnyMap& properties) const override;
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::RemoteContext& context,
const ov::AnyMap& properties) const override;
ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override;
};