Publishing 2020.1 content
[platform/upstream/dldt.git] / inference-engine / include / ie_data.h
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 &name, const TensorDesc& desc) as a replacement."
51                                 "The ctor will be removed in 2020 R2")
52     Data(const std::string& name, const SizeVector& a_dims, Precision _precision, Layout layout = NCHW);
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      * @return owner of this data layer, parent layer in di-graph
130      */
131     virtual CNNLayerWeakPtr& getCreatorLayer();
132
133     /**
134      * @return name of the data object
135      */
136     const std::string& getName() const;
137
138     /**
139      * @brief Sets a name the Data object
140      *
141      * @param newName Name of the data node
142      */
143
144     void setName(const std::string& newName);
145
146     /**
147      * @brief returns child layers in di-graph
148      */
149     virtual std::map<std::string, CNNLayerPtr>& getInputTo();
150
151     /**
152      * @return convenient arbitrary user data holder
153      */
154     const UserValue& getUserObject() const;
155
156 private:
157     /**
158      * @brief A pointer to the layer that creates this data element, null for input data elements
159      */
160     CNNLayerWeakPtr creatorLayer;
161
162     /**
163      * @brief A unique name that identifies this data node
164      */
165     std::string name;
166
167     /**
168      * @brief A map of layers that use this node as input.
169      * It is useful for recursive NN graph traversal.
170      */
171     std::map<std::string, CNNLayerPtr> inputTo;
172
173     /**
174      * @brief A user utility place holder
175      */
176     UserValue userObject;
177
178     /**
179      * @brief A tensor descriptor
180      */
181     mutable TensorDesc tensorDesc;
182 };
183 }  // namespace InferenceEngine