ie_data.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief This header file defines the main Data representation node.
7  *
8  * @file ie_data.h
9  */
10 #pragma once
11 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "details/ie_exception.hpp"
18 #include "ie_api.h"
19 #include "ie_common.h"
20 #include "ie_layouts.h"
21 #include "ie_precision.hpp"
22 
23 namespace InferenceEngine {
24 /**
25  * @brief This class represents the main Data representation node.
26  *
27  * The NN graphs are di-graphs consisting of data nodes and layer nodes.
28  */
29 
30 class INFERENCE_ENGINE_API_CLASS(Data) {
31 public:
32  /**
33  * @brief An empty constructor (dimensionless)
34  *
35  * @param name Name of the data node
36  * @param _precision Precision of the data
37  * @param layout Data layout
38  */
39  Data(const std::string& name, Precision _precision, Layout layout = NCHW);
40 
41  /**
42  * @deprecated Use Data(const std::string &name, const TensorDesc& desc)
43  * @brief A full constructor (with dimensions)
44  *
45  * @param name Name of the data node
46  * @param a_dims Data tensor dimensions
47  * @param _precision Precision of the data
48  * @param layout Data layout
49  */
50  INFERENCE_ENGINE_DEPRECATED("Use Data(const std::string &, const TensorDesc&). The ctor will be removed in 2021.1")
51  Data(const std::string& name, const SizeVector& a_dims, Precision _precision, Layout layout = NCHW);
52 
53  /**
54  * @brief A constructor with tensor descriptor
55  *
56  * @param name Name of the data node
57  * @param desc Tensor descriptor
58  */
59  Data(const std::string& name, const TensorDesc& desc);
60 
61  /**
62  * @brief A virtual destructor
63  */
64  virtual ~Data() = default;
65 
66  /**
67  * @brief Checks if the current node is resolved
68  *
69  * @return true if resolved, false otherwise.
70  */
71  bool isInitialized() const;
72 
73  /**
74  * @brief Sets the data dimensions.
75  *
76  * After the current node is marked as resolved.
77  *
78  * @param a_dims Tensor dimensions to set
79  */
80  void setDims(const SizeVector& a_dims);
81 
82  /**
83  * @brief Sets the layout value for this Data instance
84  *
85  * @param layout Layout value to set
86  */
87  void setLayout(Layout layout);
88 
89  /**
90  * @brief changes dims and layout at same time
91  *
92  * @param dims new dimensions
93  * @param layout new layout
94  */
95  void reshape(const SizeVector& dims, Layout layout);
96 
97  /**
98  * @brief Gets the layout value for this Data instance
99  */
100  Layout getLayout() const;
101 
102  /**
103  * @brief Gets Tensor descriptor reference
104  *
105  * @return reference to TensorDesc
106  */
107  const TensorDesc& getTensorDesc() const;
108 
109  /**
110  * @brief Gets a precision type of this Data instance
111  *
112  * @return Precision type
113  */
114  const Precision& getPrecision() const;
115 
116  /**
117  * @brief Sets a precision type of this Data instance
118  *
119  * @param precision Precision of the data
120  */
121  void setPrecision(const Precision& precision);
122 
123  /**
124  * @return data dimensions
125  */
126  const SizeVector& getDims() const;
127 
128  /**
129  * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2020.3
130  * @brief Returns an owner of this data layer, parent layer in di-graph
131  * @return A weak pointer to CNNLayer that creates this data
132  */
133  INFERENCE_ENGINE_INTERNAL("Migrate to IR v10 and work with ngraph::Function directly")
134  virtual CNNLayerWeakPtr& getCreatorLayer();
135 
136  /**
137  * @return name of the data object
138  */
139  const std::string& getName() const;
140 
141  /**
142  * @brief Sets a name the Data object
143  *
144  * @param newName Name of the data node
145  */
146 
147  void setName(const std::string& newName);
148 
149  /**
150  * @deprecated Migrate to IR v10 and work with ngraph::Function directly. The method will be removed in 2020.3
151  * @brief Privates child layers in di-graph
152  * @return A map of child layers
153  */
154  INFERENCE_ENGINE_INTERNAL("Migrate to IR v10 and work with ngraph::Function directly")
155  virtual std::map<std::string, CNNLayerPtr>& getInputTo();
156 
157  /**
158  * @return convenient arbitrary user data holder
159  */
160  const UserValue& getUserObject() const;
161 
162 private:
163  /**
164  * @brief A pointer to the layer that creates this data element, null for input data elements
165  */
166  CNNLayerWeakPtr creatorLayer;
167 
168  /**
169  * @brief A unique name that identifies this data node
170  */
171  std::string name;
172 
173  /**
174  * @brief A map of layers that use this node as input.
175  * It is useful for recursive NN graph traversal.
176  */
177  std::map<std::string, CNNLayerPtr> inputTo;
178 
179  /**
180  * @brief A user utility place holder
181  */
182  UserValue userObject;
183 
184  /**
185  * @brief A tensor descriptor
186  */
187  mutable TensorDesc tensorDesc;
188 };
189 } // namespace InferenceEngine
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:79
The method holds the user values to enable binding of data per graph node.
Definition: ie_common.h:69
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
std::string name
Layer name.
Definition: ie_layers.h:42
std::weak_ptr< CNNLayer > CNNLayerWeakPtr
A smart weak pointer to the CNNLayer.
Definition: ie_common.h:43
This class defines Tensor description.
Definition: ie_layouts.h:153
A header file that provides class for describing precision of data.
A header file for data layouts and conversion between them.
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
Precision precision
Layer precision.
Definition: ie_layers.h:52
NCHW layout for input / output blobs.
Definition: ie_common.h:83
std::vector< size_t > SizeVector
Represents tensor size.
Definition: ie_common.h:29
This class represents the main Data representation node.
Definition: ie_data.h:30
This is a header file with common inference engine definitions.
A header file for the main Inference Engine exception.
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:22