ie_executable_network.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file that provides wrapper classes for IExecutableNetwork
7  *
8  * @file ie_executable_network.hpp
9  */
10 #pragma once
11 
12 #include <algorithm>
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "cpp/ie_cnn_network.h"
19 #include "cpp/ie_infer_request.hpp"
20 #include "cpp/ie_memory_state.hpp"
23 #include "details/ie_so_loader.h"
24 
25 namespace InferenceEngine {
26 
27 /**
28  * @brief wrapper over IExecutableNetwork
29  */
32  details::SharedObjectLoader::Ptr plg;
33 
34 public:
35  /**
36  * @brief Default constructor
37  */
38  ExecutableNetwork() = default;
39 
40  /**
41  * @brief Destructor
42  */
44  actual = nullptr;
45  }
46 
47  /**
48  * @brief Constructs ExecutableNetwork from the initialized shared_pointer
49  *
50  * @param actual Initialized shared pointer
51  * @param plg Plugin to use
52  */
53  explicit ExecutableNetwork(IExecutableNetwork::Ptr actual, details::SharedObjectLoader::Ptr plg = {})
54  : actual(actual), plg(plg) {
55  // plg can be null, but not the actual
56  if (actual == nullptr) {
57  THROW_IE_EXCEPTION << "ExecutableNetwork wrapper was not initialized.";
58  }
59  }
60 
61  /**
62  * @copybrief IExecutableNetwork::GetOutputsInfo
63  *
64  * Wraps IExecutableNetwork::GetOutputsInfo.
65  * @return A collection that contains string as key, and const Data smart pointer as value
66  */
69  CALL_STATUS_FNC(GetOutputsInfo, data);
70  return data;
71  }
72 
73  /**
74  * @copybrief IExecutableNetwork::GetInputsInfo
75  *
76  * Wraps IExecutableNetwork::GetInputsInfo
77  * @return A collection that contains string as key, and const InputInfo smart pointer as value
78  */
80  ConstInputsDataMap info;
81  CALL_STATUS_FNC(GetInputsInfo, info);
82  return info;
83  }
84 
85  /**
86  * @brief reset owned object to new pointer.
87  *
88  * Eessential for cases when simultaneously loaded networks not expected.
89  * @param newActual actual pointed object
90  */
91  void reset(IExecutableNetwork::Ptr newActual) {
92  if (actual == nullptr) {
93  THROW_IE_EXCEPTION << "ExecutableNetwork wrapper was not initialized.";
94  }
95  if (newActual == nullptr) {
96  THROW_IE_EXCEPTION << "ExecutableNetwork wrapper used for reset was not initialized.";
97  }
98  this->actual.swap(newActual);
99  }
100 
101  /**
102  * @copybrief IExecutableNetwork::CreateInferRequest
103  *
104  * Wraps IExecutableNetwork::CreateInferRequest.
105  * @return InferRequest object
106  */
108  IInferRequest::Ptr req;
109  CALL_STATUS_FNC(CreateInferRequest, req);
110  if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
111  return InferRequest(req, plg);
112  }
113 
114  /**
115  * @copybrief IExecutableNetwork::CreateInferRequest
116  *
117  * Wraps IExecutableNetwork::CreateInferRequest.
118  * @return shared pointer on InferenceEngine::InferRequest object
119  */
121  IInferRequest::Ptr req;
122  CALL_STATUS_FNC(CreateInferRequest, req);
123  return std::make_shared<InferRequest>(req, plg);
124  }
125 
126  /**
127  * @copybrief IExecutableNetwork::Export
128  *
129  * Wraps IExecutableNetwork::Export.
130  *
131  * @see Core::ImportNetwork
132  *
133  * @param modelFileName Full path to the location of the exported file
134  */
135  void Export(const std::string& modelFileName) {
136  CALL_STATUS_FNC(Export, modelFileName);
137  }
138 
139  /**
140  * @copybrief IExecutableNetwork::Export
141  *
142  * Wraps IExecutableNetwork::Export.
143  *
144  * @see Core::ImportNetwork
145  *
146  * @param networkModel network model output stream
147  */
148  void Export(std::ostream& networkModel) {
149  CALL_STATUS_FNC(Export, networkModel);
150  }
151 
152  /**
153  * @brief cast operator is used when this wrapper initialized by LoadNetwork
154  * @return A shared pointer to IExecutableNetwork interface.
155  */
157  return actual;
158  }
159 
160  /**
161  * @copybrief IExecutableNetwork::GetExecGraphInfo
162  *
163  * Wraps IExecutableNetwork::GetExecGraphInfo.
164  * @return CNNetwork containing Executable Graph Info
165  */
167  ICNNNetwork::Ptr ptr = nullptr;
168  CALL_STATUS_FNC(GetExecGraphInfo, ptr);
169  return CNNNetwork(ptr);
170  }
171 
172  /**
173  * @copybrief IExecutableNetwork::QueryState
174  *
175  * Wraps IExecutableNetwork::QueryState
176  * @return A vector of Memory State objects
177  */
178  std::vector<MemoryState> QueryState() {
179  if (actual == nullptr) THROW_IE_EXCEPTION << "ExecutableNetwork was not initialized.";
180  IMemoryState::Ptr pState = nullptr;
181  auto res = OK;
182  std::vector<MemoryState> controller;
183  for (size_t idx = 0; res == OK; ++idx) {
184  ResponseDesc resp;
185  res = actual->QueryState(pState, idx, &resp);
186  if (res != OK && res != OUT_OF_BOUNDS) {
187  THROW_IE_EXCEPTION << resp.msg;
188  }
189  if (res != OUT_OF_BOUNDS) {
190  controller.push_back(MemoryState(pState));
191  }
192  }
193 
194  return controller;
195  }
196 
197  /**
198  * @copybrief IExecutableNetwork::SetConfig
199  *
200  * Wraps IExecutableNetwork::SetConfig.
201  * @param config Map of pairs: (config parameter name, config parameter value)
202  */
203  void SetConfig(const std::map<std::string, Parameter>& config) {
204  CALL_STATUS_FNC(SetConfig, config);
205  }
206 
207  /**
208  * @copybrief IExecutableNetwork::GetConfig
209  *
210  * Wraps IExecutableNetwork::GetConfig
211  * @param name - config key, can be found in ie_plugin_config.hpp
212  * @return Configuration paramater value
213  */
214  Parameter GetConfig(const std::string& name) const {
215  Parameter configValue;
216  CALL_STATUS_FNC(GetConfig, name, configValue);
217  return configValue;
218  }
219 
220  /**
221  * @copybrief IExecutableNetwork::GetMetric
222  *
223  * Wraps IExecutableNetwork::GetMetric
224  * @param name - metric name to request
225  * @return Metric paramater value
226  */
227  Parameter GetMetric(const std::string& name) const {
228  Parameter metricValue;
229  CALL_STATUS_FNC(GetMetric, name, metricValue);
230  return metricValue;
231  }
232 
233  /**
234  * @brief Returns pointer to plugin-specific shared context
235  * on remote accelerator device that was used to create this ExecutableNetwork
236  * @return A context
237  */
239  RemoteContext::Ptr pContext;
240  CALL_STATUS_FNC(GetContext, pContext);
241  return pContext;
242  }
243 
244  /**
245  * @brief A smart pointer to the ExecutableNetwork object
246  */
247  using Ptr = std::shared_ptr<ExecutableNetwork>;
248 };
249 
250 } // namespace InferenceEngine
ie_exception_conversion.hpp
A header file that provides macros to handle no exception methods.
InferenceEngine::ExecutableNetwork::Export
void Export(const std::string &modelFileName)
Exports the current executable network.
Definition: ie_executable_network.hpp:135
InferenceEngine::ExecutableNetwork::Export
void Export(std::ostream &networkModel)
Exports the current executable network.
Definition: ie_executable_network.hpp:148
InferenceEngine::ExecutableNetwork::CreateInferRequest
InferRequest CreateInferRequest()
Creates an inference request object used to infer the network.
Definition: ie_executable_network.hpp:107
InferenceEngine::ResponseDesc
Represents detailed information for an error.
Definition: ie_common.h:231
InferenceEngine::ExecutableNetwork::SetConfig
void SetConfig(const std::map< std::string, Parameter > &config)
Sets configuration for current executable network.
Definition: ie_executable_network.hpp:203
InferenceEngine::ExecutableNetwork::GetContext
RemoteContext::Ptr GetContext() const
Returns pointer to plugin-specific shared context on remote accelerator device that was used to creat...
Definition: ie_executable_network.hpp:238
InferenceEngine::CNNNetwork
This class contains all the information about the Neural Network and the related binary information.
Definition: ie_cnn_network.h:35
InferenceEngine::ExecutableNetwork::GetMetric
Parameter GetMetric(const std::string &name) const
Gets general runtime metric for an executable network.
Definition: ie_executable_network.hpp:227
ie_memory_state.hpp
InferenceEngine::MemoryState
C++ exception based error reporting wrapper of API class IMemoryState.
Definition: ie_memory_state.hpp:20
InferenceEngine::Parameter
This class represents an object to work with different parameters.
Definition: ie_parameter.hpp:37
InferenceEngine::IExecutableNetwork::Ptr
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:40
ie_cnn_network.h
A header file that provides wrapper for ICNNNetwork object.
InferenceEngine::ExecutableNetwork::reset
void reset(IExecutableNetwork::Ptr newActual)
reset owned object to new pointer.
Definition: ie_executable_network.hpp:91
InferenceEngine::IMemoryState::Ptr
std::shared_ptr< IMemoryState > Ptr
A shared pointer to the IMemoryState interface.
Definition: ie_imemory_state.hpp:30
InferenceEngine::ExecutableNetwork::GetOutputsInfo
ConstOutputsDataMap GetOutputsInfo() const
Gets the Executable network output Data node information.
Definition: ie_executable_network.hpp:67
InferenceEngine::ExecutableNetwork::Ptr
std::shared_ptr< ExecutableNetwork > Ptr
A smart pointer to the ExecutableNetwork object.
Definition: ie_executable_network.hpp:247
InferenceEngine::ExecutableNetwork::CreateInferRequestPtr
InferRequest::Ptr CreateInferRequestPtr()
Creates an inference request object used to infer the network.
Definition: ie_executable_network.hpp:120
ie_infer_request.hpp
A header file that provides wrapper classes for infer requests and callbacks.
ie_so_loader.h
A header file for definition of abstraction over platform specific shared objects.
InferenceEngine::InferRequest::Ptr
std::shared_ptr< InferRequest > Ptr
A smart pointer to the InferRequest object.
Definition: ie_infer_request.hpp:281
InferenceEngine::RemoteContext::Ptr
std::shared_ptr< RemoteContext > Ptr
A smart pointer to the RemoteContext object.
Definition: ie_remote_context.hpp:99
InferenceEngine::ExecutableNetwork::GetConfig
Parameter GetConfig(const std::string &name) const
Gets configuration for current executable network.
Definition: ie_executable_network.hpp:214
InferenceEngine::ExecutableNetwork
wrapper over IExecutableNetwork
Definition: ie_executable_network.hpp:30
InferenceEngine::ResponseDesc::msg
char msg[4096]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:235
InferenceEngine::ExecutableNetwork::GetExecGraphInfo
CNNNetwork GetExecGraphInfo()
Get executable graph information from a device.
Definition: ie_executable_network.hpp:166
THROW_IE_EXCEPTION
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
InferenceEngine::ConstOutputsDataMap
std::map< std::string, CDataPtr > ConstOutputsDataMap
A collection that contains string as key, and const Data smart pointer as value.
Definition: ie_iexecutable_network.hpp:30
InferenceEngine::IInferRequest::Ptr
std::shared_ptr< IInferRequest > Ptr
A shared pointer to the IInferRequest object.
Definition: ie_iinfer_request.hpp:43
InferenceEngine::ConstInputsDataMap
std::map< std::string, InputInfo::CPtr > ConstInputsDataMap
A collection that contains string as key, and const InputInfo smart pointer as value.
Definition: ie_input_info.hpp:165
InferenceEngine::ExecutableNetwork::~ExecutableNetwork
~ExecutableNetwork()
Destructor.
Definition: ie_executable_network.hpp:43
InferenceEngine::InferRequest
This is an interface of asynchronous infer request.
Definition: ie_infer_request.hpp:64
ie_iexecutable_network.hpp
a header file for IExecutableNetwork interface
InferenceEngine::ExecutableNetwork::GetInputsInfo
ConstInputsDataMap GetInputsInfo() const
Gets the executable network input Data node information.
Definition: ie_executable_network.hpp:79
InferenceEngine::ExecutableNetwork::QueryState
std::vector< MemoryState > QueryState()
Gets state control interface for given executable network.
Definition: ie_executable_network.hpp:178
InferenceEngine::ICNNNetwork::Ptr
std::shared_ptr< ICNNNetwork > Ptr
A shared pointer to a ICNNNetwork interface.
Definition: ie_icnn_network.hpp:44
InferenceEngine::ExecutableNetwork::ExecutableNetwork
ExecutableNetwork()=default
Default constructor.
InferenceEngine::ExecutableNetwork::ExecutableNetwork
ExecutableNetwork(IExecutableNetwork::Ptr actual, details::SharedObjectLoader::Ptr plg={})
Constructs ExecutableNetwork from the initialized shared_pointer.
Definition: ie_executable_network.hpp:53