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