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 #include <vector>
16 
17 #include "ie_iextension.h"
19 
20 namespace InferenceEngine {
21 namespace details {
22 
23 /**
24  * @brief The SOCreatorTrait class specialization for IExtension case, defines the name of the fabric method for
25  * creating IExtension object in DLL
26  */
27 template <>
28 class SOCreatorTrait<IExtension> {
29 public:
30  /**
31  * @brief A name of the fabric method for creating an IExtension object in DLL
32  */
33  static constexpr auto name = "CreateExtension";
34 };
35 
36 } // namespace details
37 
38 /**
39  * @brief This class is a C++ helper to work with objects created using extensions.
40  */
41 class INFERENCE_ENGINE_API_CLASS(Extension) : public IExtension {
42 public:
43  /**
44  * @brief Loads extension from a shared library
45  *
46  * @param name Full or relative path to extension library
47  */
48  template <typename C,
49  typename = details::enableIfSupportedChar<C>>
50  explicit Extension(const std::basic_string<C>& name): actual(name) {}
51 
52  /**
53  * @brief Gets the extension version information
54  *
55  * @param versionInfo A pointer to version info, set by the plugin
56  */
57  void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {
58  actual->GetVersion(versionInfo);
59  }
60 
61  /**
62  * @brief Cleans the resources up
63  */
64  void Unload() noexcept override {
65  actual->Unload();
66  }
67 
68  /**
69  * @brief Does nothing since destruction is done via the regular mechanism
70  */
71  void Release() noexcept override {}
72 
73  /**
74  * @brief Returns operation sets
75  * This method throws an exception if it was not implemented
76  * @return map of opset name to opset
77  */
78  std::map<std::string, ngraph::OpSet> getOpSets() override;
79 
80  /**
81  * @brief Returns vector of implementation types
82  * @param node shared pointer to nGraph op
83  * @return vector of strings
84  */
85  std::vector<std::string> getImplTypes(const std::shared_ptr<ngraph::Node>& node) override {
86  if (node == nullptr) THROW_IE_EXCEPTION << "Provided ngraph::Node pointer is nullptr.";
87  return actual->getImplTypes(node);
88  }
89 
90  /**
91  * @brief Returns implementation for specific nGraph op
92  * @param node shared pointer to nGraph op
93  * @param implType implementation type
94  * @return shared pointer to implementation
95  */
96  ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) override {
97  if (node == nullptr) THROW_IE_EXCEPTION << "Provided ngraph::Node pointer is nullptr.";
98  return actual->getImplementation(node, implType);
99  }
100 
101 protected:
102  /**
103  * @brief A SOPointer instance to the loaded templated object
104  */
105  details::SOPointer<IExtension> actual;
106 };
107 
108 /**
109  * @brief Creates a special shared_pointer wrapper for the given type from a specific shared module
110  *
111  * @param name A std::string name of the shared library file
112  * @return shared_pointer A wrapper for the given type from a specific shared module
113  */
114 template <>
115 inline std::shared_ptr<IExtension> make_so_pointer(const std::string& name) {
116  return std::make_shared<Extension>(name);
117 }
118 
119 #ifdef ENABLE_UNICODE_PATH_SUPPORT
120 
121 template <>
122 inline std::shared_ptr<IExtension> make_so_pointer(const std::wstring& name) {
123  return std::make_shared<Extension>(name);
124 }
125 
126 #endif
127 
128 } // namespace InferenceEngine
void GetVersion(const InferenceEngine::Version *&versionInfo) const noexcept override
Gets the extension version information.
Definition: ie_extension.h:57
void Release() noexcept override
Does nothing since destruction is done via the regular mechanism.
Definition: ie_extension.h:71
void Unload() noexcept override
Cleans the resources up.
Definition: ie_extension.h:64
std::map< std::string, ngraph::OpSet > getOpSets() override
Returns operation sets This method throws an exception if it was not implemented.
ILayerImpl::Ptr getImplementation(const std::shared_ptr< ngraph::Node > &node, const std::string &implType) override
Returns implementation for specific nGraph op.
Definition: ie_extension.h:96
std::vector< std::string > getImplTypes(const std::shared_ptr< ngraph::Node > &node) override
Returns vector of implementation types.
Definition: ie_extension.h:85
details::SOPointer< IExtension > actual
A SOPointer instance to the loaded templated object.
Definition: ie_extension.h:105
Extension(const std::basic_string< C > &name)
Loads extension from a shared library.
Definition: ie_extension.h:50
This class is the main extension interface.
Definition: ie_iextension.h:149
std::shared_ptr< ILayerImpl > Ptr
A shared pointer to the ILayerImpl interface.
Definition: ie_iextension.h:92
#define THROW_IE_EXCEPTION
A macro used to throw general exception with a description.
Definition: ie_exception.hpp:25
This is a header file for Inference Engine Extension Interface.
This is a wrapper class for handling plugin instantiation and releasing resources.
Inference Engine C++ API.
Definition: cldnn_config.hpp:15
@ C
A bias layout for operation.
Definition: ie_common.h:82
std::shared_ptr< T > make_so_pointer(const std::string &name)=delete
Creates a special shared_pointer wrapper for the given type from a specific shared module.
Definition: ie_extension.h:115
Represents version information that describes plugins and the inference engine runtime library.
Definition: ie_version.hpp:24