Infer request api (#7962)

* Introduce new API

* Fixed comments

* Fixed code style

* Introduce some new API

* Fixed code style

* Reverted names

* Exend OVExecNetwork tests

* Changed executable network API

* Fixed tests

* Fixed comments

* Fixed style

* More tests

* Applied changes

* Fixed windows build

* Fixed typo

* Fixed some tests

* Fixed code style

* Fixed pre-proc tests

* Fixed documentation comments

* Added more comments

* Fixed code style

* Remove friend

* Removed find tensor API from internal classes

* Avoid old API in new constructors

* Fixed CPU tests

* Fixed comments

* Fixed template tests

* Extended test cases

* Revert data creation

* Fixed GNA and GPU plugins

* Fixed comments

* Fixed GNA tests

* Try to fix tests for GPU

* Fixed GNA tests

* Fixed GNA

* Try to fix Myriad tests

* Removed check to see an exception message

* Fixed HETERO import

* Reverted mkl-dnn submodule

* Fixed clang-format

Co-authored-by: y <ilya.lavrenov@intel.com>
This commit is contained in:
Ilya Churaev 2021-10-20 22:08:55 +03:00 committed by GitHub
parent a9b773e4b2
commit 0f3c10c810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 1160 additions and 284 deletions

View File

@ -151,11 +151,23 @@ InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::C
networkOutputs, networkOutputs,
std::static_pointer_cast<ExecutableNetwork>(shared_from_this())); std::static_pointer_cast<ExecutableNetwork>(shared_from_this()));
} }
InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequestImpl(
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
return std::make_shared<TemplateInferRequest>(inputs,
outputs,
std::static_pointer_cast<ExecutableNetwork>(shared_from_this()));
}
// ! [executable_network:create_infer_request_impl] // ! [executable_network:create_infer_request_impl]
// ! [executable_network:create_infer_request] // ! [executable_network:create_infer_request]
InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequest() { InferenceEngine::IInferRequestInternal::Ptr TemplatePlugin::ExecutableNetwork::CreateInferRequest() {
auto internalRequest = CreateInferRequestImpl(_networkInputs, _networkOutputs); InferenceEngine::IInferRequestInternal::Ptr internalRequest;
if (this->_plugin && this->_plugin->GetCore() && this->_plugin->GetCore()->isNewAPI())
internalRequest = CreateInferRequestImpl(_parameters, _results);
if (!internalRequest)
internalRequest = CreateInferRequestImpl(_networkInputs, _networkOutputs);
return std::make_shared<TemplateAsyncInferRequest>(std::static_pointer_cast<TemplateInferRequest>(internalRequest), return std::make_shared<TemplateAsyncInferRequest>(std::static_pointer_cast<TemplateInferRequest>(internalRequest),
_taskExecutor, _taskExecutor,
_plugin->_waitExecutor, _plugin->_waitExecutor,

View File

@ -37,6 +37,9 @@ public:
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl( InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(
InferenceEngine::InputsDataMap networkInputs, InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::OutputsDataMap networkOutputs) override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override;
InferenceEngine::Parameter GetMetric(const std::string& name) const override; InferenceEngine::Parameter GetMetric(const std::string& name) const override;
InferenceEngine::Parameter GetConfig(const std::string& name) const override; InferenceEngine::Parameter GetConfig(const std::string& name) const override;

View File

@ -35,6 +35,18 @@ TemplateInferRequest::TemplateInferRequest(const InferenceEngine::InputsDataMap&
const std::shared_ptr<TemplatePlugin::ExecutableNetwork>& executableNetwork) const std::shared_ptr<TemplatePlugin::ExecutableNetwork>& executableNetwork)
: IInferRequestInternal(networkInputs, networkOutputs), : IInferRequestInternal(networkInputs, networkOutputs),
_executableNetwork(executableNetwork) { _executableNetwork(executableNetwork) {
createInferRequest();
}
TemplateInferRequest::TemplateInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const std::shared_ptr<TemplatePlugin::ExecutableNetwork>& executableNetwork)
: IInferRequestInternal(inputs, outputs),
_executableNetwork(executableNetwork) {
createInferRequest();
}
void TemplateInferRequest::createInferRequest() {
// TODO: allocate infer request device and host buffers if needed, fill actual list of profiling tasks // TODO: allocate infer request device and host buffers if needed, fill actual list of profiling tasks
auto requestID = std::to_string(_executableNetwork->_requestId.fetch_add(1)); auto requestID = std::to_string(_executableNetwork->_requestId.fetch_add(1));

View File

@ -29,6 +29,9 @@ public:
TemplateInferRequest(const InferenceEngine::InputsDataMap& networkInputs, TemplateInferRequest(const InferenceEngine::InputsDataMap& networkInputs,
const InferenceEngine::OutputsDataMap& networkOutputs, const InferenceEngine::OutputsDataMap& networkOutputs,
const std::shared_ptr<ExecutableNetwork>& executableNetwork); const std::shared_ptr<ExecutableNetwork>& executableNetwork);
TemplateInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const std::shared_ptr<ExecutableNetwork>& executableNetwork);
~TemplateInferRequest(); ~TemplateInferRequest();
void InferImpl() override; void InferImpl() override;
@ -44,6 +47,7 @@ public:
void SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& userBlob) override; void SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& userBlob) override;
private: private:
void createInferRequest();
void allocateDeviceBuffers(); void allocateDeviceBuffers();
void allocateBlobs(); void allocateBlobs();

View File

@ -57,17 +57,15 @@ void CommonReferenceTest::Infer() {
const auto& functionParams = function->get_parameters(); const auto& functionParams = function->get_parameters();
for (size_t i = 0; i < functionParams.size(); ++i) { for (size_t i = 0; i < functionParams.size(); ++i) {
const auto& param = functionParams[i]; inferRequest.set_tensor(executableNetwork.input(i), inputData[i]);
inferRequest.set_tensor(param->get_friendly_name(), inputData[i]);
} }
inferRequest.infer(); inferRequest.infer();
} }
void CommonReferenceTest::Validate() { void CommonReferenceTest::Validate() {
ASSERT_EQ(executableNetwork.outputs().size(), refOutData.size()); ASSERT_EQ(executableNetwork.outputs().size(), refOutData.size());
for (const auto& result : function->get_results()) { for (const auto& output : executableNetwork.outputs()) {
auto name = ngraph::op::util::create_ie_output_name(result->input_value(0)); actualOutData.emplace_back(inferRequest.get_tensor(output));
actualOutData.emplace_back(inferRequest.get_tensor(name));
} }
ASSERT_EQ(refOutData.size(), actualOutData.size()); ASSERT_EQ(refOutData.size(), actualOutData.size());

View File

@ -26,6 +26,7 @@
#include "cldnn_executable_network.h" #include "cldnn_executable_network.h"
#include "threading/ie_cpu_streams_executor.hpp" #include "threading/ie_cpu_streams_executor.hpp"
#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp"
#include "ie_icore.hpp"
using namespace InferenceEngine; using namespace InferenceEngine;
using namespace InferenceEngine::details; using namespace InferenceEngine::details;
@ -66,6 +67,36 @@ CLDNNExecNetwork::CLDNNExecNetwork(InferenceEngine::CNNNetwork &network, std::sh
IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(InputsDataMap networkInputs, IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(InputsDataMap networkInputs,
OutputsDataMap networkOutputs) { OutputsDataMap networkOutputs) {
OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequestImpl"); OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequestImpl");
auto ptr = std::make_shared<CLDNNInferRequest>(networkInputs, networkOutputs,
std::static_pointer_cast<CLDNNExecNetwork>(shared_from_this()));
if (m_config.throughput_streams > 1) {
ptr->EnableStreams();
}
if (m_config.useProfiling)
ptr->EnableProfiling();
ptr->SetGraph(m_graphs.front());
return ptr;
}
IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequestImpl");
auto ptr = std::make_shared<CLDNNInferRequest>(inputs, outputs,
std::static_pointer_cast<CLDNNExecNetwork>(shared_from_this()));
if (m_config.throughput_streams > 1) {
ptr->EnableStreams();
}
if (m_config.useProfiling)
ptr->EnableProfiling();
ptr->SetGraph(m_graphs.front());
return ptr;
}
IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequest() {
OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequest");
InferenceEngine::IInferRequestInternal::Ptr internalRequest;
if (m_graphs.empty()) { if (m_graphs.empty()) {
IE_THROW(NetworkNotLoaded); IE_THROW(NetworkNotLoaded);
} }
@ -80,21 +111,10 @@ IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequestImpl(InputsDataMa
} }
} }
auto ptr = std::make_shared<CLDNNInferRequest>(networkInputs, networkOutputs, if (this->_plugin && this->_plugin->GetCore() && this->_plugin->GetCore()->isNewAPI())
std::static_pointer_cast<CLDNNExecNetwork>(shared_from_this())); internalRequest = CreateInferRequestImpl(_parameters, _results);
if (m_config.throughput_streams > 1) { if (!internalRequest)
ptr->EnableStreams(); internalRequest = CreateInferRequestImpl(_networkInputs, _networkOutputs);
}
if (m_config.useProfiling)
ptr->EnableProfiling();
ptr->SetGraph(m_graphs.front());
return ptr;
}
IInferRequestInternal::Ptr CLDNNExecNetwork::CreateInferRequest() {
OV_ITT_SCOPED_TASK(itt::domains::CLDNNPlugin, "CLDNNExecNetwork::CreateInferRequest");
auto internalRequest = CreateInferRequestImpl(_networkInputs, _networkOutputs);
internalRequest->setPointerToExecutableNetworkInternal(shared_from_this()); internalRequest->setPointerToExecutableNetworkInternal(shared_from_this());
return std::make_shared<CLDNNAsyncInferRequest>(std::static_pointer_cast<CLDNNInferRequest>(internalRequest), return std::make_shared<CLDNNAsyncInferRequest>(std::static_pointer_cast<CLDNNInferRequest>(internalRequest),
m_taskExecutor, m_taskExecutor,

View File

@ -29,6 +29,8 @@ public:
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::OutputsDataMap networkOutputs) override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) override;
InferenceEngine::Parameter GetMetric(const std::string &name) const override; InferenceEngine::Parameter GetMetric(const std::string &name) const override;
InferenceEngine::Parameter GetConfig(const std::string &name) const override; InferenceEngine::Parameter GetConfig(const std::string &name) const override;

View File

@ -457,6 +457,16 @@ CLDNNInferRequest::CLDNNInferRequest(InputsDataMap networkInputs, OutputsDataMap
streamExecutor = dynamic_cast<InferenceEngine::IStreamsExecutor*>(execNetwork->m_taskExecutor.get()); streamExecutor = dynamic_cast<InferenceEngine::IStreamsExecutor*>(execNetwork->m_taskExecutor.get());
} }
CLDNNInferRequest::CLDNNInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const CLDNNExecNetwork::Ptr& execNetwork)
: IInferRequestInternal(inputs, outputs)
, m_useProfiling(false)
, m_useStreams(false) {
IE_ASSERT(nullptr != execNetwork);
streamExecutor = dynamic_cast<InferenceEngine::IStreamsExecutor*>(execNetwork->m_taskExecutor.get());
}
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //
// ---------------------------- internal pipeline stages ----------------------------------- // // ---------------------------- internal pipeline stages ----------------------------------- //
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //

View File

@ -33,6 +33,9 @@ public:
CLDNNInferRequest(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs, CLDNNInferRequest(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::OutputsDataMap networkOutputs,
const std::shared_ptr<CLDNNExecNetwork>& execNetwork); const std::shared_ptr<CLDNNExecNetwork>& execNetwork);
CLDNNInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const std::shared_ptr<CLDNNExecNetwork>& execNetwork);
CLDNNInferRequest(const CLDNNInferRequest &) = delete; CLDNNInferRequest(const CLDNNInferRequest &) = delete;

View File

@ -13,6 +13,7 @@
#include <gna/gna_config.hpp> #include <gna/gna_config.hpp>
#include <threading/ie_executor_manager.hpp> #include <threading/ie_executor_manager.hpp>
#include <cpp_interfaces/interface/ie_iexecutable_network_internal.hpp> #include <cpp_interfaces/interface/ie_iexecutable_network_internal.hpp>
#include <ie_icore.hpp>
namespace GNAPluginNS { namespace GNAPluginNS {
@ -58,6 +59,14 @@ class GNAExecutableNetwork : public InferenceEngine::IExecutableNetworkInternal
return std::make_shared<GNAInferRequest>(plg, networkInputs, networkOutputs); return std::make_shared<GNAInferRequest>(plg, networkInputs, networkOutputs);
} }
InferenceEngine::IInferRequestInternal::Ptr
CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) override {
if (!this->_plugin || !this->_plugin->GetCore() || !this->_plugin->GetCore()->isNewAPI())
return nullptr;
return std::make_shared<GNAInferRequest>(plg, inputs, outputs);
}
INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead") INFERENCE_ENGINE_DEPRECATED("Use InferRequest::QueryState instead")
std::vector<InferenceEngine::IVariableStateInternal::Ptr> QueryState() override { std::vector<InferenceEngine::IVariableStateInternal::Ptr> QueryState() override {
IE_SUPPRESS_DEPRECATED_START IE_SUPPRESS_DEPRECATED_START

View File

@ -15,17 +15,10 @@
namespace GNAPluginNS { namespace GNAPluginNS {
class GNAInferRequest : public InferenceEngine::IInferRequestInternal { class GNAInferRequest : public InferenceEngine::IInferRequestInternal {
protected: private:
std::shared_ptr<GNAPlugin> plg; void CreateInferRequest() {
uint32_t inferRequestIdx = -1;
public:
GNAInferRequest(const std::shared_ptr<GNAPlugin>& plg,
InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs)
: InferenceEngine::IInferRequestInternal(networkInputs, networkOutputs), plg(plg) {
// TODO: internal connection API - better to generalize // TODO: internal connection API - better to generalize
if (networkOutputs.empty()) { if (_networkOutputs.empty()) {
THROW_GNA_EXCEPTION << "GNAInferRequest :: network has zero outputs"; THROW_GNA_EXCEPTION << "GNAInferRequest :: network has zero outputs";
} }
@ -40,6 +33,24 @@ class GNAInferRequest : public InferenceEngine::IInferRequestInternal {
plg->GetInputBlob(input.first, input.second->getTensorDesc().getPrecision()); plg->GetInputBlob(input.first, input.second->getTensorDesc().getPrecision());
} }
} }
protected:
std::shared_ptr<GNAPlugin> plg;
uint32_t inferRequestIdx = -1;
public:
GNAInferRequest(const std::shared_ptr<GNAPlugin>& plg,
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs)
: InferenceEngine::IInferRequestInternal(inputs, outputs), plg(plg) {
CreateInferRequest();
}
GNAInferRequest(const std::shared_ptr<GNAPlugin>& plg,
InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs)
: InferenceEngine::IInferRequestInternal(networkInputs, networkOutputs), plg(plg) {
CreateInferRequest();
}
/** /**
* @brief Infers specified input(s) in synchronous mode * @brief Infers specified input(s) in synchronous mode
* @note blocks all method of InferRequest while request is ongoing (running or waiting in queue) * @note blocks all method of InferRequest while request is ongoing (running or waiting in queue)

View File

@ -732,6 +732,25 @@ void HeteroExecutableNetwork::Export(std::ostream& heteroModel) {
} }
} }
IInferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl(
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
if (!this->_plugin || !this->_plugin->GetCore() || !this->_plugin->GetCore()->isNewAPI())
return nullptr;
HeteroInferRequest::SubRequestsList inferRequests;
int index = 0;
for (auto&& subnetwork : _networks) {
HeteroInferRequest::SubRequestDesc desc;
desc._network = subnetwork._network;
desc._profilingTask = openvino::itt::handle("Infer" + std::to_string(index++));
inferRequests.push_back(desc);
}
return std::make_shared<HeteroInferRequest>(inputs,
outputs,
inferRequests,
_blobNameMap);
}
IInferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl( IInferRequestInternal::Ptr HeteroExecutableNetwork::CreateInferRequestImpl(
InputsDataMap networkInputs, InputsDataMap networkInputs,
OutputsDataMap networkOutputs) { OutputsDataMap networkOutputs) {

View File

@ -49,6 +49,9 @@ public:
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::OutputsDataMap networkOutputs) override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override;

View File

@ -16,12 +16,26 @@ using namespace HeteroPlugin;
using namespace InferenceEngine; using namespace InferenceEngine;
using namespace InferenceEngine::details; using namespace InferenceEngine::details;
HeteroInferRequest::HeteroInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const SubRequestsList& inferRequests,
const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames) :
IInferRequestInternal(inputs, outputs),
_inferRequests(inferRequests) {
CreateInferRequest(subgraphInputToOutputBlobNames);
}
HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInputs, HeteroInferRequest::HeteroInferRequest(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs, InferenceEngine::OutputsDataMap networkOutputs,
const SubRequestsList& inferRequests, const SubRequestsList& inferRequests,
const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames) : const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames) :
IInferRequestInternal(networkInputs, networkOutputs), IInferRequestInternal(networkInputs, networkOutputs),
_inferRequests(inferRequests) { _inferRequests(inferRequests) {
CreateInferRequest(subgraphInputToOutputBlobNames);
}
void HeteroInferRequest::CreateInferRequest(const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames) {
if (_networkOutputs.empty() || _networkInputs.empty()) { if (_networkOutputs.empty() || _networkInputs.empty()) {
IE_THROW() << "Internal error: no information about network's output/input"; IE_THROW() << "Internal error: no information about network's output/input";
} }

View File

@ -27,10 +27,15 @@ public:
}; };
using SubRequestsList = std::vector<SubRequestDesc>; using SubRequestsList = std::vector<SubRequestDesc>;
explicit HeteroInferRequest(InferenceEngine::InputsDataMap networkInputs, HeteroInferRequest(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs, InferenceEngine::OutputsDataMap networkOutputs,
const SubRequestsList &inferRequests, const SubRequestsList &inferRequests,
const std::unordered_map<std::string, std::string>& blobNameMap); const std::unordered_map<std::string, std::string>& blobNameMap);
HeteroInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& networkInputs,
const std::vector<std::shared_ptr<const ov::Node>>& networkOutputs,
const SubRequestsList &inferRequests,
const std::unordered_map<std::string, std::string>& blobNameMap);
void InferImpl() override; void InferImpl() override;
@ -49,6 +54,9 @@ public:
SubRequestsList _inferRequests; SubRequestsList _inferRequests;
std::map<std::string, InferenceEngine::Blob::Ptr> _blobs; std::map<std::string, InferenceEngine::Blob::Ptr> _blobs;
std::map<std::string, InferenceEngine::IInferRequestInternal*> _subRequestFromBlobName; std::map<std::string, InferenceEngine::IInferRequestInternal*> _subRequestFromBlobName;
private:
void CreateInferRequest(const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames);
}; };
} // namespace HeteroPlugin } // namespace HeteroPlugin

View File

@ -13,6 +13,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "openvino/core/node_output.hpp"
#include "openvino/runtime/common.hpp" #include "openvino/runtime/common.hpp"
#include "openvino/runtime/profiling_info.hpp" #include "openvino/runtime/profiling_info.hpp"
#include "openvino/runtime/tensor.hpp" #include "openvino/runtime/tensor.hpp"
@ -54,21 +55,103 @@ public:
/** /**
* @brief Sets input/output data to infer * @brief Sets input/output data to infer
* *
* @note Memory allocation does not happen
* @param name Name of input or output tensor. * @param name Name of input or output tensor.
* @param tensor Reference to input or output tensor. The type of a tensor must match the network input precision * @param tensor Reference to input or output tensor. The type of a tensor must match the network input/output
* and size. * precision and size.
*/ */
void set_tensor(const std::string& name, const Tensor& tensor); void set_tensor(const std::string& name, const Tensor& tensor);
/**
* @brief Sets input/output data to infer
*
* @param port Port of input or output tensor.
* @param tensor Reference to input or output tensor. The type of a tensor must match the network input/output
* precision and size.
*/
void set_tensor(const ov::Output<const ov::Node>& port, const Tensor& tensor);
/**
* @brief Sets input/output data to infer
*
* @param port Port of input or output tensor.
* @param tensor Reference to input or output tensor. The type of a tensor must match the network input/output
* precision and size.
*/
void set_tensor(const ov::Output<ov::Node>& port, const Tensor& tensor);
/**
* @brief Sets input tensor to infer
*
* @param idx Index of input tensor.
* @param tensor Reference to input tensor. The type of a tensor must match the network input precision and size.
*/
void set_input_tensor(size_t idx, const Tensor& tensor);
/**
* @brief Sets input tensor to infer models with single input
*
* @param tensor Reference to input tensor. If model has several inputs, an exception is thrown.
*/
void set_input_tensor(const Tensor& tensor);
/**
* @brief Sets output tensor to infer
*
* @param idx Index of output tensor.
* @param tensor Reference to output tensor. The type of a tensor must match the network output precision and size.
*/
void set_output_tensor(size_t idx, const Tensor& tensor);
/**
* @brief Sets output tensor to infer models with single output
*
* @param tensor Reference to output tensor. If model has several outputs, an exception is thrown.
*/
void set_output_tensor(const Tensor& tensor);
/** /**
* @brief Gets input/output data for inference * @brief Gets input/output tensor for inference
* *
* @note Memory allocation does not happen
* @param name A name of tensor to get * @param name A name of tensor to get
* @return A Tensor with a name @p name. If a tensor is not found, an exception is thrown. * @return A Tensor with a name @p name. If a tensor is not found, an exception is thrown.
*/ */
Tensor get_tensor(const std::string& name); Tensor get_tensor(const std::string& name);
/**
* @brief Gets input/output tensor for inference
*
* @param port Port of tensor to get
* @return A Tensor for the port @p port. If a tensor with specified @p port is not found, an exception is thrown.
*/
Tensor get_tensor(const ov::Output<const ov::Node>& port);
/**
* @brief Gets input/output tensor for inference
*
* @param port Port of tensor to get
* @return A Tensor for the port @p port. If a tensor with specified @p port is not found, an exception is thrown.
*/
Tensor get_tensor(const ov::Output<ov::Node>& port);
/**
* @brief Gets input tensor for inference
*
* @param idx An index of tensor to get
* @return A Tensor with an input index @p idx. If a tensor with specified @p idx is not found, an exception is
* thrown.
*/
Tensor get_input_tensor(size_t idx);
/**
* @brief Gets input tensor for inference
*
* @return An input Tensor for the model. If model has several inputs, an exception is thrown.
*/
Tensor get_input_tensor();
/**
* @brief Gets output tensor for inference
*
* @param idx An index of tensor to get
* @return A Tensor with an output index @p idx. If a tensor with specified @p idx is not found, an exception is
* thrown.
*/
Tensor get_output_tensor(size_t idx);
/**
* @brief Gets output tensor for inference
*
* @return An output Tensor for the model. If model has several outputs, an exception is thrown.
*/
Tensor get_output_tensor();
/** /**
* @brief Infers specified input(s) in synchronous mode * @brief Infers specified input(s) in synchronous mode

View File

@ -145,11 +145,11 @@ std::vector<ov::Output<const ov::Node>> ExecutableNetwork::inputs() const {
ov::Output<const ov::Node> ExecutableNetwork::input() const { ov::Output<const ov::Node> ExecutableNetwork::input() const {
OV_EXEC_NET_CALL_STATEMENT({ OV_EXEC_NET_CALL_STATEMENT({
const auto params = _impl->getInputs(); const auto inputs = _impl->getInputs();
if (params.size() != 1) { if (inputs.size() != 1) {
throw ov::Exception("input() must be called on a function with exactly one parameter."); throw ov::Exception("input() must be called on a function with exactly one parameter.");
} }
return params.at(0); return inputs.at(0);
}); });
} }
@ -179,11 +179,11 @@ std::vector<ov::Output<const ov::Node>> ExecutableNetwork::outputs() const {
} }
ov::Output<const ov::Node> ExecutableNetwork::output() const { ov::Output<const ov::Node> ExecutableNetwork::output() const {
OV_EXEC_NET_CALL_STATEMENT({ OV_EXEC_NET_CALL_STATEMENT({
const auto result = _impl->getOutputs(); const auto outputs = _impl->getOutputs();
if (result.size() != 1) { if (outputs.size() != 1) {
throw ov::Exception("output() must be called on a function with exactly one parameter."); throw ov::Exception("output() must be called on a function with exactly one parameter.");
} }
return result.at(0); return outputs.at(0);
}); });
} }
ov::Output<const ov::Node> ExecutableNetwork::output(size_t i) const { ov::Output<const ov::Node> ExecutableNetwork::output(size_t i) const {

View File

@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp"
#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp"
#include "ie_infer_async_request_base.hpp" #include "ie_infer_async_request_base.hpp"
#include "ie_ngraph_utils.hpp" #include "ie_ngraph_utils.hpp"
@ -16,6 +17,24 @@
#include "openvino/runtime/infer_request.hpp" #include "openvino/runtime/infer_request.hpp"
#include "transformations/utils/utils.hpp" #include "transformations/utils/utils.hpp"
namespace {
inline bool getPort(ov::Output<const ov::Node>& port,
const std::string& name,
const std::vector<std::vector<std::shared_ptr<const ov::Node>>>& ports) {
for (const auto& nodes : ports) {
for (const auto& node : nodes) {
const auto& names = node->get_output_tensor(0).get_names();
if (names.find(name) != names.end()) {
port = node->output(0);
return true;
}
}
}
return false;
}
} // namespace
namespace InferenceEngine { namespace InferenceEngine {
#define INFER_REQ_CALL_STATEMENT(...) \ #define INFER_REQ_CALL_STATEMENT(...) \
@ -204,6 +223,18 @@ bool InferRequest::operator==(const InferRequest& r) const noexcept {
} // namespace InferenceEngine } // namespace InferenceEngine
namespace {
std::string get_legacy_name_from_port(const ov::Output<const ov::Node>& port) {
ov::Output<ngraph::Node> p(std::const_pointer_cast<ov::Node>(port.get_node_shared_ptr()), port.get_index());
if (auto node = std::dynamic_pointer_cast<ov::op::v0::Result>(p.get_node_shared_ptr())) {
p = node->input_value(0);
}
return ngraph::op::util::create_ie_output_name(p);
}
} // namespace
namespace ov { namespace ov {
namespace runtime { namespace runtime {
@ -213,23 +244,114 @@ InferRequest::InferRequest(const std::shared_ptr<void>& so, const ie::IInferRequ
OPENVINO_ASSERT(_impl != nullptr, "InferRequest was not initialized."); OPENVINO_ASSERT(_impl != nullptr, "InferRequest was not initialized.");
} }
void InferRequest::set_tensor(const std::string& name, const Tensor& tensor){ void InferRequest::set_tensor(const ov::Output<const ov::Node>& port, const Tensor& tensor) {
OV_INFER_REQ_CALL_STATEMENT({ _impl->SetBlob(name, tensor._impl); })} OV_INFER_REQ_CALL_STATEMENT({ _impl->SetBlob(get_legacy_name_from_port(port), tensor._impl); });
}
void InferRequest::set_tensor(const ov::Output<ov::Node>& port, const Tensor& tensor) {
set_tensor(ov::Output<const ov::Node>(port.get_node(), port.get_index()), tensor);
}
void InferRequest::set_tensor(const std::string& name, const Tensor& tensor) {
OV_INFER_REQ_CALL_STATEMENT({
ov::Output<const ov::Node> port;
OPENVINO_ASSERT(::getPort(port, name, {_impl->GetInputs(), _impl->GetOutputs()}),
"Port for tensor name " + name + " was not found.");
set_tensor(port, tensor);
});
}
void InferRequest::set_input_tensor(size_t idx, const Tensor& tensor) {
OV_INFER_REQ_CALL_STATEMENT({
const auto& inputs = _impl->GetInputs();
OPENVINO_ASSERT(inputs.size() > idx,
"Input port for index ",
idx,
" was not found! The model has only ",
inputs.size(),
" inputs.");
set_tensor(inputs.at(idx)->output(0), tensor);
});
}
void InferRequest::set_input_tensor(const Tensor& tensor) {
OV_INFER_REQ_CALL_STATEMENT({
const auto inputs = _impl->GetInputs();
OPENVINO_ASSERT(inputs.size() == 1,
"set_input_tensor() must be called on a function with exactly one parameter.");
set_tensor(inputs.at(0)->output(0), tensor);
});
}
void InferRequest::set_output_tensor(size_t idx, const Tensor& tensor) {
OV_INFER_REQ_CALL_STATEMENT({
const auto& outputs = _impl->GetOutputs();
OPENVINO_ASSERT(outputs.size() > idx,
"Output port for index ",
idx,
" was not found! The model has only ",
outputs.size(),
" outputs.");
set_tensor(outputs.at(idx)->output(0), tensor);
});
}
void InferRequest::set_output_tensor(const Tensor& tensor) {
OV_INFER_REQ_CALL_STATEMENT({
const auto outputs = _impl->GetOutputs();
OPENVINO_ASSERT(outputs.size() == 1,
"set_output_tensor() must be called on a function with exactly one parameter.");
set_tensor(outputs.at(0)->output(0), tensor);
});
}
Tensor InferRequest::get_tensor(const ov::Output<const ov::Node>& port) {
OV_INFER_REQ_CALL_STATEMENT({
const auto& name = get_legacy_name_from_port(port);
auto blob = _impl->GetBlob(name);
return {_so, blob};
});
}
Tensor InferRequest::get_tensor(const ov::Output<ov::Node>& port) {
return get_tensor(ov::Output<const ov::Node>(port.get_node(), port.get_index()));
}
Tensor InferRequest::get_tensor(const std::string& name) { Tensor InferRequest::get_tensor(const std::string& name) {
OV_INFER_REQ_CALL_STATEMENT({ OV_INFER_REQ_CALL_STATEMENT({
auto blob = _impl->GetBlob(name); ov::Output<const ov::Node> port;
const bool remoteBlobPassed = blob->is<ie::RemoteBlob>(); OPENVINO_ASSERT(::getPort(port, name, {_impl->GetInputs(), _impl->GetOutputs()}),
if (blob == nullptr) { "Port for tensor name " + name + " was not found.");
IE_THROW(NotAllocated) << "Internal tensor implementation with name `" << name << "` is not allocated!"; return get_tensor(port);
});
}
Tensor InferRequest::get_input_tensor(size_t idx) {
OV_INFER_REQ_CALL_STATEMENT({ return get_tensor(_impl->GetInputs().at(idx)->output(0)); });
}
Tensor InferRequest::get_output_tensor(size_t idx) {
OV_INFER_REQ_CALL_STATEMENT({ return get_tensor(_impl->GetOutputs().at(idx)->output(0)); });
}
Tensor InferRequest::get_input_tensor() {
OV_INFER_REQ_CALL_STATEMENT({
const auto inputs = _impl->GetInputs();
if (inputs.size() != 1) {
throw ov::Exception("get_input_tensor() must be called on a function with exactly one parameter.");
} }
if (!remoteBlobPassed && blob->buffer() == nullptr) { return get_tensor(inputs.at(0)->output(0));
IE_THROW(NotAllocated) << "Internal tensor implementation with name `" << name << "` is not allocated!"; });
}
Tensor InferRequest::get_output_tensor() {
OV_INFER_REQ_CALL_STATEMENT({
const auto outputs = _impl->GetOutputs();
if (outputs.size() != 1) {
throw ov::Exception("get_output_tensor() must be called on a function with exactly one parameter.");
} }
auto tensorDesc = blob->getTensorDesc(); return get_tensor(outputs.at(0)->output(0));
auto dims = tensorDesc.getDims(); });
return {_so, blob};
})
} }
void InferRequest::infer() { void InferRequest::infer() {
@ -321,4 +443,4 @@ bool InferRequest::operator==(const InferRequest& r) const noexcept {
} }
} // namespace runtime } // namespace runtime
} // namespace ov } // namespace ov

View File

@ -14,7 +14,9 @@
#include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp" #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp"
#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "ie_icore.hpp" #include "ie_icore.hpp"
#include "ie_ngraph_utils.hpp"
#include "ie_parameter.hpp" #include "ie_parameter.hpp"
#include "openvino/core/node.hpp"
namespace InferenceEngine { namespace InferenceEngine {
@ -56,7 +58,13 @@ ConstInputsDataMap IExecutableNetworkInternal::GetInputsInfo() const {
} }
std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRequest() { std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRequest() {
auto asyncRequestImpl = CreateInferRequestImpl(_networkInputs, _networkOutputs); std::shared_ptr<IInferRequestInternal> asyncRequestImpl;
try {
asyncRequestImpl = CreateInferRequestImpl(_parameters, _results);
} catch (const NotImplemented&) {
}
if (!asyncRequestImpl)
asyncRequestImpl = CreateInferRequestImpl(_networkInputs, _networkOutputs);
asyncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); asyncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this());
return asyncRequestImpl; return asyncRequestImpl;
} }
@ -109,4 +117,10 @@ std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRe
IE_THROW(NotImplemented); IE_THROW(NotImplemented);
} }
std::shared_ptr<IInferRequestInternal> IExecutableNetworkInternal::CreateInferRequestImpl(
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
IE_THROW(NotImplemented);
}
} // namespace InferenceEngine } // namespace InferenceEngine

View File

@ -16,8 +16,10 @@
#include "ie_blob.h" #include "ie_blob.h"
#include "ie_common.h" #include "ie_common.h"
#include "ie_compound_blob.h" #include "ie_compound_blob.h"
#include "ie_ngraph_utils.hpp"
#include "ie_preprocess.hpp" #include "ie_preprocess.hpp"
#include "ie_remote_context.hpp" #include "ie_remote_context.hpp"
#include "transformations/utils/utils.hpp"
namespace InferenceEngine { namespace InferenceEngine {
@ -28,6 +30,43 @@ IInferRequestInternal::IInferRequestInternal(const InputsDataMap& networkInputs,
_networkInputs{copyInfo(networkInputs)}, _networkInputs{copyInfo(networkInputs)},
_networkOutputs{copyInfo(networkOutputs)} {} _networkOutputs{copyInfo(networkOutputs)} {}
IInferRequestInternal::IInferRequestInternal(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs)
: _parameters(inputs),
_results(outputs) {
const auto& create_old_data = [](const ov::Output<const ov::Node>& output) -> InferenceEngine::DataPtr {
IE_SUPPRESS_DEPRECATED_START
auto name = ngraph::op::util::get_ie_output_name(output);
auto shape = output.get_partial_shape();
auto rank = shape.rank().is_static() ? shape.rank().get_length() : -1;
for (const auto& dim : shape) {
if (dim.is_static() && dim.get_length() == 0)
IE_THROW() << name << " has zero dimension which is not allowed";
}
const Layout rankLayout = rank < 0 ? Layout::BLOCKED : TensorDesc::getLayoutByRank(rank);
const auto precision = InferenceEngine::details::convertPrecision(output.get_element_type());
return std::make_shared<Data>(name, precision, shape, rankLayout);
IE_SUPPRESS_DEPRECATED_END
};
const auto& create_old_input_data =
[create_old_data](const ov::Output<const ov::Node>& output) -> InferenceEngine::InputInfo::Ptr {
auto info = std::make_shared<InferenceEngine::InputInfo>();
info->setInputData(create_old_data(output));
return info;
};
for (const auto& param : _parameters) {
const auto& input = create_old_input_data(param->output(0));
_networkInputs[input->name()] = input;
}
for (const auto& result : _results) {
auto input = result->input_value(0);
const auto& output = create_old_data(ov::Output<const ov::Node>(input.get_node(), input.get_index()));
_networkOutputs[output->getName()] = output;
}
}
void IInferRequestInternal::Infer() { void IInferRequestInternal::Infer() {
checkBlobs(); checkBlobs();
InferImpl(); InferImpl();
@ -373,4 +412,12 @@ void* IInferRequestInternal::GetUserData() noexcept {
void IInferRequestInternal::SetUserData(void* userData) noexcept { void IInferRequestInternal::SetUserData(void* userData) noexcept {
_userData = userData; _userData = userData;
} }
const std::vector<std::shared_ptr<const ov::Node>>& IInferRequestInternal::GetInputs() const {
return _parameters;
}
const std::vector<std::shared_ptr<const ov::Node>>& IInferRequestInternal::GetOutputs() const {
return _results;
}
} // namespace InferenceEngine } // namespace InferenceEngine

View File

@ -542,6 +542,54 @@ public:
const std::map<std::string, std::string>& config) override { const std::map<std::string, std::string>& config) override {
auto parsed = parseDeviceNameIntoConfig(deviceName, config); auto parsed = parseDeviceNameIntoConfig(deviceName, config);
auto exec = GetCPPPluginByName(parsed._deviceName).import_model(networkModel, parsed._config); auto exec = GetCPPPluginByName(parsed._deviceName).import_model(networkModel, parsed._config);
if (isNewAPI()) {
// create getInputs() based on GetInputsInfo()
using namespace InferenceEngine::details;
if (exec->getInputs().empty()) {
const auto& inputsInfo = exec->GetInputsInfo();
OPENVINO_ASSERT(!inputsInfo.empty(), "inputsInfo is empty after network import");
std::vector<std::shared_ptr<const ov::Node>> params;
params.reserve(inputsInfo.size());
for (auto&& input : inputsInfo) {
auto param = std::make_shared<ov::op::v0::Parameter>(
convertPrecision(input.second->getPrecision()),
ov::PartialShape(input.second->getTensorDesc().getDims()));
param->set_friendly_name(input.first);
param->get_output_tensor(0).add_names({input.first});
params.emplace_back(std::move(param));
}
exec->setInputs(params);
}
if (exec->getOutputs().empty()) {
const auto& outputsInfo = exec->GetOutputsInfo();
OPENVINO_ASSERT(!outputsInfo.empty(), "outputsInfo is empty after network import");
std::vector<std::shared_ptr<const ov::Node>> results;
results.reserve(outputsInfo.size());
for (auto&& output : outputsInfo) {
auto fake_param = std::make_shared<ov::op::v0::Parameter>(
convertPrecision(output.second->getPrecision()),
ov::PartialShape(output.second->getTensorDesc().getDims()));
fake_param->set_friendly_name(output.first);
auto result = std::make_shared<ov::op::v0::Result>(fake_param);
result->get_output_tensor(0).add_names({output.first});
results.emplace_back(std::move(result));
}
exec->setOutputs(results);
}
// but for true support plugins need:
// 1. ensure order or parameters and results as in ov::Function
// 2. provide tensor names for inputs and outputs
// 3. precisions for getInputs and getOutputs should be taken from GetInputsInfo / GetOutputsInfo
// not from ngraph. Plugins should use SetExeNetworkInfo
}
return {{exec._so}, exec._ptr}; return {{exec._so}, exec._ptr};
} }
@ -1381,50 +1429,6 @@ ExecutableNetwork Core::import_model(std::istream& modelStream,
OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "Core::import_model"); OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "Core::import_model");
OV_CORE_CALL_STATEMENT({ OV_CORE_CALL_STATEMENT({
auto exec = _impl->ImportNetwork(modelStream, deviceName, config); auto exec = _impl->ImportNetwork(modelStream, deviceName, config);
// create getInputs() based on GetInputsInfo()
using namespace InferenceEngine::details;
if (exec->getInputs().empty()) {
const auto& inputsInfo = exec->GetInputsInfo();
OPENVINO_ASSERT(!inputsInfo.empty(), "inputsInfo is empty after network import");
std::vector<std::shared_ptr<const ov::Node>> params;
params.reserve(inputsInfo.size());
for (auto&& input : inputsInfo) {
auto param =
std::make_shared<ov::op::v0::Parameter>(convertPrecision(input.second->getPrecision()),
ov::PartialShape(input.second->getTensorDesc().getDims()));
param->get_output_tensor(0).add_names({input.first});
params.emplace_back(std::move(param));
}
exec->setInputs(params);
}
if (exec->getOutputs().empty()) {
const auto& outputsInfo = exec->GetOutputsInfo();
OPENVINO_ASSERT(!outputsInfo.empty(), "outputsInfo is empty after network import");
std::vector<std::shared_ptr<const ov::Node>> results;
results.reserve(outputsInfo.size());
for (auto&& output : outputsInfo) {
auto fake_param =
std::make_shared<ov::op::v0::Parameter>(convertPrecision(output.second->getPrecision()),
ov::PartialShape(output.second->getTensorDesc().getDims()));
auto result = std::make_shared<ov::op::v0::Result>(fake_param);
result->get_output_tensor(0).add_names({output.first});
results.emplace_back(std::move(result));
}
exec->setOutputs(results);
}
// but for true support plugins need:
// 1. ensure order or parameters and results as in ov::Function
// 2. provide tensor names for inputs and outputs
// 3. precisions for getInputs and getOutputs should be taken from GetInputsInfo / GetOutputsInfo
// not from ngraph. Plugins should use SetExeNetworkInfo
return {exec._so, exec._ptr}; return {exec._so, exec._ptr};
}); });
} }

View File

@ -162,7 +162,7 @@ int64_t op::NonMaxSuppressionIE3::max_boxes_output_from_input() const {
} }
const auto max_output_boxes_input = const auto max_output_boxes_input =
ov::as_type_ptr<op::Constant>(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); ov::as_type_ptr<const op::Constant>(input_value(max_output_boxes_per_class_port).get_node_shared_ptr());
max_output_boxes = max_output_boxes_input->cast_vector<int64_t>().at(0); max_output_boxes = max_output_boxes_input->cast_vector<int64_t>().at(0);
return max_output_boxes; return max_output_boxes;

View File

@ -25,11 +25,21 @@
#include <cstring> #include <cstring>
#include <ngraph/opsets/opset1.hpp> #include <ngraph/opsets/opset1.hpp>
#include <transformations/utils/utils.hpp> #include <transformations/utils/utils.hpp>
#include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "ie_icore.hpp"
using namespace MKLDNNPlugin; using namespace MKLDNNPlugin;
using namespace InferenceEngine; using namespace InferenceEngine;
using namespace InferenceEngine::details; using namespace InferenceEngine::details;
InferenceEngine::IInferRequestInternal::Ptr
MKLDNNExecNetwork::CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
if (!this->_plugin || !this->_plugin->GetCore() || !this->_plugin->GetCore()->isNewAPI())
return nullptr;
return std::make_shared<MKLDNNInferRequest>(inputs, outputs, std::static_pointer_cast<MKLDNNExecNetwork>(shared_from_this()));
}
InferenceEngine::IInferRequestInternal::Ptr InferenceEngine::IInferRequestInternal::Ptr
MKLDNNExecNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, MKLDNNExecNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) { InferenceEngine::OutputsDataMap networkOutputs) {

View File

@ -23,6 +23,10 @@ class MKLDNNExecNetwork: public InferenceEngine::ExecutableNetworkThreadSafeDefa
public: public:
typedef std::shared_ptr<MKLDNNExecNetwork> Ptr; typedef std::shared_ptr<MKLDNNExecNetwork> Ptr;
std::shared_ptr<InferenceEngine::IInferRequestInternal>
CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) override;
std::shared_ptr<InferenceEngine::IInferRequestInternal> std::shared_ptr<InferenceEngine::IInferRequestInternal>
CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::OutputsDataMap networkOutputs) override;

View File

@ -29,6 +29,18 @@ MKLDNNPlugin::MKLDNNInferRequest::MKLDNNInferRequest(InferenceEngine::InputsData
MKLDNNExecNetwork::Ptr execNetwork_) MKLDNNExecNetwork::Ptr execNetwork_)
: IInferRequestInternal(networkInputs, networkOutputs) : IInferRequestInternal(networkInputs, networkOutputs)
, execNetwork(execNetwork_) { , execNetwork(execNetwork_) {
CreateInferRequest();
}
MKLDNNPlugin::MKLDNNInferRequest::MKLDNNInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
MKLDNNExecNetwork::Ptr execNetwork_)
: IInferRequestInternal(inputs, outputs)
, execNetwork(execNetwork_) {
CreateInferRequest();
}
void MKLDNNPlugin::MKLDNNInferRequest::CreateInferRequest() {
auto id = (execNetwork->_numRequests)++; auto id = (execNetwork->_numRequests)++;
profilingTask = openvino::itt::handle("MKLDNN_INFER_" + execNetwork->_name + "_" + std::to_string(id)); profilingTask = openvino::itt::handle("MKLDNN_INFER_" + execNetwork->_name + "_" + std::to_string(id));

View File

@ -22,6 +22,10 @@ public:
InferenceEngine::OutputsDataMap networkOutputs, InferenceEngine::OutputsDataMap networkOutputs,
std::shared_ptr<MKLDNNExecNetwork> execNetwork); std::shared_ptr<MKLDNNExecNetwork> execNetwork);
MKLDNNInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
std::shared_ptr<MKLDNNExecNetwork> execNetwork);
~MKLDNNInferRequest(); ~MKLDNNInferRequest();
void InferImpl() override; void InferImpl() override;
@ -48,6 +52,7 @@ public:
void ThrowIfCanceled() const; void ThrowIfCanceled() const;
private: private:
void CreateInferRequest();
void PushInputData(); void PushInputData();
void PushStates(); void PushStates();
void PullStates(); void PullStates();

View File

@ -372,6 +372,30 @@ std::shared_ptr<InferenceEngine::ICore> MultiDeviceExecutableNetwork::GetCore()
return _plugin->GetCore(); return _plugin->GetCore();
} }
InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequestImpl(
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) {
auto num = _numRequestsCreated++;
size_t sum = 0;
InferenceEngine::SoIInferRequestInternal request_to_share_blobs_with;
if (_workModeIsAUTO) {
return std::make_shared<MultiDeviceInferRequest>(inputs, outputs, request_to_share_blobs_with);
}
// borrowing device-specific blobs from the underlying requests for the device-agnostic, user-facing requests
// this allows to potentially save on the data-copy later (if the requests are scheduled in the same order)
for (const auto& device : _devicePrioritiesInitial) {
auto& dev_requests = _workerRequests[device.deviceName];
if ((num - sum) < dev_requests.size()) {
request_to_share_blobs_with = dev_requests.at(num - sum)._inferRequest;
break;
}
sum += dev_requests.size();
}
return std::make_shared<MultiDeviceInferRequest>(inputs, outputs, request_to_share_blobs_with);
}
InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) { InferenceEngine::OutputsDataMap networkOutputs) {
auto num = _numRequestsCreated++; auto num = _numRequestsCreated++;
@ -396,7 +420,12 @@ InferenceEngine::IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::Create
} }
IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequest() { IInferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequest() {
auto syncRequestImpl = CreateInferRequestImpl(_networkInputs, _networkOutputs); IInferRequestInternal::Ptr syncRequestImpl;
if (this->_plugin && this->_plugin->GetCore() && GetCore()->isNewAPI())
syncRequestImpl = CreateInferRequestImpl(_parameters, _results);
if (!syncRequestImpl)
syncRequestImpl = CreateInferRequestImpl(_networkInputs, _networkOutputs);
syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this());
return std::make_shared<MultiDeviceAsyncInferRequest>(std::static_pointer_cast<MultiDeviceInferRequest>(syncRequestImpl), return std::make_shared<MultiDeviceAsyncInferRequest>(std::static_pointer_cast<MultiDeviceInferRequest>(syncRequestImpl),
_needPerfCounters, _needPerfCounters,

View File

@ -131,6 +131,8 @@ public:
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override; InferenceEngine::IInferRequestInternal::Ptr CreateInferRequest() override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs, InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs) override; InferenceEngine::OutputsDataMap networkOutputs) override;
InferenceEngine::IInferRequestInternal::Ptr CreateInferRequestImpl(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs) override;
std::shared_ptr<InferenceEngine::RemoteContext> GetContext() const override; std::shared_ptr<InferenceEngine::RemoteContext> GetContext() const override;
std::shared_ptr<InferenceEngine::ICore> GetCore() const; std::shared_ptr<InferenceEngine::ICore> GetCore() const;
~MultiDeviceExecutableNetwork() override; ~MultiDeviceExecutableNetwork() override;

View File

@ -14,10 +14,21 @@ namespace MultiDevicePlugin {
using namespace InferenceEngine; using namespace InferenceEngine;
// ------------------------------MultiDeviceInferRequest---------------------------- // ------------------------------MultiDeviceInferRequest----------------------------
MultiDeviceInferRequest::MultiDeviceInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const InferenceEngine::SoIInferRequestInternal & request_to_share_blobs_with)
: IInferRequestInternal(inputs, outputs) {
CreateInferRequest(request_to_share_blobs_with);
}
MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkInputs, MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkInputs,
const OutputsDataMap& networkOutputs, const OutputsDataMap& networkOutputs,
const SoIInferRequestInternal & request_to_share_blobs_with) const SoIInferRequestInternal & request_to_share_blobs_with)
: IInferRequestInternal(networkInputs, networkOutputs) { : IInferRequestInternal(networkInputs, networkOutputs) {
CreateInferRequest(request_to_share_blobs_with);
}
void MultiDeviceInferRequest::CreateInferRequest(const InferenceEngine::SoIInferRequestInternal& request_to_share_blobs_with) {
if (request_to_share_blobs_with) { if (request_to_share_blobs_with) {
// borrow device-friendly blobs from the request // borrow device-friendly blobs from the request
for (const auto &it : _networkInputs) for (const auto &it : _networkInputs)
@ -27,7 +38,7 @@ MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkI
return; return;
} }
// Allocate all input blobs // Allocate all input blobs
for (const auto &it : networkInputs) { for (const auto &it : _networkInputs) {
Layout l = it.second->getLayout(); Layout l = it.second->getLayout();
Precision p = it.second->getPrecision(); Precision p = it.second->getPrecision();
SizeVector dims = it.second->getTensorDesc().getDims(); SizeVector dims = it.second->getTensorDesc().getDims();
@ -37,7 +48,7 @@ MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkI
_inputs[it.first]->allocate(); _inputs[it.first]->allocate();
} }
// Allocate all output blobs // Allocate all output blobs
for (const auto &it : networkOutputs) { for (const auto &it : _networkOutputs) {
Layout l = it.second->getLayout(); Layout l = it.second->getLayout();
Precision p = it.second->getPrecision(); Precision p = it.second->getPrecision();
SizeVector dims = it.second->getTensorDesc().getDims(); SizeVector dims = it.second->getTensorDesc().getDims();
@ -47,7 +58,6 @@ MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkI
_outputs[it.first]->allocate(); _outputs[it.first]->allocate();
} }
} }
void MultiDeviceInferRequest::SetBlobsToAnotherRequest(const SoIInferRequestInternal& req) { void MultiDeviceInferRequest::SetBlobsToAnotherRequest(const SoIInferRequestInternal& req) {
for (const auto &it : _networkInputs) { for (const auto &it : _networkInputs) {
auto &name = it.first; auto &name = it.first;

View File

@ -24,10 +24,16 @@ public:
explicit MultiDeviceInferRequest(const InferenceEngine::InputsDataMap& networkInputs, explicit MultiDeviceInferRequest(const InferenceEngine::InputsDataMap& networkInputs,
const InferenceEngine::OutputsDataMap& networkOutputs, const InferenceEngine::OutputsDataMap& networkOutputs,
const InferenceEngine::SoIInferRequestInternal & request_to_share_blobs_with); const InferenceEngine::SoIInferRequestInternal & request_to_share_blobs_with);
explicit MultiDeviceInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const InferenceEngine::SoIInferRequestInternal & request_to_share_blobs_with);
std::map<std::string, InferenceEngine::InferenceEngineProfileInfo> GetPerformanceCounts() const override; std::map<std::string, InferenceEngine::InferenceEngineProfileInfo> GetPerformanceCounts() const override;
void InferImpl() override; void InferImpl() override;
// Multi-Device impl specific: sets the data (blobs from the device-less requests to the specific device request) // Multi-Device impl specific: sets the data (blobs from the device-less requests to the specific device request)
void SetBlobsToAnotherRequest(const InferenceEngine::SoIInferRequestInternal& req); void SetBlobsToAnotherRequest(const InferenceEngine::SoIInferRequestInternal& req);
private:
void CreateInferRequest(const InferenceEngine::SoIInferRequestInternal& request_to_share_blobs_with);
}; };
} // namespace MultiDevicePlugin } // namespace MultiDevicePlugin

View File

@ -58,7 +58,13 @@ protected:
*/ */
template <typename AsyncInferRequestType = AsyncInferRequestThreadSafeDefault> template <typename AsyncInferRequestType = AsyncInferRequestThreadSafeDefault>
IInferRequestInternal::Ptr CreateAsyncInferRequestFromSync() { IInferRequestInternal::Ptr CreateAsyncInferRequestFromSync() {
auto syncRequestImpl = this->CreateInferRequestImpl(_networkInputs, _networkOutputs); InferenceEngine::IInferRequestInternal::Ptr syncRequestImpl;
try {
syncRequestImpl = this->CreateInferRequestImpl(_parameters, _results);
} catch (const NotImplemented&) {
}
if (!syncRequestImpl)
syncRequestImpl = this->CreateInferRequestImpl(_networkInputs, _networkOutputs);
syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this());
return std::make_shared<AsyncInferRequestType>(syncRequestImpl, _taskExecutor, _callbackExecutor); return std::make_shared<AsyncInferRequestType>(syncRequestImpl, _taskExecutor, _callbackExecutor);
} }

View File

@ -145,7 +145,8 @@ public:
AsyncInferRequestThreadSafeDefault(const IInferRequestInternal::Ptr& request, AsyncInferRequestThreadSafeDefault(const IInferRequestInternal::Ptr& request,
const ITaskExecutor::Ptr& taskExecutor, const ITaskExecutor::Ptr& taskExecutor,
const ITaskExecutor::Ptr& callbackExecutor) const ITaskExecutor::Ptr& callbackExecutor)
: _syncRequest{request}, : IInferRequestInternal(*request),
_syncRequest{request},
_requestExecutor{taskExecutor}, _requestExecutor{taskExecutor},
_callbackExecutor{callbackExecutor}, _callbackExecutor{callbackExecutor},
_pipeline{{taskExecutor, _pipeline{{taskExecutor,

View File

@ -168,6 +168,17 @@ protected:
*/ */
virtual std::shared_ptr<IInferRequestInternal> CreateInferRequestImpl(InputsDataMap networkInputs, virtual std::shared_ptr<IInferRequestInternal> CreateInferRequestImpl(InputsDataMap networkInputs,
OutputsDataMap networkOutputs); OutputsDataMap networkOutputs);
/**
* @brief Creates an inference request internal implementation.
* @note The method is called by IExecutableNetworkInternal::CreateInferRequest as
* plugin-specific implementation.
* @param[in] inputs The function inputs
* @param[in] outputs The function outputs
* @return A shared pointer to inference request object.
*/
virtual std::shared_ptr<IInferRequestInternal> CreateInferRequestImpl(
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs);
InferenceEngine::InputsDataMap _networkInputs; //!< Holds information about network inputs info InferenceEngine::InputsDataMap _networkInputs; //!< Holds information about network inputs info
InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data

View File

@ -13,6 +13,7 @@
#include "ie_common.h" #include "ie_common.h"
#include "ie_input_info.hpp" #include "ie_input_info.hpp"
#include "ie_preprocess_data.hpp" #include "ie_preprocess_data.hpp"
#include "openvino/core/node_output.hpp"
#include "so_ptr.hpp" #include "so_ptr.hpp"
namespace InferenceEngine { namespace InferenceEngine {
@ -42,6 +43,14 @@ public:
*/ */
IInferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs); IInferRequestInternal(const InputsDataMap& networkInputs, const OutputsDataMap& networkOutputs);
/**
* @brief Constructs a new instance.
* @param[in] inputs The network inputs
* @param[in] outputs The network outputs
*/
IInferRequestInternal(const std::vector<std::shared_ptr<const ov::Node>>& networkInputs,
const std::vector<std::shared_ptr<const ov::Node>>& networkOutputs);
/** /**
* @brief Infers specified input(s) in synchronous mode * @brief Infers specified input(s) in synchronous mode
* @note blocks all method of InferRequest while request is ongoing (running or waiting in queue) * @note blocks all method of InferRequest while request is ongoing (running or waiting in queue)
@ -190,6 +199,9 @@ public:
INFERENCE_ENGINE_DEPRECATED("The method will be removed") INFERENCE_ENGINE_DEPRECATED("The method will be removed")
void SetUserData(void* userData) noexcept; void SetUserData(void* userData) noexcept;
const std::vector<std::shared_ptr<const ov::Node>>& GetInputs() const;
const std::vector<std::shared_ptr<const ov::Node>>& GetOutputs() const;
protected: protected:
/** /**
* @brief Destroys the object. * @brief Destroys the object.
@ -232,8 +244,10 @@ protected:
InferenceEngine::BlobMap _inputs; //!< A map of user passed blobs for network inputs InferenceEngine::BlobMap _inputs; //!< A map of user passed blobs for network inputs
InferenceEngine::BlobMap _deviceInputs; //!< A map of actual network inputs, in plugin specific format InferenceEngine::BlobMap _deviceInputs; //!< A map of actual network inputs, in plugin specific format
InferenceEngine::BlobMap _outputs; //!< A map of user passed blobs for network outputs InferenceEngine::BlobMap _outputs; //!< A map of user passed blobs for network outputs
std::map<std::string, PreProcessDataPtr> _preProcData; //!< A map of pre-process data per input std::vector<std::shared_ptr<const ov::Node>> _parameters; //!< A vector of function inputs
int m_curBatch = -1; //!< Current batch value used in dynamic batching std::vector<std::shared_ptr<const ov::Node>> _results; //!< A vector of function outputs
std::map<std::string, PreProcessDataPtr> _preProcData; //!< A map of pre-process data per input
int m_curBatch = -1; //!< Current batch value used in dynamic batching
/** /**
* @brief A shared pointer to IInferRequestInternal * @brief A shared pointer to IInferRequestInternal

View File

@ -49,14 +49,17 @@ bool has_op_with_type(const std::shared_ptr<const ngraph::Function> &function) {
} }
return false; return false;
} }
inline std::string create_ie_output_name(const ngraph::Output<ngraph::Node>& output) { inline std::string create_ie_output_name(const ngraph::Output<const ngraph::Node>& output) {
const auto& prev_layer = output.get_node_shared_ptr(); const auto& prev_layer = output.get_node_shared_ptr();
std::string out_name = prev_layer->get_friendly_name(); std::string out_name = prev_layer->get_friendly_name();
if (prev_layer->get_output_size() != 1) if (prev_layer->get_output_size() != 1)
out_name += "." + std::to_string(output.get_index()); out_name += "." + std::to_string(output.get_index());
return out_name; return out_name;
} }
inline std::string get_ie_output_name(const ngraph::Output<ngraph::Node>& output) { inline std::string create_ie_output_name(const ngraph::Output<ngraph::Node>& output) {
return create_ie_output_name(ov::Output<const ngraph::Node>(output.get_node(), output.get_index()));
}
inline std::string get_ie_output_name(const ngraph::Output<const ngraph::Node>& output) {
NGRAPH_SUPPRESS_DEPRECATED_START NGRAPH_SUPPRESS_DEPRECATED_START
auto name = output.get_tensor().get_name(); auto name = output.get_tensor().get_name();
NGRAPH_SUPPRESS_DEPRECATED_END NGRAPH_SUPPRESS_DEPRECATED_END
@ -65,6 +68,9 @@ inline std::string get_ie_output_name(const ngraph::Output<ngraph::Node>& output
} }
return name; return name;
} }
inline std::string get_ie_output_name(const ngraph::Output<ngraph::Node>& output) {
return get_ie_output_name(ov::Output<const ngraph::Node>(output.get_node(), output.get_index()));
}
template <typename T> template <typename T>
bool has_constant_value(const std::shared_ptr<ngraph::opset4::Constant>& constant, bool has_constant_value(const std::shared_ptr<ngraph::opset4::Constant>& constant,

View File

@ -80,7 +80,7 @@ int64_t op::internal::NonMaxSuppressionIEInternal::max_boxes_output_from_input()
} }
const auto max_output_boxes_input = const auto max_output_boxes_input =
ov::as_type_ptr<op::Constant>(input_value(max_output_boxes_per_class_port).get_node_shared_ptr()); ov::as_type_ptr<const op::Constant>(input_value(max_output_boxes_per_class_port).get_node_shared_ptr());
max_output_boxes = max_output_boxes_input->cast_vector<int64_t>().at(0); max_output_boxes = max_output_boxes_input->cast_vector<int64_t>().at(0);
return max_output_boxes; return max_output_boxes;

View File

@ -22,6 +22,8 @@
#include "myriad_executor.h" #include "myriad_executor.h"
#include "myriad_infer_request.h" #include "myriad_infer_request.h"
#include "myriad_async_infer_request.h" #include "myriad_async_infer_request.h"
#include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "ie_icore.hpp"
namespace vpu { namespace vpu {
namespace MyriadPlugin { namespace MyriadPlugin {
@ -52,7 +54,7 @@ public:
} }
ie::IInferRequestInternal::Ptr CreateInferRequestImpl(ie::InputsDataMap networkInputs, ie::IInferRequestInternal::Ptr CreateInferRequestImpl(ie::InputsDataMap networkInputs,
ie::OutputsDataMap networkOutputs) override { ie::OutputsDataMap networkOutputs) override {
if (!_isNetworkConstant && (_device == nullptr || !_device->isBooted())) { if (!_isNetworkConstant && (_device == nullptr || !_device->isBooted())) {
IE_THROW() << "Can not create infer request: there is no available devices with platform "; IE_THROW() << "Can not create infer request: there is no available devices with platform ";
} }
@ -67,11 +69,17 @@ public:
if (!_isNetworkConstant && (_device == nullptr || !_device->isBooted())) { if (!_isNetworkConstant && (_device == nullptr || !_device->isBooted())) {
IE_THROW() << "Can not create infer request: there is no available devices with platform "; IE_THROW() << "Can not create infer request: there is no available devices with platform ";
} }
std::shared_ptr<MyriadInferRequest> syncRequestImpl;
auto syncRequestImpl = std::make_shared<MyriadInferRequest>(_graphDesc, _networkInputs, _networkOutputs, if (this->_plugin && this->_plugin->GetCore() && this->_plugin->GetCore()->isNewAPI())
_inputInfo, _outputInfo, syncRequestImpl = std::make_shared<MyriadInferRequest>(_graphDesc, _parameters, _results,
_graphMetaData.stagesMeta, _config, _log, _inputInfo, _outputInfo,
_executor, _constDatas, _isNetworkConstant); _graphMetaData.stagesMeta, _config, _log,
_executor, _constDatas, _isNetworkConstant);
if (!syncRequestImpl)
syncRequestImpl = std::make_shared<MyriadInferRequest>(_graphDesc, _networkInputs, _networkOutputs,
_inputInfo, _outputInfo,
_graphMetaData.stagesMeta, _config, _log,
_executor, _constDatas, _isNetworkConstant);
syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this()); syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this());
auto taskExecutorGetResult = getNextTaskExecutor(); auto taskExecutorGetResult = getNextTaskExecutor();
return std::make_shared<MyriadAsyncInferRequest>( return std::make_shared<MyriadAsyncInferRequest>(

View File

@ -28,6 +28,24 @@ using namespace InferenceEngine;
#define MEMCPY(dst, src, bytes) std::copy_n((src), (bytes), (dst)) #define MEMCPY(dst, src, bytes) std::copy_n((src), (bytes), (dst))
MyriadInferRequest::MyriadInferRequest(GraphDesc &graphDesc,
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
DataInfo& compilerInputsInfo,
DataInfo& compilerOutputsInfo,
const std::vector<StageMetaInfo> &blobMetaData,
const PluginConfiguration& myriadConfig,
const Logger::Ptr &log,
const MyriadExecutorPtr &executor,
std::map<std::string, ie::Blob::Ptr> constDatas,
bool isNetworkConstant = true) :
IInferRequestInternal(inputs, outputs), _executor(executor),
_log(log), _stagesMetaData(blobMetaData), _config(myriadConfig),
_inputInfo(compilerInputsInfo), _outputInfo(compilerOutputsInfo),
_graphDesc(graphDesc), _constDatas(constDatas), _isNetworkConstant(isNetworkConstant) {
CreateInferRequest();
}
MyriadInferRequest::MyriadInferRequest(GraphDesc &graphDesc, MyriadInferRequest::MyriadInferRequest(GraphDesc &graphDesc,
InferenceEngine::InputsDataMap networkInputs, InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs, InferenceEngine::OutputsDataMap networkOutputs,
@ -43,6 +61,10 @@ MyriadInferRequest::MyriadInferRequest(GraphDesc &graphDesc,
_log(log), _stagesMetaData(blobMetaData), _config(myriadConfig), _log(log), _stagesMetaData(blobMetaData), _config(myriadConfig),
_inputInfo(compilerInputsInfo), _outputInfo(compilerOutputsInfo), _inputInfo(compilerInputsInfo), _outputInfo(compilerOutputsInfo),
_graphDesc(graphDesc), _constDatas(constDatas), _isNetworkConstant(isNetworkConstant) { _graphDesc(graphDesc), _constDatas(constDatas), _isNetworkConstant(isNetworkConstant) {
CreateInferRequest();
}
void MyriadInferRequest::CreateInferRequest() {
VPU_PROFILE(MyriadInferRequest); VPU_PROFILE(MyriadInferRequest);
const auto& ioStrides = _config.get<TensorStridesOption>(); const auto& ioStrides = _config.get<TensorStridesOption>();
@ -84,8 +106,8 @@ MyriadInferRequest::MyriadInferRequest(GraphDesc &graphDesc,
_outputs[networkOutput.first] = outputBlob; _outputs[networkOutput.first] = outputBlob;
} }
inputBuffer .resize(compilerInputsInfo.totalSize); inputBuffer .resize(_inputInfo.totalSize);
resultBuffer.resize(compilerOutputsInfo.totalSize); resultBuffer.resize(_outputInfo.totalSize);
VPU_THROW_UNLESS( VPU_THROW_UNLESS(
!_networkOutputs.empty() && !(_networkInputs.empty() && !_isNetworkConstant), !_networkOutputs.empty() && !(_networkInputs.empty() && !_isNetworkConstant),

View File

@ -35,21 +35,34 @@ class MyriadInferRequest : public InferenceEngine::IInferRequestInternal {
std::vector<uint8_t> inputBuffer; std::vector<uint8_t> inputBuffer;
std::map<std::string, ie::Blob::Ptr> _constDatas; std::map<std::string, ie::Blob::Ptr> _constDatas;
bool _isNetworkConstant; bool _isNetworkConstant;
void CreateInferRequest();
public: public:
typedef std::shared_ptr<MyriadInferRequest> Ptr; typedef std::shared_ptr<MyriadInferRequest> Ptr;
explicit MyriadInferRequest(GraphDesc &_graphDesc, MyriadInferRequest(GraphDesc &_graphDesc,
InferenceEngine::InputsDataMap networkInputs, InferenceEngine::InputsDataMap networkInputs,
InferenceEngine::OutputsDataMap networkOutputs, InferenceEngine::OutputsDataMap networkOutputs,
DataInfo& compilerInputsInfo, DataInfo& compilerInputsInfo,
DataInfo& compilerOutputsInfo, DataInfo& compilerOutputsInfo,
const std::vector<StageMetaInfo> &blobMetaData, const std::vector<StageMetaInfo> &blobMetaData,
const PluginConfiguration &myriadConfig, const PluginConfiguration &myriadConfig,
const Logger::Ptr &log, const Logger::Ptr &log,
const MyriadExecutorPtr &executor, const MyriadExecutorPtr &executor,
std::map<std::string, ie::Blob::Ptr> constDatas, std::map<std::string, ie::Blob::Ptr> constDatas,
bool isNetworkConstant); bool isNetworkConstant);
MyriadInferRequest(GraphDesc &_graphDesc,
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
DataInfo& compilerInputsInfo,
DataInfo& compilerOutputsInfo,
const std::vector<StageMetaInfo> &blobMetaData,
const PluginConfiguration &myriadConfig,
const Logger::Ptr &log,
const MyriadExecutorPtr &executor,
std::map<std::string, ie::Blob::Ptr> constDatas,
bool isNetworkConstant);
void InferImpl() override; void InferImpl() override;
void InferAsync(); void InferAsync();

View File

@ -16,12 +16,12 @@ using namespace InferenceEngine::details;
TEST(InferRequestOVTests, throwsOnUninitializedSetTensor) { TEST(InferRequestOVTests, throwsOnUninitializedSetTensor) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ASSERT_THROW(req.set_tensor({}, {}), ov::Exception); ASSERT_THROW(req.set_tensor("", {}), ov::Exception);
} }
TEST(InferRequestOVTests, throwsOnUninitializedGetTensor) { TEST(InferRequestOVTests, throwsOnUninitializedGetTensor) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ASSERT_THROW(req.get_tensor({}), ov::Exception); ASSERT_THROW(req.get_tensor(""), ov::Exception);
} }
TEST(InferRequestOVTests, throwsOnUninitializedInfer) { TEST(InferRequestOVTests, throwsOnUninitializedInfer) {
@ -60,9 +60,26 @@ TEST(InferRequestOVTests, throwsOnUninitializedQueryState) {
ASSERT_THROW(req.query_state(), ov::Exception); ASSERT_THROW(req.query_state(), ov::Exception);
} }
TEST(InferRequestOVTests, throwsOnUninitializedSetRemoteTensorWithName) {
ov::runtime::InferRequest req;
ov::runtime::RemoteTensor remote_tensor;
ASSERT_THROW(req.set_tensor("", remote_tensor), ov::Exception);
}
TEST(InferRequestOVTests, throwsOnUninitializedSetInputRemoteTensor) {
ov::runtime::InferRequest req;
ov::runtime::RemoteTensor remote_tensor;
ASSERT_THROW(req.set_input_tensor(0, remote_tensor), ov::Exception);
}
TEST(InferRequestOVTests, throwsOnUninitializedSetOutputRemoteTensor) {
ov::runtime::InferRequest req;
ov::runtime::RemoteTensor remote_tensor;
ASSERT_THROW(req.set_output_tensor(0, remote_tensor), ov::Exception);
}
TEST(InferRequestOVTests, throwsOnUninitializedSetRemoteTensor) { TEST(InferRequestOVTests, throwsOnUninitializedSetRemoteTensor) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::RemoteTensor remote_tensor; ov::runtime::RemoteTensor remote_tensor;
ASSERT_THROW(req.set_tensor({}, remote_tensor), ov::Exception); ASSERT_THROW(req.set_tensor(ov::Output<const ov::Node>(), remote_tensor), ov::Exception);
} }

View File

@ -28,12 +28,14 @@ std::shared_ptr<ngraph::Function> getFunction1() {
auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
params.front()->set_friendly_name("Param_1"); params.front()->set_friendly_name("Param_1");
params.front()->get_output_tensor(0).set_names({"Tensor_1"}); params.front()->get_output_tensor(0).set_names({"input_tensor"});
auto in2add = ngraph::builder::makeConstant(ngPrc, {1, 4, 1, 1}, std::vector<float>{}, true); auto in2add = ngraph::builder::makeConstant(ngPrc, {1, 4, 1, 1}, std::vector<float>{}, true);
auto add = ngraph::builder::makeEltwise(params[0], in2add, ngraph::helpers::EltwiseTypes::ADD); auto add = ngraph::builder::makeEltwise(params[0], in2add, ngraph::helpers::EltwiseTypes::ADD);
auto relu1 = std::make_shared<ngraph::opset1::Relu>(add->output(0)); auto relu1 = std::make_shared<ngraph::opset1::Relu>(add->output(0));
relu1->get_output_tensor(0).set_names({"relu1"});
auto relu2 = std::make_shared<ngraph::opset1::Relu>(add->output(0)); auto relu2 = std::make_shared<ngraph::opset1::Relu>(add->output(0));
relu2->get_output_tensor(0).set_names({"relu2"});
ngraph::NodeVector results{relu1, relu2}; ngraph::NodeVector results{relu1, relu2};
return std::make_shared<ngraph::Function>(results, params, "AddTwoOutputEdges"); return std::make_shared<ngraph::Function>(results, params, "AddTwoOutputEdges");
@ -45,7 +47,7 @@ std::shared_ptr<ngraph::Function> getFunction2() {
auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
params.front()->set_friendly_name("Param_1"); params.front()->set_friendly_name("Param_1");
params.front()->get_output_tensor(0).set_names({"Tensor_1"}); params.front()->get_output_tensor(0).set_names({"input_tensor"});
auto split = ngraph::builder::makeSplit(params[0], ngPrc, 2, 1); auto split = ngraph::builder::makeSplit(params[0], ngPrc, 2, 1);
auto in2add = ngraph::builder::makeConstant(ngPrc, {1, 2, 1, 1}, std::vector<float>{}, true); auto in2add = ngraph::builder::makeConstant(ngPrc, {1, 2, 1, 1}, std::vector<float>{}, true);
@ -57,6 +59,7 @@ std::shared_ptr<ngraph::Function> getFunction2() {
auto relu2 = std::make_shared<ngraph::opset1::Relu>(mult); auto relu2 = std::make_shared<ngraph::opset1::Relu>(mult);
auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{relu1->output(0), relu2->output(0)}, 3); auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{relu1->output(0), relu2->output(0)}, 3);
concat->get_output_tensor(0).set_names({"concat"});
return std::make_shared<ngraph::Function>(concat, params, "SplitAddConcat"); return std::make_shared<ngraph::Function>(concat, params, "SplitAddConcat");
} }

View File

@ -62,6 +62,7 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*OVExecutableNetworkBaseTest.*canLoadCorrectNetworkToGetExecutableWithIncorrectConfig.*)", R"(.*OVExecutableNetworkBaseTest.*canLoadCorrectNetworkToGetExecutableWithIncorrectConfig.*)",
R"(.*OVExecutableNetworkBaseTest.*CanSetConfigToExecNet.*)", R"(.*OVExecutableNetworkBaseTest.*CanSetConfigToExecNet.*)",
R"(.*OVExecutableNetworkBaseTest.*CanGetInputsInfoAndCheck.*)", R"(.*OVExecutableNetworkBaseTest.*CanGetInputsInfoAndCheck.*)",
R"(.*OVExecutableNetworkBaseTest.*getOutputsFromSplitFunctionWithSeveralOutputs.*)",
R"(.*OVClassHeteroExecutableNetworkGetMetricTest_TARGET_FALLBACK.*GetMetricNoThrow.*)", R"(.*OVClassHeteroExecutableNetworkGetMetricTest_TARGET_FALLBACK.*GetMetricNoThrow.*)",
R"(.*Behavior.*OVExecutableNetworkBaseTest.*get(Inputs|Outputs)FromFunctionWithSeveral(Inputs|Outputs).*)", R"(.*Behavior.*OVExecutableNetworkBaseTest.*get(Inputs|Outputs)FromFunctionWithSeveral(Inputs|Outputs).*)",
// TODO: Issue: 29577 // TODO: Issue: 29577

View File

@ -32,6 +32,7 @@ addIeTarget(
PUBLIC PUBLIC
pugixml::static pugixml::static
funcTestUtils funcTestUtils
ngraph_test_util
ngraphFunctions ngraphFunctions
lptNgraphFunctions lptNgraphFunctions
sharedTestClasses sharedTestClasses

View File

@ -85,7 +85,7 @@ protected:
}; };
TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithoutSetShape) { TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithoutSetShape) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
shapes[tensor_name] = {ov::Dimension::dynamic(), 4, 20, 20}; shapes[tensor_name] = {ov::Dimension::dynamic(), 4, 20, 20};
ASSERT_NO_THROW(function->reshape(shapes)); ASSERT_NO_THROW(function->reshape(shapes));
@ -95,11 +95,11 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithoutSetShape) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor; ov::runtime::Tensor tensor;
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
} }
TEST_P(InferRequestDynamicTests, InferDynamicNetworkBoundWithoutSetShape) { TEST_P(InferRequestDynamicTests, InferDynamicNetworkBoundWithoutSetShape) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
shapes[tensor_name] = {ov::Dimension(0, 5), 4, 20, 20}; shapes[tensor_name] = {ov::Dimension(0, 5), 4, 20, 20};
ASSERT_NO_THROW(function->reshape(shapes)); ASSERT_NO_THROW(function->reshape(shapes));
@ -109,12 +109,12 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkBoundWithoutSetShape) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor; ov::runtime::Tensor tensor;
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
} }
TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor) { TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -125,11 +125,10 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor) {
// Create InferRequest // Create InferRequest
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor, otensor; ov::runtime::Tensor tensor, otensor;
const std::string outputname = ngraph::op::util::create_ie_output_name( const std::string outputname = function->outputs().back().get_any_name();
function->get_results().front()->input_value(0));
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
//ASSERT_NO_THROW(req.SetShape(tensor_name, {1, 4, 20, 20})); //ASSERT_NO_THROW(req.SetShape(tensor_name, {1, 4, 20, 20}));
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20})); ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20}));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(otensor = req.get_tensor(outputname)); ASSERT_NO_THROW(otensor = req.get_tensor(outputname));
@ -144,7 +143,7 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor) {
} }
TEST_P(InferRequestDynamicTests, InferUpperBoundNetworkWithGetTensor) { TEST_P(InferRequestDynamicTests, InferUpperBoundNetworkWithGetTensor) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -155,14 +154,13 @@ TEST_P(InferRequestDynamicTests, InferUpperBoundNetworkWithGetTensor) {
// Create InferRequest // Create InferRequest
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor, otensor; ov::runtime::Tensor tensor, otensor;
const std::string outputname = ngraph::op::util::create_ie_output_name( const std::string outputname = function->outputs().back().get_any_name();
function->get_results().front()->input_value(0));
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
//ASSERT_NO_THROW(req.SetShape(tensor_name, {1, 4, 20, 20})); //ASSERT_NO_THROW(req.SetShape(tensor_name, {1, 4, 20, 20}));
ASSERT_NO_THROW(otensor = req.get_tensor(outputname)); ASSERT_NO_THROW(otensor = req.get_tensor(outputname));
ASSERT_EQ(0, otensor.get_size()); // output tensor is not allocated ASSERT_EQ(0, otensor.get_size()); // output tensor is not allocated
ASSERT_EQ(function->output().get_element_type(), otensor.get_element_type()); // by it has type ASSERT_EQ(function->output().get_element_type(), otensor.get_element_type()); // by it has type
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20})); ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20}));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
@ -172,7 +170,7 @@ TEST_P(InferRequestDynamicTests, InferUpperBoundNetworkWithGetTensor) {
} }
TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithGetTensor) { TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithGetTensor) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -183,25 +181,24 @@ TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithGetTensor) {
// Create InferRequest // Create InferRequest
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor, otensor; ov::runtime::Tensor tensor, otensor;
const std::string outputname = ngraph::op::util::create_ie_output_name( const std::string outputName = function->outputs().back().get_any_name();
function->get_results().front()->input_value(0));
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
//ASSERT_NO_THROW(req.SetShape(tensor_name, {1, 4, 20, 20})); //ASSERT_NO_THROW(req.SetShape(tensor_name, {1, 4, 20, 20}));
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20})); ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20}));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(otensor = req.get_tensor(outputname)); ASSERT_NO_THROW(otensor = req.get_tensor(outputName));
ASSERT_EQ(0, otensor.get_size()); // output tensor is not allocated ASSERT_EQ(0, otensor.get_size()); // output tensor is not allocated
ASSERT_EQ(function->output().get_element_type(), otensor.get_element_type()); // by it has type ASSERT_EQ(function->output().get_element_type(), otensor.get_element_type()); // by it has type
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
ASSERT_NO_THROW(req.wait()); ASSERT_NO_THROW(req.wait());
ASSERT_NO_THROW(otensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); ASSERT_NO_THROW(otensor = req.get_tensor(outputName));
ASSERT_EQ(otensor.get_shape(), refOutShape); ASSERT_EQ(otensor.get_shape(), refOutShape);
} }
TEST_P(InferRequestDynamicTests, InferOutOfRangeShapeNetworkWithGetTensorLower) { TEST_P(InferRequestDynamicTests, InferOutOfRangeShapeNetworkWithGetTensorLower) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -213,14 +210,14 @@ TEST_P(InferRequestDynamicTests, InferOutOfRangeShapeNetworkWithGetTensorLower)
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor; ov::runtime::Tensor tensor;
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20})); ASSERT_NO_THROW(tensor.set_shape({1, 4, 20, 20}));
// Plugin may or may not throw in case if input tensor has dimensions that are out of bounds // Plugin may or may not throw in case if input tensor has dimensions that are out of bounds
//ASSERT_THROW(req.infer(), ov::Exception); //ASSERT_THROW(req.infer(), ov::Exception);
} }
TEST_P(InferRequestDynamicTests, InferOutOfRangeShapeNetworkWithGetTensorUpper) { TEST_P(InferRequestDynamicTests, InferOutOfRangeShapeNetworkWithGetTensorUpper) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -232,14 +229,14 @@ TEST_P(InferRequestDynamicTests, InferOutOfRangeShapeNetworkWithGetTensorUpper)
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor; ov::runtime::Tensor tensor;
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape({3, 4, 20, 20})); ASSERT_NO_THROW(tensor.set_shape({3, 4, 20, 20}));
// Plugin may or may not throw in case if input tensor has dimensions that are out of bounds // Plugin may or may not throw in case if input tensor has dimensions that are out of bounds
// ASSERT_THROW(req.infer(), ov::Exception); // ASSERT_THROW(req.infer(), ov::Exception);
} }
TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor2times) { TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor2times) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refShape2 = inOutShapes[1].first; const ov::Shape refShape2 = inOutShapes[1].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
@ -253,28 +250,29 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithGetTensor2times) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor; ov::runtime::Tensor tensor;
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape(refShape)); ASSERT_NO_THROW(tensor.set_shape(refShape));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
req.wait(); req.wait();
ASSERT_NO_THROW(tensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); const std::string outputName = function->outputs().back().get_any_name();
ASSERT_NO_THROW(tensor = req.get_tensor(outputName));
ASSERT_EQ(tensor.get_shape(), refOutShape); ASSERT_EQ(tensor.get_shape(), refOutShape);
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape(refShape2)); ASSERT_NO_THROW(tensor.set_shape(refShape2));
ASSERT_EQ(tensor.get_shape(), refShape2); ASSERT_EQ(tensor.get_shape(), refShape2);
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
req.wait(); req.wait();
ASSERT_NO_THROW(tensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); ASSERT_NO_THROW(tensor = req.get_tensor(outputName));
ASSERT_EQ(tensor.get_shape(), refOutShape2); ASSERT_EQ(tensor.get_shape(), refOutShape2);
} }
TEST_P(InferRequestDynamicTests, GetSameTensor2times) { TEST_P(InferRequestDynamicTests, GetSameTensor2times) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
shapes[tensor_name] = {ov::Dimension::dynamic(), 4, 20, 20}; shapes[tensor_name] = {ov::Dimension::dynamic(), 4, 20, 20};
@ -285,15 +283,15 @@ TEST_P(InferRequestDynamicTests, GetSameTensor2times) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor; ov::runtime::Tensor tensor;
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_NO_THROW(tensor.set_shape(refShape)); ASSERT_NO_THROW(tensor.set_shape(refShape));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(tensor = req.get_tensor(function->get_parameters().back()->get_friendly_name())); ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name()));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
} }
TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor) { TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -305,17 +303,18 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor) {
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor(ov::element::f32, refShape); ov::runtime::Tensor tensor(ov::element::f32, refShape);
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(req.set_tensor(function->get_parameters().back()->get_friendly_name(), tensor)); ASSERT_NO_THROW(req.set_tensor(function->inputs().back().get_any_name(), tensor));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
ASSERT_NO_THROW(req.wait()); ASSERT_NO_THROW(req.wait());
ASSERT_NO_THROW(tensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); const std::string outputName = function->outputs().back().get_any_name();
ASSERT_NO_THROW(tensor = req.get_tensor(outputName));
ASSERT_EQ(tensor.get_shape(), refOutShape); ASSERT_EQ(tensor.get_shape(), refOutShape);
} }
TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithSetTensor) { TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithSetTensor) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
@ -326,12 +325,11 @@ TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithSetTensor) {
// Create InferRequest // Create InferRequest
ov::runtime::InferRequest req; ov::runtime::InferRequest req;
ov::runtime::Tensor tensor(ov::element::f32, refShape), otensor; ov::runtime::Tensor tensor(ov::element::f32, refShape), otensor;
const std::string outputname = ngraph::op::util::create_ie_output_name( const std::string outputName = function->outputs().back().get_any_name();
function->get_results().front()->input_value(0));
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(req.set_tensor(function->get_parameters().back()->get_friendly_name(), tensor)); ASSERT_NO_THROW(req.set_tensor(function->inputs().back().get_any_name(), tensor));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(otensor = req.get_tensor(outputname)); ASSERT_NO_THROW(otensor = req.get_tensor(outputName));
ASSERT_EQ(0, otensor.get_size()); // output tensor is not allocated ASSERT_EQ(0, otensor.get_size()); // output tensor is not allocated
ASSERT_EQ(function->output().get_element_type(), otensor.get_element_type()); // by it has type ASSERT_EQ(function->output().get_element_type(), otensor.get_element_type()); // by it has type
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
@ -339,13 +337,13 @@ TEST_P(InferRequestDynamicTests, InferFullyDynamicNetworkWithSetTensor) {
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
ASSERT_NO_THROW(req.wait()); ASSERT_NO_THROW(req.wait());
ASSERT_EQ(otensor.get_shape(), refOutShape); ASSERT_EQ(otensor.get_shape(), refOutShape);
ASSERT_NO_THROW(tensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); ASSERT_NO_THROW(tensor = req.get_tensor(outputName));
ASSERT_EQ(tensor.get_shape(), refOutShape); ASSERT_EQ(tensor.get_shape(), refOutShape);
ASSERT_EQ(otensor.get_shape(), refOutShape); ASSERT_EQ(otensor.get_shape(), refOutShape);
} }
TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor2times) { TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor2times) {
const std::string tensor_name = "Tensor_1"; const std::string tensor_name = "input_tensor";
const ov::Shape refShape = inOutShapes[0].first; const ov::Shape refShape = inOutShapes[0].first;
const ov::Shape refShape2 = inOutShapes[1].first; const ov::Shape refShape2 = inOutShapes[1].first;
const ov::Shape refOutShape = inOutShapes[0].second; const ov::Shape refOutShape = inOutShapes[0].second;
@ -353,6 +351,7 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor2times) {
std::map<std::string, ov::PartialShape> shapes; std::map<std::string, ov::PartialShape> shapes;
shapes[tensor_name] = {ov::Dimension::dynamic(), 4, 20, 20}; shapes[tensor_name] = {ov::Dimension::dynamic(), 4, 20, 20};
ASSERT_NO_THROW(function->reshape(shapes)); ASSERT_NO_THROW(function->reshape(shapes));
const std::string outputName = function->outputs().back().get_any_name();
// Load ov::Function to target plugins // Load ov::Function to target plugins
auto execNet = ie->compile_model(function, targetDevice, configuration); auto execNet = ie->compile_model(function, targetDevice, configuration);
// Create InferRequest // Create InferRequest
@ -360,22 +359,22 @@ TEST_P(InferRequestDynamicTests, InferDynamicNetworkWithSetTensor2times) {
ov::runtime::Tensor tensor(ov::element::f32, refShape); ov::runtime::Tensor tensor(ov::element::f32, refShape);
ASSERT_NO_THROW(req = execNet.create_infer_request()); ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_NO_THROW(req.set_tensor(function->get_parameters().back()->get_friendly_name(), tensor)); ASSERT_NO_THROW(req.set_tensor(function->inputs().back().get_any_name(), tensor));
ASSERT_EQ(tensor.get_shape(), refShape); ASSERT_EQ(tensor.get_shape(), refShape);
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
ASSERT_NO_THROW(req.wait()); ASSERT_NO_THROW(req.wait());
ASSERT_NO_THROW(tensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); ASSERT_NO_THROW(tensor = req.get_tensor(outputName));
ASSERT_EQ(tensor.get_shape(), refOutShape); ASSERT_EQ(tensor.get_shape(), refOutShape);
tensor = ov::runtime::Tensor(ov::element::f32, refShape2); tensor = ov::runtime::Tensor(ov::element::f32, refShape2);
ASSERT_NO_THROW(req.set_tensor(function->get_parameters().back()->get_friendly_name(), tensor)); ASSERT_NO_THROW(req.set_tensor(function->inputs().back().get_any_name(), tensor));
ASSERT_EQ(tensor.get_shape(), refShape2); ASSERT_EQ(tensor.get_shape(), refShape2);
ASSERT_NO_THROW(req.infer()); ASSERT_NO_THROW(req.infer());
ASSERT_NO_THROW(req.start_async()); ASSERT_NO_THROW(req.start_async());
ASSERT_NO_THROW(req.wait()); ASSERT_NO_THROW(req.wait());
ASSERT_NO_THROW(tensor = req.get_tensor(ngraph::op::util::create_ie_output_name(function->get_results().front()->input_value(0)))); ASSERT_NO_THROW(tensor = req.get_tensor(outputName));
ASSERT_EQ(tensor.get_shape(), refOutShape2); ASSERT_EQ(tensor.get_shape(), refOutShape2);
} }
} // namespace BehaviorTestsDefinitions } // namespace BehaviorTestsDefinitions

View File

@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
#include <chrono>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <chrono>
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
#include <string> #include <string>
@ -12,6 +13,7 @@
#include "base/behavior_test_utils.hpp" #include "base/behavior_test_utils.hpp"
#include "openvino/core/attribute_visitor.hpp" #include "openvino/core/attribute_visitor.hpp"
#include "openvino/core/function.hpp"
#include "openvino/core/node.hpp" #include "openvino/core/node.hpp"
#include "openvino/core/partial_shape.hpp" #include "openvino/core/partial_shape.hpp"
#include "openvino/core/rank.hpp" #include "openvino/core/rank.hpp"
@ -19,8 +21,6 @@
#include "openvino/core/type/element_type.hpp" #include "openvino/core/type/element_type.hpp"
#include "openvino/core/type/element_type_traits.hpp" #include "openvino/core/type/element_type_traits.hpp"
#include "openvino/op/parameter.hpp" #include "openvino/op/parameter.hpp"
#include "openvino/core/function.hpp"
#include "ngraph_functions/builders.hpp"
#include "openvino/runtime/infer_request.hpp" #include "openvino/runtime/infer_request.hpp"
#include "openvino/runtime/tensor.hpp" #include "openvino/runtime/tensor.hpp"
@ -107,9 +107,9 @@ public:
// perform inference chaining // perform inference chaining
if (outputToInput) { if (outputToInput) {
ASSERT_NO_THROW(r1.set_tensor("param_0", r0.get_tensor("result_0"))); ASSERT_NO_THROW(r1.set_tensor("input_tensor_0", r0.get_tensor("result_tensor_0")));
} else { } else {
ASSERT_NO_THROW(r0.set_tensor("result_0", r1.get_tensor("param_0"))); ASSERT_NO_THROW(r0.set_tensor("result_tensor_0", r1.get_tensor("input_tensor_0")));
} }
// create input tensors // create input tensors
@ -118,15 +118,15 @@ public:
ov::runtime::Tensor t2 = tensor(std::vector<float>{7.0f, 8.0f, 9.0f}); ov::runtime::Tensor t2 = tensor(std::vector<float>{7.0f, 8.0f, 9.0f});
ov::runtime::Tensor t3 = tensor(std::vector<float>{2.0f, 3.0f, 2.0f}); ov::runtime::Tensor t3 = tensor(std::vector<float>{2.0f, 3.0f, 2.0f});
ASSERT_NO_THROW(r0.set_tensor("param_0", t0)); ASSERT_NO_THROW(r0.set_tensor("input_tensor_0", t0));
ASSERT_NO_THROW(r0.set_tensor("param_1", t1)); ASSERT_NO_THROW(r0.set_tensor("input_tensor_1", t1));
ASSERT_NO_THROW(r0.set_tensor("param_2", t2)); ASSERT_NO_THROW(r0.set_tensor("input_tensor_2", t2));
ASSERT_NO_THROW(r1.set_tensor("param_1", t3)); ASSERT_NO_THROW(r1.set_tensor("input_tensor_1", t3));
ASSERT_NO_THROW(r2.set_tensor("param_0", t0)); ASSERT_NO_THROW(r2.set_tensor("input_tensor_0", t0));
ASSERT_NO_THROW(r2.set_tensor("param_1", t1)); ASSERT_NO_THROW(r2.set_tensor("input_tensor_1", t1));
ASSERT_NO_THROW(r2.set_tensor("param_2", t2)); ASSERT_NO_THROW(r2.set_tensor("input_tensor_2", t2));
ASSERT_NO_THROW(r2.set_tensor("param_3", t3)); ASSERT_NO_THROW(r2.set_tensor("input_tensor_3", t3));
ASSERT_NO_THROW(r0.infer()); ASSERT_NO_THROW(r0.infer());
ASSERT_NO_THROW(r1.infer()); ASSERT_NO_THROW(r1.infer());
@ -136,9 +136,9 @@ public:
std::vector<float> reference1 = {12.0f, 15.0f, 18.0f}; std::vector<float> reference1 = {12.0f, 15.0f, 18.0f};
std::vector<float> reference2 = {24.0f, 45.0f, 36.0f}; std::vector<float> reference2 = {24.0f, 45.0f, 36.0f};
auto rti = r0.get_tensor("result_0"); auto rti = r0.get_tensor("result_tensor_0");
auto rt0 = r1.get_tensor("result_0"); auto rt0 = r1.get_tensor("result_tensor_0");
auto rt1 = r2.get_tensor("result_0"); auto rt1 = r2.get_tensor("result_tensor_0");
for (size_t i = 0; i < reference1.size(); ++i) { for (size_t i = 0; i < reference1.size(); ++i) {
EXPECT_EQ(reference1[i], rti.data<float>()[i]); EXPECT_EQ(reference1[i], rti.data<float>()[i]);
@ -148,7 +148,6 @@ public:
} }
}; };
TEST_P(OVInferenceChaining, StaticOutputToStaticInput) { TEST_P(OVInferenceChaining, StaticOutputToStaticInput) {
// Skip test according to plugin specific disabledTestPatterns() (if any) // Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED() SKIP_IF_CURRENT_TEST_IS_DISABLED()

View File

@ -100,7 +100,7 @@ TEST_P(OVExecGraphImportExportTest, importExportedFunction) {
execNet.export_model(strm); execNet.export_model(strm);
ov::runtime::ExecutableNetwork importedExecNet = core->import_model(strm, targetDevice, configuration); ov::runtime::ExecutableNetwork importedExecNet = core->import_model(strm, targetDevice, configuration);
ASSERT_EQ(function->inputs().size(), 2); EXPECT_EQ(function->inputs().size(), 2);
EXPECT_EQ(function->inputs().size(), importedExecNet.inputs().size()); EXPECT_EQ(function->inputs().size(), importedExecNet.inputs().size());
EXPECT_THROW(importedExecNet.input(), ov::Exception); EXPECT_THROW(importedExecNet.input(), ov::Exception);
EXPECT_EQ(function->input(0).get_tensor().get_names(), importedExecNet.input(0).get_tensor().get_names()); EXPECT_EQ(function->input(0).get_tensor().get_names(), importedExecNet.input(0).get_tensor().get_names());
@ -194,8 +194,8 @@ TEST_P(OVExecGraphImportExportTest, readFromV10IR) {
function = core->read_model(model, ov::runtime::Tensor()); function = core->read_model(model, ov::runtime::Tensor());
EXPECT_EQ(function->inputs().size(), 1); EXPECT_EQ(function->inputs().size(), 1);
EXPECT_EQ(function->outputs().size(), 1); EXPECT_EQ(function->outputs().size(), 1);
EXPECT_NO_THROW(function->input("in1")); // remove if read_model does not change function names EXPECT_NO_THROW(function->input("in1")); // remove if read_model does not change function names
EXPECT_NO_THROW(function->output("round")); // remove if read_model does not change function names EXPECT_NO_THROW(function->output("round")); // remove if read_model does not change function names
ov::runtime::ExecutableNetwork execNet = core->compile_model(function, targetDevice, configuration); ov::runtime::ExecutableNetwork execNet = core->compile_model(function, targetDevice, configuration);
EXPECT_EQ(execNet.inputs().size(), 1); EXPECT_EQ(execNet.inputs().size(), 1);
@ -256,14 +256,14 @@ TEST_P(OVExecGraphImportExportTest, importExportedIENetwork) {
execNet.Export(strm); execNet.Export(strm);
ov::runtime::ExecutableNetwork importedExecNet = core->import_model(strm, targetDevice, configuration); ov::runtime::ExecutableNetwork importedExecNet = core->import_model(strm, targetDevice, configuration);
ASSERT_EQ(function->inputs().size(), 2); EXPECT_EQ(function->inputs().size(), 2);
EXPECT_EQ(function->inputs().size(), importedExecNet.inputs().size()); EXPECT_EQ(function->inputs().size(), importedExecNet.inputs().size());
EXPECT_THROW(importedExecNet.input(), ov::Exception); EXPECT_THROW(importedExecNet.input(), ov::Exception);
EXPECT_NO_THROW(importedExecNet.input("data1").get_node()); EXPECT_NO_THROW(importedExecNet.input("data1").get_node());
EXPECT_NO_THROW(importedExecNet.input("data2").get_node()); EXPECT_NO_THROW(importedExecNet.input("data2").get_node());
EXPECT_NO_THROW(importedExecNet.input("param1").get_node()); EXPECT_NO_THROW(importedExecNet.input("param1").get_node());
EXPECT_NO_THROW(importedExecNet.input("param2").get_node()); EXPECT_NO_THROW(importedExecNet.input("param2").get_node());
ASSERT_EQ(function->outputs().size(), 2); EXPECT_EQ(function->outputs().size(), 2);
EXPECT_EQ(function->outputs().size(), importedExecNet.outputs().size()); EXPECT_EQ(function->outputs().size(), importedExecNet.outputs().size());
EXPECT_THROW(importedExecNet.output(), ov::Exception); EXPECT_THROW(importedExecNet.output(), ov::Exception);
EXPECT_NE(function->output(0).get_tensor().get_names(), EXPECT_NE(function->output(0).get_tensor().get_names(),
@ -319,11 +319,11 @@ TEST_P(OVExecGraphImportExportTest, ieImportExportedFunction) {
execNet.export_model(strm); execNet.export_model(strm);
InferenceEngine::ExecutableNetwork importedExecNet = ie->ImportNetwork(strm, targetDevice, configuration); InferenceEngine::ExecutableNetwork importedExecNet = ie->ImportNetwork(strm, targetDevice, configuration);
ASSERT_EQ(function->inputs().size(), 2); EXPECT_EQ(function->inputs().size(), 2);
EXPECT_EQ(function->inputs().size(), importedExecNet.GetInputsInfo().size()); EXPECT_EQ(function->inputs().size(), importedExecNet.GetInputsInfo().size());
EXPECT_NO_THROW(importedExecNet.GetInputsInfo()["param1"]); EXPECT_NO_THROW(importedExecNet.GetInputsInfo()["param1"]);
EXPECT_NO_THROW(importedExecNet.GetInputsInfo()["param2"]); EXPECT_NO_THROW(importedExecNet.GetInputsInfo()["param2"]);
ASSERT_EQ(function->outputs().size(), 2); EXPECT_EQ(function->outputs().size(), 2);
EXPECT_EQ(function->outputs().size(), importedExecNet.GetOutputsInfo().size()); EXPECT_EQ(function->outputs().size(), importedExecNet.GetOutputsInfo().size());
EXPECT_NO_THROW(importedExecNet.GetOutputsInfo()["relu_op"]); EXPECT_NO_THROW(importedExecNet.GetOutputsInfo()["relu_op"]);
EXPECT_NO_THROW(importedExecNet.GetOutputsInfo()["concat_op"]); EXPECT_NO_THROW(importedExecNet.GetOutputsInfo()["concat_op"]);
@ -338,4 +338,4 @@ TEST_P(OVExecGraphImportExportTest, ieImportExportedFunction) {
} // namespace behavior } // namespace behavior
} // namespace test } // namespace test
} // namespace ov } // namespace ov

View File

@ -2,15 +2,15 @@
// SPDX-License-Identifcorer: Apache-2.0 // SPDX-License-Identifcorer: Apache-2.0
// //
#include <fstream>
#include <exec_graph_info.hpp> #include <exec_graph_info.hpp>
#include <fstream>
#include <transformations/serialize.hpp> #include <transformations/serialize.hpp>
#include "base/ov_behavior_test_utils.hpp"
#include "common_test_utils/ngraph_test_utils.hpp"
#include "common_test_utils/file_utils.hpp"
#include "base/ov_behavior_test_utils.hpp"
#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/ngraph_test_utils.hpp"
#include "functional_test_utils/plugin_cache.hpp" #include "functional_test_utils/plugin_cache.hpp"
#include "openvino/runtime/tensor.hpp"
namespace ov { namespace ov {
namespace test { namespace test {
@ -26,7 +26,7 @@ public:
std::ostringstream result; std::ostringstream result;
result << "targetDevice=" << targetDevice << "_"; result << "targetDevice=" << targetDevice << "_";
if (!configuration.empty()) { if (!configuration.empty()) {
for (auto &configItem : configuration) { for (auto& configItem : configuration) {
result << "configItem=" << configItem.first << "_" << configItem.second << "_"; result << "configItem=" << configItem.first << "_" << configItem.second << "_";
} }
} }
@ -46,6 +46,29 @@ public:
} }
} }
bool compareTensors(const ov::runtime::Tensor& t1, const ov::runtime::Tensor& t2) {
void* data1;
void* data2;
try {
data1 = t1.data();
} catch (const ov::Exception&) {
// Remote tensor
data1 = nullptr;
}
try {
data2 = t2.data();
} catch (const ov::Exception&) {
// Remote tensor
data2 = nullptr;
}
return t1.get_element_type() == t2.get_element_type() &&
t1.get_shape() == t2.get_shape() &&
t1.get_byte_size() == t2.get_byte_size() &&
t1.get_size() == t2.get_size() &&
t1.get_strides() == t2.get_strides() &&
data1 == data2;
}
protected: protected:
std::shared_ptr<ov::runtime::Core> core = utils::PluginCache::get().core(); std::shared_ptr<ov::runtime::Core> core = utils::PluginCache::get().core();
std::string targetDevice; std::string targetDevice;
@ -54,99 +77,99 @@ protected:
}; };
TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutable) { TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutable) {
ASSERT_NO_THROW(auto execNet = core->compile_model(function, targetDevice, configuration)); EXPECT_NO_THROW(auto execNet = core->compile_model(function, targetDevice, configuration));
} }
TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableWithIncorrectConfig) { TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableWithIncorrectConfig) {
std::map<std::string, std::string> incorrectConfig = {{"abc", "def"}}; std::map<std::string, std::string> incorrectConfig = {{"abc", "def"}};
ASSERT_ANY_THROW(auto execNet = core->compile_model(function, targetDevice, configuration)); EXPECT_ANY_THROW(auto execNet = core->compile_model(function, targetDevice, configuration));
} }
TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableAndCreateInferRequest) { TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableAndCreateInferRequest) {
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_NO_THROW(auto req = execNet.create_infer_request()); EXPECT_NO_THROW(auto req = execNet.create_infer_request());
} }
TEST_P(OVExecutableNetworkBaseTest, checkGetExecGraphInfoIsNotNullptr) { TEST_P(OVExecutableNetworkBaseTest, checkGetExecGraphInfoIsNotNullptr) {
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
auto execGraph = execNet.get_runtime_function(); auto execGraph = execNet.get_runtime_function();
ASSERT_NE(execGraph, nullptr); EXPECT_NE(execGraph, nullptr);
} }
TEST_P(OVExecutableNetworkBaseTest, checkGetMetric) { TEST_P(OVExecutableNetworkBaseTest, checkGetMetric) {
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_NO_THROW(execNet.get_metric(METRIC_KEY(SUPPORTED_CONFIG_KEYS))); EXPECT_NO_THROW(execNet.get_metric(METRIC_KEY(SUPPORTED_CONFIG_KEYS)));
} }
TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableAndCheckConfig) { TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableAndCheckConfig) {
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
for (const auto &configItem : configuration) { for (const auto& configItem : configuration) {
InferenceEngine::Parameter param; InferenceEngine::Parameter param;
ASSERT_NO_THROW(param = execNet.get_config(configItem.first)); EXPECT_NO_THROW(param = execNet.get_config(configItem.first));
ASSERT_FALSE(param.empty()); EXPECT_FALSE(param.empty());
ASSERT_EQ(param, InferenceEngine::Parameter(configItem.second)); EXPECT_EQ(param, InferenceEngine::Parameter(configItem.second));
} }
} }
TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNet) { TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNet) {
auto execNet = core->compile_model(function, targetDevice); auto execNet = core->compile_model(function, targetDevice);
std::map<std::string, InferenceEngine::Parameter> config; std::map<std::string, InferenceEngine::Parameter> config;
for (const auto &confItem : configuration) { for (const auto& confItem : configuration) {
config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)}); config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)});
} }
ASSERT_NO_THROW(execNet.set_config(config)); EXPECT_NO_THROW(execNet.set_config(config));
} }
TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNetWithIncorrectConfig) { TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNetWithIncorrectConfig) {
auto execNet = core->compile_model(function, targetDevice); auto execNet = core->compile_model(function, targetDevice);
std::map<std::string, std::string> incorrectConfig = {{"abc", "def"}}; std::map<std::string, std::string> incorrectConfig = {{"abc", "def"}};
std::map<std::string, InferenceEngine::Parameter> config; std::map<std::string, InferenceEngine::Parameter> config;
for (const auto &confItem : incorrectConfig) { for (const auto& confItem : incorrectConfig) {
config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)}); config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)});
} }
ASSERT_ANY_THROW(execNet.set_config(config)); EXPECT_ANY_THROW(execNet.set_config(config));
} }
TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNetAndCheckConfigAndCheck) { TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNetAndCheckConfigAndCheck) {
auto execNet = core->compile_model(function, targetDevice); auto execNet = core->compile_model(function, targetDevice);
std::map<std::string, InferenceEngine::Parameter> config; std::map<std::string, InferenceEngine::Parameter> config;
for (const auto &confItem : configuration) { for (const auto& confItem : configuration) {
config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)}); config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)});
} }
execNet.set_config(config); execNet.set_config(config);
for (const auto &configItem : configuration) { for (const auto& configItem : configuration) {
InferenceEngine::Parameter param; InferenceEngine::Parameter param;
ASSERT_NO_THROW(param = execNet.get_config(configItem.first)); EXPECT_NO_THROW(param = execNet.get_config(configItem.first));
ASSERT_FALSE(param.empty()); EXPECT_FALSE(param.empty());
ASSERT_EQ(param, InferenceEngine::Parameter(configItem.second)); EXPECT_EQ(param, InferenceEngine::Parameter(configItem.second));
} }
} }
TEST_P(OVExecutableNetworkBaseTest, CanCreateTwoExeNetworks) { TEST_P(OVExecutableNetworkBaseTest, CanCreateTwoExeNetworks) {
std::vector<ov::runtime::ExecutableNetwork> vec; std::vector<ov::runtime::ExecutableNetwork> vec;
for (auto i = 0; i < 2; i++) { for (auto i = 0; i < 2; i++) {
ASSERT_NO_THROW(vec.push_back(core->compile_model(function, targetDevice, configuration))); EXPECT_NO_THROW(vec.push_back(core->compile_model(function, targetDevice, configuration)));
ASSERT_NE(nullptr, function); EXPECT_NE(nullptr, function);
} }
} }
TEST_P(OVExecutableNetworkBaseTest, CanCreateTwoExeNetworksAndCheckFunction) { TEST_P(OVExecutableNetworkBaseTest, CanCreateTwoExeNetworksAndCheckFunction) {
std::vector<ov::runtime::ExecutableNetwork> vec; std::vector<ov::runtime::ExecutableNetwork> vec;
for (auto i = 0; i < 2; i++) { for (auto i = 0; i < 2; i++) {
ASSERT_NO_THROW(vec.push_back(core->compile_model(function, targetDevice, configuration))); EXPECT_NO_THROW(vec.push_back(core->compile_model(function, targetDevice, configuration)));
ASSERT_NE(nullptr, vec[i].get_runtime_function()); EXPECT_NE(nullptr, vec[i].get_runtime_function());
ASSERT_NE(vec.begin()->get_runtime_function(), vec[i].get_runtime_function()); EXPECT_NE(vec.begin()->get_runtime_function(), vec[i].get_runtime_function());
} }
} }
TEST_P(OVExecutableNetworkBaseTest, CanGetInputsInfo) { TEST_P(OVExecutableNetworkBaseTest, CanGetInputsInfo) {
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_NO_THROW(auto inInfo = execNet.inputs()); EXPECT_NO_THROW(auto inInfo = execNet.inputs());
} }
TEST_P(OVExecutableNetworkBaseTest, CanGetOutputsInfo) { TEST_P(OVExecutableNetworkBaseTest, CanGetOutputsInfo) {
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_NO_THROW(auto outInfo = execNet.outputs()); EXPECT_NO_THROW(auto outInfo = execNet.outputs());
} }
TEST_P(OVExecutableNetworkBaseTest, CanGetInputsInfoAndCheck) { TEST_P(OVExecutableNetworkBaseTest, CanGetInputsInfoAndCheck) {
@ -157,8 +180,9 @@ TEST_P(OVExecutableNetworkBaseTest, CanGetInputsInfoAndCheck) {
paramVec.push_back(*input.get_tensor().get_names().begin()); paramVec.push_back(*input.get_tensor().get_names().begin());
} }
auto params = function->get_parameters(); auto params = function->get_parameters();
for (const auto &param : params) { for (const auto& param : params) {
ASSERT_NE(std::find(paramVec.begin(), paramVec.end(), *param->get_output_tensor(0).get_names().begin()), paramVec.end()); EXPECT_NE(std::find(paramVec.begin(), paramVec.end(), *param->get_output_tensor(0).get_names().begin()),
paramVec.end());
} }
} }
@ -170,8 +194,9 @@ TEST_P(OVExecutableNetworkBaseTest, CanGetOutputsInfoAndCheck) {
resVec.push_back(*out.get_tensor().get_names().begin()); resVec.push_back(*out.get_tensor().get_names().begin());
} }
auto results = function->get_results(); auto results = function->get_results();
for (const auto &param : results) { for (const auto& param : results) {
ASSERT_NE(std::find(resVec.begin(), resVec.end(), *param->get_output_tensor(0).get_names().begin()), resVec.end()); EXPECT_NE(std::find(resVec.begin(), resVec.end(), *param->get_output_tensor(0).get_names().begin()),
resVec.end());
} }
} }
@ -179,20 +204,20 @@ TEST_P(OVExecutableNetworkBaseTest, CheckExecGraphInfoBeforeExecution) {
std::shared_ptr<const ov::Function> execGraph; std::shared_ptr<const ov::Function> execGraph;
// Load CNNNetwork to target plugins // Load CNNNetwork to target plugins
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_NO_THROW(execGraph = execNet.get_runtime_function()); EXPECT_NO_THROW(execGraph = execNet.get_runtime_function());
std::map<std::string, int> originalLayersMap; std::map<std::string, int> originalLayersMap;
for (const auto &layer : function->get_ops()) { for (const auto& layer : function->get_ops()) {
originalLayersMap[layer->get_friendly_name()] = 0; originalLayersMap[layer->get_friendly_name()] = 0;
} }
int constCnt = 0; int constCnt = 0;
std::shared_ptr<const ngraph::Function> getFunction = std::dynamic_pointer_cast<const ngraph::Function>(execGraph); std::shared_ptr<const ngraph::Function> getFunction = std::dynamic_pointer_cast<const ngraph::Function>(execGraph);
ASSERT_NE(getFunction, nullptr); EXPECT_NE(getFunction, nullptr);
for (const auto &op : getFunction->get_ops()) { for (const auto& op : getFunction->get_ops()) {
const ov::RTMap &rtInfo = op->get_rt_info(); const ov::RTMap& rtInfo = op->get_rt_info();
auto getExecValue = [&rtInfo](const std::string &paramName) -> std::string { auto getExecValue = [&rtInfo](const std::string& paramName) -> std::string {
auto it = rtInfo.find(paramName); auto it = rtInfo.find(paramName);
IE_ASSERT(rtInfo.end() != it); IE_ASSERT(rtInfo.end() != it);
auto value = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(it->second); auto value = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(it->second);
@ -202,7 +227,7 @@ TEST_P(OVExecutableNetworkBaseTest, CheckExecGraphInfoBeforeExecution) {
}; };
// Each layer from the execGraphInfo network must have PM data option set // Each layer from the execGraphInfo network must have PM data option set
ASSERT_EQ("not_executed", getExecValue(ExecGraphInfoSerialization::PERF_COUNTER)); EXPECT_EQ("not_executed", getExecValue(ExecGraphInfoSerialization::PERF_COUNTER));
// Parse origin layer names (fused/merged layers) from the executable graph // Parse origin layer names (fused/merged layers) from the executable graph
// and compare with layers from the original model // and compare with layers from the original model
auto origFromExecLayer = getExecValue(ExecGraphInfoSerialization::ORIGINAL_NAMES); auto origFromExecLayer = getExecValue(ExecGraphInfoSerialization::ORIGINAL_NAMES);
@ -210,20 +235,20 @@ TEST_P(OVExecutableNetworkBaseTest, CheckExecGraphInfoBeforeExecution) {
constCnt++; constCnt++;
} else { } else {
auto origFromExecLayerSep = CommonTestUtils::splitStringByDelimiter(origFromExecLayer); auto origFromExecLayerSep = CommonTestUtils::splitStringByDelimiter(origFromExecLayer);
std::for_each(origFromExecLayerSep.begin(), origFromExecLayerSep.end(), [&](const std::string &op) { std::for_each(origFromExecLayerSep.begin(), origFromExecLayerSep.end(), [&](const std::string& op) {
auto origLayer = originalLayersMap.find(op); auto origLayer = originalLayersMap.find(op);
ASSERT_NE(originalLayersMap.end(), origLayer) << op; EXPECT_NE(originalLayersMap.end(), origLayer) << op;
origLayer->second++; origLayer->second++;
}); });
} }
} }
// All layers from the original IR must be present with in ExecGraphInfo // All layers from the original IR must be present with in ExecGraphInfo
for (auto &layer : originalLayersMap) { for (auto& layer : originalLayersMap) {
if ((layer.second == 0) && (constCnt > 0)) { if ((layer.second == 0) && (constCnt > 0)) {
constCnt--; constCnt--;
} else { } else {
ASSERT_GE(layer.second, 0); EXPECT_GE(layer.second, 0);
} }
} }
} }
@ -232,21 +257,21 @@ TEST_P(OVExecutableNetworkBaseTest, CheckExecGraphInfoAfterExecution) {
std::shared_ptr<const ov::Function> execGraph; std::shared_ptr<const ov::Function> execGraph;
// Load CNNNetwork to target plugins // Load CNNNetwork to target plugins
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_NO_THROW(execGraph = execNet.get_runtime_function()); EXPECT_NO_THROW(execGraph = execNet.get_runtime_function());
std::map<std::string, int> originalLayersMap; std::map<std::string, int> originalLayersMap;
for (const auto &layer : function->get_ops()) { for (const auto& layer : function->get_ops()) {
originalLayersMap[layer->get_friendly_name()] = 0; originalLayersMap[layer->get_friendly_name()] = 0;
} }
int constCnt = 0; int constCnt = 0;
// Store all the layers from the executable graph information represented as CNNNetwork // Store all the layers from the executable graph information represented as CNNNetwork
bool hasOpWithValidTime = false; bool hasOpWithValidTime = false;
auto getFunction = std::dynamic_pointer_cast<const ngraph::Function>(execGraph); auto getFunction = std::dynamic_pointer_cast<const ngraph::Function>(execGraph);
ASSERT_NE(nullptr, getFunction); EXPECT_NE(nullptr, getFunction);
for (const auto &op : getFunction->get_ops()) { for (const auto& op : getFunction->get_ops()) {
const auto &rtInfo = op->get_rt_info(); const auto& rtInfo = op->get_rt_info();
auto getExecValue = [&rtInfo](const std::string &paramName) -> std::string { auto getExecValue = [&rtInfo](const std::string& paramName) -> std::string {
auto it = rtInfo.find(paramName); auto it = rtInfo.find(paramName);
IE_ASSERT(rtInfo.end() != it); IE_ASSERT(rtInfo.end() != it);
auto value = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(it->second); auto value = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(it->second);
@ -259,9 +284,10 @@ TEST_P(OVExecutableNetworkBaseTest, CheckExecGraphInfoAfterExecution) {
try { try {
float x = static_cast<float>(std::atof(getExecValue(ExecGraphInfoSerialization::PERF_COUNTER).c_str())); float x = static_cast<float>(std::atof(getExecValue(ExecGraphInfoSerialization::PERF_COUNTER).c_str()));
std::cout << "TIME: " << x << std::endl; std::cout << "TIME: " << x << std::endl;
ASSERT_GE(x, 0.0f); EXPECT_GE(x, 0.0f);
hasOpWithValidTime = true; hasOpWithValidTime = true;
} catch (std::exception &) {} } catch (std::exception&) {
}
// Parse origin layer names (fused/merged layers) from the executable graph // Parse origin layer names (fused/merged layers) from the executable graph
// and compare with layers from the original model // and compare with layers from the original model
@ -270,22 +296,22 @@ TEST_P(OVExecutableNetworkBaseTest, CheckExecGraphInfoAfterExecution) {
if (origFromExecLayer.empty()) { if (origFromExecLayer.empty()) {
constCnt++; constCnt++;
} else { } else {
std::for_each(origFromExecLayerSep.begin(), origFromExecLayerSep.end(), [&](const std::string &layer) { std::for_each(origFromExecLayerSep.begin(), origFromExecLayerSep.end(), [&](const std::string& layer) {
auto origLayer = originalLayersMap.find(layer); auto origLayer = originalLayersMap.find(layer);
ASSERT_NE(originalLayersMap.end(), origLayer) << layer; EXPECT_NE(originalLayersMap.end(), origLayer) << layer;
origLayer->second++; origLayer->second++;
}); });
} }
} }
ASSERT_TRUE(hasOpWithValidTime); EXPECT_TRUE(hasOpWithValidTime);
// All layers from the original IR must be present within ExecGraphInfo // All layers from the original IR must be present within ExecGraphInfo
for (auto &layer : originalLayersMap) { for (auto& layer : originalLayersMap) {
if ((layer.second == 0) && (constCnt > 0)) { if ((layer.second == 0) && (constCnt > 0)) {
constCnt--; constCnt--;
} else { } else {
ASSERT_GE(layer.second, 0); EXPECT_GE(layer.second, 0);
} }
} }
} }
@ -295,10 +321,10 @@ TEST_P(OVExecutableNetworkBaseTest, canExport) {
std::string modelName = GetTestName().substr(0, CommonTestUtils::maxFileNameLength) + "_" + ts; std::string modelName = GetTestName().substr(0, CommonTestUtils::maxFileNameLength) + "_" + ts;
auto execNet = core->compile_model(function, targetDevice, configuration); auto execNet = core->compile_model(function, targetDevice, configuration);
std::ofstream out(modelName, std::ios::out); std::ofstream out(modelName, std::ios::out);
ASSERT_NO_THROW(execNet.export_model(out)); EXPECT_NO_THROW(execNet.export_model(out));
out.close(); out.close();
ASSERT_TRUE(CommonTestUtils::fileExists(modelName + ".xml")); EXPECT_TRUE(CommonTestUtils::fileExists(modelName + ".xml"));
ASSERT_TRUE(CommonTestUtils::fileExists(modelName + ".bin")); EXPECT_TRUE(CommonTestUtils::fileExists(modelName + ".bin"));
CommonTestUtils::removeIRFiles(modelName + ".xml", modelName + ".bin"); CommonTestUtils::removeIRFiles(modelName + ".xml", modelName + ".bin");
} }
@ -314,12 +340,25 @@ TEST_P(OVExecutableNetworkBaseTest, getInputFromFunctionWithSingleInput) {
ov::runtime::ExecutableNetwork execNet; ov::runtime::ExecutableNetwork execNet;
execNet = core->compile_model(function, targetDevice, configuration); execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_EQ(function->inputs().size(), 1); EXPECT_EQ(function->inputs().size(), 1);
EXPECT_EQ(function->inputs().size(), execNet.inputs().size()); EXPECT_EQ(function->inputs().size(), execNet.inputs().size());
EXPECT_NO_THROW(execNet.input()); EXPECT_NO_THROW(execNet.input());
EXPECT_EQ(function->input().get_tensor().get_names(), execNet.input().get_tensor().get_names()); EXPECT_EQ(function->input().get_tensor().get_names(), execNet.input().get_tensor().get_names());
EXPECT_EQ(function->input().get_tensor().get_partial_shape(), execNet.input().get_tensor().get_partial_shape()); EXPECT_EQ(function->input().get_tensor().get_partial_shape(), execNet.input().get_tensor().get_partial_shape());
EXPECT_EQ(function->input().get_tensor().get_element_type(), execNet.input().get_tensor().get_element_type()); EXPECT_EQ(function->input().get_tensor().get_element_type(), execNet.input().get_tensor().get_element_type());
ov::runtime::InferRequest request = execNet.create_infer_request();
ov::runtime::Tensor tensor1, tensor2;
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.input()));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->input()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.input().get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->input().get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_input_tensor(0));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
} }
TEST_P(OVExecutableNetworkBaseTest, getOutputFromFunctionWithSingleInput) { TEST_P(OVExecutableNetworkBaseTest, getOutputFromFunctionWithSingleInput) {
@ -334,6 +373,18 @@ TEST_P(OVExecutableNetworkBaseTest, getOutputFromFunctionWithSingleInput) {
EXPECT_EQ(function->output().get_tensor().get_names(), execNet.output().get_tensor().get_names()); EXPECT_EQ(function->output().get_tensor().get_names(), execNet.output().get_tensor().get_names());
EXPECT_EQ(function->output().get_tensor().get_partial_shape(), execNet.output().get_tensor().get_partial_shape()); EXPECT_EQ(function->output().get_tensor().get_partial_shape(), execNet.output().get_tensor().get_partial_shape());
EXPECT_EQ(function->output().get_tensor().get_element_type(), execNet.output().get_tensor().get_element_type()); EXPECT_EQ(function->output().get_tensor().get_element_type(), execNet.output().get_tensor().get_element_type());
ov::runtime::InferRequest request = execNet.create_infer_request();
ov::runtime::Tensor tensor1, tensor2;
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.output()));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.output().get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output().get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_output_tensor(0));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
} }
TEST_P(OVExecutableNetworkBaseTest, getInputsFromFunctionWithSeveralInputs) { TEST_P(OVExecutableNetworkBaseTest, getInputsFromFunctionWithSeveralInputs) {
@ -361,10 +412,10 @@ TEST_P(OVExecutableNetworkBaseTest, getInputsFromFunctionWithSeveralInputs) {
result2->set_friendly_name("result2"); result2->set_friendly_name("result2");
function = std::make_shared<ngraph::Function>(ngraph::ResultVector{result1, result2}, function = std::make_shared<ngraph::Function>(ngraph::ResultVector{result1, result2},
ngraph::ParameterVector{param1, param2}); ngraph::ParameterVector{param1, param2});
function->set_friendly_name("SingleRuLU"); function->set_friendly_name("SimpleReLU");
} }
execNet = core->compile_model(function, targetDevice, configuration); execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_EQ(function->inputs().size(), 2); EXPECT_EQ(function->inputs().size(), 2);
EXPECT_EQ(function->inputs().size(), execNet.inputs().size()); EXPECT_EQ(function->inputs().size(), execNet.inputs().size());
EXPECT_THROW(execNet.input(), ov::Exception); EXPECT_THROW(execNet.input(), ov::Exception);
EXPECT_EQ(function->input(0).get_tensor().get_names(), execNet.input(0).get_tensor().get_names()); EXPECT_EQ(function->input(0).get_tensor().get_names(), execNet.input(0).get_tensor().get_names());
@ -377,6 +428,34 @@ TEST_P(OVExecutableNetworkBaseTest, getInputsFromFunctionWithSeveralInputs) {
EXPECT_NE(function->input(1).get_node(), function->input("data1").get_node()); EXPECT_NE(function->input(1).get_node(), function->input("data1").get_node());
EXPECT_EQ(function->input(1).get_node(), function->input("data2").get_node()); EXPECT_EQ(function->input(1).get_node(), function->input("data2").get_node());
EXPECT_NE(function->input(0).get_node(), function->input("data2").get_node()); EXPECT_NE(function->input(0).get_node(), function->input("data2").get_node());
ov::runtime::InferRequest request = execNet.create_infer_request();
ov::runtime::Tensor tensor1, tensor2;
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.input(0)));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->input(0)));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.input(0).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->input(0).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_input_tensor(0));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.input(1)));
try {
// To avoid case with remote tensors
tensor1.data();
EXPECT_FALSE(compareTensors(tensor1, tensor2));
} catch (const ov::Exception&) {
}
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->input(1)));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.input(1).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->input(1).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_input_tensor(1));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
} }
TEST_P(OVExecutableNetworkBaseTest, getOutputsFromFunctionWithSeveralOutputs) { TEST_P(OVExecutableNetworkBaseTest, getOutputsFromFunctionWithSeveralOutputs) {
@ -404,10 +483,10 @@ TEST_P(OVExecutableNetworkBaseTest, getOutputsFromFunctionWithSeveralOutputs) {
result2->set_friendly_name("result2"); result2->set_friendly_name("result2");
function = std::make_shared<ngraph::Function>(ngraph::ResultVector{result1, result2}, function = std::make_shared<ngraph::Function>(ngraph::ResultVector{result1, result2},
ngraph::ParameterVector{param1, param2}); ngraph::ParameterVector{param1, param2});
function->set_friendly_name("SingleRuLU"); function->set_friendly_name("SimpleReLU");
} }
execNet = core->compile_model(function, targetDevice, configuration); execNet = core->compile_model(function, targetDevice, configuration);
ASSERT_EQ(function->outputs().size(), 2); EXPECT_EQ(function->outputs().size(), 2);
EXPECT_EQ(function->outputs().size(), execNet.outputs().size()); EXPECT_EQ(function->outputs().size(), execNet.outputs().size());
EXPECT_THROW(execNet.output(), ov::Exception); EXPECT_THROW(execNet.output(), ov::Exception);
EXPECT_EQ(function->output(0).get_tensor().get_names(), execNet.output(0).get_tensor().get_names()); EXPECT_EQ(function->output(0).get_tensor().get_names(), execNet.output(0).get_tensor().get_names());
@ -420,12 +499,107 @@ TEST_P(OVExecutableNetworkBaseTest, getOutputsFromFunctionWithSeveralOutputs) {
EXPECT_NE(function->output(1).get_node(), function->output("relu").get_node()); EXPECT_NE(function->output(1).get_node(), function->output("relu").get_node());
EXPECT_EQ(function->output(1).get_node(), function->output("concat").get_node()); EXPECT_EQ(function->output(1).get_node(), function->output("concat").get_node());
EXPECT_NE(function->output(0).get_node(), function->output("concat").get_node()); EXPECT_NE(function->output(0).get_node(), function->output("concat").get_node());
ov::runtime::InferRequest request = execNet.create_infer_request();
ov::runtime::Tensor tensor1, tensor2;
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.output(0)));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(0)));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.output(0).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(0).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_output_tensor(0));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.output(1)));
try {
// To avoid case with remote tensors
tensor1.data();
EXPECT_FALSE(compareTensors(tensor1, tensor2));
} catch (const ov::Exception&) {
}
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(1)));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.output(1).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(1).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_output_tensor(1));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
}
TEST_P(OVExecutableNetworkBaseTest, getOutputsFromSplitFunctionWithSeveralOutputs) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
ov::runtime::ExecutableNetwork execNet;
// Create simple function
{
auto param1 = std::make_shared<ov::opset8::Parameter>(ov::element::Type_t::f32, ngraph::Shape({1, 4, 24, 24}));
param1->set_friendly_name("param1");
param1->output(0).get_tensor().set_names({"data1"});
auto axis_node = ov::opset8::Constant::create(element::i64, Shape{}, {1});
auto split = std::make_shared<ov::opset8::Split>(param1, axis_node, 2);
split->set_friendly_name("split");
split->output(0).get_tensor().set_names({"tensor_split_1"});
split->output(1).get_tensor().set_names({"tensor_split_2"});
auto result1 = std::make_shared<ov::opset8::Result>(split->output(0));
result1->set_friendly_name("result1");
auto result2 = std::make_shared<ov::opset8::Result>(split->output(1));
result2->set_friendly_name("result2");
function = std::make_shared<ngraph::Function>(ngraph::ResultVector{result1, result2},
ngraph::ParameterVector{param1});
function->set_friendly_name("SingleSplit");
}
execNet = core->compile_model(function, targetDevice, configuration);
EXPECT_EQ(function->outputs().size(), 2);
EXPECT_EQ(function->outputs().size(), execNet.outputs().size());
EXPECT_THROW(execNet.output(), ov::Exception);
EXPECT_EQ(function->output(0).get_tensor().get_names(), execNet.output(0).get_tensor().get_names());
EXPECT_EQ(function->output(0).get_tensor().get_partial_shape(), execNet.output(0).get_tensor().get_partial_shape());
EXPECT_EQ(function->output(0).get_tensor().get_element_type(), execNet.output(0).get_tensor().get_element_type());
EXPECT_EQ(function->output(1).get_tensor().get_names(), execNet.output(1).get_tensor().get_names());
EXPECT_EQ(function->output(1).get_tensor().get_partial_shape(), execNet.output(1).get_tensor().get_partial_shape());
EXPECT_EQ(function->output(1).get_tensor().get_element_type(), execNet.output(1).get_tensor().get_element_type());
EXPECT_EQ(function->output(0).get_node(), function->output("tensor_split_1").get_node());
EXPECT_NE(function->output(1).get_node(), function->output("tensor_split_1").get_node());
EXPECT_EQ(function->output(1).get_node(), function->output("tensor_split_2").get_node());
EXPECT_NE(function->output(0).get_node(), function->output("tensor_split_2").get_node());
ov::runtime::InferRequest request = execNet.create_infer_request();
ov::runtime::Tensor tensor1, tensor2;
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.output(0)));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(0)));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.output(0).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(0).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_output_tensor(0));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor1 = request.get_tensor(execNet.output(1)));
try {
// To avoid case with remote tensors
tensor1.data();
EXPECT_FALSE(compareTensors(tensor1, tensor2));
} catch (const ov::Exception&) {
}
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(1)));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(execNet.output(1).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_tensor(function->output(1).get_any_name()));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
EXPECT_NO_THROW(tensor2 = request.get_output_tensor(1));
EXPECT_TRUE(compareTensors(tensor1, tensor2));
} }
// Load correct network to Plugin to get executable network // Load correct network to Plugin to get executable network
TEST_P(OVExecutableNetworkBaseTest, precisionsAsInOriginalFunction) { TEST_P(OVExecutableNetworkBaseTest, precisionsAsInOriginalFunction) {
ov::runtime::ExecutableNetwork execNet; ov::runtime::ExecutableNetwork execNet;
ASSERT_NO_THROW(execNet = core->compile_model(function, targetDevice, configuration)); EXPECT_NO_THROW(execNet = core->compile_model(function, targetDevice, configuration));
EXPECT_EQ(function->get_parameters().size(), execNet.inputs().size()); EXPECT_EQ(function->get_parameters().size(), execNet.inputs().size());
auto ref_parameter = function->get_parameters().back(); auto ref_parameter = function->get_parameters().back();
@ -449,7 +623,7 @@ TEST_P(OVExecutableNetworkBaseTest, precisionsAsInOriginalIR) {
ov::pass::Serialize(m_out_xml_path_1, m_out_bin_path_1).run_on_function(function); ov::pass::Serialize(m_out_xml_path_1, m_out_bin_path_1).run_on_function(function);
ov::runtime::ExecutableNetwork execNet; ov::runtime::ExecutableNetwork execNet;
ASSERT_NO_THROW(execNet = core->compile_model(m_out_xml_path_1, targetDevice, configuration)); EXPECT_NO_THROW(execNet = core->compile_model(m_out_xml_path_1, targetDevice, configuration));
EXPECT_EQ(function->get_parameters().size(), execNet.inputs().size()); EXPECT_EQ(function->get_parameters().size(), execNet.inputs().size());
auto ref_parameter = function->get_parameters().back(); auto ref_parameter = function->get_parameters().back();
@ -467,4 +641,4 @@ TEST_P(OVExecutableNetworkBaseTest, precisionsAsInOriginalIR) {
} }
} // namespace behavior } // namespace behavior
} // namespace test } // namespace test
} // namespace ov } // namespace ov

View File

@ -51,7 +51,7 @@ inline std::shared_ptr<ngraph::Function> makeSplitConvConcat(std::vector<size_t>
ngraph::element::Type_t ngPrc = ngraph::element::Type_t::f32) { ngraph::element::Type_t ngPrc = ngraph::element::Type_t::f32) {
auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
params.front()->set_friendly_name("Param_1"); params.front()->set_friendly_name("Param_1");
params.front()->get_output_tensor(0).set_names({"Tensor_1"}); params.front()->get_output_tensor(0).set_names({"input_tensor"});
auto split = ngraph::builder::makeSplit(params[0], ngPrc, 2, 1); auto split = ngraph::builder::makeSplit(params[0], ngPrc, 2, 1);
auto conv1 = ngraph::builder::makeConvolution(split->output(0), ngPrc, {3, 3}, {1, 1}, {0, 0}, {0, 0}, {1, 1}, auto conv1 = ngraph::builder::makeConvolution(split->output(0), ngPrc, {3, 3}, {1, 1}, {0, 0}, {0, 0}, {1, 1},
@ -63,6 +63,7 @@ inline std::shared_ptr<ngraph::Function> makeSplitConvConcat(std::vector<size_t>
auto relu2 = std::make_shared<ngraph::opset1::Relu>(conv2); auto relu2 = std::make_shared<ngraph::opset1::Relu>(conv2);
auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{relu1->output(0), relu2->output(0)}, 1); auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{relu1->output(0), relu2->output(0)}, 1);
concat->get_output_tensor(0).set_names({"concat_tensor"});
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(concat)}; ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(concat)};
std::shared_ptr<ngraph::Function> fnPtr = std::make_shared<ngraph::Function>(results, params); std::shared_ptr<ngraph::Function> fnPtr = std::make_shared<ngraph::Function>(results, params);
fnPtr->set_friendly_name("SplitConvConcat"); fnPtr->set_friendly_name("SplitConvConcat");

View File

@ -84,7 +84,7 @@ const std::unordered_set<std::string>& Output<Node>::get_names() const {
} }
std::string Output<Node>::get_any_name() const { std::string Output<Node>::get_any_name() const {
return m_node->m_outputs.at(m_index).get_tensor_ptr()->get_any_name(); return get_tensor().get_any_name();
} }
void Output<Node>::set_names(const std::unordered_set<std::string>& names) { void Output<Node>::set_names(const std::unordered_set<std::string>& names) {
@ -100,7 +100,7 @@ const std::unordered_set<std::string>& Output<const Node>::get_names() const {
} }
std::string Output<const Node>::get_any_name() const { std::string Output<const Node>::get_any_name() const {
return m_node->m_outputs.at(m_index).get_tensor_ptr()->get_any_name(); return get_tensor().get_any_name();
} }
bool Output<Node>::operator==(const Output& other) const { bool Output<Node>::operator==(const Output& other) const {

View File

@ -0,0 +1,91 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "all_close.hpp"
::testing::AssertionResult ov::test::all_close(const ov::runtime::Tensor& a,
const ov::runtime::Tensor& b,
float rtol,
float atol) {
if (a.get_element_type() != b.get_element_type()) {
return ::testing::AssertionFailure() << "Cannot compare tensors with different element types";
}
switch (a.get_element_type()) {
case ov::element::u8:
return all_close<ov::element_type_traits<ov::element::u8>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::u8>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::u8>::value_type>(atol));
case ov::element::u16:
return all_close<ov::element_type_traits<ov::element::u16>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::u16>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::u16>::value_type>(atol));
case ov::element::u32:
return all_close<ov::element_type_traits<ov::element::u32>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::u32>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::u32>::value_type>(atol));
case ov::element::u64:
return all_close<ov::element_type_traits<ov::element::u64>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::u64>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::u64>::value_type>(atol));
case ov::element::i8:
return all_close<ov::element_type_traits<ov::element::i8>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::i8>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::i8>::value_type>(atol));
case ov::element::i16:
return all_close<ov::element_type_traits<ov::element::i16>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::i16>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::i16>::value_type>(atol));
case ov::element::i32:
return all_close<ov::element_type_traits<ov::element::i32>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::i32>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::i32>::value_type>(atol));
case ov::element::i64:
return all_close<ov::element_type_traits<ov::element::i64>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::i64>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::i64>::value_type>(atol));
// case ov::element::bf16:
// return all_close<ov::element_type_traits<ov::element::bf16>::value_type>(
// a,
// b,
// static_cast<ov::element_type_traits<ov::element::bf16>::value_type>(rtol),
// static_cast<ov::element_type_traits<ov::element::bf16>::value_type>(atol));
// case ov::element::f16:
// return all_close<ov::element_type_traits<ov::element::f16>::value_type>(
// a,
// b,
// static_cast<ov::element_type_traits<ov::element::f16>::value_type>(rtol),
// static_cast<ov::element_type_traits<ov::element::f16>::value_type>(atol));
case ov::element::f32:
return all_close<ov::element_type_traits<ov::element::f32>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::f32>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::f32>::value_type>(atol));
case ov::element::f64:
return all_close<ov::element_type_traits<ov::element::f64>::value_type>(
a,
b,
static_cast<ov::element_type_traits<ov::element::f64>::value_type>(rtol),
static_cast<ov::element_type_traits<ov::element::f64>::value_type>(atol));
default:
return ::testing::AssertionFailure()
<< "Cannot compare tensors with unsupported element type: " << a.get_element_type();
}
}

View File

@ -11,6 +11,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ngraph/pass/manager.hpp" #include "ngraph/pass/manager.hpp"
#include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type.hpp"
#include "openvino/runtime/tensor.hpp"
namespace ngraph { namespace ngraph {
namespace test { namespace test {
@ -116,3 +117,35 @@ template <typename T>
} }
} // namespace test } // namespace test
} // namespace ngraph } // namespace ngraph
namespace ov {
namespace test {
/// \brief Same as numpy.allclose
/// \param a First tensor to compare
/// \param b Second tensor to compare
/// \param rtol Relative tolerance
/// \param atol Absolute tolerance
/// Returns true if shapes match and for all elements, |a_i-b_i| <= atol + rtol*|b_i|.
template <typename T>
::testing::AssertionResult all_close(const ov::runtime::Tensor& a,
const ov::runtime::Tensor& b,
T rtol = 1e-5f,
T atol = 1e-8f) {
auto a_t = std::make_shared<ngraph::runtime::HostTensor>(a.get_element_type(), a.get_shape(), a.data());
auto b_t = std::make_shared<ngraph::runtime::HostTensor>(b.get_element_type(), b.get_shape(), b.data());
return ngraph::test::all_close(a_t, b_t, rtol, atol);
}
/// \brief Same as numpy.allclose
/// \param a First tensor to compare
/// \param b Second tensor to compare
/// \param rtol Relative tolerance
/// \param atol Absolute tolerance
/// Returns true if shapes match and for all elements, |a_i-b_i| <= atol + rtol*|b_i|.
::testing::AssertionResult all_close(const ov::runtime::Tensor& a,
const ov::runtime::Tensor& b,
float rtol = 1e-5f,
float atol = 1e-8f);
} // namespace test
} // namespace ov