Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / hetero_plugin / hetero_plugin_base.hpp
1 //
2 // Copyright (C) 2018-2019 Intel Corporation.
3 //
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
11 //
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
15 //
16
17 /**
18  * \brief inference engine plugin API wrapper, to be used by particular implementors
19  * \file ie_plugin_base.hpp
20  */
21
22 #pragma once
23
24 #include <memory>
25 #include <map>
26 #include <string>
27 #include <ie_plugin.hpp>
28 #include <ie_ihetero_plugin.hpp>
29 #include "description_buffer.hpp"
30 #include "cpp_interfaces/exception2status.hpp"
31
32 namespace InferenceEngine {
33
34 /**
35  * @brief cpp interface for plugin, to avoid dll boundaries ,and simplify internal development
36  * @tparam T Minimal CPP implementation of IInferencePlugin (e.g. IInferencePluginInternal)
37  * @details can be used to create external wrapper too
38  */
39 template<class T>
40 class HeteroPluginBase : public IHeteroInferencePlugin {
41 protected:
42     class VersionStore : public Version {
43         std::string _dsc;
44         std::string _buildNumber;
45     public:
46         explicit VersionStore(const Version &v) {
47             _dsc = v.description;
48             _buildNumber = v.buildNumber;
49             description = _dsc.c_str();
50             buildNumber = _buildNumber.c_str();
51             apiVersion = v.apiVersion;
52         }
53     } _version;
54
55     std::shared_ptr<T> _impl;
56
57 public:
58     /**
59      *
60      * @param actualReported version that are to be reported
61      */
62     HeteroPluginBase(const Version &actualReported, std::shared_ptr<T> impl) : _version(actualReported) {
63         if (impl.get() == nullptr) {
64             THROW_IE_EXCEPTION << "implementation not defined";
65         }
66         _impl = impl;
67     }
68
69     /**
70      * @brief return plugin's version information
71      * @param versionInfo pointer to version info, will be set by plugin
72      */
73     void GetVersion(const Version *&versionInfo) noexcept override {
74         versionInfo = &_version;
75     }
76
77     void SetLogCallback(IErrorListener &listener) noexcept override {
78         NO_EXCEPT_CALL_RETURN_VOID(_impl->SetLogCallback(listener));
79     }
80
81     StatusCode LoadNetwork(ICNNNetwork &network, ResponseDesc *resp) noexcept override {
82         TO_STATUS(_impl->LoadNetwork(network));
83     }
84
85     StatusCode LoadNetwork(IExecutableNetwork::Ptr &executableNetwork,
86                            ICNNNetwork &network,
87                            const std::map<std::string, std::string> &config,
88                            ResponseDesc *resp)noexcept override {
89         TO_STATUS(_impl->LoadNetwork(executableNetwork, network, config));
90     }
91
92     StatusCode Infer(const Blob &input, Blob &result, ResponseDesc *resp) noexcept override {
93         TO_STATUS(_impl->Infer(input, result));
94     }
95
96     StatusCode Infer(const BlobMap &input, BlobMap &result, ResponseDesc *resp)noexcept override {
97         TO_STATUS(_impl->Infer(input, result));
98     }
99
100     StatusCode GetPerformanceCounts(std::map<std::string,
101             InferenceEngineProfileInfo> &perfMap, ResponseDesc *resp) const noexcept override {
102         TO_STATUS(_impl->GetPerformanceCounts(perfMap));
103     }
104
105     StatusCode AddExtension(InferenceEngine::IExtensionPtr extension,
106                             InferenceEngine::ResponseDesc *resp) noexcept override {
107         TO_STATUS(_impl->AddExtension(extension));
108     }
109
110     StatusCode SetConfig(const std::map<std::string, std::string> &config, ResponseDesc *resp) noexcept override {
111         TO_STATUS(_impl->SetConfig(config));
112     }
113
114     StatusCode ImportNetwork(IExecutableNetwork::Ptr &ret, const std::string &modelFileName,
115                              const std::map<std::string, std::string> &config, ResponseDesc *resp) noexcept override {
116         TO_STATUS(ret = _impl->ImportNetwork(modelFileName, config));
117     }
118
119     void Release() noexcept override {
120         delete this;
121     }
122
123     void SetDeviceLoader(const std::string &device, IHeteroDeviceLoader::Ptr loader)noexcept override {
124         _impl->SetDeviceLoader(device, loader);
125     }
126
127     StatusCode SetAffinity(
128         ICNNNetwork& network,
129         const std::map<std::string, std::string> &config,
130         ResponseDesc *resp) noexcept override {
131         TO_STATUS(_impl->SetAffinity(network, config));
132     }
133
134
135  private:
136     ~HeteroPluginBase() = default;
137 };
138
139 }  // namespace InferenceEngine