ie_plugin_cpp.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 This is a header file for the Inference Engine plugin C++ API
7  * @file ie_plugin_cpp.hpp
8  */
9 #pragma once
10 
11 #include <map>
12 #include <string>
13 #include <memory>
14 
15 #include "ie_plugin.hpp"
18 #include "ie_plugin_ptr.hpp"
19 #include "ie_cnn_network.h"
20 
21 
22 namespace InferenceEngine {
23 
24 /**
25  * @brief This class is a C++ API wrapper for IInferencePlugin.
26  * It can throw exceptions safely for the application, where it is properly handled.
27  */
30 
31 public:
32  /** @brief A default constructor */
33  InferencePlugin() = default;
34 
35  /**
36  * @brief Constructs a plugin instance from the given pointer.
37  * @param pointer Initialized Plugin pointer
38  */
39  explicit InferencePlugin(const InferenceEnginePluginPtr &pointer) : actual(pointer) {}
40 
41  /**
42  * @brief Wraps original method
43  * IInferencePlugin::GetVersion
44  */
45  const Version *GetVersion() {
46  const Version *versionInfo = nullptr;
47  actual->GetVersion(versionInfo);
48  if (versionInfo == nullptr) {
49  THROW_IE_EXCEPTION << "Unknown device is used";
50  }
51  return versionInfo;
52  }
53 
54  /**
55  * @deprecated Use InferencePlugin::LoadNetwork(ICNNNetwork &, const std::map<std::string, std::string> &)
56  * @brief Wraps original method IInferencePlugin::LoadNetwork(ICNNNetwork &, ResponseDesc *)
57  * @param network A network object to load
58  */
59  INFERENCE_ENGINE_DEPRECATED
60  void LoadNetwork(ICNNNetwork &network) {
61  IE_SUPPRESS_DEPRECATED_START
62  CALL_STATUS_FNC(LoadNetwork, network);
63  IE_SUPPRESS_DEPRECATED_END
64  }
65 
66  /**
67  * @brief Wraps original method
68  * IInferencePlugin::LoadNetwork(IExecutableNetwork::Ptr&, ICNNNetwork&, const std::map<std::string, std::string> &, ResponseDesc*).
69  * @param network A network object to load
70  * @param config A map of configuration options
71  * @return Created Executable Network object
72  */
73  ExecutableNetwork LoadNetwork(ICNNNetwork &network, const std::map<std::string, std::string> &config) {
75  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
76  return ExecutableNetwork(ret, actual);
77  }
78 
79  /**
80  * @brief Wraps original method
81  * IInferencePlugin::LoadNetwork(IExecutableNetwork::Ptr&, ICNNNetwork&, const std::map<std::string, std::string> &, ResponseDesc*).
82  * @param network A network object to load
83  * @param config A map of configuration options
84  * @return Created Executable Network object
85  */
86  ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map<std::string, std::string> &config) {
88  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
89  if (ret.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to executable network is null";
90  return ExecutableNetwork(ret, actual);
91  }
92 
93  /**
94  * @deprecated Use IExecutableNetwork to create IInferRequest.
95  * @brief Wraps original method IInferencePlugin::Infer(const BlobMap&, BlobMap&, ResponseDesc *)
96  * @param input A map of input blobs accessed by input names
97  * @param result A map of output blobs accessed by output names
98  */
99  INFERENCE_ENGINE_DEPRECATED
100  void Infer(const BlobMap &input, BlobMap &result) {
101  IE_SUPPRESS_DEPRECATED_START
102  CALL_STATUS_FNC(Infer, input, result);
103  IE_SUPPRESS_DEPRECATED_END
104  }
105 
106  /**
107  * @deprecated Use IInferRequest to get performance counters
108  * @brief Wraps original method IInferencePlugin::GetPerformanceCounts
109  * @return Map of layers names to profiling information for that layers
110  */
111  INFERENCE_ENGINE_DEPRECATED
112  std::map<std::string, InferenceEngineProfileInfo> GetPerformanceCounts() const {
113  std::map<std::string, InferenceEngineProfileInfo> perfMap;
114  IE_SUPPRESS_DEPRECATED_START
115  CALL_STATUS_FNC(GetPerformanceCounts, perfMap);
116  IE_SUPPRESS_DEPRECATED_END
117  return perfMap;
118  }
119 
120  /**
121  * @brief Wraps original method
122  * IInferencePlugin::AddExtension
123  * @param extension Pointer to loaded Extension
124  */
125  void AddExtension(InferenceEngine::IExtensionPtr extension) {
126  CALL_STATUS_FNC(AddExtension, extension);
127  }
128 
129  /**
130  * @brief Wraps original method
131  * IInferencePlugin::SetConfig
132  * @param config A configuration map
133  */
134  void SetConfig(const std::map<std::string, std::string> &config) {
135  CALL_STATUS_FNC(SetConfig, config);
136  }
137 
138  /**
139  * @brief Wraps original method
140  * IInferencePlugin::ImportNetwork
141  * @param modelFileName A path to the imported network
142  * @param config A configuration map
143  * @return Created Executable Network object
144  */
145  ExecutableNetwork ImportNetwork(const std::string &modelFileName, const std::map<std::string, std::string> &config) {
147  CALL_STATUS_FNC(ImportNetwork, ret, modelFileName, config);
148  return ExecutableNetwork(ret, actual);
149  }
150 
151  /**
152  * @deprecated Use InferencePlugin::QueryNetwork(const ICNNNetwork &, const std::map<std::string, std::string> &, QueryNetworkResult &) const
153  * @brief Wraps original method
154  * IInferencePlugin::QueryNetwork(const ICNNNetwork&, QueryNetworkResult& ) const
155  * @param network A network object to query
156  * @param res Query results
157  */
158  INFERENCE_ENGINE_DEPRECATED
159  void QueryNetwork(const ICNNNetwork &network, QueryNetworkResult &res) const {
160  QueryNetwork(network, { }, res);
161  }
162 
163  /**
164  * @brief Wraps original method
165  * IInferencePlugin::QueryNetwork(const ICNNNetwork&, const std::map<std::string, std::string> &, QueryNetworkResult&) const
166  * @param network A network object to query
167  * @param config A configuration map
168  * @param res Query results
169  */
170  void QueryNetwork(const ICNNNetwork &network, const std::map<std::string, std::string> &config, QueryNetworkResult &res) const {
171  actual->QueryNetwork(network, config, res);
172  if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg;
173  }
174 
175  /**
176  * @brief Converts InferenceEngine to InferenceEnginePluginPtr pointer
177  * @return Wrapped object
178  */
180  return actual;
181  }
182 
183  /**
184  * @deprecated Deprecated since HeteroPluginPtr is deprecated
185  * @brief Converts InferenceEngine to HeteroPluginPtr pointer
186  * @return Wrapped Hetero object if underlined object is HeteroPlugin instance, nullptr otherwise
187  */
188  IE_SUPPRESS_DEPRECATED_START
190  return actual;
191  }
192  IE_SUPPRESS_DEPRECATED_END
193 
194  /**
195  * @brief Shared pointer on InferencePlugin object
196  */
197  using Ptr = std::shared_ptr<InferencePlugin>;
198 };
199 } // namespace InferenceEngine
#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
A header file that provides wrapper classes for IExecutableNetwork.
A header file that provides wrapper for ICNNNetwork object.
ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map< std::string, std::string > &config)
Wraps original method IInferencePlugin::LoadNetwork(IExecutableNetwork::Ptr&, ICNNNetwork&, const std::map<std::string, std::string> &, ResponseDesc*).
Definition: ie_plugin_cpp.hpp:86
Definition: ie_argmax_layer.hpp:11
Represents version information that describes plugins and the inference engine runtime library...
Definition: ie_version.hpp:20
This class is a C++ API wrapper for IInferencePlugin. It can throw exceptions safely for the applicat...
Definition: ie_plugin_cpp.hpp:28
A header file for Main Inference Engine API.
A header file that provides macros to handle no exception methods.
ResponseDesc resp
Response mssage.
Definition: ie_plugin.hpp:73
InferencePlugin()=default
A default constructor.
InferenceEngine::details::SOPointer< IHeteroInferencePlugin > HeteroPluginPtr
Definition: ie_plugin_ptr.hpp:56
A header file contains a wrapper class for handling plugin instantiation and releasing resources...
void LoadNetwork(ICNNNetwork &network)
Wraps original method IInferencePlugin::LoadNetwork(ICNNNetwork &, ResponseDesc *) ...
Definition: ie_plugin_cpp.hpp:60
void QueryNetwork(const ICNNNetwork &network, QueryNetworkResult &res) const
Wraps original method IInferencePlugin::QueryNetwork(const ICNNNetwork&, QueryNetworkResult& ) const...
Definition: ie_plugin_cpp.hpp:159
std::map< std::string, InferenceEngineProfileInfo > GetPerformanceCounts() const
Wraps original method IInferencePlugin::GetPerformanceCounts.
Definition: ie_plugin_cpp.hpp:112
void AddExtension(InferenceEngine::IExtensionPtr extension)
Wraps original method IInferencePlugin::AddExtension.
Definition: ie_plugin_cpp.hpp:125
void Infer(const BlobMap &input, BlobMap &result)
Wraps original method IInferencePlugin::Infer(const BlobMap&, BlobMap&, ResponseDesc *) ...
Definition: ie_plugin_cpp.hpp:100
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:35
wrapper over IExecutableNetwork
Definition: ie_executable_network.hpp:28
std::shared_ptr< InferencePlugin > Ptr
Shared pointer on InferencePlugin object.
Definition: ie_plugin_cpp.hpp:197
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:29
StatusCode rc
A status code.
Definition: ie_plugin.hpp:68
std::map< std::string, Blob::Ptr > BlobMap
This is a convenient type for working with a map containing pairs(string, pointer to a Blob instance)...
Definition: ie_blob.h:478
ExecutableNetwork LoadNetwork(ICNNNetwork &network, const std::map< std::string, std::string > &config)
Wraps original method IInferencePlugin::LoadNetwork(IExecutableNetwork::Ptr&, ICNNNetwork&, const std::map<std::string, std::string> &, ResponseDesc*).
Definition: ie_plugin_cpp.hpp:73
const Version * GetVersion()
Wraps original method IInferencePlugin::GetVersion.
Definition: ie_plugin_cpp.hpp:45
void SetConfig(const std::map< std::string, std::string > &config)
Wraps original method IInferencePlugin::SetConfig.
Definition: ie_plugin_cpp.hpp:134
char msg[256]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:232
void QueryNetwork(const ICNNNetwork &network, const std::map< std::string, std::string > &config, QueryNetworkResult &res) const
Wraps original method IInferencePlugin::QueryNetwork(const ICNNNetwork&, const std::map<std::string, std::string> &, QueryNetworkResult&) const.
Definition: ie_plugin_cpp.hpp:170
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:38
Responce structure encapsulating information about supported layer.
Definition: ie_plugin.hpp:50
ExecutableNetwork ImportNetwork(const std::string &modelFileName, const std::map< std::string, std::string > &config)
Wraps original method IInferencePlugin::ImportNetwork.
Definition: ie_plugin_cpp.hpp:145
InferencePlugin(const InferenceEnginePluginPtr &pointer)
Constructs a plugin instance from the given pointer.
Definition: ie_plugin_cpp.hpp:39