ie_core.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 Core class C++ API
7  *
8  * @file ie_core.hpp
9  */
10 #pragma once
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "cpp/ie_plugin_cpp.hpp"
19 #include "ie_extension.h"
20 #include "ie_remote_context.hpp"
21 
22 namespace InferenceEngine {
23 
24 /**
25  * @brief This class represents Inference Engine Core entity.
26  *
27  * It can throw exceptions safely for the application, where it is properly handled.
28  */
29 class INFERENCE_ENGINE_API_CLASS(Core) {
30  class Impl;
31  std::shared_ptr<Impl> _impl;
32 
33 public:
34  /** @brief Constructs Inference Engine Core instance using XML configuration file with
35  * plugins description.
36  *
37  * See RegisterPlugins for more details.
38  *
39  * @param xmlConfigFile A path to .xml file with plugins to load from. If XML configuration file is not specified,
40  * then default Inference Engine plugins are loaded from the default plugin.xml file.
41  */
42  explicit Core(const std::string& xmlConfigFile = std::string());
43 
44  /**
45  * @brief Returns plugins version information
46  *
47  * @param deviceName Device name to indentify plugin
48  * @return A vector of versions
49  */
50  std::map<std::string, Version> GetVersions(const std::string& deviceName) const;
51 
52  /**
53  * @deprecated IErrorListener is not used anymore. An exception is thrown in case of any unexpected situations.
54  * @brief Sets logging callback
55  *
56  * Logging is used to track what is going on inside the plugins, Inference Engine library
57  *
58  * @param listener Logging sink
59  */
60  IE_SUPPRESS_DEPRECATED_START
61  INFERENCE_ENGINE_DEPRECATED("IErrorListener is not used anymore. An exception is thrown in case of any unexpected situations.")
62  void SetLogCallback(IErrorListener& listener) const;
63  IE_SUPPRESS_DEPRECATED_END
64 
65 #ifdef ENABLE_UNICODE_PATH_SUPPORT
66  /**
67  * @brief Reads IR xml and bin files
68  * @param modelPath path to IR file
69  * @param binPath path to bin file, if path is empty, will try to read bin file with the same name as xml and
70  * if bin file with the same name was not found, will load IR without weights.
71  * @return CNNNetwork
72  */
73  CNNNetwork ReadNetwork(const std::wstring& modelPath, const std::wstring& binPath = std::wstring()) const {
74  return ReadNetwork(details::wStringtoMBCSstringChar(modelPath), details::wStringtoMBCSstringChar(binPath));
75  }
76 #endif
77 
78  /**
79  * @brief Reads IR xml and bin files
80  * @param modelPath path to IR file
81  * @param binPath path to bin file, if path is empty, will try to read bin file with the same name as xml and
82  * if bin file with the same name was not found, will load IR without weights.
83  * @return CNNNetwork
84  */
85  CNNNetwork ReadNetwork(const std::string& modelPath, const std::string& binPath = "") const;
86  /**
87  * @brief Reads IR xml and bin (with the same name) files
88  * @param model string with IR
89  * @param weights shared pointer to constant blob with weights
90  * @return CNNNetwork
91  */
92  CNNNetwork ReadNetwork(const std::string& model, const Blob::CPtr& weights) const;
93 
94  /**
95  * @brief Creates an executable network from a network object.
96  *
97  * Users can create as many networks as they need and use
98  * them simultaneously (up to the limitation of the hardware resources)
99  *
100  * @param network CNNNetwork object acquired from CNNNetReader
101  * @param deviceName Name of device to load network to
102  * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load
103  * operation
104  * @return An executable network reference
105  */
106  ExecutableNetwork LoadNetwork(
107  const CNNNetwork network, const std::string& deviceName,
108  const std::map<std::string, std::string>& config = std::map<std::string, std::string>());
109 
110  /**
111  * @brief Registers extension
112  * @param extension Pointer to already loaded extension
113  */
114  void AddExtension(const IExtensionPtr& extension);
115 
116  /**
117  * @brief Creates an executable network from a network object within a specified remote context.
118  * @param network CNNNetwork object acquired from CNNNetReader
119  * @param context Pointer to RemoteContext object
120  * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load
121  * operation
122  * @return An executable network reference
123  */
124  ExecutableNetwork LoadNetwork(
125  const CNNNetwork network, RemoteContext::Ptr context,
126  const std::map<std::string, std::string>& config = std::map<std::string, std::string>());
127 
128  /**
129  * @brief Registers extension for the specified plugin
130  *
131  * @param extension Pointer to already loaded extension
132  * @param deviceName Device name to identify plugin to add an executable extension
133  */
134  void AddExtension(IExtensionPtr extension, const std::string& deviceName);
135 
136  /**
137  * @brief Creates an executable network from a previously exported network
138  *
139  * @param deviceName Name of device load executable network on
140  * @param modelFileName Path to the location of the exported file
141  * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load
142  * operation*
143  * @return An executable network reference
144  */
145  ExecutableNetwork ImportNetwork(
146  const std::string& modelFileName, const std::string& deviceName,
147  const std::map<std::string, std::string>& config = std::map<std::string, std::string>());
148 
149  /**
150  * @brief Creates an executable network from a previously exported network
151  * @param deviceName Name of device load executable network on
152  * @param networkModel network model stream
153  * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load
154  * operation*
155  * @return An executable network reference
156  */
157  ExecutableNetwork ImportNetwork(std::istream& networkModel, const std::string& deviceName = {},
158  const std::map<std::string, std::string>& config = {});
159 
160  /**
161  * @brief Creates an executable network from a previously exported network within a specified
162  * remote context.
163  *
164  * @param networkModel Network model stream
165  * @param context Pointer to RemoteContext object
166  * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load
167  * operation
168  * @return An executable network reference
169  */
170  ExecutableNetwork ImportNetwork(std::istream& networkModel,
171  const RemoteContext::Ptr& context,
172  const std::map<std::string, std::string>& config = {});
173 
174  /**
175  * @brief Query device if it supports specified network with specified configuration
176  *
177  * @param deviceName A name of a device to query
178  * @param network Network object to query
179  * @param config Optional map of pairs: (config parameter name, config parameter value)
180  * @return Pointer to the response message that holds a description of an error if any occurred
181  */
182  QueryNetworkResult QueryNetwork(
183  const ICNNNetwork& network, const std::string& deviceName,
184  const std::map<std::string, std::string>& config = std::map<std::string, std::string>()) const;
185 
186  /**
187  * @brief Sets configuration for device, acceptable keys can be found in ie_plugin_config.hpp
188  *
189  * @param deviceName An optinal name of a device. If device name is not specified, the config is set for all the
190  * registered devices.
191  *
192  * @param config Map of pairs: (config parameter name, config parameter value)
193  */
194  void SetConfig(const std::map<std::string, std::string>& config, const std::string& deviceName = std::string());
195 
196  /**
197  * @brief Gets configuration dedicated to device behaviour.
198  *
199  * The method is targeted to extract information which can be set via SetConfig method.
200  *
201  * @param deviceName - A name of a device to get a configuration value.
202  * @param name - value of config corresponding to config key.
203  * @return Value of config corresponding to config key.
204  */
205  Parameter GetConfig(const std::string& deviceName, const std::string& name) const;
206 
207  /**
208  * @brief Gets general runtime metric for dedicated hardware.
209  *
210  * The method is needed to request common device properties
211  * which are executable network agnostic. It can be device name, temperature, other devices-specific values.
212  *
213  * @param deviceName - A name of a device to get a metric value.
214  * @param name - metric name to request.
215  * @return Metric value corresponding to metric key.
216  */
217  Parameter GetMetric(const std::string& deviceName, const std::string& name) const;
218 
219  /**
220  * @brief Returns devices available for neural networks inference
221  *
222  * @return A vector of devices. The devices are returned as { CPU, FPGA.0, FPGA.1, MYRIAD }
223  If there more than one device of specific type, they are enumerated with .# suffix.
224  */
225  std::vector<std::string> GetAvailableDevices() const;
226 
227  /**
228  * @brief Register new device and plugin which implement this device inside Inference Engine.
229  *
230  * @param pluginName A name of plugin. Depending on platform pluginName is wrapped with shared library suffix and
231  * prefix to identify library full name
232  *
233  * @param deviceName A device name to register plugin for. If device name is not specified, then it's taken from
234  * plugin using InferenceEnginePluginPtr::GetName function
235  */
236  void RegisterPlugin(const std::string& pluginName, const std::string& deviceName);
237 
238  /**
239  * @brief Unloads previously loaded plugin with a specified name from Inference Engine
240  * The method is needed to remove plugin instance and free its resources. If plugin for a
241  * specified device has not been created before, the method throws an exception.
242  *
243  * @param deviceName Device name identifying plugin to remove from Inference Engine
244  */
245  void UnregisterPlugin(const std::string& deviceName);
246 
247  /** @brief Registers plugin to Inference Engine Core instance using XML configuration file with
248  * plugins description.
249  *
250  * XML file has the following structure:
251  *
252  * ```xml
253  * <ie>
254  * <plugins>
255  * <plugin name="" location="">
256  * <extensions>
257  * <extension location=""/>
258  * </extensions>
259  * <properties>
260  * <property key="" value=""/>
261  * </properties>
262  * </plugin>
263  * </plugins>
264  * </ie>
265  * ```
266  *
267  * - `name` identifies name of device enabled by plugin
268  * - `location` specifies absolute path to dynamic library with plugin. A path can also be relative to inference
269  * engine shared library. It allows to have common config for different systems with different configurations.
270  * - Properties are set to plugin via the `SetConfig` method.
271  * - Extensions are set to plugin via the `AddExtension` method.
272  *
273  * @param xmlConfigFile A path to .xml file with plugins to register.
274  */
275  void RegisterPlugins(const std::string& xmlConfigFile);
276 
277  /**
278  * @brief Create a new shared context object on specified accelerator device
279  * using specified plugin-specific low level device API parameters (device handle, pointer, etc.)
280  * @param deviceName Name of a device to create new shared context on.
281  * @param params Map of device-specific shared context parameters.
282  * @return A shared pointer to a created remote context.
283  */
284  RemoteContext::Ptr CreateContext(const std::string& deviceName, const ParamMap& params);
285 
286  /**
287  * @brief Get a pointer to default(plugin-supplied) shared context object for specified accelerator device.
288  * @param deviceName - A name of a device to get create shared context from.
289  * @return A shared pointer to a default remote context.
290  */
291  RemoteContext::Ptr GetDefaultContext(const std::string& deviceName);
292 };
293 } // namespace InferenceEngine
This class represents Inference Engine Core entity.
Definition: ie_core.hpp:29
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
std::string name
Layer name.
Definition: ie_layers.h:42
This is a header file for the IE RemoteContext and RemoteBlob classes.
std::shared_ptr< const Blob > CPtr
A smart pointer to the const Blob object.
Definition: ie_blob.h:47
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:344
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:38
std::map< std::string, Parameter > ParamMap
An std::map object containing low-level object parameters of classes that are derived from RemoteBlob...
Definition: ie_remote_context.hpp:26
std::map< std::string, std::string > params
Map of pairs: (parameter name, parameter value)
Definition: ie_layers.h:607
This is a header file with functions related to filesystem operations.
This class represents an object to work with different parameters.
Definition: ie_parameter.hpp:37
This class represents a custom error listener.
Definition: ie_error.hpp:17
This is a header file for the Inference Engine plugin C++ API.
Responce structure encapsulating information about supported layer.
Definition: ie_plugin.hpp:54
std::shared_ptr< RemoteContext > Ptr
A smart pointer to the RemoteContext object.
Definition: ie_remote_context.hpp:99
A header file that defines a wrapper class for handling extension instantiation and releasing resourc...