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