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  ExecutableNetwork() = default;
35  actual = nullptr;
36  }
37 
39  : actual(actual), plg(plg) {}
40 
41  /**
42  * @brief Wraps original method
43  * IExecutableNetwork::getOutputsInfo
44  */
47  CALL_STATUS_FNC(GetOutputsInfo, data);
48  return data;
49  }
50 
51  /**
52  * @brief Wraps original method
53  * IExecutableNetwork::getInputsInfo
54  */
56  ConstInputsDataMap info;
57  CALL_STATUS_FNC(GetInputsInfo, info);
58  return info;
59  }
60 
61  /**
62  * @brief reset owned object to new pointer, essential for cases when simultaneously loaded networks not expected
63  * @param actual actual pointed object
64  */
65  void reset(IExecutableNetwork::Ptr newActual) {
66  this->actual.swap(newActual);
67  }
68 
69  /**
70  * @brief Wraps original method
71  * IExecutableNetwork::CreateInferRequest
72  */
74  IInferRequest::Ptr req;
75  CALL_STATUS_FNC(CreateInferRequest, req);
76  if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
77  return InferRequest(req, plg);
78  }
79 
80  /**
81  * @brief Wraps original method
82  * IExecutableNetwork::CreateInferRequestPtr
83  * @return shared pointer on InferRequest object
84  */
85  InferRequest::Ptr CreateInferRequestPtr() {
86  IInferRequest::Ptr req;
87  CALL_STATUS_FNC(CreateInferRequest, req);
88  return std::make_shared<InferRequest>(req, plg);
89  }
90 
91  /**
92  * @brief Exports the current executable network so it can be used later in the Import() main API
93  * @param modelFileName Full path to the location of the exported file
94  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
95  */
96  void Export(const std::string &modelFileName) {
97  CALL_STATUS_FNC(Export, modelFileName);
98  }
99 
100  /**
101  * @brief Gets the mapping of IR layer names to implemented kernels
102  * @param deployedTopology Map of PrimitiveInfo objects that represent the deployed topology
103  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
104  */
105  void GetMappedTopology(std::map<std::string, std::vector<PrimitiveInfo::Ptr>> &deployedTopology) {
106  CALL_STATUS_FNC(GetMappedTopology, deployedTopology);
107  }
108 
109  /**
110  * cast operator is used when this wrapper initialized by LoadNetwork
111  * @return
112  */
113  operator IExecutableNetwork::Ptr &() {
114  return actual;
115  }
116 
117  /**
118  * @brief Get executable graph information from a plugin represented as CNNNetwork
119  * @return CNNetwork containing Executable Graph Info
120  */
122  ICNNNetwork::Ptr ptr = nullptr;
123  CALL_STATUS_FNC(GetExecGraphInfo, ptr);
124  return CNNNetwork(ptr);
125  }
126 
127  /**
128  *@brief see original function InferenceEngine::IExecutableNetwork::QueryState
129  */
130  std::vector<MemoryState> QueryState() {
131  IMemoryState::Ptr pState = nullptr;
132  auto res = OK;
133  std::vector<MemoryState> controller;
134  for (size_t idx = 0; res == OK; ++idx) {
135  ResponseDesc resp;
136  res = actual->QueryState(pState, idx, &resp);
137  if (res != OK && res != OUT_OF_BOUNDS) {
138  THROW_IE_EXCEPTION << resp.msg;
139  }
140  if (res != OUT_OF_BOUNDS) {
141  controller.push_back(MemoryState(pState));
142  }
143  }
144 
145  return controller;
146  }
147 
148  /**
149  * @brief Sets configuration for current executable network
150  * @param config Map of pairs: (config parameter name, config parameter value)
151  * @param resp Pointer to the response message that holds a description of an error if any occurred
152  */
153  void SetConfig(const std::map<std::string, Parameter> &config) {
154  CALL_STATUS_FNC(SetConfig, config);
155  }
156 
157  /** @brief Gets configuration dedicated to plugin behaviour
158  * @param name - config key, can be found in ie_plugin_config.hpp
159  * @param options - configuration details for coonfig value
160  * @param result - value of config corresponding to config key
161  * @param resp Pointer to the response message that holds a description of an error if any occurred
162  */
163  Parameter GetConfig(const std::string &name) const {
164  Parameter configValue;
165  CALL_STATUS_FNC(GetConfig, name, configValue);
166  return configValue;
167  }
168 
169  /**
170  * @brief Gets general runtime metric for dedicated hardware
171  * @param name - metric name to request
172  * @param options - configuration details for metric
173  * @param result - metric value corresponding to metric key
174  * @param resp - Pointer to the response message that holds a description of an error if any
175  * occurred
176  * @return code of the operation. OK if succeeded
177  */
178  Parameter GetMetric(const std::string &name) const {
179  Parameter metricValue;
180  CALL_STATUS_FNC(GetMetric, name, metricValue);
181  return metricValue;
182  }
183 
184  using Ptr = std::shared_ptr<ExecutableNetwork>;
185 };
186 
187 } // namespace InferenceEngine
void SetConfig(const std::map< std::string, Parameter > &config)
Sets configuration for current executable network.
Definition: ie_executable_network.hpp:153
#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 dedicated to plugin behaviour.
Definition: ie_executable_network.hpp:163
A header file that provides wrapper for ICNNNetwork object.
std::vector< MemoryState > QueryState()
see original function InferenceEngine::IExecutableNetwork::QueryState
Definition: ie_executable_network.hpp:130
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...
InferRequest CreateInferRequest()
Wraps original method IExecutableNetwork::CreateInferRequest.
Definition: ie_executable_network.hpp:73
ConstOutputsDataMap GetOutputsInfo() const
Wraps original method IExecutableNetwork::getOutputsInfo.
Definition: ie_executable_network.hpp:45
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
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)
Gets the mapping of IR layer names to implemented kernels.
Definition: ie_executable_network.hpp:105
CNNNetwork GetExecGraphInfo()
Get executable graph information from a plugin represented as CNNNetwork.
Definition: ie_executable_network.hpp:121
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:29
c++ exception based error reporting wrapper of API class IMemoryState
Definition: ie_memory_state.hpp:13
void Export(const std::string &modelFileName)
Exports the current executable network so it can be used later in the Import() main API...
Definition: ie_executable_network.hpp:96
ConstInputsDataMap GetInputsInfo() const
Wraps original method IExecutableNetwork::getInputsInfo.
Definition: ie_executable_network.hpp:55
This class represents an object to work with different parameters.
Definition: ie_parameter.hpp:27
Parameter GetMetric(const std::string &name) const
Gets general runtime metric for dedicated hardware.
Definition: ie_executable_network.hpp:178
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.
void reset(IExecutableNetwork::Ptr newActual)
reset owned object to new pointer, essential for cases when simultaneously loaded networks not expect...
Definition: ie_executable_network.hpp:65
InferRequest::Ptr CreateInferRequestPtr()
Wraps original method IExecutableNetwork::CreateInferRequestPtr.
Definition: ie_executable_network.hpp:85