1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief A header file that provides wrapper classes for IExecutableNetwork
7 * @file ie_executable_network.hpp
16 #include "ie_iexecutable_network.hpp"
17 #include "ie_plugin_ptr.hpp"
18 #include "cpp/ie_infer_request.hpp"
19 #include "cpp/ie_memory_state.hpp"
20 #include "cpp/ie_cnn_network.h"
21 #include "details/ie_exception_conversion.hpp"
23 namespace InferenceEngine {
26 * @brief wrapper over IExecutableNetwork
28 class ExecutableNetwork {
29 IExecutableNetwork::Ptr actual;
30 InferenceEnginePluginPtr plg;
34 * @brief Default constructor
36 ExecutableNetwork() = default;
41 ~ExecutableNetwork() {
46 * @brief Constructs ExecutableNetwork from the initialized shared_pointer
47 * @param actual Initialized shared pointer
48 * @param plg Plugin to use
50 explicit ExecutableNetwork(IExecutableNetwork::Ptr actual, InferenceEnginePluginPtr plg = {})
51 : actual(actual), plg(plg) {}
54 * @copybrief IExecutableNetwork::GetOutputsInfo
56 * Wraps IExecutableNetwork::GetOutputsInfo.
57 * @return A collection that contains string as key, and const Data smart pointer as value
59 ConstOutputsDataMap GetOutputsInfo() const {
60 ConstOutputsDataMap data;
61 CALL_STATUS_FNC(GetOutputsInfo, data);
66 * @copybrief IExecutableNetwork::GetInputsInfo
68 * Wraps IExecutableNetwork::GetInputsInfo
69 * @return A collection that contains string as key, and const InputInfo smart pointer as value
71 ConstInputsDataMap GetInputsInfo() const {
72 ConstInputsDataMap info;
73 CALL_STATUS_FNC(GetInputsInfo, info);
78 * @brief reset owned object to new pointer.
80 * Eessential for cases when simultaneously loaded networks not expected.
81 * @param newActual actual pointed object
83 void reset(IExecutableNetwork::Ptr newActual) {
84 this->actual.swap(newActual);
88 * @copybrief IExecutableNetwork::CreateInferRequest
90 * Wraps IExecutableNetwork::CreateInferRequest.
91 * @return InferRequest object
93 InferRequest CreateInferRequest() {
94 IInferRequest::Ptr req;
95 CALL_STATUS_FNC(CreateInferRequest, req);
96 if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
97 return InferRequest(req, plg);
101 * @copybrief IExecutableNetwork::CreateInferRequest
103 * Wraps IExecutableNetwork::CreateInferRequest.
104 * @return shared pointer on InferenceEngine::InferRequest object
106 InferRequest::Ptr CreateInferRequestPtr() {
107 IInferRequest::Ptr req;
108 CALL_STATUS_FNC(CreateInferRequest, req);
109 return std::make_shared<InferRequest>(req, plg);
113 * @copybrief IExecutableNetwork::Export
115 * Wraps IExecutableNetwork::Export.
117 * @see Core::ImportNetwork
118 * @see InferencePlugin::ImportNetwork
120 * @param modelFileName Full path to the location of the exported file
122 void Export(const std::string &modelFileName) {
123 CALL_STATUS_FNC(Export, modelFileName);
127 * @copybrief IExecutableNetwork::GetMappedTopology
129 * Wraps IExecutableNetwork::GetMappedTopology.
130 * @param deployedTopology Map of PrimitiveInfo objects that represent the deployed topology
132 void GetMappedTopology(std::map<std::string, std::vector<PrimitiveInfo::Ptr>> &deployedTopology) {
133 CALL_STATUS_FNC(GetMappedTopology, deployedTopology);
137 * cast operator is used when this wrapper initialized by LoadNetwork
140 operator IExecutableNetwork::Ptr &() {
145 * @copybrief IExecutableNetwork::GetExecGraphInfo
147 * Wraps IExecutableNetwork::GetExecGraphInfo.
148 * @return CNNetwork containing Executable Graph Info
150 CNNNetwork GetExecGraphInfo() {
151 ICNNNetwork::Ptr ptr = nullptr;
152 CALL_STATUS_FNC(GetExecGraphInfo, ptr);
153 return CNNNetwork(ptr);
157 * @copybrief IExecutableNetwork::QueryState
159 * Wraps IExecutableNetwork::QueryState
160 * @return A vector of Memory State objects
162 std::vector<MemoryState> QueryState() {
163 IMemoryState::Ptr pState = nullptr;
165 std::vector<MemoryState> controller;
166 for (size_t idx = 0; res == OK; ++idx) {
168 res = actual->QueryState(pState, idx, &resp);
169 if (res != OK && res != OUT_OF_BOUNDS) {
170 THROW_IE_EXCEPTION << resp.msg;
172 if (res != OUT_OF_BOUNDS) {
173 controller.push_back(MemoryState(pState));
181 * @copybrief IExecutableNetwork::SetConfig
183 * Wraps IExecutableNetwork::SetConfig.
184 * @param config Map of pairs: (config parameter name, config parameter value)
186 void SetConfig(const std::map<std::string, Parameter> &config) {
187 CALL_STATUS_FNC(SetConfig, config);
190 /** @copybrief IExecutableNetwork::GetConfig
192 * Wraps IExecutableNetwork::GetConfig
193 * @param name - config key, can be found in ie_plugin_config.hpp
194 * @return Configuration paramater value
196 Parameter GetConfig(const std::string &name) const {
197 Parameter configValue;
198 CALL_STATUS_FNC(GetConfig, name, configValue);
203 * @copybrief IExecutableNetwork::GetMetric
205 * Wraps IExecutableNetwork::GetMetric
206 * @param name - metric name to request
207 * @return Metric paramater value
209 Parameter GetMetric(const std::string &name) const {
210 Parameter metricValue;
211 CALL_STATUS_FNC(GetMetric, name, metricValue);
216 * @brief A smart pointer to the ExecutableNetwork object
218 using Ptr = std::shared_ptr<ExecutableNetwork>;
221 } // namespace InferenceEngine