1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief a header file for the Inference Engine Network interface
7 * @file ie_inetwork.hpp
16 #include <ie_parameter.hpp>
17 #include <ie_context.hpp>
18 #include <ie_layouts.h>
21 namespace InferenceEngine {
24 * @brief A type of network objects indexes.
29 * @brief This class contains a pair from layerId and port index
34 * @brief The constructor creates a PortInfo object for port 0
35 * @param layerID Layer id
37 PortInfo(idx_t layerID): layer(layerID), port(0) {} // NOLINT
40 * @brief The constructor creates a PortInfo object
41 * @param layerID Layer id
42 * @param portID Port id
44 PortInfo(idx_t layerID, idx_t portID): layer(layerID), port(portID) {}
50 idx_t layerId() const {
58 idx_t portId() const {
63 * @brief Compares the given PortInfo object with the current one
64 * @param portInfo PortInfo object to compare with
65 * @return true if the given PortInfo object is equal to the current one, false - otherwise
67 bool operator==(const PortInfo& portInfo) const {
68 return layer == portInfo.layerId() && port == portInfo.portId();
72 * @brief Checks if the given PortInfo object is not equal to the current one
73 * @param portInfo PortInfo object to compare with
74 * @return true if the given PortInfo object is not equal to the current one, false - otherwise
76 bool operator!=(const PortInfo& portInfo) const {
77 return !(*this == portInfo);
86 * @brief This class is the main object to describe the Inference Engine connection.
91 * @brief Constructor of a connection object.
92 * @param input pair of the index of input layer and the index of output port
93 * @param output pair of the index of output layer and the index of input port
95 Connection(const PortInfo& input, const PortInfo& output): input(input), output(output) {}
98 * @brief Compares the given Connection with the current one
99 * @param connection Connection to compare with
100 * @return true if the given Connection is equal to the current one, false - otherwise
102 bool operator==(const Connection& connection) const {
103 return input == connection.from() && output == connection.to();
107 * @brief Checks if the given Connection is not equal to the current one
108 * @param connection Connection to compare with
109 * @return true if the given Connection is not equal to the current one, false - otherwise
111 bool operator!=(const Connection& connection) const {
112 return !(*this == connection);
116 * Returns a constant reference to a pair of input layer index and output port index.
117 * @return pair of the index of input layer and the index of output port
119 const PortInfo& from() const {
124 * Returns a constant reference to a pair of output layer index and input port index.
125 * @return pair of the index of output layer and the index of input port
127 const PortInfo& to() const {
137 * @brief This class is the main object to describe the Inference Engine port.
142 * @brief Default constructor of a port object.
146 * @brief Constructor of a port object with shapes.
147 * @param shapes port shapes
149 explicit Port(const SizeVector& shapes): pShapes(shapes) {}
152 * @brief Copy constructor.
153 * @param port object to copy
155 Port(const Port& port) {
156 this->pShapes = port.pShapes;
160 * @brief Returns a constant reference to a vector with shapes.
161 * Shapes should be initialized if shape is empty.
162 * @return constant reference to shapes
164 const SizeVector& shape() const noexcept {
169 * @brief Returns a reference to a vector with shapes.
170 * Shapes should be initialized if shape is empty.
171 * @return reference to shapes
173 SizeVector& shape() noexcept {
182 * @brief This class is the main interface to describe the Inference Engine layer parameters.
183 * All methods here are constant and do not throw exceptions.
188 * @brief A shared pointer to the IParameters object.
190 using Ptr = std::shared_ptr<IParameters>;
193 * @brief Virtual destructor for the parameters interface
195 virtual ~IParameters() = default;
198 * @brief Returns a constant reference to a map with parameters.
199 * @return Map of parameters
201 virtual const std::map<std::string, Parameter>& getParameters() const noexcept = 0;
204 * @brief Returns a constant reference to a constant pointers to constant data.
205 * @return Map of constant pointers to constant data
207 virtual const std::map<std::string, Blob::CPtr>& getConstantData() const noexcept = 0;
212 class INetwotkIterator;
215 * @brief This class is the main interface to describe the Inference Engine layer.
216 * All methods here are constant and do not throw exceptions.
221 * @brief A shared pointer to the ILayer object
223 using Ptr = std::shared_ptr<ILayer>;
225 * @brief A shared pointer to the const ILayer object
227 using CPtr = std::shared_ptr<const ILayer>;
230 * @brief Virtual destructor for the layer interface
232 virtual ~ILayer() = default;
235 * @brief Returns a id of the layer.
238 virtual idx_t getId() const noexcept = 0;
241 * @brief Returns a layer name.
244 virtual const std::string& getName() const noexcept = 0;
247 * @brief Returns a layer type.
250 virtual const std::string& getType() const noexcept = 0;
253 * @brief Returns a constant smart pointer reference to a Network interface.
254 * @return Network interface smart pointer
256 virtual const std::shared_ptr<INetwork>& getGraph() const noexcept = 0;
259 * @brief Returns a constant smart pointer reference to a Parameters interface.
260 * @return Parameters interface smart pointer
262 virtual const IParameters::Ptr& getParameters() const noexcept = 0;
265 * @brief Returns a constant reference to a vector with input ports.
266 * @return Vector of input ports
268 virtual const std::vector<Port>& getInputPorts() const noexcept = 0;
271 * @brief Returns a constant reference to a vector with output ports.
272 * @return Vector of output ports
274 virtual const std::vector<Port>& getOutputPorts() const noexcept = 0;
279 template<class NT, class LT>
280 class INetworkIterator;
282 } // namespace details
285 * @brief This class is the main interface to describe the Inference Engine network.
287 * All methods here are constant and do not throw exceptions.
292 * @brief A shared pointer to the INetwork object.
294 using Ptr = std::shared_ptr<INetwork>;
296 * @brief A constant iterator for INetwork objects definition
298 using const_iterator = details::INetworkIterator<const INetwork, const ILayer>;
301 * @brief Virtual destructor for the network interface
303 virtual ~INetwork() = default;
306 * @brief Begin network iterator
307 * @return const INetwork iterator
309 virtual const_iterator begin() const noexcept = 0;
312 * @brief End network iterator
313 * @return const INetwork iterator
315 virtual const_iterator end() const noexcept = 0;
318 * @brief Returns a number of layers in the network.
319 * @return Layers count
321 virtual size_t size() const noexcept = 0;
324 * @brief Returns a constant smart pointer to a Layer interface.
325 * If the layer is missing, returns nullptr.
326 * @param id Id of the Layer
327 * @return Layer interface smart pointer
329 virtual const ILayer::Ptr getLayer(idx_t id) const noexcept = 0;
332 * @brief Returns a constant vector of input layers.
333 * @return Vector of input layers
335 virtual const std::vector<ILayer::Ptr> getInputs() const noexcept = 0;
338 * @brief Returns a constant vector of output layers.
339 * @return Vector of output layers
341 virtual const std::vector<ILayer::Ptr> getOutputs() const noexcept = 0;
344 * @brief Returns a constant vector of connections for specific layer.
345 * If the layer is missing, returns empty vector.
346 * @param layerId layer index
347 * @return Vector of connections
349 virtual const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept = 0;
352 * @brief Returns a network name.
353 * @return Network name
355 virtual const std::string& getName() const noexcept = 0;
358 * @brief Returns a network context
359 * @return const reference to Context
361 virtual const Context& getContext() const noexcept = 0;
364 } // namespace InferenceEngine
366 #include <details/ie_inetwork_iterator.hpp>