Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | b14a0f0 | 2021-01-08 03:14:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | #include "arm_compute/core/TensorInfo.h" |
| 25 | |
| 26 | #include "arm_compute/core/Error.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Helpers.h" |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/TensorInfo.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Validate.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 30 | #include "src/core/helpers/Utils.h" |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 31 | |
| 32 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | |
| 34 | using namespace arm_compute; |
| 35 | |
| 36 | TensorInfo::TensorInfo() |
Georgios Pinitas | b14a0f0 | 2021-01-08 03:14:31 +0000 | [diff] [blame] | 37 | : _total_size(0), _offset_first_element_in_bytes(0), _strides_in_bytes(), _num_channels(0), _tensor_shape(), _dims_state(), _data_type(DataType::UNKNOWN), _format(Format::UNKNOWN), _is_resizable{ true }, |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 38 | _valid_region{ Coordinates(), _tensor_shape }, _padding{ 0 }, _quantization_info(), _data_layout(DataLayout::NCHW) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | { |
| 40 | } |
| 41 | |
| 42 | TensorInfo::TensorInfo(const ITensorInfo &info) |
| 43 | : TensorInfo() |
| 44 | { |
| 45 | _total_size = info.total_size(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | _offset_first_element_in_bytes = info.offset_first_element_in_bytes(); |
| 47 | _strides_in_bytes = info.strides_in_bytes(); |
| 48 | _num_channels = info.num_channels(); |
| 49 | _tensor_shape = info.tensor_shape(); |
Georgios Pinitas | b14a0f0 | 2021-01-08 03:14:31 +0000 | [diff] [blame] | 50 | _dims_state = info.tensor_dims_state(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 51 | _data_type = info.data_type(); |
| 52 | _format = info.format(); |
| 53 | _is_resizable = info.is_resizable(); |
| 54 | _valid_region = info.valid_region(); |
| 55 | _padding = info.padding(); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 56 | _quantization_info = info.quantization_info(); |
Isabella Gottardi | d17a677 | 2018-02-27 17:41:55 +0000 | [diff] [blame] | 57 | _data_layout = info.data_layout(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TensorInfo::TensorInfo(Format format) |
| 61 | : TensorInfo(TensorShape(), format) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | TensorInfo::TensorInfo(unsigned int width, unsigned int height, Format format) |
| 66 | : TensorInfo(TensorShape(width, height), format) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | TensorInfo::TensorInfo(const TensorShape &tensor_shape, Format format) |
| 71 | : TensorInfo() |
| 72 | { |
| 73 | init(tensor_shape, format); |
| 74 | } |
| 75 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 76 | TensorInfo::TensorInfo(size_t num_channels, DataType data_type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 77 | : TensorInfo() |
| 78 | { |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 79 | init(TensorShape(), num_channels, data_type); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 82 | TensorInfo::TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | : TensorInfo() |
| 84 | { |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 85 | init(tensor_shape, num_channels, data_type); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 88 | TensorInfo::TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type, QuantizationInfo quantization_info) |
| 89 | : TensorInfo() |
| 90 | { |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 91 | init(tensor_shape, num_channels, data_type); |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 92 | _quantization_info = std::move(quantization_info); |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Manuel Bottini | 581f178 | 2019-11-13 17:24:43 +0000 | [diff] [blame] | 95 | TensorInfo::TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type, DataLayout data_layout) |
| 96 | : TensorInfo() |
| 97 | { |
| 98 | init(tensor_shape, num_channels, data_type); |
| 99 | _data_layout = data_layout; |
| 100 | } |
| 101 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | void TensorInfo::init(Format format) |
| 103 | { |
| 104 | init(TensorShape(), format); |
| 105 | } |
| 106 | |
| 107 | void TensorInfo::init(const TensorShape &tensor_shape, Format format) |
| 108 | { |
| 109 | size_t num_channels = num_channels_from_format(format); |
| 110 | const DataType type = data_type_from_format(format); |
| 111 | |
| 112 | init(tensor_shape, num_channels, type); |
| 113 | |
| 114 | _format = format; |
| 115 | } |
| 116 | |
| 117 | void TensorInfo::init(const TensorShape &tensor_shape, Format format, |
| 118 | const Strides &strides_in_bytes, size_t offset_first_element_in_bytes, |
| 119 | size_t total_size_in_bytes) |
| 120 | { |
| 121 | size_t num_channels = num_channels_from_format(format); |
| 122 | const DataType type = data_type_from_format(format); |
| 123 | |
| 124 | init(tensor_shape, num_channels, type, strides_in_bytes, offset_first_element_in_bytes, total_size_in_bytes); |
| 125 | |
| 126 | _format = format; |
| 127 | } |
| 128 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 129 | void TensorInfo::init(size_t num_channels, DataType data_type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 130 | { |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 131 | init(TensorShape(), num_channels, data_type); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 134 | void TensorInfo::init(const TensorShape &tensor_shape, size_t num_channels, DataType data_type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | { |
| 136 | ARM_COMPUTE_ERROR_ON(num_channels == 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 137 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 138 | _data_type = data_type; |
| 139 | _num_channels = num_channels; |
| 140 | _format = Format::UNKNOWN; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | |
| 142 | set_tensor_shape(tensor_shape); |
| 143 | } |
| 144 | |
| 145 | void TensorInfo::init(const TensorShape &tensor_shape, size_t num_channels, DataType data_type, |
| 146 | const Strides &strides_in_bytes, size_t offset_first_element_in_bytes, |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 147 | size_t total_size_in_bytes) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 148 | { |
| 149 | ARM_COMPUTE_ERROR_ON(num_channels == 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 150 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 151 | _data_type = data_type; |
| 152 | _num_channels = num_channels; |
| 153 | _format = Format::UNKNOWN; |
| 154 | _tensor_shape = tensor_shape; |
| 155 | _offset_first_element_in_bytes = offset_first_element_in_bytes; |
| 156 | _strides_in_bytes = strides_in_bytes; |
| 157 | _total_size = total_size_in_bytes; |
| 158 | |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 159 | _valid_region = ValidRegion{ Coordinates(), _tensor_shape }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 162 | size_t TensorInfo::init_auto_padding(const TensorShape &tensor_shape, Format format) |
| 163 | { |
| 164 | const size_t num_channels = num_channels_from_format(format); |
| 165 | const DataType type = data_type_from_format(format); |
| 166 | size_t total_size = init_auto_padding(tensor_shape, num_channels, type); |
| 167 | |
| 168 | _format = format; |
| 169 | |
| 170 | return total_size; |
| 171 | } |
| 172 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 173 | size_t TensorInfo::init_auto_padding(const TensorShape &tensor_shape, size_t num_channels, DataType data_type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 174 | { |
| 175 | ARM_COMPUTE_ERROR_ON(num_channels == 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 176 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 177 | _data_type = data_type; |
| 178 | _num_channels = num_channels; |
| 179 | _format = Format::UNKNOWN; |
| 180 | _tensor_shape = tensor_shape; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 181 | |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 182 | _valid_region = ValidRegion{ Coordinates(), _tensor_shape }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | |
| 184 | auto_padding(); |
| 185 | |
| 186 | return _total_size; |
| 187 | } |
| 188 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 189 | bool TensorInfo::auto_padding() |
| 190 | { |
| 191 | ARM_COMPUTE_ERROR_ON(!_is_resizable); |
| 192 | |
| 193 | // Some kernels compute 32 elements at the time, worst case scenario they |
| 194 | // will read 32 values after the last element |
| 195 | const size_t extra_pad_x = _tensor_shape.num_dimensions() < 1 ? 0 : 32; |
| 196 | const size_t pad_x = _tensor_shape.num_dimensions() < 1 ? 0 : 4; |
| 197 | const size_t pad_y = _tensor_shape.num_dimensions() < 2 ? 0 : 4; |
| 198 | |
| 199 | return extend_padding(PaddingSize(pad_y, pad_x + extra_pad_x, pad_y, pad_x)); |
| 200 | } |
| 201 | |
| 202 | std::tuple<Strides, size_t, size_t> TensorInfo::calculate_padding_requirements(const PaddingSize &padding) |
| 203 | { |
| 204 | // Calculate resulting stride for the X, Y and Z dimension |
| 205 | const size_t stride_x = element_size(); |
| 206 | const size_t stride_y = (padding.left + _tensor_shape[0] + padding.right) * stride_x; |
| 207 | const size_t stride_z = (padding.top + _tensor_shape[1] + padding.bottom) * stride_y; |
| 208 | |
| 209 | Strides required_strides; |
| 210 | size_t required_total_size = 0; |
| 211 | const size_t required_offset_first_element = padding.left * stride_x + padding.top * stride_y; |
| 212 | |
| 213 | switch(_tensor_shape.num_dimensions()) |
| 214 | { |
| 215 | case 0: |
| 216 | { |
| 217 | if(_tensor_shape.total_size() > 0) |
| 218 | { |
Gian Marco Iodice | ee94f6a | 2017-09-11 17:38:02 +0100 | [diff] [blame] | 219 | required_strides = Strides(stride_x, stride_x); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 220 | required_total_size = stride_z; |
| 221 | } |
| 222 | break; |
| 223 | } |
| 224 | case 1: |
Gian Marco Iodice | ee94f6a | 2017-09-11 17:38:02 +0100 | [diff] [blame] | 225 | required_strides = compute_strides(*this, stride_x, stride_y); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 226 | required_total_size = stride_z; |
| 227 | break; |
| 228 | case 2: |
| 229 | required_strides = compute_strides(*this, stride_x, stride_y); |
| 230 | required_total_size = stride_z; |
| 231 | break; |
| 232 | default: |
| 233 | { |
| 234 | required_strides = compute_strides(*this, stride_x, stride_y, stride_z); |
| 235 | |
| 236 | const unsigned int idx_last_dimension = _tensor_shape.num_dimensions() - 1; |
| 237 | |
Sheri Zhang | a3e6b6d | 2020-08-18 10:07:35 +0100 | [diff] [blame] | 238 | required_total_size = static_cast<size_t>(_tensor_shape[idx_last_dimension]) * required_strides[idx_last_dimension]; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 239 | break; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | return std::make_tuple(required_strides, required_offset_first_element, required_total_size); |
| 244 | } |
| 245 | |
| 246 | bool TensorInfo::extend_padding(const PaddingSize &padding) |
| 247 | { |
| 248 | ARM_COMPUTE_ERROR_ON(!_is_resizable); |
| 249 | |
| 250 | bool updated = false; |
| 251 | |
| 252 | if(padding.top > _padding.top) |
| 253 | { |
| 254 | _padding.top = padding.top; |
| 255 | updated = true; |
| 256 | } |
| 257 | |
| 258 | if(padding.right > _padding.right) |
| 259 | { |
| 260 | _padding.right = padding.right; |
| 261 | updated = true; |
| 262 | } |
| 263 | |
| 264 | if(padding.bottom > _padding.bottom) |
| 265 | { |
| 266 | _padding.bottom = padding.bottom; |
| 267 | updated = true; |
| 268 | } |
| 269 | |
| 270 | if(padding.left > _padding.left) |
| 271 | { |
| 272 | _padding.left = padding.left; |
| 273 | updated = true; |
| 274 | } |
| 275 | |
| 276 | std::tie(_strides_in_bytes, _offset_first_element_in_bytes, _total_size) = calculate_padding_requirements(_padding); |
| 277 | |
| 278 | return updated; |
| 279 | } |
| 280 | |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 281 | std::unique_ptr<ITensorInfo> TensorInfo::clone() const |
| 282 | { |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 283 | return std::make_unique<TensorInfo>(*this); |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | ITensorInfo &TensorInfo::set_data_type(DataType data_type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 287 | { |
| 288 | _data_type = data_type; |
| 289 | _format = Format::UNKNOWN; |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 290 | return set_tensor_shape(tensor_shape()); // Force total size and strides to update |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 293 | ITensorInfo &TensorInfo::set_num_channels(int num_channels) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 294 | { |
| 295 | _num_channels = num_channels; |
| 296 | _format = Format::UNKNOWN; |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 297 | return *this; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 300 | ITensorInfo &TensorInfo::set_format(Format format) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 301 | { |
| 302 | _format = format; |
| 303 | |
| 304 | if(_data_type == DataType::UNKNOWN) |
| 305 | { |
| 306 | _num_channels = num_channels_from_format(format); |
| 307 | _data_type = data_type_from_format(format); |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | ARM_COMPUTE_ERROR_ON(num_channels_from_format(format) != _num_channels); |
| 312 | ARM_COMPUTE_ERROR_ON(data_type_from_format(format) != _data_type); |
| 313 | } |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 314 | return *this; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 317 | ITensorInfo &TensorInfo::set_tensor_shape(const TensorShape &shape) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 318 | { |
| 319 | _tensor_shape = shape; |
| 320 | _offset_first_element_in_bytes = 0; |
| 321 | _strides_in_bytes = compute_strides(*this); |
| 322 | |
| 323 | if(_tensor_shape.num_dimensions() == 0) |
| 324 | { |
| 325 | _total_size = _strides_in_bytes[0]; |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | const unsigned int idx_last_dimension = _tensor_shape.num_dimensions() - 1; |
Sheri Zhang | a3e6b6d | 2020-08-18 10:07:35 +0100 | [diff] [blame] | 330 | _total_size = static_cast<size_t>(_tensor_shape[idx_last_dimension]) * _strides_in_bytes[idx_last_dimension]; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 333 | std::tie(_strides_in_bytes, _offset_first_element_in_bytes, _total_size) = calculate_padding_requirements(_padding); |
| 334 | |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 335 | _valid_region = ValidRegion{ Coordinates(), _tensor_shape }; |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 336 | return *this; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Georgios Pinitas | b14a0f0 | 2021-01-08 03:14:31 +0000 | [diff] [blame] | 339 | ITensorInfo &TensorInfo::set_tensor_dims_state(const TensorDimsState &state) |
| 340 | { |
| 341 | _dims_state = state; |
| 342 | return *this; |
| 343 | } |
| 344 | |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 345 | ITensorInfo &TensorInfo::set_quantization_info(const QuantizationInfo &quantization_info) |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 346 | { |
| 347 | _quantization_info = quantization_info; |
| 348 | return *this; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 349 | } |
| 350 | |
Isabella Gottardi | d17a677 | 2018-02-27 17:41:55 +0000 | [diff] [blame] | 351 | ITensorInfo &TensorInfo::set_data_layout(const DataLayout &data_layout) |
| 352 | { |
| 353 | _data_layout = data_layout; |
| 354 | return *this; |
| 355 | } |
| 356 | |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 357 | ITensorInfo &TensorInfo::reset_padding() |
| 358 | { |
| 359 | _padding = PaddingSize(); |
| 360 | if(((_format != Format::UNKNOWN) || (_data_type != DataType::UNKNOWN)) && _total_size != 0) |
| 361 | { |
| 362 | std::tie(_strides_in_bytes, _offset_first_element_in_bytes, _total_size) = calculate_padding_requirements(_padding); |
| 363 | } |
| 364 | return *this; |
| 365 | } |
| 366 | |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 367 | int32_t TensorInfo::offset_element_in_bytes(const Coordinates &pos) const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 368 | { |
| 369 | ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE(pos, _tensor_shape.num_dimensions()); |
| 370 | |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 371 | int32_t offset = _offset_first_element_in_bytes; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 372 | |
| 373 | for(size_t i = 0; i < _tensor_shape.num_dimensions(); ++i) |
| 374 | { |
| 375 | offset += pos[i] * _strides_in_bytes[i]; |
| 376 | } |
| 377 | |
| 378 | return offset; |
| 379 | } |