ie_executable_network.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018 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"
20 
21 namespace InferenceEngine {
22 
23 /**
24  * @brief wrapper over IExecutableNetwork
25  */
28 
29 public:
30  ExecutableNetwork() = default;
31 
32  explicit ExecutableNetwork(IExecutableNetwork::Ptr actual) : actual(actual) {}
33 
34  /**
35  * @brief Wraps original method
36  * IExecutableNetwork::getOutputsInfo
37  */
40  CALL_STATUS_FNC(GetOutputsInfo, data);
41  return data;
42  }
43 
44  /**
45  * @brief Wraps original method
46  * IExecutableNetwork::getInputsInfo
47  */
49  ConstInputsDataMap info;
50  CALL_STATUS_FNC(GetInputsInfo, info);
51  return info;
52  }
53 
54  /**
55  * @brief reset owned object to new pointer, essential for cases when simultaneously loaded networks not expected
56  * @param actual actual pointed object
57  */
58  void reset(IExecutableNetwork::Ptr newActual) {
59  this->actual.swap(newActual);
60  }
61 
62  /**
63  * @brief Wraps original method
64  * IExecutableNetwork::CreateInferRequest
65  */
67  IInferRequest::Ptr req;
68  CALL_STATUS_FNC(CreateInferRequest, req);
69  if (req.get() == nullptr) THROW_IE_EXCEPTION << "Internal error: pointer to infer request is null";
70  return InferRequest(req);
71  }
72 
73  /**
74  * @brief Wraps original method
75  * IExecutableNetwork::CreateInferRequestPtr
76  * @return shared pointer on InferRequest object
77  */
78  InferRequest::Ptr CreateInferRequestPtr() {
79  IInferRequest::Ptr req;
80  CALL_STATUS_FNC(CreateInferRequest, req);
81  return std::make_shared<InferRequest>(req);
82  }
83 
84  /**
85  * @brief Exports the current executable network so it can be used later in the Import() main API
86  * @param modelFileName Full path to the location of the exported file
87  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
88  */
89  void Export(const std::string &modelFileName) {
90  CALL_STATUS_FNC(Export, modelFileName);
91  }
92 
93  /**
94  * @brief Gets the mapping of IR layer names to implemented kernels
95  * @param deployedTopology Map of PrimitiveInfo objects that represent the deployed topology
96  * @param resp Optional: pointer to an already allocated object to contain information in case of failure
97  */
98  void GetMappedTopology(std::map<std::string, std::vector<PrimitiveInfo::Ptr>> &deployedTopology) {
99  CALL_STATUS_FNC(GetMappedTopology, deployedTopology);
100  }
101 
102  /**
103  * cast operator is used when this wrapper initialized by LoadNetwork
104  * @return
105  */
106  operator IExecutableNetwork::Ptr &() {
107  return actual;
108  }
109 
110 
111  /**
112  *@brief see original function InferenceEngine::IExecutableNetwork::QueryState
113  */
114  std::vector<MemoryState> QueryState() {
115  IMemoryState::Ptr pState = nullptr;
116  auto res = OK;
117  std::vector<MemoryState> controller;
118  for (size_t idx = 0; res == OK; ++idx) {
119  ResponseDesc resp;
120  res = actual->QueryState(pState, idx, &resp);
121  if (res != OK && res != OUT_OF_BOUNDS) {
122  THROW_IE_EXCEPTION << resp.msg;
123  }
124  if (res != OUT_OF_BOUNDS) {
125  controller.push_back(MemoryState(pState));
126  }
127  }
128 
129  return controller;
130  }
131 
132 
133  using Ptr = std::shared_ptr<ExecutableNetwork>;
134 };
135 
136 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
std::vector< MemoryState > QueryState()
see original function InferenceEngine::IExecutableNetwork::QueryState
Definition: ie_executable_network.hpp:114
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:66
ConstOutputsDataMap GetOutputsInfo() const
Wraps original method IExecutableNetwork::getOutputsInfo.
Definition: ie_executable_network.hpp:38
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:26
Represents detailed information for an error.
Definition: ie_common.h:195
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:26
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:98
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:89
ConstInputsDataMap GetInputsInfo() const
Wraps original method IExecutableNetwork::getInputsInfo.
Definition: ie_executable_network.hpp:48
char msg[256]
A character buffer that holds the detailed information for an error.
Definition: ie_common.h:199
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:36
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:58
InferRequest::Ptr CreateInferRequestPtr()
Wraps original method IExecutableNetwork::CreateInferRequestPtr.
Definition: ie_executable_network.hpp:78