1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief This is a header file for Inference Engine Extension Interface
8 * @file ie_iextension.h
17 #include "details/ie_no_copy.hpp"
19 #include "ie_error.hpp"
20 #include "ie_layers.h"
21 #include "ie_version.hpp"
24 * @def INFERENCE_EXTENSION_API(TYPE)
25 * @brief Defines Inference Engine Extension API method
28 #if defined(_WIN32) && defined(IMPLEMENT_INFERENCE_EXTENSION_API)
29 #define INFERENCE_EXTENSION_API(TYPE) extern "C" __declspec(dllexport) TYPE
31 #define INFERENCE_EXTENSION_API(TYPE) INFERENCE_ENGINE_API(TYPE)
40 namespace InferenceEngine {
44 * @brief This structure describes data configuration
48 * @brief Format of memory descriptor
52 * @brief Index of in-place memory. If -1 memory cannot be in-place
56 * @brief Flag for determination of the constant memory. If layer contains all constant memory we can calculate it
59 bool constant = false;
64 * @brief This structure describes Layer configuration
68 * @brief Supported dynamic batch. If false, dynamic batch is not supported
70 bool dynBatchSupport = false;
72 * @brief Vector of input data configs
74 std::vector<DataConfig> inConfs;
76 * @brief Vector of output data configs
78 std::vector<DataConfig> outConfs;
82 * @brief This class provides interface for extension implementations
86 using Ptr = std::shared_ptr<ILayerImpl>;
91 virtual ~ILayerImpl() = default;
94 * @brief Gets all supported configurations for the current layer
96 * @param conf Vector with supported configurations
97 * @param resp Response descriptor
100 virtual StatusCode getSupportedConfigurations(std::vector<LayerConfig>& conf, ResponseDesc* resp) noexcept = 0;
103 * @brief Initializes the implementation
105 * @param config Selected supported configuration
106 * @param resp Response descriptor
107 * @return Status code
109 virtual StatusCode init(LayerConfig& config, ResponseDesc* resp) noexcept = 0;
113 * @brief This class provides interface for the implementation with the custom execution code
115 class ILayerExecImpl : public ILayerImpl {
118 * @brief Execute method
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
125 virtual StatusCode execute(std::vector<Blob::Ptr>& inputs, std::vector<Blob::Ptr>& outputs,
126 ResponseDesc* resp) noexcept = 0;
130 * @brief This class provides interface for extension factories
132 class ILayerImplFactory {
134 using Ptr = std::shared_ptr<ILayerImplFactory>;
135 using ImplCreator = std::function<ILayerImpl*()>;
140 virtual ~ILayerImplFactory() = default;
143 * @brief Gets all possible implementations for the given cnn Layer
145 * @param impls the vector with implementations which is ordered by priority
146 * @param resp response descriptor
147 * @return status code
149 virtual StatusCode getImplementations(std::vector<ILayerImpl::Ptr>& impls, ResponseDesc* resp) noexcept = 0;
153 * @class IShapeInferImpl
154 * @brief This class provides interface for the implementation with the custom execution code
156 class IShapeInferImpl {
158 using Ptr = std::shared_ptr<IShapeInferImpl>;
160 virtual ~IShapeInferImpl() = default;
163 * @brief check that reshape can be applied, that parameters and shapes are valid
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
174 * @class IShapeInferExtension
175 * @brief This class is the reader extension interface to provide implementation for shape propagation
177 class IShapeInferExtension : public InferenceEngine::details::IRelease {
180 * @brief Sets logging callback.
182 * Logging is used to track what is going on inside.
184 * @param listener Logging sink
186 virtual void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept = 0;
189 * @brief Gets extension version information and stores in versionInfo
191 * @param versionInfo Pointer to version info, will be set by plugin
193 virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
196 * @brief Cleans resources up
198 virtual void Unload() noexcept = 0;
201 * @brief Fills passed array with types of layers which shape infer implementations are included in the extension
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
208 virtual StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
211 * @brief Gets shape propagation implementation for the given string-type of cnn Layer
213 * @param impl the vector with implementations which is ordered by priority
214 * @param resp response descriptor
215 * @return status code
217 virtual StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept = 0;
221 * @brief This class is the main extension interface
223 class IExtension : public IShapeInferExtension {
225 virtual StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
226 ResponseDesc* resp) noexcept = 0;
229 * @brief Fills passed array with types of layers which kernel implementations are included in the extension
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
236 virtual StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
238 StatusCode getShapeInferTypes(char**&, unsigned int&, ResponseDesc*) noexcept override {
239 return NOT_IMPLEMENTED;
242 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr&, const char*, ResponseDesc*) noexcept override {
243 return NOT_IMPLEMENTED;
247 * @brief Returns operation sets
248 * This method throws an exception if it was not implemented
249 * @return map of opset name to opset
251 virtual std::map<std::string, ngraph::OpSet> getOpSets() {
252 THROW_IE_EXCEPTION << "Method is not implemented!";
256 using IExtensionPtr = std::shared_ptr<IExtension>;
257 using IShapeInferExtensionPtr = std::shared_ptr<IShapeInferExtension>;
260 * @brief Creates the default instance of the extension
262 * @param ext Extension interface
263 * @param resp Response description
264 * @return Status code
266 INFERENCE_EXTENSION_API(StatusCode) CreateExtension(IExtension*& ext, ResponseDesc* resp) noexcept;
269 * @brief Creates the default instance of the shape infer extension
271 * @param ext Shape Infer Extension interface
272 * @param resp Response description
273 * @return Status code
275 INFERENCE_EXTENSION_API(StatusCode) CreateShapeInferExtension(IShapeInferExtension*& ext, ResponseDesc* resp) noexcept;
277 } // namespace InferenceEngine