1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief A header file that defines a wrapper class for handling extension instantiation and releasing resources
16 #include "details/ie_so_pointer.hpp"
17 #include "ie_iextension.h"
19 namespace InferenceEngine {
23 * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
24 * creating IExtension object in DLL
27 class SOCreatorTrait<IExtension> {
30 * @brief A name of the fabric method for creating an IExtension object in DLL
32 static constexpr auto name = "CreateExtension";
36 * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
37 * creating IExtension object in DLL
40 class SOCreatorTrait<IShapeInferExtension> {
43 * @brief A name of the fabric method for creating an IShapeInferExtension object in DLL
45 static constexpr auto name = "CreateShapeInferExtension";
48 } // namespace details
51 * @brief This class is a C++ helper to work with objects created using extensions.
53 class Extension : public IExtension {
56 * @brief Loads extension from a shared library
58 * @param name Full or relative path to extension library
60 explicit Extension(const file_name_t& name): actual(name) {}
63 * @brief Gets the extension version information
65 * @param versionInfo A pointer to version info, set by the plugin
67 void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
68 actual->GetVersion(versionInfo);
72 * @brief Sets a log callback that is used to track what is going on inside
74 * @param listener Logging listener
76 void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
77 actual->SetLogCallback(listener);
81 * @brief Cleans the resources up
83 void Unload() noexcept override {
88 * @brief Does nothing since destruction is done via the regular mechanism
90 void Release() noexcept override {}
93 * @brief Gets the array with types of layers which are included in the extension
95 * @param types Types array
96 * @param size Size of the types array
97 * @param resp Response descriptor
100 StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
101 return actual->getPrimitiveTypes(types, size, resp);
105 * @brief Gets the factory with implementations for a given layer
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
112 StatusCode getFactoryFor(ILayerImplFactory*& factory, const CNNLayer* cnnLayer,
113 ResponseDesc* resp) noexcept override {
114 return actual->getFactoryFor(factory, cnnLayer, resp);
117 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
118 return actual->getShapeInferImpl(impl, type, resp);
123 * @brief A SOPointer instance to the loaded templated object
125 InferenceEngine::details::SOPointer<IExtension> actual;
129 * @brief This class is a C++ helper to work with objects created using extensions.
131 class ShapeInferExtension : public IShapeInferExtension {
134 * @brief Loads extension from a shared library
136 * @param name Full or relative path to extension library
138 explicit ShapeInferExtension(const file_name_t& name): actual(name) {}
141 * @brief Gets the extension version information
143 * @param versionInfo A pointer to version info, set by the plugin
145 void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
146 actual->GetVersion(versionInfo);
150 * @brief Sets a log callback that is used to track what is going on inside
152 * @param listener Logging listener
154 void SetLogCallback(InferenceEngine::IErrorListener& listener) noexcept override {
155 actual->SetLogCallback(listener);
159 * @brief Cleans the resources up
161 void Unload() noexcept override {
166 * @brief Does nothing since destruction is done via the regular mechanism
168 void Release() noexcept override {}
171 * @brief Gets the array with types of layers which are included in the extension
173 * @param types Types array
174 * @param size Size of the types array
175 * @param resp Response descriptor
176 * @return Status code
178 StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
179 return actual->getShapeInferTypes(types, size, resp);
183 * @brief Gets shape propagation implementation for the given string-type of cnn Layer
185 * @param impl the vector with implementations which is ordered by priority
186 * @param resp response descriptor
187 * @return status code
189 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
190 return actual->getShapeInferImpl(impl, type, resp);
195 * @brief A SOPointer instance to the loaded templated object
197 InferenceEngine::details::SOPointer<IShapeInferExtension> actual;
201 * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
203 * @param name Name of the shared library file
204 * @return shared_pointer A wrapper for the given type from a specific shared module
207 inline std::shared_ptr<IShapeInferExtension> make_so_pointer(const file_name_t& name) {
208 return std::make_shared<ShapeInferExtension>(name);
212 * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
214 * @param name Name of the shared library file
215 * @return shared_pointer A wrapper for the given type from a specific shared module
218 inline std::shared_ptr<IExtension> make_so_pointer(const file_name_t& name) {
219 return std::make_shared<Extension>(name);
222 } // namespace InferenceEngine