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 "ie_plugin_ptr.hpp"
24 
25 namespace InferenceEngine {
26 
27 /**
28  * @brief wrapper over IExecutableNetwork
29  */
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  */
54  : actual(actual), plg(plg) {}
55 
56  /**
57  * @copybrief IExecutableNetwork::GetOutputsInfo
58  *
59  * Wraps IExecutableNetwork::GetOutputsInfo.
60  * @return A collection that contains string as key, and const Data smart pointer as value
61  */
64  CALL_STATUS_FNC(GetOutputsInfo, data);
65  return data;
66  }
67 
68  /**
69  * @copybrief IExecutableNetwork::GetInputsInfo
70  *
71  * Wraps IExecutableNetwork::GetInputsInfo
72  * @return A collection that contains string as key, and const InputInfo smart pointer as value
73  */
75  ConstInputsDataMap info;
76  CALL_STATUS_FNC(GetInputsInfo, info);
77  return info;
78  }
79 
80  /**
81  * @brief reset owned object to new pointer.
82  *
83  * Eessential for cases when simultaneously loaded networks not expected.
84  * @param newActual actual pointed object
85  */
86  void reset(IExecutableNetwork::Ptr newActual) {
87  this->actual.swap(newActual);
88  }
89 
90  /**
91  * @copybrief IExecutableNetwork::CreateInferRequest
92  *
93  * Wraps IExecutableNetwork::CreateInferRequest.
94  * @return InferRequest object
95  */
98  CALL_STATUS_FNC(CreateInferRequest, req);
99  if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
100  return InferRequest(req, plg);
101  }
102 
103  /**
104  * @copybrief IExecutableNetwork::CreateInferRequest
105  *
106  * Wraps IExecutableNetwork::CreateInferRequest.
107  * @return shared pointer on InferenceEngine::InferRequest object
108  */
110  IInferRequest::Ptr req;
111  CALL_STATUS_FNC(CreateInferRequest, req);
112  return std::make_shared<InferRequest>(req, plg);
113  }
114 
115  /**
116  * @copybrief IExecutableNetwork::Export
117  *
118  * Wraps IExecutableNetwork::Export.
119  *
120  * @see Core::ImportNetwork
121  * @see InferencePlugin::ImportNetwork
122  *
123  * @param modelFileName Full path to the location of the exported file
124  */
125  void Export(const std::string& modelFileName) {
126  CALL_STATUS_FNC(Export, modelFileName);
127  }
128 
129  /**
130  * @copybrief IExecutableNetwork::Export
131  *
132  * Wraps IExecutableNetwork::Export.
133  *
134  * @see Core::ImportNetwork
135  * @see InferencePlugin::ImportNetwork
136  *
137  * @param networkModel network model output stream
138  */
139  void Export(std::ostream& networkModel) {
140  CALL_STATUS_FNC(Export, networkModel);
141  }
142 
143  /**
144  * @copybrief IExecutableNetwork::GetMappedTopology
145  *
146  * Wraps IExecutableNetwork::GetMappedTopology.
147  * @param deployedTopology Map of PrimitiveInfo objects that represent the deployed topology
148  */
149  void GetMappedTopology(std::map<std::string, std::vector<PrimitiveInfo::Ptr>>& deployedTopology) {
150  CALL_STATUS_FNC(GetMappedTopology, deployedTopology);
151  }
152 
153  /**
154  * cast operator is used when this wrapper initialized by LoadNetwork
155  * @return
156  */
158  return actual;
159  }
160 
161  /**
162  * @copybrief IExecutableNetwork::GetExecGraphInfo
163  *
164  * Wraps IExecutableNetwork::GetExecGraphInfo.
165  * @return CNNetwork containing Executable Graph Info
166  */
168  ICNNNetwork::Ptr ptr = nullptr;
169  CALL_STATUS_FNC(GetExecGraphInfo, ptr);
170  return CNNNetwork(ptr);
171  }
172 
173  /**
174  * @copybrief IExecutableNetwork::QueryState
175  *
176  * Wraps IExecutableNetwork::QueryState
177  * @return A vector of Memory State objects
178  */
179  std::vector<MemoryState> QueryState() {
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  /** @copybrief IExecutableNetwork::GetConfig
208  *
209  * Wraps IExecutableNetwork::GetConfig
210  * @param name - config key, can be found in ie_plugin_config.hpp
211  * @return Configuration paramater value
212  */
213  Parameter GetConfig(const std::string& name) const {
214  Parameter configValue;
215  CALL_STATUS_FNC(GetConfig, name, configValue);
216  return configValue;
217  }
218 
219  /**
220  * @copybrief IExecutableNetwork::GetMetric
221  *
222  * Wraps IExecutableNetwork::GetMetric
223  * @param name - metric name to request
224  * @return Metric paramater value
225  */
226  Parameter GetMetric(const std::string& name) const {
227  Parameter metricValue;
228  CALL_STATUS_FNC(GetMetric, name, metricValue);
229  return metricValue;
230  }
231 
232  /**
233  * @brief Returns pointer to plugin-specific shared context
234  * on remote accelerator device that was used to create this ExecutableNetwork
235  */
237  RemoteContext::Ptr pContext;
238  CALL_STATUS_FNC(GetContext, pContext);
239  return pContext;
240  }
241 
242  /**
243  * @brief A smart pointer to the ExecutableNetwork object
244  */
245  using Ptr = std::shared_ptr<ExecutableNetwork>;
246 };
247 
248 } // namespace InferenceEngine
void SetConfig(const std::map< std::string, Parameter > &config)
Definition: ie_executable_network.hpp:203
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
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:236
Parameter GetConfig(const std::string &name) const
Gets configuration for current executable network.
Definition: ie_executable_network.hpp:213
A header file that provides wrapper for ICNNNetwork object.
InferenceEngine::details::SOPointer< IInferencePlugin > InferenceEnginePluginPtr
A C++ helper to work with objects created by the plugin.
Definition: ie_plugin_ptr.hpp:43
std::vector< MemoryState > QueryState()
Definition: ie_executable_network.hpp:179
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
a header file for IExecutableNetwork interface
A header file that provides macros to handle no exception methods.
A header file contains a wrapper class for handling plugin instantiation and releasing resources...
ExecutableNetwork(IExecutableNetwork::Ptr actual, InferenceEnginePluginPtr plg={})
Constructs ExecutableNetwork from the initialized shared_pointer.
Definition: ie_executable_network.hpp:53
InferRequest CreateInferRequest()
Definition: ie_executable_network.hpp:96
ConstOutputsDataMap GetOutputsInfo() const
Definition: ie_executable_network.hpp:62
Definition: ie_infer_request.hpp:64
std::shared_ptr< InferRequest > Ptr
A smart pointer to the InferRequest object.
Definition: ie_infer_request.hpp:265
ExecutableNetwork()=default
Default constructor.
Represents detailed information for an error.
Definition: ie_common.h:239
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:31
char msg[4096]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:243
wrapper over IExecutableNetwork
Definition: ie_executable_network.hpp:30
void GetMappedTopology(std::map< std::string, std::vector< PrimitiveInfo::Ptr >> &deployedTopology)
Definition: ie_executable_network.hpp:149
CNNNetwork GetExecGraphInfo()
Definition: ie_executable_network.hpp:167
void Export(std::ostream &networkModel)
Definition: ie_executable_network.hpp:139
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:38
~ExecutableNetwork()
Destructor.
Definition: ie_executable_network.hpp:43
C++ exception based error reporting wrapper of API class IMemoryState.
Definition: ie_memory_state.hpp:17
void Export(const std::string &modelFileName)
Definition: ie_executable_network.hpp:125
ConstInputsDataMap GetInputsInfo() const
Definition: ie_executable_network.hpp:74
This class represents an object to work with different parameters.
Definition: ie_parameter.hpp:38
Parameter GetMetric(const std::string &name) const
Definition: ie_executable_network.hpp:226
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:169
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:41
std::shared_ptr< RemoteContext > Ptr
A smart pointer to the RemoteContext object.
Definition: ie_remote_context.hpp:99
A header file that provides wrapper classes for infer requests and callbacks.
std::shared_ptr< ExecutableNetwork > Ptr
A smart pointer to the ExecutableNetwork object.
Definition: ie_executable_network.hpp:245
void reset(IExecutableNetwork::Ptr newActual)
reset owned object to new pointer.
Definition: ie_executable_network.hpp:86
std::shared_ptr< IInferRequest > Ptr
A shared pointer to the IInferRequest object.
Definition: ie_iinfer_request.hpp:44
InferRequest::Ptr CreateInferRequestPtr()
Definition: ie_executable_network.hpp:109