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_layers.h"
13 #include "ie_error.hpp"
14 #include "ie_version.hpp"
20 #include "details/ie_no_copy.hpp"
23 * @def INFERENCE_EXTENSION_API(TYPE)
24 * @brief Defines Inference Engine Extension API method
27 #if defined(_WIN32) && defined(IMPLEMENT_INFERENCE_EXTENSION_API)
28 # define INFERENCE_EXTENSION_API(TYPE) extern "C" __declspec(dllexport) TYPE
30 # define INFERENCE_EXTENSION_API(TYPE) INFERENCE_ENGINE_API(TYPE)
34 namespace InferenceEngine {
38 * @brief This structure describes data configuration
42 * @brief Format of memory descriptor
46 * @brief Index of in-place memory. If -1 memory cannot be in-place
50 * @brief Flag for determination of the constant memory. If layer contains all constant memory we can calculate it on the load stage.
52 bool constant = false;
57 * @brief This structure describes Layer configuration
61 * @brief Supported dynamic batch. If false, dynamic batch is not supported
63 bool dynBatchSupport = false;
65 * @brief Vector of input data configs
67 std::vector<DataConfig> inConfs;
69 * @brief Vector of output data configs
71 std::vector<DataConfig> outConfs;
75 * @brief This class provides interface for extension implementations
79 using Ptr = std::shared_ptr<ILayerImpl>;
84 virtual ~ILayerImpl() = default;
87 * @brief Gets all supported configurations for the current layer
88 * @param conf Vector with supported configurations
89 * @param resp Response descriptor
92 virtual StatusCode getSupportedConfigurations(std::vector<LayerConfig>& conf, ResponseDesc* resp) noexcept = 0;
95 * @brief Initializes the implementation
96 * @param config Selected supported configuration
97 * @param resp Response descriptor
100 virtual StatusCode init(LayerConfig& config, ResponseDesc* resp) noexcept = 0;
104 * @brief This class provides interface for the implementation with the custom execution code
106 class ILayerExecImpl : public ILayerImpl {
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
115 virtual StatusCode execute(std::vector<Blob::Ptr>& inputs,
116 std::vector<Blob::Ptr>& outputs, ResponseDesc* resp) noexcept = 0;
120 * @brief This class provides interface for extension factories
122 class ILayerImplFactory {
124 using Ptr = std::shared_ptr<ILayerImplFactory>;
125 using ImplCreator = std::function<ILayerImpl*()>;
130 virtual ~ILayerImplFactory() = default;
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
138 virtual StatusCode getImplementations(std::vector<ILayerImpl::Ptr>& impls, ResponseDesc* resp) noexcept = 0;
142 * @class IShapeInferImpl
143 * @brief This class provides interface for the implementation with the custom execution code
145 class IShapeInferImpl {
147 using Ptr = std::shared_ptr<IShapeInferImpl>;
149 virtual ~IShapeInferImpl() = default;
152 * @brief check that reshape can be applied, that parameters and shapes are valid
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*/,
158 ResponseDesc* /*resp*/) noexcept { return NOT_IMPLEMENTED; } // For backward-compatibility
162 * @class IShapeInferExtension
163 * @brief This class is the reader extension interface to provide implementation for shape propagation
165 class IShapeInferExtension : public InferenceEngine::details::IRelease {
168 * @brief Sets logging callback.
169 * Logging is used to track what is going on inside.
170 * @param listener Logging sink
172 virtual void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept = 0;
175 * @brief Gets extension version information and stores in versionInfo
176 * @param versionInfo Pointer to version info, will be set by plugin
178 virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
181 * @brief Cleans resources up
183 virtual void Unload() noexcept = 0;
186 * @brief Fills passed array with types of layers which shape infer implementations are included in the extension
187 * @param types Array to store the layer types
188 * @param size Size of the layer types array
189 * @param resp Response descriptor
190 * @return Status code
192 virtual StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
195 * @brief Gets shape propagation implementation for the given string-type of cnn Layer
196 * @param impl the vector with implementations which is ordered by priority
197 * @param resp response descriptor
198 * @return status code
200 virtual StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl,
202 ResponseDesc* resp) noexcept = 0;
206 * @brief This class is the main extension interface
208 class IExtension : public IShapeInferExtension {
210 virtual StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
211 ResponseDesc* resp) noexcept = 0;
214 * @brief Fills passed array with types of layers which kernel implementations are included in the extension
215 * @param types Array to store the layer types
216 * @param size Size of the layer types array
217 * @param resp Response descriptor
218 * @return Status code
220 virtual StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept = 0;
222 StatusCode getShapeInferTypes(char**&, unsigned int&, ResponseDesc*) noexcept override {
223 return NOT_IMPLEMENTED;
226 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr&, const char*, ResponseDesc*) noexcept override {
227 return NOT_IMPLEMENTED;
231 using IExtensionPtr = std::shared_ptr<IExtension>;
232 using IShapeInferExtensionPtr = std::shared_ptr<IShapeInferExtension>;
235 * @brief Creates the default instance of the extension
236 * @param ext Extension interface
237 * @param resp Response description
238 * @return Status code
240 INFERENCE_EXTENSION_API(StatusCode) CreateExtension(IExtension*& ext, ResponseDesc* resp) noexcept;
243 * @brief Creates the default instance of the shape infer extension
244 * @param ext Shape Infer Extension interface
245 * @param resp Response description
246 * @return Status code
248 INFERENCE_EXTENSION_API(StatusCode) CreateShapeInferExtension(IShapeInferExtension*& ext, ResponseDesc* resp) noexcept;
251 } // namespace InferenceEngine