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 "ie_api.h"
18 #include "ie_common.h"
19 #include "ie_layouts.h"
20 #include "ie_blob.h"
21 #include "ie_version.hpp"
22 #include "details/ie_no_copy.hpp"
23 
24 /**
25  * @def INFERENCE_EXTENSION_API(TYPE)
26  * @brief Defines Inference Engine Extension API method
27  */
28 
29 #if defined(_WIN32) && defined(IMPLEMENT_INFERENCE_EXTENSION_API)
30 #define INFERENCE_EXTENSION_API(TYPE) extern "C" __declspec(dllexport) TYPE
31 #else
32 #define INFERENCE_EXTENSION_API(TYPE) INFERENCE_ENGINE_API(TYPE)
33 #endif
34 
35 namespace ngraph {
36 
37 class OpSet;
38 class Node;
39 
40 } // namespace ngraph
41 
42 namespace InferenceEngine {
43 
44 /**
45  * @struct DataConfig
46  * @brief This structure describes data configuration
47  */
48 struct DataConfig {
49  /**
50  * @brief Format of memory descriptor
51  */
53  /**
54  * @brief Index of in-place memory. If -1 memory cannot be in-place
55  */
56  int inPlace = -1;
57  /**
58  * @brief Flag for determination of the constant memory. If layer contains all constant memory we can calculate it
59  * on the load stage.
60  */
61  bool constant = false;
62 };
63 
64 /**
65  * @struct LayerConfig
66  * @brief This structure describes Layer configuration
67  */
68 struct LayerConfig {
69  /**
70  * @brief Supported dynamic batch. If false, dynamic batch is not supported
71  */
72  bool dynBatchSupport = false;
73  /**
74  * @brief Vector of input data configs
75  */
76  std::vector<DataConfig> inConfs;
77  /**
78  * @brief Vector of output data configs
79  */
80  std::vector<DataConfig> outConfs;
81 };
82 
83 /**
84  * @interface ILayerImpl
85  * @brief This class provides interface for extension implementations
86  */
87 class INFERENCE_ENGINE_API_CLASS(ILayerImpl) {
88 public:
89  /**
90  * @brief A shared pointer to the ILayerImpl interface
91  */
92  using Ptr = std::shared_ptr<ILayerImpl>;
93 
94  /**
95  * @brief Destructor
96  */
97  virtual ~ILayerImpl();
98 };
99 
100 /**
101  * @interface ILayerExecImpl
102  * @brief This class provides interface for the implementation with the custom execution code
103  */
104 class INFERENCE_ENGINE_API_CLASS(ILayerExecImpl) : public ILayerImpl {
105 public:
106  /**
107  * @brief A shared pointer to the ILayerExecImpl interface
108  */
109  using Ptr = std::shared_ptr<ILayerExecImpl>;
110 
111  /**
112  * @brief Destructor
113  */
114  virtual ~ILayerExecImpl();
115 
116  /**
117  * @brief Gets all supported configurations for the current layer
118  *
119  * @param conf Vector with supported configurations
120  * @param resp Response descriptor
121  * @return Status code
122  */
123  virtual StatusCode getSupportedConfigurations(std::vector<LayerConfig>& conf, ResponseDesc* resp) noexcept = 0;
124 
125  /**
126  * @brief Initializes the implementation
127  *
128  * @param config Selected supported configuration
129  * @param resp Response descriptor
130  * @return Status code
131  */
132  virtual StatusCode init(LayerConfig& config, ResponseDesc* resp) noexcept = 0;
133 
134  /**
135  * @brief Execute method
136  *
137  * @param inputs Vector of blobs with input memory
138  * @param outputs Vector of blobs with output memory
139  * @param resp Response descriptor
140  * @return Status code
141  */
142  virtual StatusCode execute(std::vector<Blob::Ptr>& inputs, std::vector<Blob::Ptr>& outputs,
143  ResponseDesc* resp) noexcept = 0;
144 };
145 
146 /**
147  * @brief This class is the main extension interface
148  */
149 class INFERENCE_ENGINE_API_CLASS(IExtension) : public InferenceEngine::details::IRelease {
150 public:
151  /**
152  * @brief Returns operation sets
153  * This method throws an exception if it was not implemented
154  * @return map of opset name to opset
155  */
156  virtual std::map<std::string, ngraph::OpSet> getOpSets();
157 
158  /**
159  * @brief Returns vector of implementation types
160  * @param node shared pointer to nGraph op
161  * @return vector of strings
162  */
163  virtual std::vector<std::string> getImplTypes(const std::shared_ptr<ngraph::Node>& node) {
164  (void)node;
165  return {};
166  }
167 
168  /**
169  * @brief Returns implementation for specific nGraph op
170  * @param node shared pointer to nGraph op
171  * @param implType implementation type
172  * @return shared pointer to implementation
173  */
174  virtual ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) {
175  (void)node;
176  (void)implType;
177  return nullptr;
178  }
179 
180  /**
181  * @brief Cleans resources up
182  */
183  virtual void Unload() noexcept = 0;
184 
185  /**
186  * @brief Gets extension version information and stores in versionInfo
187  * @param versionInfo Pointer to version info, will be set by plugin
188  */
189  virtual void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept = 0;
190 };
191 
192 /**
193  * @brief A shared pointer to a IExtension interface
194  */
195 using IExtensionPtr = std::shared_ptr<IExtension>;
196 
197 /**
198  * @brief Creates the default instance of the extension
199  *
200  * @param ext Extension interface
201  * @param resp Response description
202  * @return Status code
203  */
204 INFERENCE_EXTENSION_API(StatusCode) CreateExtension(IExtension*& ext, ResponseDesc* resp) noexcept;
205 
206 } // namespace InferenceEngine
InferenceEngine::LayerConfig::outConfs
std::vector< DataConfig > outConfs
Vector of output data configs.
Definition: ie_iextension.h:80
InferenceEngine::ILayerImpl::~ILayerImpl
virtual ~ILayerImpl()
Destructor.
InferenceEngine::IExtension::getImplementation
virtual ILayerImpl::Ptr getImplementation(const std::shared_ptr< ngraph::Node > &node, const std::string &implType)
Returns implementation for specific nGraph op.
Definition: ie_iextension.h:174
ie_api.h
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS.
InferenceEngine::DataConfig
This structure describes data configuration.
Definition: ie_iextension.h:48
InferenceEngine::ResponseDesc
Represents detailed information for an error.
Definition: ie_common.h:231
InferenceEngine::Version
Represents version information that describes plugins and the inference engine runtime library.
Definition: ie_version.hpp:21
InferenceEngine::ILayerExecImpl::execute
virtual StatusCode execute(std::vector< Blob::Ptr > &inputs, std::vector< Blob::Ptr > &outputs, ResponseDesc *resp) noexcept=0
Execute method.
InferenceEngine::DataConfig::constant
bool constant
Flag for determination of the constant memory. If layer contains all constant memory we can calculate...
Definition: ie_iextension.h:61
InferenceEngine::TensorDesc
This class defines Tensor description.
Definition: ie_layouts.h:153
InferenceEngine::ILayerImpl
This class provides interface for extension implementations.
Definition: ie_iextension.h:87
ie_blob.h
A header file for Blob and generic TBlob<>
InferenceEngine::StatusCode
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:208
InferenceEngine::ILayerExecImpl::init
virtual StatusCode init(LayerConfig &config, ResponseDesc *resp) noexcept=0
Initializes the implementation.
InferenceEngine::LayerConfig::inConfs
std::vector< DataConfig > inConfs
Vector of input data configs.
Definition: ie_iextension.h:76
InferenceEngine::DataConfig::desc
TensorDesc desc
Format of memory descriptor.
Definition: ie_iextension.h:52
InferenceEngine::LayerConfig
This structure describes Layer configuration.
Definition: ie_iextension.h:68
InferenceEngine::IExtension::getOpSets
virtual std::map< std::string, ngraph::OpSet > getOpSets()
Returns operation sets This method throws an exception if it was not implemented.
InferenceEngine::IExtension
This class is the main extension interface.
Definition: ie_iextension.h:149
InferenceEngine::IExtensionPtr
std::shared_ptr< IExtension > IExtensionPtr
A shared pointer to a IExtension interface.
Definition: ie_iextension.h:195
InferenceEngine::ILayerImpl::Ptr
std::shared_ptr< ILayerImpl > Ptr
A shared pointer to the ILayerImpl interface.
Definition: ie_iextension.h:92
InferenceEngine::IExtension::getImplTypes
virtual std::vector< std::string > getImplTypes(const std::shared_ptr< ngraph::Node > &node)
Returns vector of implementation types.
Definition: ie_iextension.h:163
ie_common.h
This is a header file with common inference engine definitions.
InferenceEngine::LayerConfig::dynBatchSupport
bool dynBatchSupport
Supported dynamic batch. If false, dynamic batch is not supported.
Definition: ie_iextension.h:72
ie_layouts.h
A header file for data layouts and conversion between them.
InferenceEngine::ILayerExecImpl::getSupportedConfigurations
virtual StatusCode getSupportedConfigurations(std::vector< LayerConfig > &conf, ResponseDesc *resp) noexcept=0
Gets all supported configurations for the current layer.
InferenceEngine::ILayerExecImpl::~ILayerExecImpl
virtual ~ILayerExecImpl()
Destructor.
ie_no_copy.hpp
header file for no_copy class
InferenceEngine::DataConfig::inPlace
int inPlace
Index of in-place memory. If -1 memory cannot be in-place.
Definition: ie_iextension.h:56
InferenceEngine::IExtension::Unload
virtual void Unload() noexcept=0
Cleans resources up.
ie_version.hpp
A header file that provides versioning information for the inference engine shared library.