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