ie_executable_network.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file that provides wrapper classes for IExecutableNetwork
7  * @file ie_executable_network.hpp
8  */
9 #pragma once
10 
11 #include <map>
12 #include <string>
13 #include <vector>
14 #include <memory>
15 #include <algorithm>
17 #include "cpp/ie_infer_request.hpp"
18 #include "cpp/ie_memory_state.hpp"
19 #include "cpp/ie_cnn_network.h"
21 
22 namespace InferenceEngine {
23 
24 /**
25  * @brief wrapper over IExecutableNetwork
26  */
29 
30 public:
31  ExecutableNetwork() = default;
32 
33  explicit ExecutableNetwork(IExecutableNetwork::Ptr actual) : actual(actual) {}
34 
35  /**
36  * @brief Wraps original method
37  * IExecutableNetwork::getOutputsInfo
38  */
41  CALL_STATUS_FNC(GetOutputsInfo, data);
42  return data;
43  }
44 
45  /**
46  * @brief Wraps original method
47  * IExecutableNetwork::getInputsInfo
48  */
50  ConstInputsDataMap info;
51  CALL_STATUS_FNC(GetInputsInfo, info);
52  return info;
53  }
54 
55  /**
56  * @brief reset owned object to new pointer, essential for cases when simultaneously loaded networks not expected
57  * @param actual actual pointed object
58  */
59  void reset(IExecutableNetwork::Ptr newActual) {
60  this->actual.swap(newActual);
61  }
62 
63  /**
64  * @brief Wraps original method
65  * IExecutableNetwork::CreateInferRequest
66  */
68  IInferRequest::Ptr req;
69  CALL_STATUS_FNC(CreateInferRequest, req);
70  if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
71  return InferRequest(req);
72  }
73 
74  /**
75  * @brief Wraps original method
76  * IExecutableNetwork::CreateInferRequestPtr
77  * @return shared pointer on InferRequest object
78  */
79  InferRequest::Ptr CreateInferRequestPtr() {
80  IInferRequest::Ptr req;
81  CALL_STATUS_FNC(CreateInferRequest, req);
82  return std::make_shared<InferRequest>(req);
83  }
84 
85  /**
86  * @brief Exports the current executable network so it can be used later in the Import() main API
87  * @param modelFileName Full path to the location of the exported file
88  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
89  */
90  void Export(const std::string &modelFileName) {
91  CALL_STATUS_FNC(Export, modelFileName);
92  }
93 
94  /**
95  * @brief Gets the mapping of IR layer names to implemented kernels
96  * @param deployedTopology Map of PrimitiveInfo objects that represent the deployed topology
97  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
98  */
99  void GetMappedTopology(std::map<std::string, std::vector<PrimitiveInfo::Ptr>> &deployedTopology) {
100  CALL_STATUS_FNC(GetMappedTopology, deployedTopology);
101  }
102 
103  /**
104  * cast operator is used when this wrapper initialized by LoadNetwork
105  * @return
106  */
107  operator IExecutableNetwork::Ptr &() {
108  return actual;
109  }
110 
111  /**
112  * @brief Get executable graph information from a plugin represented as CNNNetwork
113  * @return CNNetwork containing Executable Graph Info
114  */
116  ICNNNetwork::Ptr ptr = nullptr;
117  CALL_STATUS_FNC(GetExecGraphInfo, ptr);
118  return CNNNetwork(ptr);
119  }
120 
121  /**
122  *@brief see original function InferenceEngine::IExecutableNetwork::QueryState
123  */
124  std::vector<MemoryState> QueryState() {
125  IMemoryState::Ptr pState = nullptr;
126  auto res = OK;
127  std::vector<MemoryState> controller;
128  for (size_t idx = 0; res == OK; ++idx) {
129  ResponseDesc resp;
130  res = actual->QueryState(pState, idx, &resp);
131  if (res != OK && res != OUT_OF_BOUNDS) {
132  THROW_IE_EXCEPTION << resp.msg;
133  }
134  if (res != OUT_OF_BOUNDS) {
135  controller.push_back(MemoryState(pState));
136  }
137  }
138 
139  return controller;
140  }
141 
142 
143  using Ptr = std::shared_ptr<ExecutableNetwork>;
144 };
145 
146 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
A header file that provides wrapper for ICNNNetwork object.
std::vector< MemoryState > QueryState()
see original function InferenceEngine::IExecutableNetwork::QueryState
Definition: ie_executable_network.hpp:124
Definition: ie_argmax_layer.hpp:11
a header file for IExecutableNetwork interface
A header file that provides macros to handle no exception methods.
InferRequest CreateInferRequest()
Wraps original method IExecutableNetwork::CreateInferRequest.
Definition: ie_executable_network.hpp:67
ConstOutputsDataMap GetOutputsInfo() const
Wraps original method IExecutableNetwork::getOutputsInfo.
Definition: ie_executable_network.hpp:39
This class is a wrapper of IInferRequest to provide setters/getters of input/output which operates wi...
Definition: ie_infer_request.hpp:58
std::map< std::string, CDataPtr > ConstOutputsDataMap
A collection that contains string as key, and const Data smart pointer as value.
Definition: ie_iexecutable_network.hpp:27
Represents detailed information for an error.
Definition: ie_common.h:198
std::map< std::string, InputInfo::CPtr > ConstInputsDataMap
A collection that contains string as key, and const InputInfo smart pointer as value.
Definition: ie_input_info.hpp:198
wrapper over IExecutableNetwork
Definition: ie_executable_network.hpp:27
void GetMappedTopology(std::map< std::string, std::vector< PrimitiveInfo::Ptr >> &deployedTopology)
Gets the mapping of IR layer names to implemented kernels.
Definition: ie_executable_network.hpp:99
CNNNetwork GetExecGraphInfo()
Get executable graph information from a plugin represented as CNNNetwork.
Definition: ie_executable_network.hpp:115
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:29
c++ exception based error reporting wrapper of API class IMemoryState
Definition: ie_memory_state.hpp:13
void Export(const std::string &modelFileName)
Exports the current executable network so it can be used later in the Import() main API...
Definition: ie_executable_network.hpp:90
ConstInputsDataMap GetInputsInfo() const
Wraps original method IExecutableNetwork::getInputsInfo.
Definition: ie_executable_network.hpp:49
char msg[256]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:202
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:37
A header file that provides wrapper classes for infer requests and callbacks.
void reset(IExecutableNetwork::Ptr newActual)
reset owned object to new pointer, essential for cases when simultaneously loaded networks not expect...
Definition: ie_executable_network.hpp:59
InferRequest::Ptr CreateInferRequestPtr()
Wraps original method IExecutableNetwork::CreateInferRequestPtr.
Definition: ie_executable_network.hpp:79