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