Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2023 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_ITENSORINFO_H |
| 25 | #define ARM_COMPUTE_ITENSORINFO_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/utils/misc/Utility.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 33 | #include "support/ICloneable.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | #include <cstddef> |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
Matthew Bentham | 043613f | 2023-05-30 16:43:14 +0000 | [diff] [blame] | 39 | class QuantizationInfo; |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 40 | // Note: Any changes to the fields of the class below that have setters should be mirrored |
| 41 | // (if possible) in the auto_init_if_empty function in AutoConfiguration.h |
| 42 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | /** Store the tensor's metadata */ |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 44 | class ITensorInfo : public misc::ICloneable<ITensorInfo> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | { |
| 46 | public: |
Giorgio Arena | 61b6e24 | 2021-09-23 12:40:39 +0100 | [diff] [blame] | 47 | using TensorDimsState = std::vector<int>; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 48 | /** An id that uniquely identifies an ITensorInfo within some domain (e.g. a workload) |
| 49 | */ |
| 50 | using Id = int32_t; |
| 51 | /** An invalid tensor id within a domain */ |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 52 | static constexpr Id invalid_tensor_id = 0; |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 53 | /** Get the value representing dynamic dimension state |
| 54 | * |
| 55 | * @return Value representing dynamic dimension state |
| 56 | * |
| 57 | */ |
| 58 | static constexpr int32_t get_dynamic_state_value() |
| 59 | { |
| 60 | return _dynamic_dimension; |
| 61 | } |
| 62 | /** Get the value representing static dimension state |
| 63 | * |
| 64 | * @return Value representing static dimension state |
| 65 | * |
| 66 | */ |
| 67 | static constexpr int32_t get_static_state_value() |
| 68 | { |
| 69 | return _static_dimension; |
| 70 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 71 | /** Default virtual destructor */ |
| 72 | virtual ~ITensorInfo() = default; |
| 73 | /** Set the data type to the specified value. |
| 74 | * |
| 75 | * @warning This resets the format to UNKNOWN. |
| 76 | * |
| 77 | * @param[in] data_type The new data type. |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 78 | * |
| 79 | * @return Reference to this ITensorInfo object |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | */ |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 81 | virtual ITensorInfo &set_data_type(DataType data_type) = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | /** Set the number of channels to the specified value. |
| 83 | * |
| 84 | * @warning This resets the format to UNKNOWN. |
| 85 | * |
| 86 | * @param[in] num_channels New number of channels. |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 87 | * |
| 88 | * @return Reference to this ITensorInfo object |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 89 | */ |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 90 | virtual ITensorInfo &set_num_channels(int num_channels) = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 91 | /** Set the format of an already initialized tensor. |
| 92 | * |
| 93 | * @note If the data type has already been configured (i.e. not UNKNOWN) it |
| 94 | * must match the new format. If data type hasn't been configured it will |
| 95 | * be based on the format. |
| 96 | * |
| 97 | * @param[in] format Single-plane format of the tensor. |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 98 | * |
| 99 | * @return Reference to this ITensorInfo object |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | */ |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 101 | virtual ITensorInfo &set_format(Format format) = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | /** Set the shape of an already initialized tensor. |
| 103 | * |
| 104 | * @warning Changing the shape requires to recompute the strides and is |
| 105 | * therefore only possible if the tensor hasn't been allocated yet. |
| 106 | * |
| 107 | * @param[in] shape New tensor shape. |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 108 | * |
| 109 | * @return Reference to this ITensorInfo object |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 110 | */ |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 111 | virtual ITensorInfo &set_tensor_shape(const TensorShape &shape) = 0; |
Georgios Pinitas | b14a0f0 | 2021-01-08 03:14:31 +0000 | [diff] [blame] | 112 | /** Set the state for each dimension of the tensor |
| 113 | * |
| 114 | * This sets the state of each dimension of the shape in terms of dynamic behavior using -1 where appropriate. |
| 115 | * The index in the state is a 1 to 1 mapping with the shape dimension index. |
| 116 | * For example if you want to express [?, 3, 3] as a dynamic input then [-1, 3, 3] has to be set as a state |
| 117 | * |
| 118 | * @param[in] state Tensor dimensions state |
| 119 | * |
| 120 | * @return Reference to this ITensorInfo object |
| 121 | */ |
| 122 | virtual ITensorInfo &set_tensor_dims_state(const TensorDimsState &state) = 0; |
Georgios Pinitas | 283c179 | 2017-11-10 18:14:06 +0000 | [diff] [blame] | 123 | /** Set the quantization settings (scale and offset) of the tensor. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 124 | * |
| 125 | * @param[in] quantization_info QuantizationInfo containing the scale and offset |
| 126 | * |
| 127 | * @return Reference to this ITensorInfo object |
| 128 | */ |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 129 | virtual ITensorInfo &set_quantization_info(const QuantizationInfo &quantization_info) = 0; |
Isabella Gottardi | d17a677 | 2018-02-27 17:41:55 +0000 | [diff] [blame] | 130 | /** Set the data layout of the tensor. |
| 131 | * |
| 132 | * @param[in] data_layout DataLayout containing the layout data information. |
| 133 | * |
| 134 | * @return Reference to this ITensorInfo object |
| 135 | */ |
| 136 | virtual ITensorInfo &set_data_layout(const DataLayout &data_layout) = 0; |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 137 | /** Resets the padding settings of the tensor. |
| 138 | * |
| 139 | * @return Reference to this ITensorInfo object |
| 140 | */ |
| 141 | virtual ITensorInfo &reset_padding() = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 142 | /** Update the offset to the first element and the strides to automatically computed values. |
| 143 | * |
| 144 | * @note The padding used by this method is really conservative so that the tensor can be used for most functions. |
| 145 | * |
| 146 | * @return True if the strides or the offset to the first element have changed. |
| 147 | */ |
| 148 | virtual bool auto_padding() = 0; |
Ramy Elgammal | d2d9361 | 2022-12-22 15:21:03 +0000 | [diff] [blame] | 149 | /** Set the lock paddings flag of the tensor. |
| 150 | * It should be set to True, when the tensor could be mapped to camera or frame buffer. |
| 151 | * |
| 152 | * @return Reference to this ITensorInfo object |
| 153 | */ |
| 154 | virtual ITensorInfo &set_lock_paddings(bool flag) = 0; |
| 155 | /** Get the lock paddings flag value |
| 156 | * |
| 157 | * @return lock paddings flag value |
| 158 | */ |
| 159 | virtual bool lock_paddings() const = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 160 | /** Update the offset to the first element, the strides and the total size. |
| 161 | * |
| 162 | * @note This function can only increase the offset, strides and total size. |
| 163 | * |
| 164 | * @param[in] padding Padding around the XY plane in number of elements. |
| 165 | * |
| 166 | * @return True if the strides, offset and total size have changed. |
| 167 | */ |
| 168 | virtual bool extend_padding(const PaddingSize &padding) = 0; |
| 169 | /** Return the size of the requested dimension |
| 170 | * |
| 171 | * @param[in] index Index of the dimension |
| 172 | * |
| 173 | * @return Dimension of the requested dimension |
| 174 | */ |
| 175 | virtual size_t dimension(size_t index) const = 0; |
Isabella Gottardi | d56e770 | 2018-02-28 14:29:36 +0000 | [diff] [blame] | 176 | /** Return the size of the requested data layout dimension |
| 177 | * |
| 178 | * @param[in] dimension DataLayoutDimension of the dimension |
| 179 | * |
| 180 | * @return Dimension of the requested dimension |
| 181 | */ |
| 182 | virtual size_t dimension(DataLayoutDimension dimension) const = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | /** The strides in bytes for accessing each dimension of the tensor |
| 184 | * |
| 185 | * @return Strides in bytes for each tensor dimension |
| 186 | */ |
| 187 | virtual const Strides &strides_in_bytes() const = 0; |
| 188 | /** The offset from the beginning of the memory allocation to the first element of the tensor. |
| 189 | * This can be used to access efficiently elements in a 2D tensor |
| 190 | * |
| 191 | * @return The offset in bytes to access the first element of the tensor. |
| 192 | */ |
| 193 | virtual size_t offset_first_element_in_bytes() const = 0; |
| 194 | /** The offset in bytes from the beginning of the memory allocation to access the element at position (x, y, z ...) |
| 195 | * |
| 196 | * @param[in] pos Vector with the coordinates of the element to access. |
| 197 | * The size of this vector must be equal to the number of dimensions of the tensor |
| 198 | * |
| 199 | * @return Offset in bytes from the beginning of the memory allocation to access the element (x, y, z, ...) |
| 200 | */ |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 201 | virtual int32_t offset_element_in_bytes(const Coordinates &pos) const = 0; |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 202 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 203 | /** Element size in bytes calculated as data_size() * num_channels() |
| 204 | * |
| 205 | * @return The size of one element in bytes |
| 206 | */ |
| 207 | virtual size_t element_size() const = 0; |
| 208 | /** The number of dimensions of the tensor (rank) |
| 209 | * |
| 210 | * @return The number of dimensions of the tensor (rank) |
| 211 | */ |
| 212 | virtual size_t num_dimensions() const = 0; |
| 213 | /** The number of channels for each tensor element |
| 214 | * |
| 215 | * @return The number of channels for each tensor element |
| 216 | */ |
| 217 | virtual size_t num_channels() const = 0; |
| 218 | /** Size for each dimension of the tensor |
| 219 | * |
| 220 | * @return A vector with the size for each dimension of the tensor |
| 221 | */ |
| 222 | virtual const TensorShape &tensor_shape() const = 0; |
Georgios Pinitas | b14a0f0 | 2021-01-08 03:14:31 +0000 | [diff] [blame] | 223 | /** State of each dimension of the tensor shape |
| 224 | * |
| 225 | * @return A vector with the state for each dimension of the tensor, where -1 specifies dynamic dimension |
| 226 | */ |
| 227 | virtual const TensorDimsState &tensor_dims_state() const = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 228 | /** Data type used for each element of the tensor |
| 229 | * |
| 230 | * @return Tensor data type |
| 231 | */ |
| 232 | virtual DataType data_type() const = 0; |
| 233 | /** Colour format of the image |
| 234 | * |
| 235 | * @return Colour format of the image |
| 236 | */ |
| 237 | virtual Format format() const = 0; |
| 238 | /** Returns the total size of the tensor in bytes. |
| 239 | * |
| 240 | * @return Total size of the tensor in bytes. |
| 241 | */ |
| 242 | virtual size_t total_size() const = 0; |
| 243 | /** Padding of tensor. |
| 244 | * |
| 245 | * @return Padding. |
| 246 | */ |
| 247 | virtual PaddingSize padding() const = 0; |
| 248 | /** Checks if the tensor has been allocated with padding or not. |
| 249 | * |
| 250 | * @return True if padding is allocated in the tensor, otherwise false. |
| 251 | */ |
| 252 | virtual bool has_padding() const = 0; |
| 253 | /** Flag indicating whether the size of the tensor can be changed. |
| 254 | * |
| 255 | * @return True if the tensor size can be changed. |
| 256 | */ |
| 257 | virtual bool is_resizable() const = 0; |
Georgios Pinitas | 49be2e3 | 2019-09-02 13:18:55 +0100 | [diff] [blame] | 258 | /** Flag indicating whether the shape of the tensor is dynamic, meaning that it can change on kernel/function execution. |
| 259 | * |
| 260 | * @return True if its dynamic else false |
| 261 | */ |
| 262 | virtual bool is_dynamic() const = 0; |
Giorgio Arena | 63e0beb | 2021-09-24 14:04:27 +0100 | [diff] [blame] | 263 | /** Flag indicating whether the values of the tensor are constant, meaning that they can change on kernel/function execution. |
| 264 | * |
| 265 | * @return True if values are constant else false |
| 266 | */ |
| 267 | virtual bool are_values_constant() const = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 268 | /** Set the flag whether the tensor size can be changed. |
| 269 | * |
| 270 | * @param[in] is_resizable Flag that marks the tensor if it can be changed or not. |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 271 | * |
| 272 | * @return Reference to this ITensorInfo object |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 273 | */ |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 274 | virtual ITensorInfo &set_is_resizable(bool is_resizable) = 0; |
Giorgio Arena | 63e0beb | 2021-09-24 14:04:27 +0100 | [diff] [blame] | 275 | /** Set the flag whether the tensor values can change during kernel/function execution. |
| 276 | * |
| 277 | * @param[in] are_values_constant Flag that marks the tensor values if they can be changed or not. |
| 278 | * |
| 279 | * @return Reference to this ITensorInfo object |
| 280 | */ |
| 281 | virtual ITensorInfo &set_are_values_constant(bool are_values_constant) = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 282 | /** Valid region of the tensor. All elements in the valid region have defined values, i.e. are not undefined. |
| 283 | * |
| 284 | * @return The valid region. |
| 285 | */ |
| 286 | virtual ValidRegion valid_region() const = 0; |
| 287 | /** Set the valid region of the tensor. |
| 288 | * |
| 289 | * @param[in] valid_region Valid region to set. |
| 290 | */ |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 291 | virtual void set_valid_region(const ValidRegion &valid_region) = 0; |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 292 | |
| 293 | /** Get the quantization settings (scale and offset) of the tensor. |
| 294 | * |
| 295 | * @return A QuantizationInfo containing the scale and offset. |
| 296 | */ |
| 297 | virtual QuantizationInfo quantization_info() const = 0; |
Isabella Gottardi | d17a677 | 2018-02-27 17:41:55 +0000 | [diff] [blame] | 298 | /** Get the data layout of the tensor. |
| 299 | * |
| 300 | * @return A DataLayout containing the layout data information. |
| 301 | */ |
| 302 | virtual DataLayout data_layout() const = 0; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 303 | /** Get the workload tensor id of the tensor. |
| 304 | * |
| 305 | * @return Workload tensor id of the tensor |
| 306 | */ |
| 307 | virtual Id id() const = 0; |
| 308 | /** Set the tensor id |
| 309 | */ |
| 310 | virtual ITensorInfo &set_id(ITensorInfo::Id id) = 0; |
| 311 | /** Check if the tensor id is valid |
| 312 | */ |
| 313 | bool has_valid_id() const |
| 314 | { |
| 315 | return id() != invalid_tensor_id; |
| 316 | } |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 317 | /** If infos are broadcast compatible tensor info's, return the broadcasted shape and the intersection of |
| 318 | * the broadcasted valid regions of the tensors. |
| 319 | * |
| 320 | * Two tensor info's are broadcast compatible if their shapes are broadcast compatible. |
| 321 | * |
| 322 | * Two tensor shapes are broadcast compatible if for each dimension, they're equal or one of them is 1. |
| 323 | * |
| 324 | * If two shapes are compatible, each dimension in the broadcasted shape is the max of the original dimensions. |
| 325 | * |
| 326 | * @param[in] infos Tensor info's. |
| 327 | * |
| 328 | * @return The broadcasted shape and valid region, or an empty shape and valid region if the info's are |
| 329 | * not broadcast compatible. |
| 330 | */ |
| 331 | template <typename... Infos> |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 332 | static std::pair<TensorShape, ValidRegion> broadcast_shape_and_valid_region(const Infos &...infos) |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 333 | { |
| 334 | TensorShape bc_shape = TensorShape::broadcast_shape(infos.tensor_shape()...); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 335 | ValidRegion bc_valid_region{Coordinates(), bc_shape}; |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 336 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 337 | auto broadcast_valid_region = [&bc_valid_region](const ITensorInfo &info) |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 338 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 339 | if (info.num_dimensions() != 0) |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 340 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 341 | for (size_t d = 0; d < bc_valid_region.shape.num_dimensions(); ++d) |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 342 | { |
| 343 | const bool is_broadcast = (info.tensor_shape()[d] == 1); |
| 344 | |
| 345 | const int anchor_max = std::max(bc_valid_region.anchor[d], info.valid_region().anchor[d]); |
| 346 | const size_t valid_min = std::min(bc_valid_region.shape[d], info.valid_region().shape[d]); |
| 347 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 348 | if (!is_broadcast || (valid_min == 0)) |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 349 | { |
| 350 | bc_valid_region.anchor.set(d, anchor_max); |
| 351 | bc_valid_region.shape.set(d, valid_min); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | }; |
| 356 | |
| 357 | utility::for_each(broadcast_valid_region, infos...); |
| 358 | |
| 359 | return std::pair<TensorShape, ValidRegion>(bc_shape, bc_valid_region); |
| 360 | } |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 361 | |
| 362 | private: |
| 363 | static constexpr int32_t _dynamic_dimension = -1; |
| 364 | static constexpr int32_t _static_dimension = 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 365 | }; |
Georgios Pinitas | 49be2e3 | 2019-09-02 13:18:55 +0100 | [diff] [blame] | 366 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 367 | #endif /*ARM_COMPUTE_TENSORINFO_H */ |