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 "cpp/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 2021.1
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 2021.1") 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  if (actual == nullptr) THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized";
61  actual->GetVersion(versionInfo);
62  IE_SUPPRESS_DEPRECATED_END
63  if (versionInfo == nullptr) {
64  THROW_IE_EXCEPTION << "Unknown device is used";
65  }
66  return versionInfo;
67  }
68 
69  /**
70  * @copybrief IInferencePlugin::LoadNetwork
71  *
72  * Wraps IInferencePlugin::LoadNetwork
73  *
74  * @param network A network object to load
75  * @param config A map of configuration options
76  * @return Created Executable Network object
77  */
78  ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map<std::string, std::string>& config) {
80  IE_SUPPRESS_DEPRECATED_START
81  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
82  return ExecutableNetwork(ret, actual);
83  IE_SUPPRESS_DEPRECATED_END
84  }
85 
86  /**
87  * @copybrief InferencePlugin::LoadNetwork
88  *
89  * Wraps IInferencePlugin::LoadNetwork
90  * @param network A network object to load
91  * @param config A map of configuration options
92  * @return Created Executable Network object
93  */
94  ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map<std::string, std::string>& config) {
96  IE_SUPPRESS_DEPRECATED_START
97  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
98  if (ret.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to executable network is null";
99  return ExecutableNetwork(ret, actual);
100  IE_SUPPRESS_DEPRECATED_END
101  }
102 
103  /**
104  * @copybrief IInferencePlugin::AddExtension
105  *
106  * Wraps IInferencePlugin::AddExtension
107  *
108  * @param extension Pointer to loaded Extension
109  */
111  IE_SUPPRESS_DEPRECATED_START
112  CALL_STATUS_FNC(AddExtension, extension);
113  IE_SUPPRESS_DEPRECATED_END
114  }
115 
116  /**
117  * @copybrief IInferencePlugin::SetConfig
118  *
119  * Wraps IInferencePlugin::SetConfig
120  * @param config A configuration map
121  */
122  void SetConfig(const std::map<std::string, std::string>& config) {
123  IE_SUPPRESS_DEPRECATED_START
124  CALL_STATUS_FNC(SetConfig, config);
125  IE_SUPPRESS_DEPRECATED_END
126  }
127 
128  /**
129  * @copybrief IInferencePlugin::ImportNetwork
130  *
131  * Wraps IInferencePlugin::ImportNetwork
132  * @param modelFileName A path to the imported network
133  * @param config A configuration map
134  * @return Created Executable Network object
135  */
136  ExecutableNetwork ImportNetwork(const std::string& modelFileName,
137  const std::map<std::string, std::string>& config) {
139  IE_SUPPRESS_DEPRECATED_START
140  CALL_STATUS_FNC(ImportNetwork, ret, modelFileName, config);
141  return ExecutableNetwork(ret, actual);
142  IE_SUPPRESS_DEPRECATED_END
143  }
144 
145  /**
146  * @copybrief IInferencePlugin::QueryNetwork
147  *
148  * Wraps IInferencePlugin::QueryNetwork
149  *
150  * @param network A network object to query
151  * @param config A configuration map
152  * @param res Query results
153  */
154  void QueryNetwork(const ICNNNetwork& network, const std::map<std::string, std::string>& config,
155  QueryNetworkResult& res) const {
156  IE_SUPPRESS_DEPRECATED_START
157  if (actual == nullptr) THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized";
158  actual->QueryNetwork(network, config, res);
159  IE_SUPPRESS_DEPRECATED_END
160  if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg;
161  }
162 
163  IE_SUPPRESS_DEPRECATED_START
164 
165  /**
166  * @brief Converts InferenceEngine to InferenceEnginePluginPtr pointer
167  *
168  * @return Wrapped object
169  */
171  return actual;
172  }
173 
174  /**
175  * @brief Shared pointer on InferencePlugin object
176  *
177  */
178  using Ptr = std::shared_ptr<InferencePlugin>;
179 
180  IE_SUPPRESS_DEPRECATED_END
181 };
182 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
InferenceEngine::details::SOPointer< IInferencePlugin > InferenceEnginePluginPtr
A C++ helper to work with objects created by the plugin.
Definition: ie_plugin_ptr.hpp:43
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:51
ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:94
ExecutableNetwork LoadNetwork(const ICNNNetwork &network, const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:78
Definition: cldnn_config.hpp:16
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 message.
Definition: ie_core.hpp:43
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:110
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< InferencePlugin > Ptr
Shared pointer on InferencePlugin object.
Definition: ie_plugin_cpp.hpp:178
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_core.hpp:38
const Version * GetVersion()
Definition: ie_plugin_cpp.hpp:57
void SetConfig(const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:122
std::shared_ptr< IExtension > IExtensionPtr
A shared pointer to a IExtension interface.
Definition: ie_iextension.h:359
void QueryNetwork(const ICNNNetwork &network, const std::map< std::string, std::string > &config, QueryNetworkResult &res) const
Definition: ie_plugin_cpp.hpp:154
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_core.hpp:27
ExecutableNetwork ImportNetwork(const std::string &modelFileName, const std::map< std::string, std::string > &config)
Definition: ie_plugin_cpp.hpp:136
InferencePlugin(const InferenceEnginePluginPtr &pointer)
Constructs a plugin instance from the given pointer.
Definition: ie_plugin_cpp.hpp:43