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 IShapeInferExtension 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  if (node == nullptr) THROW_IE_EXCEPTION << "Provided ngraph::Node pointer is nullptr.";
183  return actual->getImplTypes(node);
184  }
185 
186  /**
187  * @brief Returns implementation for specific nGraph op
188  * @param node shared pointer to nGraph op
189  * @param implType implementation type
190  * @return shared pointer to implementation
191  */
192  ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) override {
193  if (node == nullptr) THROW_IE_EXCEPTION << "Provided ngraph::Node pointer is nullptr.";
194  return actual->getImplementation(node, implType);
195  }
196 
197 protected:
198  /**
199  * @brief A SOPointer instance to the loaded templated object
200  */
201  InferenceEngine::details::SOPointer<IExtension> actual;
202 };
203 
204 /**
205  * @deprecated Use a common Extension class. The interface will be removed in 2021.1 release.
206  * @brief This class is a C++ helper to work with objects created using extensions.
207  */
208 class INFERENCE_ENGINE_DEPRECATED("Use a common Extension interface") ShapeInferExtension :
209  public IShapeInferExtension {
210 public:
211  /**
212  * @brief Loads extension from a shared library
213  *
214  * @param name Full or relative path to extension library
215  */
216  IE_SUPPRESS_DEPRECATED_START_WIN
217  explicit ShapeInferExtension(const file_name_t& name): actual(name) {}
218  IE_SUPPRESS_DEPRECATED_END_WIN
219 
220  /**
221  * @brief Gets the extension version information
222  *
223  * @param versionInfo A pointer to version info, set by the plugin
224  */
225  void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
226  actual->GetVersion(versionInfo);
227  }
228 
229  /**
230  * @brief IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations
231  * The method will be removed in 2021.1 release.
232  * @brief Sets a log callback that is used to track what is going on inside
233  *
234  * @param listener Logging listener
235  */
236  IE_SUPPRESS_DEPRECATED_START
237  INFERENCE_ENGINE_DEPRECATED("IErrorListener is not used anymore. StatusCode is provided in case of unexpected situations")
238  void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
239  actual->SetLogCallback(listener);
240  }
241  IE_SUPPRESS_DEPRECATED_END
242 
243  /**
244  * @brief Cleans the resources up
245  */
246  void Unload() noexcept override {
247  actual->Unload();
248  }
249 
250  /**
251  * @brief Does nothing since destruction is done via the regular mechanism
252  */
253  void Release() noexcept override {}
254 
255  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
256  StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
257  IE_SUPPRESS_DEPRECATED_START
258  return actual->getShapeInferTypes(types, size, resp);
259  IE_SUPPRESS_DEPRECATED_END
260  }
261 
262  INFERENCE_ENGINE_DEPRECATED("Implement ngraph::op::Op::validate_and_infer_types method in a custom ngraph operation")
263  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
264  IE_SUPPRESS_DEPRECATED_START
265  return actual->getShapeInferImpl(impl, type, resp);
266  IE_SUPPRESS_DEPRECATED_END
267  }
268 
269 protected:
270  /**
271  * @brief A SOPointer instance to the loaded templated object
272  */
273  InferenceEngine::details::SOPointer<IShapeInferExtension> actual;
274 };
275 IE_SUPPRESS_DEPRECATED_END_WIN
276 
277 /**
278  * @deprecated Use make_so_pointer with IExtension as template argument type.
279  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
280  *
281  * @param name Name of the shared library file
282  * @return shared_pointer A wrapper for the given type from a specific shared module
283  */
284 template <>
285 inline std::shared_ptr<IShapeInferExtension> make_so_pointer(const file_name_t& name) {
286  IE_SUPPRESS_DEPRECATED_START
287  return std::make_shared<ShapeInferExtension>(name);
288  IE_SUPPRESS_DEPRECATED_END
289 }
290 
291 /**
292  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
293  *
294  * @param name Name of the shared library file
295  * @return shared_pointer A wrapper for the given type from a specific shared module
296  */
297 template <>
298 inline std::shared_ptr<IExtension> make_so_pointer(const file_name_t& name) {
299  return std::make_shared<Extension>(name);
300 }
301 
302 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
ShapeInferExtension(const file_name_t &name)
Loads extension from a shared library.
Definition: ie_extension.h:217
This class provides interface for the implementation with the custom execution code.
Definition: ie_iextension.h:186
std::string type
Layer type.
Definition: ie_layers.h:47
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:273
Definition: cldnn_config.hpp:16
Represents version information that describes plugins and the inference engine runtime library...
Definition: ie_version.hpp:21
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
InferenceEngine::details::SOPointer< IExtension > actual
A SOPointer instance to the loaded templated object.
Definition: ie_extension.h:201
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
std::string name
Layer name.
Definition: ie_layers.h:42
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:253
Represents detailed information for an error.
Definition: ie_common.h:247
void Unload() noexcept override
Cleans the resources up.
Definition: ie_extension.h:246
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:285
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:225
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:208
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:192
This class is a C++ helper to work with objects created using extensions.
Definition: ie_extension.h:56