1 // Copyright (C) 2018-2019 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
11 #include "details/ie_so_pointer.hpp"
12 #include "ie_iextension.h"
17 namespace InferenceEngine {
21 * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for creating IExtension object in DLL
24 class SOCreatorTrait<IExtension> {
27 * @brief A name of the fabric method for creating an IExtension object in DLL
29 static constexpr auto name = "CreateExtension";
33 * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for creating IExtension object in DLL
36 class SOCreatorTrait<IShapeInferExtension> {
39 * @brief A name of the fabric method for creating an IShapeInferExtension object in DLL
41 static constexpr auto name = "CreateShapeInferExtension";
44 } // namespace details
47 * @brief This class is a C++ helper to work with objects created using extensions.
49 class Extension : public IExtension {
52 * @brief Loads extension from a shared library
53 * @param name Full or relative path to extension library
55 explicit Extension(const file_name_t &name)
59 * @brief Gets the extension version information
60 * @param versionInfo A pointer to version info, set by the plugin
62 void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override {
63 actual->GetVersion(versionInfo);
67 * @brief Sets a log callback that is used to track what is going on inside
68 * @param listener Logging listener
70 void SetLogCallback(InferenceEngine::IErrorListener &listener) noexcept override {
71 actual->SetLogCallback(listener);
75 * @brief Cleans the resources up
77 void Unload() noexcept override {
82 * @brief Does nothing since destruction is done via the regular mechanism
84 void Release() noexcept override {}
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
93 StatusCode getPrimitiveTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
94 return actual->getPrimitiveTypes(types, size, resp);
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
104 StatusCode getFactoryFor(ILayerImplFactory *&factory, const CNNLayer *cnnLayer,
105 ResponseDesc *resp) noexcept override {
106 return actual->getFactoryFor(factory, cnnLayer, resp);
109 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
110 return actual->getShapeInferImpl(impl, type, resp);
115 * @brief A SOPointer instance to the loaded templated object
117 InferenceEngine::details::SOPointer<IExtension> actual;
121 * @brief This class is a C++ helper to work with objects created using extensions.
123 class ShapeInferExtension : public IShapeInferExtension {
126 * @brief Loads extension from a shared library
127 * @param name Full or relative path to extension library
129 explicit ShapeInferExtension(const file_name_t &name)
133 * @brief Gets the extension version information
134 * @param versionInfo A pointer to version info, set by the plugin
136 void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override {
137 actual->GetVersion(versionInfo);
141 * @brief Sets a log callback that is used to track what is going on inside
142 * @param listener Logging listener
144 void SetLogCallback(InferenceEngine::IErrorListener &listener) noexcept override {
145 actual->SetLogCallback(listener);
149 * @brief Cleans the resources up
151 void Unload() noexcept override {
156 * @brief Does nothing since destruction is done via the regular mechanism
158 void Release() noexcept override {}
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
167 StatusCode getShapeInferTypes(char**& types, unsigned int& size, ResponseDesc* resp) noexcept override {
168 return actual->getShapeInferTypes(types, size, resp);
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
177 StatusCode getShapeInferImpl(IShapeInferImpl::Ptr& impl, const char* type, ResponseDesc* resp) noexcept override {
178 return actual->getShapeInferImpl(impl, type, resp);
183 * @brief A SOPointer instance to the loaded templated object
185 InferenceEngine::details::SOPointer<IShapeInferExtension> actual;
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
194 inline std::shared_ptr<IShapeInferExtension> make_so_pointer(const file_name_t &name) {
195 return std::make_shared<ShapeInferExtension>(name);
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
204 inline std::shared_ptr<IExtension> make_so_pointer(const file_name_t &name) {
205 return std::make_shared<Extension>(name);
208 } // namespace InferenceEngine