ie_extension.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 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  * @file ie_extension.h
8  */
9 #pragma once
10 
11 #include <map>
12 #include <memory>
13 #include <string>
14 
15 #include "details/ie_so_pointer.hpp"
16 #include "ie_iextension.h"
17 
18 namespace InferenceEngine {
19 namespace details {
20 
21 /**
22  * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
23  * creating IExtension object in DLL
24  */
25 template <>
26 class SOCreatorTrait<IExtension> {
27 public:
28  /**
29  * @brief A name of the fabric method for creating an IExtension object in DLL
30  */
31  static constexpr auto name = "CreateExtension";
32 };
33 
34 /**
35  * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
36  * creating IExtension object in DLL
37  */
38 template <>
39 class SOCreatorTrait<IShapeInferExtension> {
40 public:
41  /**
42  * @brief A name of the fabric method for creating an IShapeInferExtension object in DLL
43  */
44  static constexpr auto name = "CreateShapeInferExtension";
45 };
46 
47 } // namespace details
48 
49 /**
50  * @brief This class is a C++ helper to work with objects created using extensions.
51  */
52 class Extension : public IExtension {
53 public:
54  /**
55  * @brief Loads extension from a shared library
56  * @param name Full or relative path to extension library
57  */
58  explicit Extension(const file_name_t& name): actual(name) {}
59 
60  /**
61  * @brief Gets the extension version information
62  * @param versionInfo A pointer to version info, set by the plugin
63  */
64  void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
65  actual->GetVersion(versionInfo);
66  }
67 
68  /**
69  * @brief Sets a log callback that is used to track what is going on inside
70  * @param listener Logging listener
71  */
72  void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
73  actual->SetLogCallback(listener);
74  }
75 
76  /**
77  * @brief Cleans the resources up
78  */
79  void Unload() noexcept override {
80  actual->Unload();
81  }
82 
83  /**
84  * @brief Does nothing since destruction is done via the regular mechanism
85  */
86  void Release() noexcept override {}
87 
88  /**
89  * @brief Gets the array with types of layers which are included in the extension
90  * @param types Types array
91  * @param size Size of the types array
92  * @param resp Response descriptor
93  * @return Status code
94  */
95  StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
96  return actual->getPrimitiveTypes(types, size, resp);
97  }
98 
99  /**
100  * @brief Gets the factory with implementations for a given layer
101  * @param factory Factory with implementations
102  * @param cnnLayer A layer to get the factory for
103  * @param resp Response descriptor
104  * @return Status code
105  */
107  ResponseDesc* resp) noexcept override {
108  return actual->getFactoryFor(factory, cnnLayer, resp);
109  }
110 
111  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
112  return actual->getShapeInferImpl(impl, type, resp);
113  }
114 
115 protected:
116  /**
117  * @brief A SOPointer instance to the loaded templated object
118  */
119  InferenceEngine::details::SOPointer<IExtension> actual;
120 };
121 
122 /**
123  * @brief This class is a C++ helper to work with objects created using extensions.
124  */
126 public:
127  /**
128  * @brief Loads extension from a shared library
129  * @param name Full or relative path to extension library
130  */
131  explicit ShapeInferExtension(const file_name_t& name): actual(name) {}
132 
133  /**
134  * @brief Gets the extension version information
135  * @param versionInfo A pointer to version info, set by the plugin
136  */
137  void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
138  actual->GetVersion(versionInfo);
139  }
140 
141  /**
142  * @brief Sets a log callback that is used to track what is going on inside
143  * @param listener Logging listener
144  */
145  void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
146  actual->SetLogCallback(listener);
147  }
148 
149  /**
150  * @brief Cleans the resources up
151  */
152  void Unload() noexcept override {
153  actual->Unload();
154  }
155 
156  /**
157  * @brief Does nothing since destruction is done via the regular mechanism
158  */
159  void Release() noexcept override {}
160 
161  /**
162  * @brief Gets the array with types of layers which are included in the extension
163  * @param types Types array
164  * @param size Size of the types array
165  * @param resp Response descriptor
166  * @return Status code
167  */
168  StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
169  return actual->getShapeInferTypes(types, size, resp);
170  }
171 
172  /**
173  * @brief Gets shape propagation implementation for the given string-type of cnn Layer
174  * @param impl the vector with implementations which is ordered by priority
175  * @param resp response descriptor
176  * @return status code
177  */
178  StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
179  return actual->getShapeInferImpl(impl, type, resp);
180  }
181 
182 protected:
183  /**
184  * @brief A SOPointer instance to the loaded templated object
185  */
186  InferenceEngine::details::SOPointer<IShapeInferExtension> actual;
187 };
188 
189 /**
190  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
191  * @param name Name of the shared library file
192  * @return shared_pointer A wrapper for the given type from a specific shared module
193  */
194 template <>
195 inline std::shared_ptr<IShapeInferExtension> make_so_pointer(const file_name_t& name) {
196  return std::make_shared<ShapeInferExtension>(name);
197 }
198 
199 /**
200  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
201  * @param name Name of the shared library file
202  * @return shared_pointer A wrapper for the given type from a specific shared module
203  */
204 template <>
205 inline std::shared_ptr<IExtension> make_so_pointer(const file_name_t& name) {
206  return std::make_shared<Extension>(name);
207 }
208 
209 } // namespace InferenceEngine
ShapeInferExtension(const file_name_t &name)
Loads extension from a shared library.
Definition: ie_extension.h:131
void Release() noexcept override
Does nothing since destruction is done via the regular mechanism.
Definition: ie_extension.h:86
InferenceEngine::details::SOPointer< IShapeInferExtension > actual
A SOPointer instance to the loaded templated object.
Definition: ie_extension.h:186
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
Represents version information that describes plugins and the inference engine runtime library...
Definition: ie_version.hpp:20
StatusCode getFactoryFor(ILayerImplFactory *&factory, const CNNLayer *cnnLayer, ResponseDesc *resp) noexcept override
Gets the factory with implementations for a given layer.
Definition: ie_extension.h:106
StatusCode getShapeInferImpl(IShapeInferImpl::Ptr &impl, const char *type, ResponseDesc *resp) noexcept override
Gets shape propagation implementation for the given string-type of cnn Layer.
Definition: ie_extension.h:178
InferenceEngine::details::SOPointer< IExtension > actual
A SOPointer instance to the loaded templated object.
Definition: ie_extension.h:119
This class provides interface for extension factories.
Definition: ie_iextension.h:122
Extension(const file_name_t &name)
Loads extension from a shared library.
Definition: ie_extension.h:58
void Unload() noexcept override
Cleans the resources up.
Definition: ie_extension.h:79
void Release() noexcept override
Does nothing since destruction is done via the regular mechanism.
Definition: ie_extension.h:159
Represents detailed information for an error.
Definition: ie_common.h:235
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:212
void Unload() noexcept override
Cleans the resources up.
Definition: ie_extension.h:152
This is a header file for Inference Engine Extension Interface.
void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override
Gets the extension version information.
Definition: ie_extension.h:137
void SetLogCallback(InferenceEngine::IErrorListener &listener) noexcept override
Sets a log callback that is used to track what is going on inside.
Definition: ie_extension.h:72
StatusCode getShapeInferImpl(IShapeInferImpl::Ptr &impl, const char *type, ResponseDesc *resp) noexcept override
Gets shape propagation implementation for the given string-type of cnn Layer.
Definition: ie_extension.h:111
This is a base abstraction Layer - all DNN Layers inherit from this class.
Definition: ie_layers.h:41
void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override
Gets the extension version information.
Definition: ie_extension.h:64
This class is a C++ helper to work with objects created using extensions.
Definition: ie_extension.h:125
StatusCode getPrimitiveTypes(char **&types, unsigned int &size, ResponseDesc *resp) noexcept override
Gets the array with types of layers which are included in the extension.
Definition: ie_extension.h:95
This class represents a custom error listener. Plugin consumers can provide it via InferenceEngine::S...
Definition: ie_error.hpp:16
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:166
This class is the main extension interface.
Definition: ie_iextension.h:207
void SetLogCallback(InferenceEngine::IErrorListener &listener) noexcept override
Sets a log callback that is used to track what is going on inside.
Definition: ie_extension.h:145
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:195
StatusCode getShapeInferTypes(char **&types, unsigned int &size, ResponseDesc *resp) noexcept override
Gets the array with types of layers which are included in the extension.
Definition: ie_extension.h:168
This class is a C++ helper to work with objects created using extensions.
Definition: ie_extension.h:52