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