ie_plugin_cpp.hpp 5.43 KB
Newer Older
1
// Copyright (C) 2018-2020 Intel Corporation
openvino-pushbot's avatar
openvino-pushbot committed
2 3 4 5 6
// SPDX-License-Identifier: Apache-2.0
//

/**
 * @brief This is a header file for the Inference Engine plugin C++ API
7
 *
openvino-pushbot's avatar
openvino-pushbot committed
8 9 10 11 12 13
 * @file ie_plugin_cpp.hpp
 */
#pragma once

#include <map>
#include <memory>
14
#include <string>
openvino-pushbot's avatar
openvino-pushbot committed
15 16

#include "cpp/ie_executable_network.hpp"
17
#include "details/ie_exception_conversion.hpp"
openvino-pushbot's avatar
openvino-pushbot committed
18
#include "ie_cnn_network.h"
19 20
#include "ie_plugin.hpp"
#include "ie_plugin_ptr.hpp"
openvino-pushbot's avatar
openvino-pushbot committed
21 22 23 24

namespace InferenceEngine {

/**
25
 * @deprecated Use InferenceEngine::Core instead. Will be removed in 2020.3
openvino-pushbot's avatar
openvino-pushbot committed
26
 * @brief This class is a C++ API wrapper for IInferencePlugin.
27
 *
openvino-pushbot's avatar
openvino-pushbot committed
28 29
 * It can throw exceptions safely for the application, where it is properly handled.
 */
30
class INFERENCE_ENGINE_DEPRECATED("Use InferenceEngine::Core instead. Will be removed in 2020.3") InferencePlugin {
31
    IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
32 33 34 35 36 37 38 39
    InferenceEnginePluginPtr actual;

public:
    /** @brief A default constructor */
    InferencePlugin() = default;

    /**
     * @brief Constructs a plugin instance from the given pointer.
40
     *
41
     * @param pointer Initialized Plugin pointer
openvino-pushbot's avatar
openvino-pushbot committed
42
     */
43 44 45 46 47
    explicit InferencePlugin(const InferenceEnginePluginPtr& pointer): actual(pointer) {
        if (actual == nullptr) {
            THROW_IE_EXCEPTION << "InferencePlugin wrapper was not initialized.";
        }
    }
48 49

    IE_SUPPRESS_DEPRECATED_END
openvino-pushbot's avatar
openvino-pushbot committed
50 51

    /**
52 53 54
     * @copybrief IInferencePlugin::GetVersion
     *
     * Wraps IInferencePlugin::GetVersion
55
     * @return A plugin version
openvino-pushbot's avatar
openvino-pushbot committed
56
     */
57 58 59
    const Version* GetVersion() {
        const Version* versionInfo = nullptr;
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
60
        actual->GetVersion(versionInfo);
61
        IE_SUPPRESS_DEPRECATED_END
62 63 64
        if (versionInfo == nullptr) {
            THROW_IE_EXCEPTION << "Unknown device is used";
        }
openvino-pushbot's avatar
openvino-pushbot committed
65 66 67 68
        return versionInfo;
    }

    /**
69
     * @copybrief IInferencePlugin::LoadNetwork
70
     *
71
     * Wraps IInferencePlugin::LoadNetwork
72
     *
73 74 75
     * @param network A network object to load
     * @param config A map of configuration options
     * @return Created Executable Network object
openvino-pushbot's avatar
openvino-pushbot committed
76
     */
77
    ExecutableNetwork LoadNetwork(const ICNNNetwork& network, const std::map<std::string, std::string>& config) {
openvino-pushbot's avatar
openvino-pushbot committed
78
        IExecutableNetwork::Ptr ret;
79
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
80
        CALL_STATUS_FNC(LoadNetwork, ret, network, config);
81
        IE_SUPPRESS_DEPRECATED_END
82
        return ExecutableNetwork(ret, actual);
openvino-pushbot's avatar
openvino-pushbot committed
83 84 85
    }

    /**
86
     * @copybrief InferencePlugin::LoadNetwork
87
     *
88
     * Wraps IInferencePlugin::LoadNetwork
89 90 91
     * @param network A network object to load
     * @param config A map of configuration options
     * @return Created Executable Network object
openvino-pushbot's avatar
openvino-pushbot committed
92
     */
93
    ExecutableNetwork LoadNetwork(CNNNetwork network, const std::map<std::string, std::string>& config) {
openvino-pushbot's avatar
openvino-pushbot committed
94
        IExecutableNetwork::Ptr ret;
95
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
96
        CALL_STATUS_FNC(LoadNetwork, ret, network, config);
97
        IE_SUPPRESS_DEPRECATED_END
openvino-pushbot's avatar
openvino-pushbot committed
98
        if (ret.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to executable network is null";
99
        return ExecutableNetwork(ret, actual);
openvino-pushbot's avatar
openvino-pushbot committed
100 101 102
    }

    /**
103 104 105 106
     * @copybrief IInferencePlugin::AddExtension
     *
     * Wraps IInferencePlugin::AddExtension
     *
107
     * @param extension Pointer to loaded Extension
openvino-pushbot's avatar
openvino-pushbot committed
108 109
     */
    void AddExtension(InferenceEngine::IExtensionPtr extension) {
110
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
111
        CALL_STATUS_FNC(AddExtension, extension);
112
        IE_SUPPRESS_DEPRECATED_END
openvino-pushbot's avatar
openvino-pushbot committed
113 114 115
    }

    /**
116 117 118
     * @copybrief IInferencePlugin::SetConfig
     *
     * Wraps IInferencePlugin::SetConfig
119
     * @param config A configuration map
openvino-pushbot's avatar
openvino-pushbot committed
120
     */
121 122
    void SetConfig(const std::map<std::string, std::string>& config) {
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
123
        CALL_STATUS_FNC(SetConfig, config);
124
        IE_SUPPRESS_DEPRECATED_END
openvino-pushbot's avatar
openvino-pushbot committed
125 126 127
    }

    /**
128 129 130
     * @copybrief IInferencePlugin::ImportNetwork
     *
     * Wraps IInferencePlugin::ImportNetwork
131 132 133 134
     * @param modelFileName A path to the imported network
     * @param config A configuration map
     * @return Created Executable Network object
     */
135 136
    ExecutableNetwork ImportNetwork(const std::string& modelFileName,
                                    const std::map<std::string, std::string>& config) {
openvino-pushbot's avatar
openvino-pushbot committed
137
        IExecutableNetwork::Ptr ret;
138
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
139
        CALL_STATUS_FNC(ImportNetwork, ret, modelFileName, config);
140
        IE_SUPPRESS_DEPRECATED_END
141
        return ExecutableNetwork(ret, actual);
openvino-pushbot's avatar
openvino-pushbot committed
142 143 144
    }

    /**
145
     * @copybrief IInferencePlugin::QueryNetwork
146
     *
147
     * Wraps IInferencePlugin::QueryNetwork
148
     *
149 150 151
     * @param network A network object to query
     * @param config A configuration map
     * @param res Query results
openvino-pushbot's avatar
openvino-pushbot committed
152
     */
153 154 155
    void QueryNetwork(const ICNNNetwork& network, const std::map<std::string, std::string>& config,
                      QueryNetworkResult& res) const {
        IE_SUPPRESS_DEPRECATED_START
openvino-pushbot's avatar
openvino-pushbot committed
156
        actual->QueryNetwork(network, config, res);
157
        IE_SUPPRESS_DEPRECATED_END
openvino-pushbot's avatar
openvino-pushbot committed
158 159 160
        if (res.rc != OK) THROW_IE_EXCEPTION << res.resp.msg;
    }

161 162
    IE_SUPPRESS_DEPRECATED_START

openvino-pushbot's avatar
openvino-pushbot committed
163
    /**
164
     * @brief Converts InferenceEngine to InferenceEnginePluginPtr pointer
165
     *
166
     * @return Wrapped object
openvino-pushbot's avatar
openvino-pushbot committed
167 168 169 170 171 172 173
     */
    operator InferenceEngine::InferenceEnginePluginPtr() {
        return actual;
    }

    /**
     * @brief Shared pointer on InferencePlugin object
174
     *
openvino-pushbot's avatar
openvino-pushbot committed
175 176
     */
    using Ptr = std::shared_ptr<InferencePlugin>;
177 178

    IE_SUPPRESS_DEPRECATED_END
openvino-pushbot's avatar
openvino-pushbot committed
179 180
};
}  // namespace InferenceEngine