ie_iextension.h
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 Inference Engine Extension Interface
7  *
8  * @file ie_iextension.h
9  */
10 #pragma once
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "details/ie_no_copy.hpp"
18 #include "ie_api.h"
19 #include "ie_error.hpp"
20 #include "ie_common.h"
21 #include "ie_layouts.h"
22 #include "ie_blob.h"
23 #include "ie_layers.h"
24 #include "ie_version.hpp"
25 
26 /**
27  * @def INFERENCE_EXTENSION_API(TYPE)
28  * @brief Defines Inference Engine Extension API method
29  */
30 
31 #if defined(_WIN32) && defined(IMPLEMENT_INFERENCE_EXTENSION_API)
32 #define INFERENCE_EXTENSION_API(TYPE) extern "C" __declspec(dllexport) TYPE
33 #else
34 #define INFERENCE_EXTENSION_API(TYPE) INFERENCE_ENGINE_API(TYPE)
35 #endif
36 
37 namespace ngraph {
38 
39 class OpSet;
40 class Node;
41 
42 } // namespace ngraph
43 
44 namespace InferenceEngine {
45 
46 /**
47  * @struct DataConfig
48  * @brief This structure describes data configuration
49  */
50 struct DataConfig {
51  /**
52  * @brief Format of memory descriptor
53  */
55  /**
56  * @brief Index of in-place memory. If -1 memory cannot be in-place
57  */
58  int inPlace = -1;
59  /**
60  * @brief Flag for determination of the constant memory. If layer contains all constant memory we can calculate it
61  * on the load stage.
62  */
63  bool constant = false;
64 };
65 
66 /**
67  * @struct LayerConfig
68  * @brief This structure describes Layer configuration
69  */
70 struct LayerConfig {
71  /**
72  * @brief Supported dynamic batch. If false, dynamic batch is not supported
73  */
74  bool dynBatchSupport = false;
75  /**
76  * @brief Vector of input data configs
77  */
78  std::vector<DataConfig> inConfs;
79  /**
80  * @brief Vector of output data configs
81  */
82  std::vector<DataConfig> outConfs;
83 };
84 
85 /**
86  * @interface ILayerImpl
87  * @brief This class provides interface for extension implementations
88  */
89 class INFERENCE_ENGINE_API_CLASS(ILayerImpl) {
90 public:
91  /**
92  * @brief A shared pointer to the ILayerImpl interface
93  */
94  using Ptr = std::shared_ptr<ILayerImpl>;
95 
96  /**
97  * @brief Destructor
98  */
99  virtual ~ILayerImpl();
100 };
101 
102 /**
103  * @interface ILayerExecImpl
104  * @brief This class provides interface for the implementation with the custom execution code
105  */
106 class INFERENCE_ENGINE_API_CLASS(ILayerExecImpl) : public ILayerImpl {
107 public:
108  /**
109  * @brief A shared pointer to the ILayerExecImpl interface
110  */
111  using Ptr = std::shared_ptr<ILayerExecImpl>;
112 
113  /**
114  * @brief Destructor
115  */
116  virtual ~ILayerExecImpl();
117 
118  /**
119  * @brief Gets all supported configurations for the current layer
120  *
121  * @param conf Vector with supported configurations
122  * @param resp Response descriptor
123  * @return Status code
124  */
125  virtual StatusCode getSupportedConfigurations(std::vector<LayerConfig>& conf, ResponseDesc* resp) noexcept = 0;
126 
127  /**
128  * @brief Initializes the implementation
129  *
130  * @param config Selected supported configuration
131  * @param resp Response descriptor
132  * @return Status code
133  */
134  virtual StatusCode init(LayerConfig& config, ResponseDesc* resp) noexcept = 0;
135 
136  /**
137  * @brief Execute method
138  *
139  * @param inputs Vector of blobs with input memory
140  * @param outputs Vector of blobs with output memory
141  * @param resp Response descriptor
142  * @return Status code
143  */
144  virtual StatusCode execute(std::vector<Blob::Ptr>& inputs, std::vector<Blob::Ptr>& outputs,
145  ResponseDesc* resp) noexcept = 0;
146 };
147 
148 /**
149  * @deprecated Implement IExtension::getImplTypes and IExtension::getImplementation
150  * The interface will be removed in 2021.1 release.
151  * @interface ILayerImplFactory
152  * @brief This class provides interface for extension factories
153  */
154 class INFERENCE_ENGINE_DEPRECATED("Implement IExtension::getImplTypes and IExtension::getImplementation") ILayerImplFactory {
155 public:
156  /**
157  * @brief A shared pointer to the ILayerImplFactory interface
158  */
159  IE_SUPPRESS_DEPRECATED_START
160  using Ptr = std::shared_ptr<ILayerImplFactory>;
161  IE_SUPPRESS_DEPRECATED_END
162 
163  using ImplCreator = std::function<ILayerImpl*()>;
164 
165  /**
166  * @brief Destructor
167  */
168  virtual ~ILayerImplFactory() = default;
169 
170  /**
171  * @brief Gets all possible implementations for the given cnn Layer
172  *
173  * @param impls the vector with implementations which is ordered by priority
174  * @param resp response descriptor
175  * @return status code
176  */
177  virtual StatusCode getImplementations(std::vector<ILayerImpl::Ptr>& impls, ResponseDesc* resp) noexcept = 0;
178 };
179 
180 /**
181  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation.
182  * The interface will be removed in 2021.1 release.
183  * @class IShapeInferImpl
184  * @brief This class provides interface for the implementation with the custom execution code
185  */
186 class INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation") IShapeInferImpl {
187 public:
188  /**
189  * @brief A shared pointer to a IShapeInferImpl object
190  */
191  IE_SUPPRESS_DEPRECATED_START
192  using Ptr = std::shared_ptr<IShapeInferImpl>;
193  IE_SUPPRESS_DEPRECATED_END
194 
195  virtual ~IShapeInferImpl() = default;
196 
197  /**
198  * @brief check that reshape can be applied, that parameters and shapes are valid
199  */
200  virtual StatusCode inferShapes(const std::vector<Blob::CPtr>& /*inBlobs*/,
201  const std::map<std::string, std::string>& /*params*/,
202  const std::map<std::string, Blob::Ptr>& /*blobs*/,
203  std::vector<SizeVector>& /*outShapes*/, ResponseDesc* /*resp*/) noexcept {
204  return NOT_IMPLEMENTED;
205  } // For backward-compatibility
206 };
207 
208 /**
209  * @deprecated Implement a custom ngraph operation derived from ngraph::op::Op in IExtension implementation
210  * @class IShapeInferExtension
211  * @brief This class is the reader extension interface to provide implementation for shape propagation
212  */
213 class IShapeInferExtension : public InferenceEngine::details::IRelease {
214 public:
215  /**
216  * @deprecated IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations
217  * The method will be removed in 2021.1 release.
218  * @brief Sets logging callback.
219  *
220  * Logging is used to track what is going on inside.
221  *
222  * @param listener Logging sink
223  */
224  IE_SUPPRESS_DEPRECATED_START
225  INFERENCE_ENGINE_DEPRECATED("IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations")
226  virtual void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept { (void)listener; }
227  IE_SUPPRESS_DEPRECATED_END
228 
229  /**
230  * @brief Gets extension version information and stores in versionInfo
231  * @param versionInfo Pointer to version info, will be set by plugin
232  */
233  virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
234 
235  /**
236  * @brief Cleans resources up
237  */
238  virtual void Unload() noexcept = 0;
239 
240  /**
241  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation.
242  * The method will be removed in 2021.1 release.
243  * @brief Fills passed array with types of layers which shape infer implementations are included in the extension
244  *
245  * @param types Array to store the layer types
246  * @param size Size of the layer types array
247  * @param resp Response descriptor
248  * @return Status code
249  */
250  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
251  virtual StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
252 
253  /**
254  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation.
255  * The method will be removed in 2021.1 release.
256  * @brief Gets shape propagation implementation for the given string-type of CNNLayer
257  *
258  * @param impl the vector with implementations which is ordered by priority
259  * @param type A type of CNNLayer
260  * @param resp response descriptor
261  * @return status code
262  */
263  IE_SUPPRESS_DEPRECATED_START
264  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
265  virtual StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept = 0;
266  IE_SUPPRESS_DEPRECATED_END
267 };
268 
269 IE_SUPPRESS_DEPRECATED_START_WIN
270 
271 /**
272  * @brief This class is the main extension interface
273  */
274 class INFERENCE_ENGINE_API_CLASS(IExtension) : public IShapeInferExtension {
275 public:
276  /**
277  * @deprecated Use IExtension::getImplementation to get a concrete implementation
278  * The method will be removed in 2021.1 release.
279  * @brief Provides a factory for a specified CNNLayer
280  * @param factory A factory returned from an extension plugin
281  * @param cnnLayer A CNNLayer object to provide factory for
282  * @param resp Response descriptor
283  * @return Status code
284  */
285  IE_SUPPRESS_DEPRECATED_START
286  INFERENCE_ENGINE_DEPRECATED("Use IExtension::getImplementation to get a concrete implementation")
287  virtual StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
288  ResponseDesc* resp) noexcept {
289  (void)factory;
290  (void)cnnLayer;
291  (void)resp;
292  return NOT_IMPLEMENTED;
293  }
294  IE_SUPPRESS_DEPRECATED_END
295 
296  /**
297  * @deprecated Use IExtension::getImplTypes to get implementation types for a particular node
298  * The method will be removed in 2021.1 release.
299  * @brief Fills passed array with types of layers which kernel implementations are included in the extension
300  *
301  * @param types Array to store the layer types
302  * @param size Size of the layer types array
303  * @param resp Response descriptor
304  * @return Status code
305  */
306  INFERENCE_ENGINE_DEPRECATED("Use IExtension::getImplTypes to get implementation types for a particular node")
307  virtual StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept {
308  (void)types;
309  (void)size;
310  (void)resp;
311  return NOT_IMPLEMENTED;
312  }
313 
314  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
315  StatusCode getShapeInferTypes(char**&, unsigned int&, ResponseDesc*) noexcept override {
316  return NOT_IMPLEMENTED;
317  }
318 
319  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
320  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr&, const char*, ResponseDesc*) noexcept override {
321  return NOT_IMPLEMENTED;
322  }
323 
324  /**
325  * @brief Returns operation sets
326  * This method throws an exception if it was not implemented
327  * @return map of opset name to opset
328  */
329  virtual std::map<std::string, ngraph::OpSet> getOpSets();
330 
331  /**
332  * @brief Returns vector of implementation types
333  * @param node shared pointer to nGraph op
334  * @return vector of strings
335  */
336  virtual std::vector<std::string> getImplTypes(const std::shared_ptr<ngraph::Node>& node) {
337  (void)node;
338  return {};
339  }
340 
341  /**
342  * @brief Returns implementation for specific nGraph op
343  * @param node shared pointer to nGraph op
344  * @param implType implementation type
345  * @return shared pointer to implementation
346  */
347  virtual ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) {
348  (void)node;
349  (void)implType;
350  return nullptr;
351  }
352 };
353 
354 IE_SUPPRESS_DEPRECATED_END_WIN
355 
356 /**
357  * @brief A shared pointer to a IExtension interface
358  */
359 using IExtensionPtr = std::shared_ptr<IExtension>;
360 
361 /**
362  * @deprecated Migrate to IR v10 and implement shape inference in the ngraph::op::Op::validate_and_infer_types method
363  * This API will be removed in 2021.1 release.
364  * @brief A shared pointer to a IShapeInferExtension interface
365  */
366 using IShapeInferExtensionPtr = std::shared_ptr<IShapeInferExtension>;
367 
368 /**
369  * @brief Creates the default instance of the extension
370  *
371  * @param ext Extension interface
372  * @param resp Response description
373  * @return Status code
374  */
375 INFERENCE_EXTENSION_API(StatusCode) CreateExtension(IExtension*& ext, ResponseDesc* resp) noexcept;
376 
377 /**
378  * @deprecated Migrate to IR v10 and implement shape inference in the ngraph::op::Op::validate_and_infer_types method
379  * This API will be removed in 2021.1 release.
380  * @brief Creates the default instance of the shape infer extension
381  *
382  * @param ext Shape Infer Extension interface
383  * @param resp Response description
384  * @return Status code
385  */
386 INFERENCE_EXTENSION_API(StatusCode)
388 
389 } // namespace InferenceEngine
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:186
A header file that provides versioning information for the inference engine shared library...
A header file for a plugin logging mechanism.
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
std::shared_ptr< IShapeInferExtension > IShapeInferExtensionPtr
A shared pointer to a IShapeInferExtension interface.
Definition: ie_iextension.h:366
std::vector< DataConfig > inConfs
Vector of input data configs.
Definition: ie_iextension.h:78
This class provides interface for extension factories.
Definition: ie_iextension.h:154
A header file for Blob and generic TBlob<>
This structure describes data configuration.
Definition: ie_iextension.h:50
This structure describes Layer configuration.
Definition: ie_iextension.h:70
StatusCode CreateExtension(IExtension *&ext, ResponseDesc *resp) noexcept
Creates the default instance of the extension.
virtual ILayerImpl::Ptr getImplementation(const std::shared_ptr< ngraph::Node > &node, const std::string &implType)
Returns implementation for specific nGraph op.
Definition: ie_iextension.h:347
StatusCode CreateShapeInferExtension(IShapeInferExtension *&ext, ResponseDesc *resp) noexcept
Creates the default instance of the shape infer extension.
This class defines Tensor description.
Definition: ie_layouts.h:153
virtual std::vector< std::string > getImplTypes(const std::shared_ptr< ngraph::Node > &node)
Returns vector of implementation types.
Definition: ie_iextension.h:336
Represents detailed information for an error.
Definition: ie_common.h:247
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
std::vector< DataConfig > outConfs
Vector of output data configs.
Definition: ie_iextension.h:82
a header file for internal Layers structure to describe layers information
TensorDesc desc
Format of memory descriptor.
Definition: ie_iextension.h:54
A header file for data layouts and conversion between them.
Definition: ie_cnn_network.h:27
std::shared_ptr< IExtension > IExtensionPtr
A shared pointer to a IExtension interface.
Definition: ie_iextension.h:359
virtual StatusCode inferShapes(const std::vector< Blob::CPtr > &, const std::map< std::string, std::string > &, const std::map< std::string, Blob::Ptr > &, std::vector< SizeVector > &, ResponseDesc *) noexcept
check that reshape can be applied, that parameters and shapes are valid
Definition: ie_iextension.h:200
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
std::shared_ptr< IShapeInferImpl > Ptr
A shared pointer to a IShapeInferImpl object.
Definition: ie_iextension.h:192
std::shared_ptr< ILayerImpl > Ptr
A shared pointer to the ILayerImpl interface.
Definition: ie_iextension.h:94
This class provides interface for extension implementations.
Definition: ie_iextension.h:89
std::string type
Layer type.
Definition: ie_layers.h:47
This class represents a custom error listener.
Definition: ie_error.hpp:18
header file for no_copy class
std::shared_ptr< ILayerImplFactory > Ptr
A shared pointer to the ILayerImplFactory interface.
Definition: ie_iextension.h:160
This class is the reader extension interface to provide implementation for shape propagation.
Definition: ie_iextension.h:213
This class is the main extension interface.
Definition: ie_iextension.h:274
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:106
This is a header file with common inference engine definitions.