ie_iextension.h
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 Inference Engine Extension Interface
7  * @file ie_iextension.h
8  */
9 #pragma once
10 
11 #include "ie_api.h"
12 #include "ie_device.hpp"
13 #include "ie_layers.h"
14 #include "ie_error.hpp"
15 #include "ie_version.hpp"
16 #include <vector>
17 #include <string>
18 #include <memory>
19 #include <map>
20 
21 #include "details/ie_no_copy.hpp"
22 
23 /**
24  * @def INFERENCE_EXTENSION_API(TYPE)
25  * @brief Defines Inference Engine Extension API method
26  */
27 
28 #if defined(_WIN32) && defined(IMPLEMENT_INFERENCE_EXTENSION_API)
29 # define INFERENCE_EXTENSION_API(TYPE) extern "C" __declspec(dllexport) TYPE
30 #else
31 # define INFERENCE_EXTENSION_API(TYPE) INFERENCE_ENGINE_API(TYPE)
32 #endif
33 
34 
35 namespace InferenceEngine {
36 
37 /**
38  * @struct DataConfig
39  * @brief This structure describes data configuration
40  */
41 struct DataConfig {
42  /**
43  * @brief Format of memory descriptor
44  */
46  /**
47  * @brief Index of in-place memory. If -1 memory cannot be in-place
48  */
49  int inPlace = -1;
50  /**
51  * @brief Flag for determination of the constant memory. If layer contains all constant memory we can calculate it on the load stage.
52  */
53  bool constant = false;
54 };
55 
56 /**
57  * @struct LayerConfig
58  * @brief This structure describes Layer configuration
59  */
60 struct LayerConfig {
61  /**
62  * @brief Supported dynamic batch. If false, dynamic batch is not supported
63  */
64  bool dynBatchSupport = false;
65  /**
66  * @brief Vector of input data configs
67  */
68  std::vector<DataConfig> inConfs;
69  /**
70  * @brief Vector of output data configs
71  */
72  std::vector<DataConfig> outConfs;
73 };
74 
75 /**
76  * @brief This class provides interface for extension implementations
77  */
78 class ILayerImpl {
79 public:
80  using Ptr = std::shared_ptr<ILayerImpl>;
81 
82  /**
83  * @brief Destructor
84  */
85  virtual ~ILayerImpl() = default;
86 
87  /**
88  * @brief Gets all supported configurations for the current layer
89  * @param conf Vector with supported configurations
90  * @param resp Response descriptor
91  * @return Status code
92  */
93  virtual StatusCode getSupportedConfigurations(std::vector<LayerConfig>& conf, ResponseDesc* resp) noexcept = 0;
94 
95  /**
96  * @brief Initializes the implementation
97  * @param config Selected supported configuration
98  * @param resp Response descriptor
99  * @return Status code
100  */
101  virtual StatusCode init(LayerConfig& config, ResponseDesc* resp) noexcept = 0;
102 };
103 
104 /**
105  * @brief This class provides interface for the implementation with the custom execution code
106  */
107 class ILayerExecImpl : public ILayerImpl {
108 public:
109  /**
110  * @brief Execute method
111  * @param inputs Vector of blobs with input memory
112  * @param outputs Vector of blobs with output memory
113  * @param resp Response descriptor
114  * @return Status code
115  */
116  virtual StatusCode execute(std::vector<Blob::Ptr>& inputs,
117  std::vector<Blob::Ptr>& outputs, ResponseDesc* resp) noexcept = 0;
118 };
119 
120 /**
121  * @brief This class provides interface for extension factories
122  */
124 public:
125  using Ptr = std::shared_ptr<ILayerImplFactory>;
126  using ImplCreator = std::function<ILayerImpl*()>;
127 
128  /**
129  * @brief Destructor
130  */
131  virtual ~ILayerImplFactory() = default;
132 
133  /**
134  * @deprecated Implement IShapeInferImpl extension for shape inference.
135  * @brief Sets output shapes by input shapes.
136  * @param inShapes Shapes of all inputs coming in this layer
137  * @param outShapes Generated shapes coming from this layer given the input
138  * @param resp Response descriptor
139  * @return Status code
140  */
141  INFERENCE_ENGINE_DEPRECATED
142  virtual StatusCode getShapes(const std::vector<TensorDesc>& /*inShapes*/, std::vector<TensorDesc>& /*outShapes*/,
143  ResponseDesc* /*resp*/) noexcept {
144  return NOT_IMPLEMENTED;
145  }
146 
147  /**
148  * @brief Gets all possible implementations for the given cnn Layer
149  * @param impls the vector with implementations which is ordered by priority
150  * @param resp response descriptor
151  * @return status code
152  */
153  virtual StatusCode getImplementations(std::vector<ILayerImpl::Ptr>& impls, ResponseDesc* resp) noexcept = 0;
154 };
155 
156 /**
157  * @class IShapeInferImpl
158  * @brief This class provides interface for the implementation with the custom execution code
159  */
161 public:
162  using Ptr = std::shared_ptr<IShapeInferImpl>;
163 
164  virtual ~IShapeInferImpl() = default;
165 
166  /**
167  * @brief check that reshape can be applied, that parameters and shapes are valid
168  */
169  virtual StatusCode inferShapes(const std::vector<Blob::CPtr>& /*inBlobs*/,
170  const std::map<std::string, std::string>& /*params*/,
171  const std::map<std::string, Blob::Ptr>& /*blobs*/,
172  std::vector<SizeVector>& /*outShapes*/,
173  ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; } // For backward-compatibility
174 
175  /**
176  * @deprecated Use IShapeInferImpl::inferShapes(const std::vector<Blob::CPtr>&, const std::map<std::string, std::string>&,
177  const std::map<std::string, Blob::Ptr>&, std::vector<SizeVector>&, ResponseDesc* ) noexcept.
178  * @brief check that reshape can be applied, that parameters and shapes are valid
179  */
180  INFERENCE_ENGINE_DEPRECATED
181  virtual StatusCode inferShapes(const std::vector<SizeVector>& /*inShapes*/,
182  const std::map<std::string, std::string>& /*params*/,
183  const std::map<std::string, Blob::Ptr>& /*blobs*/,
184  std::vector<SizeVector>& /*outShapes*/,
185  ResponseDesc* /*resp*/) noexcept {
186  return NOT_IMPLEMENTED;
187  }
188 };
189 
190 /**
191  * @class IShapeInferExtension
192  * @brief This class is the reader extension interface to provide implementation for shape propagation
193  */
194 class IShapeInferExtension : public InferenceEngine::details::IRelease {
195 public:
196  /**
197  * @brief Sets logging callback.
198  * Logging is used to track what is going on inside.
199  * @param listener Logging sink
200  */
201  virtual void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept = 0;
202 
203  /**
204  * @brief Gets extension version information and stores in versionInfo
205  * @param versionInfo Pointer to version info, will be set by plugin
206  */
207  virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
208 
209  /**
210  * @brief Cleans resources up
211  */
212  virtual void Unload() noexcept = 0;
213 
214  /**
215  * @brief Fills passed array with types of layers which shape infer implementations are included in the extension
216  * @param types Array to store the layer types
217  * @param size Size of the layer types array
218  * @param resp Response descriptor
219  * @return Status code
220  */
221  virtual StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
222 
223  /**
224  * @brief Gets shape propagation implementation for the given string-type of cnn Layer
225  * @param impl the vector with implementations which is ordered by priority
226  * @param resp response descriptor
227  * @return status code
228  */
229  virtual StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl,
230  const char* type,
231  ResponseDesc* resp) noexcept = 0;
232 };
233 
234 /**
235  * @brief This class is the main extension interface
236  */
238 public:
239  virtual StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
240  ResponseDesc* resp) noexcept = 0;
241 
242  /**
243  * @brief Fills passed array with types of layers which kernel implementations are included in the extension
244  * @param types Array to store the layer types
245  * @param size Size of the layer types array
246  * @param resp Response descriptor
247  * @return Status code
248  */
249  virtual StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
250 
251  StatusCode getShapeInferTypes(char**&, unsigned int&, ResponseDesc*) noexcept override {
252  return NOT_IMPLEMENTED;
253  };
254 
255  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr&, const char*, ResponseDesc*) noexcept override {
256  return NOT_IMPLEMENTED;
257  };
258 };
259 
260 using IExtensionPtr = std::shared_ptr<IExtension>;
261 using IShapeInferExtensionPtr = std::shared_ptr<IShapeInferExtension>;
262 
263 /**
264  * @brief Creates the default instance of the extension
265  * @param ext Extension interface
266  * @param resp Response description
267  * @return Status code
268  */
270 
271 /**
272  * @brief Creates the default instance of the shape infer extension
273  * @param ext Shape Infer Extension interface
274  * @param resp Response description
275  * @return Status code
276  */
278 
279 
280 } // namespace InferenceEngine
#define INFERENCE_EXTENSION_API(TYPE)
Defines Inference Engine Extension API method.
Definition: ie_iextension.h:31
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:160
A header file that provides versioning information for the inference engine shared library...
A header file for a plugin logging mechanism.
StatusCode getShapeInferTypes(char **&, unsigned int &, ResponseDesc *) noexcept override
Fills passed array with types of layers which shape infer implementations are included in the extensi...
Definition: ie_iextension.h:251
StatusCode getShapeInferImpl(IShapeInferImpl::Ptr &, const char *, ResponseDesc *) noexcept override
Gets shape propagation implementation for the given string-type of cnn Layer.
Definition: ie_iextension.h:255
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
Represents version information that describes plugins and the inference engine runtime library...
Definition: ie_version.hpp:20
virtual StatusCode inferShapes(const std::vector< SizeVector > &, 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:181
std::vector< DataConfig > inConfs
Vector of input data configs.
Definition: ie_iextension.h:68
virtual StatusCode getShapes(const std::vector< TensorDesc > &, std::vector< TensorDesc > &, ResponseDesc *) noexcept
Sets output shapes by input shapes.
Definition: ie_iextension.h:142
This class provides interface for extension factories.
Definition: ie_iextension.h:123
This structure describes data configuration.
Definition: ie_iextension.h:41
This structure describes Layer configuration.
Definition: ie_iextension.h:60
StatusCode CreateExtension(IExtension *&ext, ResponseDesc *resp) noexcept
Creates the default instance of the extension.
int inPlace
Index of in-place memory. If -1 memory cannot be in-place.
Definition: ie_iextension.h:49
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:143
Represents detailed information for an error.
Definition: ie_common.h:230
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:207
std::vector< DataConfig > outConfs
Vector of output data configs.
Definition: ie_iextension.h:72
a header file for internal Layers structure to describe layers information
TensorDesc desc
Format of memory descriptor.
Definition: ie_iextension.h:45
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:169
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
This header file contains aspects of working on different devices like CPU, GEN, FPGA, etc.
This class provides interface for extension implementations.
Definition: ie_iextension.h:78
This is a base abstraction Layer - all DNN Layers inherit from this class.
Definition: ie_layers.h:41
This class represents a custom error listener. Plugin consumers can provide it via InferenceEngine::S...
Definition: ie_error.hpp:16
header file for no_copy class
This class is the reader extension interface to provide implementation for shape propagation.
Definition: ie_iextension.h:194
This class is the main extension interface.
Definition: ie_iextension.h:237
bool constant
Flag for determination of the constant memory. If layer contains all constant memory we can calculate...
Definition: ie_iextension.h:53
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:107