ie_extension.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 A header file that defines a wrapper class for handling extension instantiation and releasing resources
7  *
8  * @file ie_extension.h
9  */
10 #pragma once
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
18 #include "ie_iextension.h"
19 
20 namespace InferenceEngine {
21 namespace details {
22 
23 /**
24  * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
25  * creating IExtension object in DLL
26  */
27 template <>
28 class SOCreatorTrait<IExtension> {
29 public:
30  /**
31  * @brief A name of the fabric method for creating an IExtension object in DLL
32  */
33  static constexpr auto name = "CreateExtension";
34 };
35 
36 /**
37  * @deprecated Implement IExtension interface. The interface will be removed in 2021.1 release.
38  * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
39  * creating IExtension object in DLL
40  */
41 template <>
42 class INFERENCE_ENGINE_DEPRECATED("Implement IExtension") SOCreatorTrait<IShapeInferExtension> {
43 public:
44  /**
45  * @brief A name of the fabric method for creating an IShapeInferExtension object in DLL
46  */
47  static constexpr auto name = "CreateShapeInferExtension";
48 };
49 
50 } // namespace details
51 
52 /**
53  * @brief This class is a C++ helper to work with objects created using extensions.
54  */
55 IE_SUPPRESS_DEPRECATED_START_WIN
56 class INFERENCE_ENGINE_API_CLASS(Extension) : public IExtension {
57 public:
58  /**
59  * @brief Loads extension from a shared library
60  *
61  * @param name Full or relative path to extension library
62  */
63  explicit Extension(const file_name_t& name): actual(name) {}
64 
65  /**
66  * @brief Gets the extension version information
67  *
68  * @param versionInfo A pointer to version info, set by the plugin
69  */
70  void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
71  actual->GetVersion(versionInfo);
72  }
73 
74  /**
75  * @deprecated IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations
76  * The method will be removed in 2021.1 release.
77  * @brief Sets a log callback that is used to track what is going on inside
78  *
79  * @param listener Logging listener
80  */
81  IE_SUPPRESS_DEPRECATED_START
82  INFERENCE_ENGINE_DEPRECATED("IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations")
83  void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
84  actual->SetLogCallback(listener);
85  }
86  IE_SUPPRESS_DEPRECATED_END
87 
88  /**
89  * @brief Cleans the resources up
90  */
91  void Unload() noexcept override {
92  actual->Unload();
93  }
94 
95  /**
96  * @brief Does nothing since destruction is done via the regular mechanism
97  */
98  void Release() noexcept override {}
99 
100  /**
101  * @deprecated Use IExtension::getImplTypes to get implementation types for a particular node.
102  * The method will removed in 2021.1 release.
103  * @brief Gets the array with types of layers which are included in the extension
104  *
105  * @param types Types array
106  * @param size Size of the types array
107  * @param resp Response descriptor
108  * @return Status code
109  */
110  INFERENCE_ENGINE_DEPRECATED("Use IExtension::getImplTypes to get implementation types for a particular node")
111  StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
112  IE_SUPPRESS_DEPRECATED_START
113  return actual->getPrimitiveTypes(types, size, resp);
114  IE_SUPPRESS_DEPRECATED_END
115  }
116 
117  /**
118  * @deprecated Use IExtension::getImplementation to get a concrete implementation.
119  * The method will be removed in 2021.1 release.
120  * @brief Gets the factory with implementations for a given layer
121  *
122  * @param factory Factory with implementations
123  * @param cnnLayer A layer to get the factory for
124  * @param resp Response descriptor
125  * @return Status code
126  */
127  IE_SUPPRESS_DEPRECATED_START
128  INFERENCE_ENGINE_DEPRECATED("Use IExtension::getImplementation to get a concrete implementation")
129  StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
130  ResponseDesc* resp) noexcept override {
131  return actual->getFactoryFor(factory, cnnLayer, resp);
132  }
133  IE_SUPPRESS_DEPRECATED_END
134 
135  /**
136  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation
137  * The method will be removed in 2021.1 release.
138  * @brief Gets shape propagation implementation for the given string-type of CNNLayer
139  *
140  * @param impl the vector with implementations which is ordered by priority
141  * @param type A type of CNNLayer
142  * @param resp response descriptor
143  * @return status code
144  */
145  IE_SUPPRESS_DEPRECATED_START
146  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
147  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
148  return actual->getShapeInferImpl(impl, type, resp);
149  }
150  IE_SUPPRESS_DEPRECATED_END
151 
152  /**
153  * @deprecated Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation
154  * The method will be removed in 2021.1 release.
155  * @brief Gets the array with types of layers which are included in the extension
156  *
157  * @param types Types array
158  * @param size Size of the types array
159  * @param resp Response descriptor
160  * @return Status code
161  */
162  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
163  StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
164  IE_SUPPRESS_DEPRECATED_START
165  return actual->getShapeInferTypes(types, size, resp);
166  IE_SUPPRESS_DEPRECATED_END
167  }
168 
169  /**
170  * @brief Returns operation sets
171  * This method throws an exception if it was not implemented
172  * @return map of opset name to opset
173  */
174  std::map<std::string, ngraph::OpSet> getOpSets() override;
175 
176  /**
177  * @brief Returns vector of implementation types
178  * @param node shared pointer to nGraph op
179  * @return vector of strings
180  */
181  std::vector<std::string> getImplTypes(const std::shared_ptr<ngraph::Node>& node) override {
182  return actual->getImplTypes(node);
183  }
184 
185  /**
186  * @brief Returns implementation for specific nGraph op
187  * @param node shared pointer to nGraph op
188  * @param implType implementation type
189  * @return shared pointer to implementation
190  */
191  ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) override {
192  return actual->getImplementation(node, implType);
193  }
194 
195 protected:
196  /**
197  * @brief A SOPointer instance to the loaded templated object
198  */
199  InferenceEngine::details::SOPointer<IExtension> actual;
200 };
201 
202 /**
203  * @deprecated Use a common Extension class. The interface will be removed in 2021.1 release.
204  * @brief This class is a C++ helper to work with objects created using extensions.
205  */
206 class INFERENCE_ENGINE_DEPRECATED("Use a common Extension interface") ShapeInferExtension :
207  public IShapeInferExtension {
208 public:
209  /**
210  * @brief Loads extension from a shared library
211  *
212  * @param name Full or relative path to extension library
213  */
214  IE_SUPPRESS_DEPRECATED_START_WIN
215  explicit ShapeInferExtension(const file_name_t& name): actual(name) {}
216  IE_SUPPRESS_DEPRECATED_END_WIN
217 
218  /**
219  * @brief Gets the extension version information
220  *
221  * @param versionInfo A pointer to version info, set by the plugin
222  */
223  void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
224  actual->GetVersion(versionInfo);
225  }
226 
227  /**
228  * @brief IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations
229  * The method will be removed in 2021.1 release.
230  * @brief Sets a log callback that is used to track what is going on inside
231  *
232  * @param listener Logging listener
233  */
234  IE_SUPPRESS_DEPRECATED_START
235  INFERENCE_ENGINE_DEPRECATED("IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations")
236  void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
237  actual->SetLogCallback(listener);
238  }
239  IE_SUPPRESS_DEPRECATED_END
240 
241  /**
242  * @brief Cleans the resources up
243  */
244  void Unload() noexcept override {
245  actual->Unload();
246  }
247 
248  /**
249  * @brief Does nothing since destruction is done via the regular mechanism
250  */
251  void Release() noexcept override {}
252 
253  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
254  StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
255  IE_SUPPRESS_DEPRECATED_START
256  return actual->getShapeInferTypes(types, size, resp);
257  IE_SUPPRESS_DEPRECATED_END
258  }
259 
260  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
261  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
262  IE_SUPPRESS_DEPRECATED_START
263  return actual->getShapeInferImpl(impl, type, resp);
264  IE_SUPPRESS_DEPRECATED_END
265  }
266 
267 protected:
268  /**
269  * @brief A SOPointer instance to the loaded templated object
270  */
271  InferenceEngine::details::SOPointer<IShapeInferExtension> actual;
272 };
273 IE_SUPPRESS_DEPRECATED_END_WIN
274 
275 /**
276  * @deprecated Use make_so_pointer with IExtension as template argument type.
277  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
278  *
279  * @param name Name of the shared library file
280  * @return shared_pointer A wrapper for the given type from a specific shared module
281  */
282 template <>
283 inline std::shared_ptr<IShapeInferExtension> make_so_pointer(const file_name_t& name) {
284  IE_SUPPRESS_DEPRECATED_START
285  return std::make_shared<ShapeInferExtension>(name);
286  IE_SUPPRESS_DEPRECATED_END
287 }
288 
289 /**
290  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
291  *
292  * @param name Name of the shared library file
293  * @return shared_pointer A wrapper for the given type from a specific shared module
294  */
295 template <>
296 inline std::shared_ptr<IExtension> make_so_pointer(const file_name_t& name) {
297  return std::make_shared<Extension>(name);
298 }
299 
300 } // namespace InferenceEngine
ShapeInferExtension(const file_name_t &name)
Loads extension from a shared library.
Definition: ie_extension.h:215
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:186
void Release() noexcept override
Does nothing since destruction is done via the regular mechanism.
Definition: ie_extension.h:98
InferenceEngine::details::SOPointer< IShapeInferExtension > actual
A SOPointer instance to the loaded templated object.
Definition: ie_extension.h:271
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
Represents version information that describes plugins and the inference engine runtime library...
Definition: ie_version.hpp:21
std::string name
Layer name.
Definition: ie_layers.h:42
InferenceEngine::details::SOPointer< IExtension > actual
A SOPointer instance to the loaded templated object.
Definition: ie_extension.h:199
This class provides interface for extension factories.
Definition: ie_iextension.h:154
Extension(const file_name_t &name)
Loads extension from a shared library.
Definition: ie_extension.h:63
void Unload() noexcept override
Cleans the resources up.
Definition: ie_extension.h:91
void Release() noexcept override
Does nothing since destruction is done via the regular mechanism.
Definition: ie_extension.h:251
Represents detailed information for an error.
Definition: ie_common.h:247
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
void Unload() noexcept override
Cleans the resources up.
Definition: ie_extension.h:244
std::vector< std::string > getImplTypes(const std::shared_ptr< ngraph::Node > &node) override
Returns vector of implementation types.
Definition: ie_extension.h:181
This is a header file for Inference Engine Extension Interface.
std::shared_ptr< ILayerImpl > Ptr
A shared pointer to the ILayerImpl interface.
Definition: ie_iextension.h:94
void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override
Gets the extension version information.
Definition: ie_extension.h:223
void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override
Gets the extension version information.
Definition: ie_extension.h:70
This class is a C++ helper to work with objects created using extensions.
Definition: ie_extension.h:206
std::string type
Layer type.
Definition: ie_layers.h:47
This class represents a custom error listener.
Definition: ie_error.hpp:18
This is a wrapper class for handling plugin instantiation and releasing resources.
This class is the reader extension interface to provide implementation for shape propagation.
Definition: ie_iextension.h:213
This class is the main extension interface.
Definition: ie_iextension.h:274
ILayerImpl::Ptr getImplementation(const std::shared_ptr< ngraph::Node > &node, const std::string &implType) override
Returns implementation for specific nGraph op.
Definition: ie_extension.h:191
std::shared_ptr< T > make_so_pointer(const file_name_t &name)=delete
Creates a special shared_pointer wrapper for the given type from a specific shared module...
Definition: ie_extension.h:283
This class is a C++ helper to work with objects created using extensions.
Definition: ie_extension.h:56