Files
openvino/inference-engine/include/cpp/ie_executable_network.hpp

251 lines
7.1 KiB
C++
Raw Normal View History

2020-02-11 22:48:49 +03:00
// Copyright (C) 2018-2020 Intel Corporation
2018-10-16 13:45:03 +03:00
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief A header file that provides wrapper classes for IExecutableNetwork
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* @file ie_executable_network.hpp
*/
#pragma once
2020-02-11 22:48:49 +03:00
#include <algorithm>
2018-10-16 13:45:03 +03:00
#include <map>
2020-02-11 22:48:49 +03:00
#include <memory>
2018-10-16 13:45:03 +03:00
#include <string>
#include <vector>
2020-02-11 22:48:49 +03:00
#include "cpp/ie_cnn_network.h"
2018-10-16 13:45:03 +03:00
#include "cpp/ie_infer_request.hpp"
#include "cpp/ie_memory_state.hpp"
2020-07-30 18:40:28 +03:00
#include "ie_iexecutable_network.hpp"
2018-10-16 13:45:03 +03:00
#include "details/ie_exception_conversion.hpp"
#include "details/ie_so_loader.h"
2018-10-16 13:45:03 +03:00
namespace InferenceEngine {
/**
* @brief wrapper over IExecutableNetwork
*/
class ExecutableNetwork {
IExecutableNetwork::Ptr actual;
details::SharedObjectLoader::Ptr plg;
2018-10-16 13:45:03 +03:00
public:
2019-10-04 19:26:43 +03:00
/**
* @brief Default constructor
*/
2018-10-16 13:45:03 +03:00
ExecutableNetwork() = default;
2019-10-04 19:26:43 +03:00
/**
* @brief Destructor
*/
2019-08-09 19:02:42 +03:00
~ExecutableNetwork() {
actual = nullptr;
}
2018-10-16 13:45:03 +03:00
2019-10-04 19:26:43 +03:00
/**
* @brief Constructs ExecutableNetwork from the initialized shared_pointer
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* @param actual Initialized shared pointer
* @param plg Plugin to use
*/
explicit ExecutableNetwork(IExecutableNetwork::Ptr actual, details::SharedObjectLoader::Ptr plg = {})
2020-04-13 21:17:23 +03:00
: actual(actual), plg(plg) {
// plg can be null, but not the actual
if (actual == nullptr) {
THROW_IE_EXCEPTION << "ExecutableNetwork wrapper was not initialized.";
}
}
2018-10-16 13:45:03 +03:00
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::GetOutputsInfo
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::GetOutputsInfo.
* @return A collection that contains string as key, and const Data smart pointer as value
2018-10-16 13:45:03 +03:00
*/
ConstOutputsDataMap GetOutputsInfo() const {
ConstOutputsDataMap data;
CALL_STATUS_FNC(GetOutputsInfo, data);
return data;
}
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::GetInputsInfo
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::GetInputsInfo
* @return A collection that contains string as key, and const InputInfo smart pointer as value
2018-10-16 13:45:03 +03:00
*/
ConstInputsDataMap GetInputsInfo() const {
ConstInputsDataMap info;
CALL_STATUS_FNC(GetInputsInfo, info);
return info;
}
/**
2019-10-04 19:26:43 +03:00
* @brief reset owned object to new pointer.
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Eessential for cases when simultaneously loaded networks not expected.
* @param newActual actual pointed object
2018-10-16 13:45:03 +03:00
*/
void reset(IExecutableNetwork::Ptr newActual) {
2020-04-13 21:17:23 +03:00
if (actual == nullptr) {
THROW_IE_EXCEPTION << "ExecutableNetwork wrapper was not initialized.";
}
if (newActual == nullptr) {
THROW_IE_EXCEPTION << "ExecutableNetwork wrapper used for reset was not initialized.";
}
2018-10-16 13:45:03 +03:00
this->actual.swap(newActual);
}
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::CreateInferRequest
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::CreateInferRequest.
* @return InferRequest object
2018-10-16 13:45:03 +03:00
*/
InferRequest CreateInferRequest() {
IInferRequest::Ptr req;
CALL_STATUS_FNC(CreateInferRequest, req);
if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
2019-08-09 19:02:42 +03:00
return InferRequest(req, plg);
2018-10-16 13:45:03 +03:00
}
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::CreateInferRequest
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::CreateInferRequest.
* @return shared pointer on InferenceEngine::InferRequest object
2018-10-16 13:45:03 +03:00
*/
InferRequest::Ptr CreateInferRequestPtr() {
IInferRequest::Ptr req;
CALL_STATUS_FNC(CreateInferRequest, req);
2019-08-09 19:02:42 +03:00
return std::make_shared<InferRequest>(req, plg);
2018-10-16 13:45:03 +03:00
}
/**
2020-02-11 22:48:49 +03:00
* @copybrief IExecutableNetwork::Export
*
* Wraps IExecutableNetwork::Export.
*
* @see Core::ImportNetwork
*
* @param modelFileName Full path to the location of the exported file
*/
void Export(const std::string& modelFileName) {
2018-10-16 13:45:03 +03:00
CALL_STATUS_FNC(Export, modelFileName);
}
/**
2020-02-11 22:48:49 +03:00
* @copybrief IExecutableNetwork::Export
*
* Wraps IExecutableNetwork::Export.
*
* @see Core::ImportNetwork
*
* @param networkModel network model output stream
*/
void Export(std::ostream& networkModel) {
CALL_STATUS_FNC(Export, networkModel);
}
2018-10-16 13:45:03 +03:00
/**
2020-04-13 21:17:23 +03:00
* @brief cast operator is used when this wrapper initialized by LoadNetwork
* @return A shared pointer to IExecutableNetwork interface.
2020-02-11 22:48:49 +03:00
*/
operator IExecutableNetwork::Ptr&() {
2018-10-16 13:45:03 +03:00
return actual;
}
2019-04-12 18:25:53 +03:00
/**
2020-02-11 22:48:49 +03:00
* @copybrief IExecutableNetwork::GetExecGraphInfo
*
* Wraps IExecutableNetwork::GetExecGraphInfo.
* @return CNNetwork containing Executable Graph Info
*/
2019-04-12 18:25:53 +03:00
CNNNetwork GetExecGraphInfo() {
ICNNNetwork::Ptr ptr = nullptr;
CALL_STATUS_FNC(GetExecGraphInfo, ptr);
return CNNNetwork(ptr);
}
2018-10-16 13:45:03 +03:00
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::QueryState
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::QueryState
* @return A vector of Memory State objects
2018-10-16 13:45:03 +03:00
*/
std::vector<MemoryState> QueryState() {
if (actual == nullptr) THROW_IE_EXCEPTION << "ExecutableNetwork was not initialized.";
2018-10-16 13:45:03 +03:00
IMemoryState::Ptr pState = nullptr;
auto res = OK;
std::vector<MemoryState> controller;
for (size_t idx = 0; res == OK; ++idx) {
ResponseDesc resp;
res = actual->QueryState(pState, idx, &resp);
if (res != OK && res != OUT_OF_BOUNDS) {
THROW_IE_EXCEPTION << resp.msg;
}
if (res != OUT_OF_BOUNDS) {
controller.push_back(MemoryState(pState));
}
}
return controller;
}
2019-08-09 19:02:42 +03:00
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::SetConfig
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::SetConfig.
2019-08-09 19:02:42 +03:00
* @param config Map of pairs: (config parameter name, config parameter value)
*/
2020-02-11 22:48:49 +03:00
void SetConfig(const std::map<std::string, Parameter>& config) {
2019-08-09 19:02:42 +03:00
CALL_STATUS_FNC(SetConfig, config);
}
2020-04-13 21:17:23 +03:00
/**
* @copybrief IExecutableNetwork::GetConfig
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::GetConfig
* @param name - config key, can be found in ie_plugin_config.hpp
* @return Configuration paramater value
*/
2020-02-11 22:48:49 +03:00
Parameter GetConfig(const std::string& name) const {
2019-08-09 19:02:42 +03:00
Parameter configValue;
CALL_STATUS_FNC(GetConfig, name, configValue);
return configValue;
}
/**
2019-10-04 19:26:43 +03:00
* @copybrief IExecutableNetwork::GetMetric
2020-02-11 22:48:49 +03:00
*
2019-10-04 19:26:43 +03:00
* Wraps IExecutableNetwork::GetMetric
2019-08-09 19:02:42 +03:00
* @param name - metric name to request
2019-10-04 19:26:43 +03:00
* @return Metric paramater value
2019-08-09 19:02:42 +03:00
*/
2020-02-11 22:48:49 +03:00
Parameter GetMetric(const std::string& name) const {
2019-08-09 19:02:42 +03:00
Parameter metricValue;
CALL_STATUS_FNC(GetMetric, name, metricValue);
return metricValue;
}
2018-10-16 13:45:03 +03:00
2020-02-11 22:48:49 +03:00
/**
* @brief Returns pointer to plugin-specific shared context
* on remote accelerator device that was used to create this ExecutableNetwork
2020-04-13 21:17:23 +03:00
* @return A context
2020-02-11 22:48:49 +03:00
*/
RemoteContext::Ptr GetContext() const {
RemoteContext::Ptr pContext;
CALL_STATUS_FNC(GetContext, pContext);
return pContext;
}
2019-10-04 19:26:43 +03:00
/**
* @brief A smart pointer to the ExecutableNetwork object
*/
2018-10-16 13:45:03 +03:00
using Ptr = std::shared_ptr<ExecutableNetwork>;
};
} // namespace InferenceEngine