blob: 4f69442b488f73ba35e8035e3a9b1a2f321bf43e [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_ITENSORINFO_H__
25#define __ARM_COMPUTE_ITENSORINFO_H__
26
27#include "arm_compute/core/Coordinates.h"
28#include "arm_compute/core/Strides.h"
29#include "arm_compute/core/TensorShape.h"
30#include "arm_compute/core/Types.h"
31#include "arm_compute/core/Utils.h"
Georgios Pinitas283c1792017-11-10 18:14:06 +000032#include "arm_compute/core/utils/misc/ICloneable.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
34#include <cstddef>
35
36namespace arm_compute
37{
38/** Store the tensor's metadata */
Georgios Pinitas283c1792017-11-10 18:14:06 +000039class ITensorInfo : public misc::ICloneable<ITensorInfo>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040{
41public:
42 /** Default virtual destructor */
43 virtual ~ITensorInfo() = default;
44 /** Set the data type to the specified value.
45 *
46 * @warning This resets the format to UNKNOWN.
47 *
48 * @param[in] data_type The new data type.
Georgios Pinitas283c1792017-11-10 18:14:06 +000049 *
50 * @return Reference to this ITensorInfo object
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051 */
Georgios Pinitas283c1792017-11-10 18:14:06 +000052 virtual ITensorInfo &set_data_type(DataType data_type) = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 /** Set the number of channels to the specified value.
54 *
55 * @warning This resets the format to UNKNOWN.
56 *
57 * @param[in] num_channels New number of channels.
Georgios Pinitas283c1792017-11-10 18:14:06 +000058 *
59 * @return Reference to this ITensorInfo object
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 */
Georgios Pinitas283c1792017-11-10 18:14:06 +000061 virtual ITensorInfo &set_num_channels(int num_channels) = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 /** Set the format of an already initialized tensor.
63 *
64 * @note If the data type has already been configured (i.e. not UNKNOWN) it
65 * must match the new format. If data type hasn't been configured it will
66 * be based on the format.
67 *
68 * @param[in] format Single-plane format of the tensor.
Georgios Pinitas283c1792017-11-10 18:14:06 +000069 *
70 * @return Reference to this ITensorInfo object
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 */
Georgios Pinitas283c1792017-11-10 18:14:06 +000072 virtual ITensorInfo &set_format(Format format) = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 /** Set the shape of an already initialized tensor.
74 *
75 * @warning Changing the shape requires to recompute the strides and is
76 * therefore only possible if the tensor hasn't been allocated yet.
77 *
78 * @param[in] shape New tensor shape.
Georgios Pinitas283c1792017-11-10 18:14:06 +000079 *
80 * @return Reference to this ITensorInfo object
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 */
Georgios Pinitas283c1792017-11-10 18:14:06 +000082 virtual ITensorInfo &set_tensor_shape(TensorShape shape) = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083 /** Set the fixed point position to the specified value
84 *
85 * @warning The fixed point position must be set once the data type has been configured
86 *
87 * @param[in] fixed_point_position The new fixed point position
Georgios Pinitas283c1792017-11-10 18:14:06 +000088 *
89 * @return Reference to this ITensorInfo object
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090 */
Georgios Pinitas283c1792017-11-10 18:14:06 +000091 virtual ITensorInfo &set_fixed_point_position(int fixed_point_position) = 0;
92 /** Set the quantization settings (scale and offset) of the tensor.
93 *
94 * @param[in] quantization_info QuantizationInfo containing the scale and offset
95 *
96 * @return Reference to this ITensorInfo object
97 */
98 virtual ITensorInfo &set_quantization_info(QuantizationInfo quantization_info) = 0;
Georgios Pinitas30902ed2017-11-14 15:32:57 +000099 /** Resets the padding settings of the tensor.
100 *
101 * @return Reference to this ITensorInfo object
102 */
103 virtual ITensorInfo &reset_padding() = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104 /** Update the offset to the first element and the strides to automatically computed values.
105 *
106 * @note The padding used by this method is really conservative so that the tensor can be used for most functions.
107 *
108 * @return True if the strides or the offset to the first element have changed.
109 */
110 virtual bool auto_padding() = 0;
111 /** Update the offset to the first element, the strides and the total size.
112 *
113 * @note This function can only increase the offset, strides and total size.
114 *
115 * @param[in] padding Padding around the XY plane in number of elements.
116 *
117 * @return True if the strides, offset and total size have changed.
118 */
119 virtual bool extend_padding(const PaddingSize &padding) = 0;
120 /** Return the size of the requested dimension
121 *
122 * @param[in] index Index of the dimension
123 *
124 * @return Dimension of the requested dimension
125 */
126 virtual size_t dimension(size_t index) const = 0;
127 /** The strides in bytes for accessing each dimension of the tensor
128 *
129 * @return Strides in bytes for each tensor dimension
130 */
131 virtual const Strides &strides_in_bytes() const = 0;
132 /** The offset from the beginning of the memory allocation to the first element of the tensor.
133 * This can be used to access efficiently elements in a 2D tensor
134 *
135 * @return The offset in bytes to access the first element of the tensor.
136 */
137 virtual size_t offset_first_element_in_bytes() const = 0;
138 /** The offset in bytes from the beginning of the memory allocation to access the element at position (x, y, z ...)
139 *
140 * @param[in] pos Vector with the coordinates of the element to access.
141 * The size of this vector must be equal to the number of dimensions of the tensor
142 *
143 * @return Offset in bytes from the beginning of the memory allocation to access the element (x, y, z, ...)
144 */
145 virtual size_t offset_element_in_bytes(const Coordinates &pos) const = 0;
146 /** Fixed point position used when the tensor data type is QS8 or QS16
147 *
148 * @return The fixed point position that expresses the number of bits for the fractional part of the number
149 */
150 virtual int fixed_point_position() const = 0;
151 /** Element size in bytes calculated as data_size() * num_channels()
152 *
153 * @return The size of one element in bytes
154 */
155 virtual size_t element_size() const = 0;
156 /** The number of dimensions of the tensor (rank)
157 *
158 * @return The number of dimensions of the tensor (rank)
159 */
160 virtual size_t num_dimensions() const = 0;
161 /** The number of channels for each tensor element
162 *
163 * @return The number of channels for each tensor element
164 */
165 virtual size_t num_channels() const = 0;
166 /** Size for each dimension of the tensor
167 *
168 * @return A vector with the size for each dimension of the tensor
169 */
170 virtual const TensorShape &tensor_shape() const = 0;
171 /** Data type used for each element of the tensor
172 *
173 * @return Tensor data type
174 */
175 virtual DataType data_type() const = 0;
176 /** Colour format of the image
177 *
178 * @return Colour format of the image
179 */
180 virtual Format format() const = 0;
181 /** Returns the total size of the tensor in bytes.
182 *
183 * @return Total size of the tensor in bytes.
184 */
185 virtual size_t total_size() const = 0;
186 /** Padding of tensor.
187 *
188 * @return Padding.
189 */
190 virtual PaddingSize padding() const = 0;
191 /** Checks if the tensor has been allocated with padding or not.
192 *
193 * @return True if padding is allocated in the tensor, otherwise false.
194 */
195 virtual bool has_padding() const = 0;
196 /** Flag indicating whether the size of the tensor can be changed.
197 *
198 * @return True if the tensor size can be changed.
199 */
200 virtual bool is_resizable() const = 0;
201 /** Set the flag whether the tensor size can be changed.
202 *
203 * @param[in] is_resizable Flag that marks the tensor if it can be changed or not.
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000204 *
205 * @return Reference to this ITensorInfo object
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100206 */
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000207 virtual ITensorInfo &set_is_resizable(bool is_resizable) = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208 /** Valid region of the tensor. All elements in the valid region have defined values, i.e. are not undefined.
209 *
210 * @return The valid region.
211 */
212 virtual ValidRegion valid_region() const = 0;
213 /** Set the valid region of the tensor.
214 *
215 * @param[in] valid_region Valid region to set.
216 */
217 virtual void set_valid_region(ValidRegion valid_region) = 0;
Michel Iwaniec00633802017-10-12 14:14:15 +0100218
219 /** Get the quantization settings (scale and offset) of the tensor.
220 *
221 * @return A QuantizationInfo containing the scale and offset.
222 */
223 virtual QuantizationInfo quantization_info() const = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224};
225}
226#endif /*__ARM_COMPUTE_TENSORINFO_H__ */