1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief A header file that provides wrapper classes for IExecutableNetwork
7 * @file ie_executable_network.hpp
16 #include "ie_iexecutable_network.hpp"
17 #include "ie_plugin_ptr.hpp"
18 #include "cpp/ie_infer_request.hpp"
19 #include "cpp/ie_memory_state.hpp"
20 #include "cpp/ie_cnn_network.h"
21 #include "details/ie_exception_conversion.hpp"
23 namespace InferenceEngine {
26 * @brief wrapper over IExecutableNetwork
28 class ExecutableNetwork {
29 IExecutableNetwork::Ptr actual;
30 InferenceEnginePluginPtr plg;
33 ExecutableNetwork() = default;
34 ~ExecutableNetwork() {
38 explicit ExecutableNetwork(IExecutableNetwork::Ptr actual, InferenceEnginePluginPtr plg = {})
39 : actual(actual), plg(plg) {}
42 * @brief Wraps original method
43 * IExecutableNetwork::getOutputsInfo
45 ConstOutputsDataMap GetOutputsInfo() const {
46 ConstOutputsDataMap data;
47 CALL_STATUS_FNC(GetOutputsInfo, data);
52 * @brief Wraps original method
53 * IExecutableNetwork::getInputsInfo
55 ConstInputsDataMap GetInputsInfo() const {
56 ConstInputsDataMap info;
57 CALL_STATUS_FNC(GetInputsInfo, info);
62 * @brief reset owned object to new pointer, essential for cases when simultaneously loaded networks not expected
63 * @param actual actual pointed object
65 void reset(IExecutableNetwork::Ptr newActual) {
66 this->actual.swap(newActual);
70 * @brief Wraps original method
71 * IExecutableNetwork::CreateInferRequest
73 InferRequest CreateInferRequest() {
74 IInferRequest::Ptr req;
75 CALL_STATUS_FNC(CreateInferRequest, req);
76 if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
77 return InferRequest(req, plg);
81 * @brief Wraps original method
82 * IExecutableNetwork::CreateInferRequestPtr
83 * @return shared pointer on InferRequest object
85 InferRequest::Ptr CreateInferRequestPtr() {
86 IInferRequest::Ptr req;
87 CALL_STATUS_FNC(CreateInferRequest, req);
88 return std::make_shared<InferRequest>(req, plg);
92 * @brief Exports the current executable network so it can be used later in the Import() main API
93 * @param modelFileName Full path to the location of the exported file
94 * @param resp Optional: pointer to an already allocated object to contain information in case of failure
96 void Export(const std::string &modelFileName) {
97 CALL_STATUS_FNC(Export, modelFileName);
101 * @brief Gets the mapping of IR layer names to implemented kernels
102 * @param deployedTopology Map of PrimitiveInfo objects that represent the deployed topology
103 * @param resp Optional: pointer to an already allocated object to contain information in case of failure
105 void GetMappedTopology(std::map<std::string, std::vector<PrimitiveInfo::Ptr>> &deployedTopology) {
106 CALL_STATUS_FNC(GetMappedTopology, deployedTopology);
110 * cast operator is used when this wrapper initialized by LoadNetwork
113 operator IExecutableNetwork::Ptr &() {
118 * @brief Get executable graph information from a plugin represented as CNNNetwork
119 * @return CNNetwork containing Executable Graph Info
121 CNNNetwork GetExecGraphInfo() {
122 ICNNNetwork::Ptr ptr = nullptr;
123 CALL_STATUS_FNC(GetExecGraphInfo, ptr);
124 return CNNNetwork(ptr);
128 *@brief see original function InferenceEngine::IExecutableNetwork::QueryState
130 std::vector<MemoryState> QueryState() {
131 IMemoryState::Ptr pState = nullptr;
133 std::vector<MemoryState> controller;
134 for (size_t idx = 0; res == OK; ++idx) {
136 res = actual->QueryState(pState, idx, &resp);
137 if (res != OK && res != OUT_OF_BOUNDS) {
138 THROW_IE_EXCEPTION << resp.msg;
140 if (res != OUT_OF_BOUNDS) {
141 controller.push_back(MemoryState(pState));
149 * @brief Sets configuration for current executable network
150 * @param config Map of pairs: (config parameter name, config parameter value)
151 * @param resp Pointer to the response message that holds a description of an error if any occurred
153 void SetConfig(const std::map<std::string, Parameter> &config) {
154 CALL_STATUS_FNC(SetConfig, config);
157 /** @brief Gets configuration dedicated to plugin behaviour
158 * @param name - config key, can be found in ie_plugin_config.hpp
159 * @param options - configuration details for coonfig value
160 * @param result - value of config corresponding to config key
161 * @param resp Pointer to the response message that holds a description of an error if any occurred
163 Parameter GetConfig(const std::string &name) const {
164 Parameter configValue;
165 CALL_STATUS_FNC(GetConfig, name, configValue);
170 * @brief Gets general runtime metric for dedicated hardware
171 * @param name - metric name to request
172 * @param options - configuration details for metric
173 * @param result - metric value corresponding to metric key
174 * @param resp - Pointer to the response message that holds a description of an error if any
176 * @return code of the operation. OK if succeeded
178 Parameter GetMetric(const std::string &name) const {
179 Parameter metricValue;
180 CALL_STATUS_FNC(GetMetric, name, metricValue);
184 using Ptr = std::shared_ptr<ExecutableNetwork>;
187 } // namespace InferenceEngine