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