1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * \brief inference engine plugin API wrapper, to be used by particular implementors
7 * \file ie_plugin_base.hpp
15 #include <ie_plugin.hpp>
16 #include "description_buffer.hpp"
17 #include "cpp_interfaces/exception2status.hpp"
19 namespace InferenceEngine {
22 * @brief cpp interface for plugin, to avoid dll boundaries ,and simplify internal development
23 * @tparam T Minimal CPP implementation of IInferencePlugin (e.g. IInferencePluginInternal)
24 * @details can be used to create external wrapper too
27 class PluginBase : public IInferencePlugin {
29 class VersionStore : public Version {
31 std::string _buildNumber;
33 explicit VersionStore(const Version &v) {
35 _buildNumber = v.buildNumber;
36 description = _dsc.c_str();
37 buildNumber = _buildNumber.c_str();
38 apiVersion = v.apiVersion;
42 std::shared_ptr<T> _impl;
47 * @param actualReported version that are to be reported
49 PluginBase(const Version &actualReported, std::shared_ptr<T> impl) : _version(actualReported) {
50 if (impl.get() == nullptr) {
51 THROW_IE_EXCEPTION << "implementation not defined";
57 * @brief return plugin's version information
58 * @param versionInfo pointer to version info, will be set by plugin
60 void GetVersion(const Version *&versionInfo) noexcept override {
61 versionInfo = &_version;
64 void SetLogCallback(IErrorListener &listener) noexcept override {
65 NO_EXCEPT_CALL_RETURN_VOID(_impl->SetLogCallback(listener));
68 StatusCode LoadNetwork(ICNNNetwork &network, ResponseDesc *resp) noexcept override {
69 TO_STATUS(_impl->LoadNetwork(network));
72 StatusCode LoadNetwork(IExecutableNetwork::Ptr &executableNetwork,
74 const std::map<std::string, std::string> &config,
75 ResponseDesc *resp)noexcept override {
76 TO_STATUS(_impl->LoadNetwork(executableNetwork, network, config));
79 StatusCode Infer(const Blob &input, Blob &result, ResponseDesc *resp) noexcept override {
80 TO_STATUS(_impl->Infer(input, result));
83 StatusCode Infer(const BlobMap &input, BlobMap &result, ResponseDesc *resp)noexcept override {
84 TO_STATUS(_impl->Infer(input, result));
87 StatusCode GetPerformanceCounts(std::map<std::string,
88 InferenceEngineProfileInfo> &perfMap, ResponseDesc *resp) const noexcept override {
89 TO_STATUS(_impl->GetPerformanceCounts(perfMap));
92 StatusCode AddExtension(InferenceEngine::IExtensionPtr extension,
93 InferenceEngine::ResponseDesc *resp) noexcept override {
94 TO_STATUS(_impl->AddExtension(extension));
97 StatusCode SetConfig(const std::map<std::string, std::string> &config, ResponseDesc *resp) noexcept override {
98 TO_STATUS(_impl->SetConfig(config));
101 StatusCode ImportNetwork(IExecutableNetwork::Ptr &ret, const std::string &modelFileName,
102 const std::map<std::string, std::string> &config, ResponseDesc *resp) noexcept override {
103 TO_STATUS(ret = _impl->ImportNetwork(modelFileName, config));
106 void Release() noexcept override {
111 * @depricated Use the version with config parameter
113 void QueryNetwork(const ICNNNetwork &network, QueryNetworkResult &res) const noexcept override {
114 QueryNetwork(network, {}, res);
117 void QueryNetwork(const ICNNNetwork &network, const std::map<std::string, std::string>& config, QueryNetworkResult &res) const noexcept override {
118 _impl->QueryNetwork(network, config, res);
122 ~PluginBase() = default;
126 inline IInferencePlugin *make_ie_compatible_plugin(const Version &reported, std::shared_ptr<T> impl) {
127 return new PluginBase<T>(reported, impl);
130 } // namespace InferenceEngine