ie_executable_network_internal.hpp
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <algorithm>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 #include <fstream>
13 
14 #include "cpp_interfaces/impl/ie_infer_async_request_internal.hpp"
15 #include "cpp_interfaces/impl/ie_infer_request_internal.hpp"
16 #include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp"
17 #include "cpp_interfaces/interface/ie_iinfer_request_internal.hpp"
19 
20 namespace InferenceEngine {
21 
22 /**
23  * @brief Minimum implementation of IExecutableNetworkInternal interface. Must not be used as a base class in plugins
24  * As base classes, use ExecutableNetworkThreadSafeDefault or ExecutableNetworkThreadSafeAsyncOnly
25  * @ingroup ie_dev_api_exec_network_api
26  */
28 public:
29  /**
30  * @brief A shared pointer to ExecutableNetworkInternal object
31  */
32  typedef std::shared_ptr<ExecutableNetworkInternal> Ptr;
33 
34  /**
35  * @brief Sets the network inputs info.
36  * @param[in] networkInputs The network inputs info
37  */
38  virtual void setNetworkInputs(const InferenceEngine::InputsDataMap networkInputs) {
39  _networkInputs = networkInputs;
40  }
41 
42  /**
43  * @brief Sets the network outputs data.
44  * @param[in] networkOutputs The network outputs
45  */
46  virtual void setNetworkOutputs(const InferenceEngine::OutputsDataMap networkOutputs) {
47  _networkOutputs = networkOutputs;
48  }
49 
51  ConstOutputsDataMap outputMap;
52  for (const auto& output : _networkOutputs) {
53  outputMap[output.first] = output.second;
54  }
55  return outputMap;
56  }
57 
58  ConstInputsDataMap GetInputsInfo() const override {
59  ConstInputsDataMap inputMap;
60  for (const auto& input : _networkInputs) {
61  inputMap[input.first] = input.second;
62  }
63  return inputMap;
64  }
65 
66  void Export(const std::string& modelFileName) override {
67  // we need to write to stringstream first
68  // because in case of exception in ExportImpl the file is not created
69  std::stringstream strm;
70  ExportImpl(strm);
71  std::ofstream(modelFileName.c_str()) << strm.rdbuf();
72  }
73 
74  void Export(std::ostream& networkModel) override {
75  std::stringstream strm;
76  strm.write(exportMagic.data(), exportMagic.size());
77  strm << _plugin->GetName() << std::endl;
78  ExportImpl(strm);
79  networkModel << strm.rdbuf();
80  }
81 
83  THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
84  }
85 
86  /**
87  * @brief Sets the pointer to plugin internal.
88  * @param[in] plugin The plugin
89  * @note Needed to correctly handle ownership between objects.
90  */
92  _plugin = plugin;
93  }
94 
95  std::vector<IVariableStateInternal::Ptr> QueryState() override {
96  THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
97  }
98 
99  void SetConfig(const std::map<std::string, Parameter>& config) override {
100  if (config.empty()) {
101  THROW_IE_EXCEPTION << "The list of configuration values is empty";
102  }
103  THROW_IE_EXCEPTION << "The following config value cannot be changed dynamically for ExecutableNetwork: "
104  << config.begin()->first;
105  }
106 
107  Parameter GetConfig(const std::string& name) const override {
108  (void)name;
109  THROW_IE_EXCEPTION << "GetConfig for executable network is not supported by this device";
110  }
111 
112  Parameter GetMetric(const std::string& name) const override {
113  (void)name;
114  THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
115  }
116 
117  RemoteContext::Ptr GetContext() const override {
118  THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
119  }
120 
121 protected:
122  /**
123  * @brief Exports an internal hardware-dependent model to a stream.
124  * @note The function is called from ExecutableNetworkInternal::Export(std::ostream&),
125  * which performs common export first and calls this plugin-dependent implementation after.
126  * @param networkModel A stream to export network to.
127  */
128  virtual void ExportImpl(std::ostream& networkModel) {
129  (void)networkModel;
130  THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
131  }
132 
133  InferenceEngine::InputsDataMap _networkInputs; //!< Holds infromation about network inputs info
134  InferenceEngine::OutputsDataMap _networkOutputs; //!< Holds information about network outputs data
135 
136  /**
137  * @brief A pointer to a IInferencePlugin interface.
138  * @note Needed to correctly handle ownership between objects.
139  */
141 };
142 
143 } // namespace InferenceEngine
Minimum implementation of IExecutableNetworkInternal interface. Must not be used as a base class in p...
Definition: ie_executable_network_internal.hpp:27
virtual void setNetworkOutputs(const InferenceEngine::OutputsDataMap networkOutputs)
Sets the network outputs data.
Definition: ie_executable_network_internal.hpp:46
ConstOutputsDataMap GetOutputsInfo() const override
Gets the Executable network output Data node information. The received info is stored in the given Da...
Definition: ie_executable_network_internal.hpp:50
IInferencePlugin::Ptr _plugin
A pointer to a IInferencePlugin interface.
Definition: ie_executable_network_internal.hpp:140
ConstInputsDataMap GetInputsInfo() const override
Gets the Executable network input Data node information. The received info is stored in the given Inp...
Definition: ie_executable_network_internal.hpp:58
virtual void ExportImpl(std::ostream &networkModel)
Exports an internal hardware-dependent model to a stream.
Definition: ie_executable_network_internal.hpp:128
CNNNetwork GetExecGraphInfo() override
Get executable graph information from a device.
Definition: ie_executable_network_internal.hpp:82
RemoteContext::Ptr GetContext() const override
Gets the remote context.
Definition: ie_executable_network_internal.hpp:117
std::shared_ptr< ExecutableNetworkInternal > Ptr
A shared pointer to ExecutableNetworkInternal object.
Definition: ie_executable_network_internal.hpp:32
void Export(const std::string &modelFileName) override
Export the current created executable network so it can be used later in the Import() main API.
Definition: ie_executable_network_internal.hpp:66
std::vector< IVariableStateInternal::Ptr > QueryState() override
Queries memory states.
Definition: ie_executable_network_internal.hpp:95
virtual void setNetworkInputs(const InferenceEngine::InputsDataMap networkInputs)
Sets the network inputs info.
Definition: ie_executable_network_internal.hpp:38
InferenceEngine::InputsDataMap _networkInputs
Holds infromation about network inputs info.
Definition: ie_executable_network_internal.hpp:133
void SetPointerToPlugin(IInferencePlugin::Ptr plugin)
Sets the pointer to plugin internal.
Definition: ie_executable_network_internal.hpp:91
Parameter GetMetric(const std::string &name) const override
Gets general runtime metric for dedicated hardware.
Definition: ie_executable_network_internal.hpp:112
InferenceEngine::OutputsDataMap _networkOutputs
Holds information about network outputs data.
Definition: ie_executable_network_internal.hpp:134
void SetConfig(const std::map< std::string, Parameter > &config) override
Sets configuration for current executable network.
Definition: ie_executable_network_internal.hpp:99
Parameter GetConfig(const std::string &name) const override
Gets configuration dedicated to plugin behaviour.
Definition: ie_executable_network_internal.hpp:107
void Export(std::ostream &networkModel) override
Export the current created executable network so it can be used later in the Import() main API.
Definition: ie_executable_network_internal.hpp:74
An internal API of executable network to be implemented by plugin, which is used in ExecutableNetwork...
Definition: ie_iexecutable_network_internal.hpp:23
std::shared_ptr< IInferencePlugin > Ptr
A shared pointer to IInferencePlugin interface.
Definition: ie_iplugin_internal.hpp:125
std::shared_ptr< RemoteContext > Ptr
#define THROW_IE_EXCEPTION_WITH_STATUS(__status)
Throws an exception along with the status (which is eventually converted to the typed exception)
Definition: exception2status.hpp:19
constexpr static const ExportMagic exportMagic
Magic number used by ie core to identify exported network with plugin name.
Definition: ie_icore.hpp:119
#define THROW_IE_EXCEPTION
Inference Engine plugin API wrapper, to be used by particular implementors.
Inference Engine Plugin API namespace.
std::map< std::string, InputInfo::Ptr > InputsDataMap
std::map< std::string, CDataPtr > ConstOutputsDataMap
std::map< std::string, InputInfo::CPtr > ConstInputsDataMap
std::map< std::string, DataPtr > OutputsDataMap