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  */
38  explicit InferencePlugin(const InferenceEnginePluginPtr &pointer) : actual(pointer) {}
39 
40  /**
41  * @brief Wraps original method
42  * IInferencePlugin::GetVersion
43  */
44  const Version *GetVersion() {
45  const Version *versionInfo = nullptr;
46  actual->GetVersion(versionInfo);
47  if (versionInfo == nullptr) {
48  THROW_IE_EXCEPTION << "Unknown device is used";
49  }
50  return versionInfo;
51  }
52 
53  /**
54  * @brief Wraps original method
55  * IInferencePlugin::LoadNetwork
56  */
57  void LoadNetwork(ICNNNetwork &network) {
58  CALL_STATUS_FNC(LoadNetwork, network);
59  }
60 
61  /**
62  * @brief Wraps original method
63  * IInferencePlugin::LoadNetwork(IExecutableNetwork::Ptr&, ICNNNetwork&, const std::map<std::string, std::string> &, ResponseDesc*).
64  */
65  ExecutableNetwork LoadNetwork(ICNNNetwork &network, const std::map<std::string, std::string> &config) {
67  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
68  return ExecutableNetwork(ret);
69  }
70 
71  /**
72  * @brief Wraps original method
73  * IInferencePlugin::LoadNetwork(IExecutableNetwork::Ptr&, ICNNNetwork&, const std::map<std::string, std::string> &, ResponseDesc*).
74  */
75  ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map<std::string, std::string> &config) {
77  CALL_STATUS_FNC(LoadNetwork, ret, network, config);
78  if (ret.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to executable network is null";
79  return ExecutableNetwork(ret);
80  }
81 
82  /**
83  * @deprecated Loads IExecutableNetwork to create IInferRequest.
84  * @brief Wraps original method
85  * IInferencePlugin::Infer(const BlobMap&, BlobMap&, ResponseDesc *resp)
86  */
87  void Infer(const BlobMap &input, BlobMap &result) {
88  CALL_STATUS_FNC(Infer, input, result);
89  }
90 
91  /**
92  * @brief Wraps original method
93  * IInferencePlugin::GetPerformanceCounts
94  */
95  std::map<std::string, InferenceEngineProfileInfo> GetPerformanceCounts() const {
96  std::map<std::string, InferenceEngineProfileInfo> perfMap;
97  CALL_STATUS_FNC(GetPerformanceCounts, perfMap);
98  return perfMap;
99  }
100 
101  /**
102  * @brief Wraps original method
103  * IInferencePlugin::AddExtension
104  */
105  void AddExtension(InferenceEngine::IExtensionPtr extension) {
106  CALL_STATUS_FNC(AddExtension, extension);
107  }
108 
109  /**
110  * @brief Wraps original method
111  * IInferencePlugin::SetConfig
112  */
113  void SetConfig(const std::map<std::string, std::string> &config) {
114  CALL_STATUS_FNC(SetConfig, config);
115  }
116 
117  /**
118  * @brief Wraps original method
119  * IInferencePlugin::ImportNetwork
120  */
121  ExecutableNetwork ImportNetwork(const std::string &modelFileName, const std::map<std::string, std::string> &config) {
123  CALL_STATUS_FNC(ImportNetwork, ret, modelFileName, config);
124  return ExecutableNetwork(ret);
125  }
126 
127  /**
128  * @depricated Use the version with config parameter
129  * @brief Wraps original method
130  * IInferencePlugin::QueryNetwork
131  */
132  void QueryNetwork(const ICNNNetwork &network, QueryNetworkResult &res) const {
133  actual->QueryNetwork(network, res);
134  if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg;
135  }
136 
137  /**
138  * @brief Wraps original method
139  * IInferencePlugin::QueryNetwork
140  */
141  void QueryNetwork(const ICNNNetwork &network, const std::map<std::string, std::string> &config, QueryNetworkResult &res) const {
142  actual->QueryNetwork(network, config, res);
143  if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg;
144  }
145 
146  /**
147  * @brief Returns wrapped object
148  */
150  return actual;
151  }
152 
153  /**
154  * @return wrapped Hetero object if underlined object is HeteroPlugin instance, nullptr otherwise
155  */
157  return actual;
158  }
159 
160  /**
161  * @brief Shared pointer on InferencePlugin object
162  */
163  using Ptr = std::shared_ptr<InferencePlugin>;
164 };
165 } // 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:50
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:75
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.
InferencePlugin()=default
A default constructor.
InferenceEngine::details::SOPointer< IHeteroInferencePlugin > HeteroPluginPtr
Definition: ie_plugin_ptr.hpp:53
A header file contains a wrapper class for handling plugin instantiation and releasing resources...
void LoadNetwork(ICNNNetwork &network)
Wraps original method IInferencePlugin::LoadNetwork.
Definition: ie_plugin_cpp.hpp:57
void QueryNetwork(const ICNNNetwork &network, QueryNetworkResult &res) const
Wraps original method IInferencePlugin::QueryNetwork.
Definition: ie_plugin_cpp.hpp:132
std::map< std::string, InferenceEngineProfileInfo > GetPerformanceCounts() const
Wraps original method IInferencePlugin::GetPerformanceCounts.
Definition: ie_plugin_cpp.hpp:95
void AddExtension(InferenceEngine::IExtensionPtr extension)
Wraps original method IInferencePlugin::AddExtension.
Definition: ie_plugin_cpp.hpp:105
void Infer(const BlobMap &input, BlobMap &result)
Wraps original method IInferencePlugin::Infer(const BlobMap&, BlobMap&, ResponseDesc *resp) ...
Definition: ie_plugin_cpp.hpp:87
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:35
wrapper over IExecutableNetwork
Definition: ie_executable_network.hpp:27
std::shared_ptr< InferencePlugin > Ptr
Shared pointer on InferencePlugin object.
Definition: ie_plugin_cpp.hpp:163
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:29
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:267
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:65
const Version * GetVersion()
Wraps original method IInferencePlugin::GetVersion.
Definition: ie_plugin_cpp.hpp:44
void SetConfig(const std::map< std::string, std::string > &config)
Wraps original method IInferencePlugin::SetConfig.
Definition: ie_plugin_cpp.hpp:113
char msg[256]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:202
void QueryNetwork(const ICNNNetwork &network, const std::map< std::string, std::string > &config, QueryNetworkResult &res) const
Wraps original method IInferencePlugin::QueryNetwork.
Definition: ie_plugin_cpp.hpp:141
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:37
Responce structure encapsulating information about supported layer.
Definition: ie_plugin.hpp:46
ExecutableNetwork ImportNetwork(const std::string &modelFileName, const std::map< std::string, std::string > &config)
Wraps original method IInferencePlugin::ImportNetwork.
Definition: ie_plugin_cpp.hpp:121
InferencePlugin(const InferenceEnginePluginPtr &pointer)
Constructs a plugin instance from the given pointer.
Definition: ie_plugin_cpp.hpp:38