1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief A header file for data layouts and conversion between them
15 #include "ie_common.h"
16 #include "ie_precision.hpp"
18 namespace InferenceEngine {
21 * @brief This class describes blocking layouts
23 class INFERENCE_ENGINE_API_CLASS(BlockingDesc) {
26 * @brief The default constructor which creates empty blocking descriptor
30 * @brief The constructor which allows to create blocking descriptors for standard layouts
32 * @param dims real dimensions
33 * @param layout memory layout
35 BlockingDesc(const SizeVector& dims, Layout layout);
37 * @brief The constructor allows to create blocking descriptors for blocked memory
39 * @param blocked_dims blocked dimensions
40 * @param order the order of dimensions
42 BlockingDesc(const SizeVector& blocked_dims, const SizeVector& order);
44 * @brief The constructor allows to create blocking descriptors for blocked memory
46 * @param blocked_dims blocked dimensions
47 * @param order the order of dimensions
48 * @param offset offset to the current memory block
50 BlockingDesc(const SizeVector& blocked_dims, const SizeVector& order, size_t offset);
52 * @brief The constructor allows to create blocking descriptors for blocked memory
54 * @param blocked_dims blocked dimensions
55 * @param order the order of dimensions
56 * @param offset offset to the current memory block
57 * @param dimOffsets per-dimension offset from the padding to actual data,
59 BlockingDesc(const SizeVector& blocked_dims, const SizeVector& order, size_t offset, const SizeVector& dimOffsets);
61 * @brief The constructor allows to create blocking descriptors for blocked memory
63 * @param blocked_dims blocked dimensions
64 * @param order the order of dimensions
65 * @param offset offset to the current memory block
66 * @param dimOffsets per-dimension offset from the padding to actual data,
67 * @param strides strides for each dimension
69 BlockingDesc(const SizeVector& blocked_dims, const SizeVector& order, size_t offset,
70 const SizeVector& dimOffsets, const SizeVector& strides);
73 * @brief Returns the blocked dimensions vector
75 * @return blocked dimensions
77 const SizeVector& getBlockDims() const {
82 * @brief Returns the vector of order
86 const SizeVector& getOrder() const {
91 * @brief Returns the per-dimension offset vector
95 const SizeVector& getOffsetPaddingToData() const {
96 return offsetPaddingToData;
100 * @brief Returns the offset to the current memory block
104 size_t getOffsetPadding() const {
105 return offsetPadding;
109 * @brief Returns strides for each dimension
113 const SizeVector& getStrides() const {
118 * @brief The comparison operator for the BlockingDesc
120 * @param rhs object to compare
121 * @return true if objects are equal
123 bool operator==(const BlockingDesc& rhs) const;
125 * @brief The comparison operator for the BlockingDesc
127 * @param rhs object to compare
128 * @return true if objects aren't equal
130 bool operator!=(const BlockingDesc& rhs) const;
133 void fillDesc(const SizeVector& blocked_dims, const SizeVector& order);
136 /** Blocked dimensions. */
137 SizeVector blockedDims;
138 /** Strides for blocked dimensions */
140 /** The order of blocked dimensions **/
142 /** Per-dimension offset from the padding to actual data, the top-level
143 * tensor with offsets applied must lie within the padding area. */
144 SizeVector offsetPaddingToData;
145 /** Offset from memory origin to the current block, non-zero only in
146 * a description of a memory sub-block. */
147 size_t offsetPadding;
151 * @brief This class defines Tensor description
153 class INFERENCE_ENGINE_API_CLASS(TensorDesc) {
156 * @brief The constructor creates the tensor descriptor using blocking descriptor
158 * @param precision memory precision
159 * @param dims memory dimensions
160 * @param blockDesc blocking descriptor
162 TensorDesc(const Precision& precision, const SizeVector& dims, const BlockingDesc& blockDesc);
164 * @brief The constructor creates the tensor descriptor using standard layout
166 * @param precision memory precision
167 * @param dims memory dimensions
168 * @param layout memory layout
170 TensorDesc(const Precision& precision, const SizeVector& dims, Layout layout);
172 * @brief The constructor creates the empty tensor descriptor with precision and layout
174 * @param precision memory precision
175 * @param layout memory layout
177 TensorDesc(const Precision& precision, Layout layout);
179 * @brief The default constructor which creates empty tensor descriptor
184 * @brief Reshapes the tensor descriptor
186 * @param dims new dimensions
187 * @param layout new layout if it is necessary
189 void reshape(const SizeVector& dims, Layout layout = Layout::ANY);
191 * @brief Reshapes the tensor descriptor
193 * @param dims new dimensions
194 * @param blockDesc new blocking descriptor
196 void reshape(const SizeVector& dims, const BlockingDesc& blockDesc);
199 * @brief Returns the vector of dimensions
203 SizeVector& getDims() {
207 * @brief Returns the constant vector of dimensions
211 const SizeVector& getDims() const noexcept {
215 * @brief Sets dimensions
217 * @param dims new dimensions
219 void setDims(const SizeVector& dims);
222 * @brief Returns the memory layout
226 Layout getLayout() const {
231 * @brief Sets the layout
233 * @param l memory layout
235 void setLayout(Layout l);
238 * @brief Returns the memory precision
242 const Precision& getPrecision() const {
247 * @brief Sets the memory precision
251 void setPrecision(const Precision& p) {
256 * @brief Returns the blocking descriptor
258 * @return blocking descriptor
260 const BlockingDesc& getBlockingDesc() const {
265 * @brief The comparison operator for the TensorDesc
267 * @param rhs object to compare
268 * @return true if objects are equal
270 bool operator==(const TensorDesc& rhs) const;
272 * @brief The comparison operator for the TensorDesc
274 * @param rhs object to compare
275 * @return true if objects aren't equal
277 bool operator!=(const TensorDesc& rhs) const;
280 * @brief Calculates offset for the vector of dimensions
282 * @param v vector of dimensions
285 size_t offset(const SizeVector& v) const;
287 * @brief Calculates offset for the local offset
289 * @param l local offset
292 size_t offset(size_t l) const;
295 * @brief Returns the standard layout for dimensions
297 * @param dims the vector of dimensions
298 * @return the standard memory layout
300 static Layout getLayoutByDims(const SizeVector& dims);
308 * @brief blob's dimensions
312 * @brief memory precision
316 * Detailed information about layout construction
318 BlockingDesc blockingDesc;
321 } // namespace InferenceEngine