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