1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief This is a header file for Inference Engine Extension Interface
7 * @file ie_iextension.h
12 #include "ie_device.hpp"
13 #include "ie_layers.h"
14 #include "ie_error.hpp"
15 #include "ie_version.hpp"
21 #include "details/ie_no_copy.hpp"
24 #if defined(_WIN32) && defined(IMPLEMENT_INFERENCE_EXTENSION_API)
25 #define INFERENCE_EXTENSION_API(TYPE) extern "C" __declspec(dllexport) TYPE
27 #define INFERENCE_EXTENSION_API(TYPE) INFERENCE_ENGINE_API(TYPE)
31 namespace InferenceEngine {
35 * @brief This structure describes data configuration
39 * @brief Format of memory descriptor
43 * @brief Index of in-place memory. If -1 memory cannot be in-place
47 * @brief Flag for determination of the constant memory. If layer contains all constant memory we can calculate it on the load stage.
49 bool constant = false;
54 * @brief This structure describes Layer configuration
58 * @brief Supported dynamic batch. If false, dynamic batch is not supported
60 bool dynBatchSupport = false;
62 * @brief Vector of input data configs
64 std::vector<DataConfig> inConfs;
66 * @brief Vector of output data configs
68 std::vector<DataConfig> outConfs;
72 * @brief This class provides interface for extension implementations
76 using Ptr = std::shared_ptr<ILayerImpl>;
81 virtual ~ILayerImpl() = default;
84 * @brief Gets all supported configurations for the current layer
85 * @param conf Vector with supported configurations
86 * @param resp Response descriptor
89 virtual StatusCode getSupportedConfigurations(std::vector<LayerConfig>& conf, ResponseDesc* resp) noexcept = 0;
92 * @brief Initializes the implementation
93 * @param config Selected supported configuration
94 * @param resp Response descriptor
97 virtual StatusCode init(LayerConfig& config, ResponseDesc* resp) noexcept = 0;
101 * @brief This class provides interface for the implementation with the custom execution code
103 class ILayerExecImpl : public ILayerImpl {
106 * @brief Execute method
107 * @param inputs Vector of blobs with input memory
108 * @param outputs Vector of blobs with output memory
109 * @param resp Response descriptor
110 * @return Status code
112 virtual StatusCode execute(std::vector<Blob::Ptr>& inputs,
113 std::vector<Blob::Ptr>& outputs, ResponseDesc* resp) noexcept = 0;
117 * @brief This class provides interface for extension factories
119 class ILayerImplFactory {
121 using Ptr = std::shared_ptr<ILayerImplFactory>;
122 using ImplCreator = std::function<ILayerImpl*()>;
127 virtual ~ILayerImplFactory() = default;
131 * @brief Sets output shapes by input shapes.
132 * @param inShapes Shapes of all inputs coming in this layer
133 * @param outShapes Generated shapes coming from this layer given the input
134 * @param resp Response descriptor
135 * @return Status code
137 virtual StatusCode getShapes(const std::vector<TensorDesc>& /*inShapes*/, std::vector<TensorDesc>& /*outShapes*/,
138 ResponseDesc* /*resp*/) noexcept {
139 return NOT_IMPLEMENTED;
143 * @brief Gets all possible implementations for the given cnn Layer
144 * @param impls the vector with implementations which is ordered by priority
145 * @param resp response descriptor
146 * @return status code
148 virtual StatusCode getImplementations(std::vector<ILayerImpl::Ptr>& impls, ResponseDesc* resp) noexcept = 0;
152 * @class IShapeInferImpl
153 * @brief This class provides interface for the implementation with the custom execution code
155 class IShapeInferImpl {
157 using Ptr = std::shared_ptr<IShapeInferImpl>;
159 virtual ~IShapeInferImpl() = default;
162 * @brief check that reshape can be applied, that parameters and shapes are valid
164 virtual StatusCode inferShapes(const std::vector<Blob::CPtr>& /*inBlobs*/,
165 const std::map<std::string, std::string>& /*params*/,
166 const std::map<std::string, Blob::Ptr>& /*blobs*/,
167 std::vector<SizeVector>& /*outShapes*/,
168 ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; } // For backward-compatibility
172 * @brief check that reshape can be applied, that parameters and shapes are valid
174 virtual StatusCode inferShapes(const std::vector<SizeVector>& /*inShapes*/,
175 const std::map<std::string, std::string>& /*params*/,
176 const std::map<std::string, Blob::Ptr>& /*blobs*/,
177 std::vector<SizeVector>& /*outShapes*/,
178 ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; } // For backward-compatibility
182 * @class IShapeInferExtension
183 * @brief This class is the reader extension interface to provide implementation for shape propagation
185 class IShapeInferExtension : public InferenceEngine::details::IRelease {
188 * @brief Sets logging callback.
189 * Logging is used to track what is going on inside.
190 * @param listener Logging sink
192 virtual void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept = 0;
195 * @brief Gets extension version information and stores in versionInfo
196 * @param versionInfo Pointer to version info, will be set by plugin
198 virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
201 * @brief Cleans resources up
203 virtual void Unload() noexcept = 0;
206 * @brief Fills passed array with types of layers which shape infer implementations are included in the extension
207 * @param types Array to store the layer types
208 * @param size Size of the layer types array
209 * @param resp Response descriptor
210 * @return Status code
212 virtual StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
215 * @brief Gets shape propagation implementation for the given string-type of cnn Layer
216 * @param impl the vector with implementations which is ordered by priority
217 * @param resp response descriptor
218 * @return status code
220 virtual StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl,
222 ResponseDesc* resp) noexcept = 0;
226 * @brief This class is the main extension interface
228 class IExtension : public IShapeInferExtension {
230 virtual StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
231 ResponseDesc* resp) noexcept = 0;
234 * @brief Fills passed array with types of layers which kernel implementations are included in the extension
235 * @param types Array to store the layer types
236 * @param size Size of the layer types array
237 * @param resp Response descriptor
238 * @return Status code
240 virtual StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
242 StatusCode getShapeInferTypes(char**&, unsigned int&, ResponseDesc*) noexcept override {
243 return NOT_IMPLEMENTED;
246 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr&, const char*, ResponseDesc*) noexcept override {
247 return NOT_IMPLEMENTED;
251 using IExtensionPtr = std::shared_ptr<IExtension>;
252 using IShapeInferExtensionPtr = std::shared_ptr<IShapeInferExtension>;
255 * @brief Creates the default instance of the extension
256 * @param ext Extension interface
257 * @param resp Response description
258 * @return Status code
260 INFERENCE_EXTENSION_API(StatusCode) CreateExtension(IExtension*& ext, ResponseDesc* resp) noexcept;
263 * @brief Creates the default instance of the shape infer extension
264 * @param ext Shape Infer Extension interface
265 * @param resp Response description
266 * @return Status code
268 INFERENCE_EXTENSION_API(StatusCode) CreateShapeInferExtension(IShapeInferExtension*& ext, ResponseDesc* resp) noexcept;
271 } // namespace InferenceEngine