1 // Copyright (C) 2018-2019 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 * This class describes port data
139 class INFERENCE_ENGINE_API_CLASS(PortData) {
142 * @brief A shared pointer to the PortData object.
144 using Ptr = std::shared_ptr<PortData>;
147 * @brief Default constructor
152 * Creates port data with precision and shape
153 * @param shape Dimensions
154 * @param precision Precision
156 PortData(const SizeVector& shape, const Precision& precision);
159 * @brief virtual destructor
161 virtual ~PortData() = default;
164 * @brief Returns data
165 * @return Blob with data
167 const Blob::Ptr& getData() const;
171 * @param data Blob with data
173 void setData(const Blob::Ptr& data);
176 * @brief Returns data parameters
177 * @return Map of parameters
179 const std::map<std::string, Parameter>& getParameters() const noexcept;
182 * @brief Sets new shapes for data
183 * @param shape New shapes
185 void setShape(const SizeVector& shape);
189 std::map<std::string, Parameter> parameters;
191 void createData(const TensorDesc& desc);
195 * @brief This class is the main object to describe the Inference Engine port.
197 class INFERENCE_ENGINE_API_CLASS(Port) {
200 * @brief Default constructor of a port object.
204 * @brief Constructor of a port object with shapes.
205 * @param shapes port shapes
206 * @param precision Port precision
208 explicit Port(const SizeVector& shapes,
209 const Precision& precision = Precision::UNSPECIFIED);
212 * @brief Copy constructor.
213 * @param port object to copy
215 Port(const Port& port);
218 * @brief Virtual destructor
220 virtual ~Port() = default;
223 * @brief Compares the given Port with the current one
224 * @param rhs Port to compare with
225 * @return true if the given Port is equal to the current one, false - otherwise
227 bool operator== (const Port& rhs) const;
230 * @brief Compares the given Port with the current one
231 * @param rhs Port to compare with
232 * @return true if the given Port is NOT equal to the current one, false - otherwise
234 bool operator!= (const Port& rhs) const;
237 * @brief Returns a constant reference to a vector with shapes.
238 * Shapes should be initialized if shape is empty.
239 * @return constant reference to shapes
241 const SizeVector& shape() const noexcept;
244 * @brief Sets new shapes for current port
245 * @param shape New shapes
247 void setShape(const SizeVector& shape);
250 * @brief Returns a constant reference to parameters
251 * @return Map with parameters
253 const std::map<std::string, Parameter>& getParameters() const noexcept;
256 * @brief Sets new parameters for current port
257 * @param params New parameters
259 void setParameters(const std::map<std::string, Parameter>& params) noexcept;
262 * @brief Sets the new parameter for current port
263 * @param name Name of parameter
264 * @param param New value
266 void setParameter(const std::string& name, const Parameter& param);
269 * @brief Returns port data
272 const PortData::Ptr& getData() const noexcept;
275 * @brief Sets new port data for current port
276 * @param data Port data
278 void setData(const PortData::Ptr& data);
281 std::map<std::string, Parameter> parameters;
287 class INetwotkIterator;
290 * @brief This class is the main interface to describe the Inference Engine layer.
291 * All methods here are constant and do not throw exceptions.
296 * @brief A shared pointer to the const ILayer object
298 using CPtr = std::shared_ptr<const ILayer>;
301 * @brief Virtual destructor for the layer interface
303 virtual ~ILayer() = default;
306 * @brief Returns a id of the layer.
309 virtual idx_t getId() const noexcept = 0;
312 * @brief Returns a layer name.
315 virtual const std::string& getName() const noexcept = 0;
318 * @brief Returns a layer type.
321 virtual const std::string& getType() const noexcept = 0;
324 * @brief Returns a constant smart pointer reference to a Parameters interface.
325 * @return Parameters interface smart pointer
327 virtual const std::map<std::string, Parameter>& getParameters() const noexcept = 0;
330 * @brief Returns a constant reference to a vector with input ports.
331 * @return Vector of input ports
333 virtual const std::vector<Port>& getInputPorts() const noexcept = 0;
336 * @brief Returns a constant reference to a vector with output ports.
337 * @return Vector of output ports
339 virtual const std::vector<Port>& getOutputPorts() const noexcept = 0;
344 template<class NT, class LT>
345 class INetworkIterator;
347 } // namespace details
350 * @brief This class is the main interface to describe the Inference Engine network.
352 * All methods here are constant and do not throw exceptions.
357 * @brief A shared pointer to the constant INetwork object.
359 using CPtr = std::shared_ptr<const INetwork>;
361 * @brief A constant iterator for INetwork definition
363 using const_iterator = details::INetworkIterator<const INetwork, const ILayer>;
366 * @brief Virtual destructor for the network interface
368 virtual ~INetwork() = default;
371 * @brief Begin network iterator
372 * @return const INetwork iterator
374 virtual const_iterator begin() const noexcept = 0;
377 * @brief End network iterator
378 * @return const INetwork iterator
380 virtual const_iterator end() const noexcept = 0;
383 * @brief Returns a number of layers in the network.
384 * @return Layers count
386 virtual size_t size() const noexcept = 0;
389 * @brief Returns a constant smart pointer to a Layer interface.
390 * If the layer is missing, returns nullptr.
391 * @param id Id of the Layer
392 * @return Layer interface smart pointer
394 virtual const ILayer::CPtr getLayer(idx_t id) const noexcept = 0;
397 * @brief Returns a constant vector of input layers.
398 * @return Vector of input layers
400 virtual const std::vector<ILayer::CPtr> getInputs() const noexcept = 0;
403 * @brief Returns a constant vector of output layers.
404 * @return Vector of output layers
406 virtual const std::vector<ILayer::CPtr> getOutputs() const noexcept = 0;
409 * @brief Returns a constant vector of connections for specific layer.
410 * If the layer is missing, returns empty vector.
411 * @param layerId layer index
412 * @return Vector of connections
414 virtual const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept = 0;
417 * @brief Returns a network name.
418 * @return Network name
420 virtual const std::string& getName() const noexcept = 0;
423 * @brief Returns a network context
424 * @return const reference to Context
426 virtual const Context& getContext() const noexcept = 0;
429 } // namespace InferenceEngine
431 #include <details/ie_inetwork_iterator.hpp>