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  * @interface ILayerImplFactory
151  * @brief This class provides interface for extension factories
152  */
153 class INFERENCE_ENGINE_DEPRECATED("Implement IExtension::getImplTypes and IExtension::getImplementation") ILayerImplFactory {
154 public:
155  /**
156  * @brief A shared pointer to the ILayerImplFactory interface
157  */
158  IE_SUPPRESS_DEPRECATED_START
159  using Ptr = std::shared_ptr<ILayerImplFactory>;
160  IE_SUPPRESS_DEPRECATED_END
161 
162  using ImplCreator = std::function<ILayerImpl*()>;
163 
164  /**
165  * @brief Destructor
166  */
167  virtual ~ILayerImplFactory() = default;
168 
169  /**
170  * @brief Gets all possible implementations for the given cnn Layer
171  *
172  * @param impls the vector with implementations which is ordered by priority
173  * @param resp response descriptor
174  * @return status code
175  */
176  virtual StatusCode getImplementations(std::vector<ILayerImpl::Ptr>& impls, ResponseDesc* resp) noexcept = 0;
177 };
178 
179 /**
180  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation.
181  * @class IShapeInferImpl
182  * @brief This class provides interface for the implementation with the custom execution code
183  */
184 class INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation") IShapeInferImpl {
185 public:
186  /**
187  * @brief A shared pointer to a IShapeInferImpl object
188  */
189  IE_SUPPRESS_DEPRECATED_START
190  using Ptr = std::shared_ptr<IShapeInferImpl>;
191  IE_SUPPRESS_DEPRECATED_END
192 
193  virtual ~IShapeInferImpl() = default;
194 
195  /**
196  * @brief check that reshape can be applied, that parameters and shapes are valid
197  */
198  virtual StatusCode inferShapes(const std::vector<Blob::CPtr>& /*inBlobs*/,
199  const std::map<std::string, std::string>& /*params*/,
200  const std::map<std::string, Blob::Ptr>& /*blobs*/,
201  std::vector<SizeVector>& /*outShapes*/, ResponseDesc* /*resp*/) noexcept {
202  return NOT_IMPLEMENTED;
203  } // For backward-compatibility
204 };
205 
206 /**
207  * @deprecated Implement a custom ngraph operation derived from ngraph::op::Op in IExtension implementation
208  * @class IShapeInferExtension
209  * @brief This class is the reader extension interface to provide implementation for shape propagation
210  */
211 class IShapeInferExtension : public InferenceEngine::details::IRelease {
212 public:
213  /**
214  * @deprecated IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations
215  * @brief Sets logging callback.
216  *
217  * Logging is used to track what is going on inside.
218  *
219  * @param listener Logging sink
220  */
221  IE_SUPPRESS_DEPRECATED_START
222  INFERENCE_ENGINE_DEPRECATED("IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations")
223  virtual void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept { (void)listener; }
224  IE_SUPPRESS_DEPRECATED_END
225 
226  /**
227  * @brief Gets extension version information and stores in versionInfo
228  *
229  * @param versionInfo Pointer to version info, will be set by plugin
230  */
231  virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
232 
233  /**
234  * @brief Cleans resources up
235  */
236  virtual void Unload() noexcept = 0;
237 
238  /**
239  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation.
240  * @brief Fills passed array with types of layers which shape infer implementations are included in the extension
241  *
242  * @param types Array to store the layer types
243  * @param size Size of the layer types array
244  * @param resp Response descriptor
245  * @return Status code
246  */
247  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
248  virtual StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
249 
250  /**
251  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation.
252  * @brief Gets shape propagation implementation for the given string-type of CNNLayer
253  *
254  * @param impl the vector with implementations which is ordered by priority
255  * @param type A type of CNNLayer
256  * @param resp response descriptor
257  * @return status code
258  */
259  IE_SUPPRESS_DEPRECATED_START
260  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
261  virtual StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept = 0;
262  IE_SUPPRESS_DEPRECATED_END
263 };
264 
265 IE_SUPPRESS_DEPRECATED_START_WIN
266 
267 /**
268  * @brief This class is the main extension interface
269  */
270 class INFERENCE_ENGINE_API_CLASS(IExtension) : public IShapeInferExtension {
271 public:
272  /**
273  * @deprecated Use IExtension::getImplementation to get a concrete implementation
274  * @brief Provides a factory for a specified CNNLayer
275  * @param factory A factory returned from an extension plugin
276  * @param cnnLayer A CNNLayer object to provide factory for
277  * @param resp Response descriptor
278  * @return Status code
279  */
280  IE_SUPPRESS_DEPRECATED_START
281  INFERENCE_ENGINE_DEPRECATED("Use IExtension::getImplementation to get a concrete implementation")
282  virtual StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
283  ResponseDesc* resp) noexcept {
284  return NOT_IMPLEMENTED;
285  }
286  IE_SUPPRESS_DEPRECATED_END
287 
288  /**
289  * @deprecated Use IExtension::getImplTypes to get implementation types for a particular node
290  * @brief Fills passed array with types of layers which kernel implementations are included in the extension
291  *
292  * @param types Array to store the layer types
293  * @param size Size of the layer types array
294  * @param resp Response descriptor
295  * @return Status code
296  */
297  INFERENCE_ENGINE_DEPRECATED("Use IExtension::getImplTypes to get implementation types for a particular node")
298  virtual StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept {
299  return NOT_IMPLEMENTED;
300  }
301 
302  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
303  StatusCode getShapeInferTypes(char**&, unsigned int&, ResponseDesc*) noexcept override {
304  return NOT_IMPLEMENTED;
305  }
306 
307  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
308  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr&, const char*, ResponseDesc*) noexcept override {
309  return NOT_IMPLEMENTED;
310  }
311 
312  /**
313  * @brief Returns operation sets
314  * This method throws an exception if it was not implemented
315  * @return map of opset name to opset
316  */
317  virtual std::map<std::string, ngraph::OpSet> getOpSets();
318 
319  /**
320  * @brief Returns vector of implementation types
321  * @param node shared pointer to nGraph op
322  * @return vector of strings
323  */
324  virtual std::vector<std::string> getImplTypes(const std::shared_ptr<ngraph::Node>& node) {
325  return {};
326  }
327 
328  /**
329  * @brief Returns implementation for specific nGraph op
330  * @param node shared pointer to nGraph op
331  * @param implType implementation type
332  * @return shared pointer to implementation
333  */
334  virtual ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) {
335  return nullptr;
336  }
337 };
338 
339 IE_SUPPRESS_DEPRECATED_END_WIN
340 
341 /**
342  * @brief A shared pointer to a IExtension interface
343  */
344 using IExtensionPtr = std::shared_ptr<IExtension>;
345 
346 /**
347  * @deprecated Migrate to IR v10 and implement shape inference in the ngraph::op::Op::validate_and_infer_types method
348  * @brief A shared pointer to a IShapeInferExtension interface
349  */
350 using IShapeInferExtensionPtr = std::shared_ptr<IShapeInferExtension>;
351 
352 /**
353  * @brief Creates the default instance of the extension
354  *
355  * @param ext Extension interface
356  * @param resp Response description
357  * @return Status code
358  */
359 INFERENCE_EXTENSION_API(StatusCode) CreateExtension(IExtension*& ext, ResponseDesc* resp) noexcept;
360 
361 /**
362  * @deprecated Migrate to IR v10 and implement shape inference in the ngraph::op::Op::validate_and_infer_types method
363  * @brief Creates the default instance of the shape infer extension
364  *
365  * @param ext Shape Infer Extension interface
366  * @param resp Response description
367  * @return Status code
368  */
369 INFERENCE_EXTENSION_API(StatusCode)
371 
372 } // namespace InferenceEngine
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:184
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:350
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:153
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:334
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:324
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:344
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:198
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:190
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:17
header file for no_copy class
std::shared_ptr< ILayerImplFactory > Ptr
A shared pointer to the ILayerImplFactory interface.
Definition: ie_iextension.h:159
This class is the reader extension interface to provide implementation for shape propagation.
Definition: ie_iextension.h:211
This class is the main extension interface.
Definition: ie_iextension.h:270
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.