ie_plugin_cpp.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 This is a header file for the Inference Engine plugin C++ API
7  *
8  * @file ie_plugin_cpp.hpp
9  */
10 #pragma once
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 
18 #include "ie_cnn_network.h"
19 #include "ie_plugin.hpp"
20 #include "ie_plugin_ptr.hpp"
21 
22 namespace InferenceEngine {
23 
24 /**
25  * @deprecated Use InferenceEngine::Core instead. Will be removed in 2020.3
26  * @brief This class is a C++ API wrapper for IInferencePlugin.
27  *
28  * It can throw exceptions safely for the application, where it is properly handled.
29  */
30 class INFERENCE_ENGINE_DEPRECATED("Use InferenceEngine::Core instead. Will be removed in 2020.3") InferencePlugin {
31  IE_SUPPRESS_DEPRECATED_START
33 
34 public:
35  /** @brief A default constructor */
36  InferencePlugin() = default;
37 
38  /**
39  * @brief Constructs a plugin instance from the given pointer.
40  *
41  * @param pointer Initialized Plugin pointer
42  */
43  explicit InferencePlugin(const InferenceEnginePluginPtr& pointer): actual(pointer) {
44  if (actual == nullptr) {
45  THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized.";
46  }
47  }
48 
49  IE_SUPPRESS_DEPRECATED_END
50 
51  /**
52  * @copybrief IInferencePlugin::GetVersion
53  *
54  * Wraps IInferencePlugin::GetVersion
55  * @return A plugin version
56  */
57  const Version* GetVersion() {
58  const Version* versionInfo = nullptr;
59  IE_SUPPRESS_DEPRECATED_START
60  actual->GetVersion(versionInfo);
61  IE_SUPPRESS_DEPRECATED_END
62  if (versionInfo == nullptr) {
63  THROW_IE_EXCEPTION << "Unknown device is used";
64  }
65  return versionInfo;
66  }
67 
68  /**
69  * @copybrief IInferencePlugin::LoadNetwork
70  *
71  * Wraps IInferencePlugin::LoadNetwork
72  *
73  * @param network A network object to load
74  * @param config A map of configuration options
75  * @return Created Executable Network object
76  */
77  ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map<std::string, std::string>& config) {
79  IE_SUPPRESS_DEPRECATED_START
80  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
81  return ExecutableNetwork(ret, actual);
82  IE_SUPPRESS_DEPRECATED_END
83  }
84 
85  /**
86  * @copybrief InferencePlugin::LoadNetwork
87  *
88  * Wraps IInferencePlugin::LoadNetwork
89  * @param network A network object to load
90  * @param config A map of configuration options
91  * @return Created Executable Network object
92  */
93  ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map<std::string, std::string>& config) {
95  IE_SUPPRESS_DEPRECATED_START
96  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
97  if (ret.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to executable network is null";
98  return ExecutableNetwork(ret, actual);
99  IE_SUPPRESS_DEPRECATED_END
100  }
101 
102  /**
103  * @copybrief IInferencePlugin::AddExtension
104  *
105  * Wraps IInferencePlugin::AddExtension
106  *
107  * @param extension Pointer to loaded Extension
108  */
110  IE_SUPPRESS_DEPRECATED_START
111  CALL_STATUS_FNC(AddExtension, extension);
112  IE_SUPPRESS_DEPRECATED_END
113  }
114 
115  /**
116  * @copybrief IInferencePlugin::SetConfig
117  *
118  * Wraps IInferencePlugin::SetConfig
119  * @param config A configuration map
120  */
121  void SetConfig(const std::map<std::string, std::string>& config) {
122  IE_SUPPRESS_DEPRECATED_START
123  CALL_STATUS_FNC(SetConfig, config);
124  IE_SUPPRESS_DEPRECATED_END
125  }
126 
127  /**
128  * @copybrief IInferencePlugin::ImportNetwork
129  *
130  * Wraps IInferencePlugin::ImportNetwork
131  * @param modelFileName A path to the imported network
132  * @param config A configuration map
133  * @return Created Executable Network object
134  */
135  ExecutableNetwork ImportNetwork(const std::string& modelFileName,
136  const std::map<std::string, std::string>& config) {
138  IE_SUPPRESS_DEPRECATED_START
139  CALL_STATUS_FNC(ImportNetwork, ret, modelFileName, config);
140  return ExecutableNetwork(ret, actual);
141  IE_SUPPRESS_DEPRECATED_END
142  }
143 
144  /**
145  * @copybrief IInferencePlugin::QueryNetwork
146  *
147  * Wraps IInferencePlugin::QueryNetwork
148  *
149  * @param network A network object to query
150  * @param config A configuration map
151  * @param res Query results
152  */
153  void QueryNetwork(const ICNNNetwork& network, const std::map<std::string, std::string>& config,
154  QueryNetworkResult& res) const {
155  IE_SUPPRESS_DEPRECATED_START
156  actual->QueryNetwork(network, config, res);
157  IE_SUPPRESS_DEPRECATED_END
158  if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg;
159  }
160 
161  IE_SUPPRESS_DEPRECATED_START
162 
163  /**
164  * @brief Converts InferenceEngine to InferenceEnginePluginPtr pointer
165  *
166  * @return Wrapped object
167  */
169  return actual;
170  }
171 
172  /**
173  * @brief Shared pointer on InferencePlugin object
174  *
175  */
176  using Ptr = std::shared_ptr<InferencePlugin>;
177 
178  IE_SUPPRESS_DEPRECATED_END
179 };
180 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
A header file that provides wrapper classes for IExecutableNetwork.
A header file that provides wrapper for ICNNNetwork object.
This class represents Inference Engine Core entity.
Definition: ie_core.hpp:29
ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:93
InferenceEngine::details::SOPointer< IInferencePlugin > InferenceEnginePluginPtr
A C++ helper to work with objects created by the plugin.
Definition: ie_plugin_ptr.hpp:43
ExecutableNetwork LoadNetwork(const ICNNNetwork &network, const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:77
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
Represents version information that describes plugins and the inference engine runtime library...
Definition: ie_version.hpp:21
This class is a C++ API wrapper for IInferencePlugin.
Definition: ie_plugin_cpp.hpp:30
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:70
A header file contains a wrapper class for handling plugin instantiation and releasing resources...
char msg[4096]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:251
void AddExtension(InferenceEngine::IExtensionPtr extension)
Definition: ie_plugin_cpp.hpp:109
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:43
wrapper over IExecutableNetwork
Definition: ie_executable_network.hpp:30
std::shared_ptr< IExtension > IExtensionPtr
A shared pointer to a IExtension interface.
Definition: ie_iextension.h:359
std::shared_ptr< InferencePlugin > Ptr
Shared pointer on InferencePlugin object.
Definition: ie_plugin_cpp.hpp:176
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:38
StatusCode rc
A status code.
Definition: ie_plugin.hpp:65
const Version * GetVersion()
Definition: ie_plugin_cpp.hpp:57
void SetConfig(const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:121
void QueryNetwork(const ICNNNetwork &network, const std::map< std::string, std::string > &config, QueryNetworkResult &res) const
Definition: ie_plugin_cpp.hpp:153
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:41
Responce structure encapsulating information about supported layer.
Definition: ie_plugin.hpp:54
ExecutableNetwork ImportNetwork(const std::string &modelFileName, const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:135
InferencePlugin(const InferenceEnginePluginPtr &pointer)
Constructs a plugin instance from the given pointer.
Definition: ie_plugin_cpp.hpp:43