Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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" |
| 32 | |
| 33 | #include <cstddef> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | /** Store the tensor's metadata */ |
| 38 | class ITensorInfo |
| 39 | { |
| 40 | public: |
| 41 | /** Default virtual destructor */ |
| 42 | virtual ~ITensorInfo() = default; |
| 43 | /** Set the data type to the specified value. |
| 44 | * |
| 45 | * @warning This resets the format to UNKNOWN. |
| 46 | * |
| 47 | * @param[in] data_type The new data type. |
| 48 | */ |
| 49 | virtual void set_data_type(DataType data_type) = 0; |
| 50 | /** Set the number of channels to the specified value. |
| 51 | * |
| 52 | * @warning This resets the format to UNKNOWN. |
| 53 | * |
| 54 | * @param[in] num_channels New number of channels. |
| 55 | */ |
| 56 | virtual void set_num_channels(int num_channels) = 0; |
| 57 | /** Set the format of an already initialized tensor. |
| 58 | * |
| 59 | * @note If the data type has already been configured (i.e. not UNKNOWN) it |
| 60 | * must match the new format. If data type hasn't been configured it will |
| 61 | * be based on the format. |
| 62 | * |
| 63 | * @param[in] format Single-plane format of the tensor. |
| 64 | */ |
| 65 | virtual void set_format(Format format) = 0; |
| 66 | /** Set the shape of an already initialized tensor. |
| 67 | * |
| 68 | * @warning Changing the shape requires to recompute the strides and is |
| 69 | * therefore only possible if the tensor hasn't been allocated yet. |
| 70 | * |
| 71 | * @param[in] shape New tensor shape. |
| 72 | */ |
| 73 | virtual void set_tensor_shape(TensorShape shape) = 0; |
| 74 | /** Set the fixed point position to the specified value |
| 75 | * |
| 76 | * @warning The fixed point position must be set once the data type has been configured |
| 77 | * |
| 78 | * @param[in] fixed_point_position The new fixed point position |
| 79 | */ |
| 80 | virtual void set_fixed_point_position(int fixed_point_position) = 0; |
| 81 | /** Update the offset to the first element and the strides to automatically computed values. |
| 82 | * |
| 83 | * @note The padding used by this method is really conservative so that the tensor can be used for most functions. |
| 84 | * |
| 85 | * @return True if the strides or the offset to the first element have changed. |
| 86 | */ |
| 87 | virtual bool auto_padding() = 0; |
| 88 | /** Update the offset to the first element, the strides and the total size. |
| 89 | * |
| 90 | * @note This function can only increase the offset, strides and total size. |
| 91 | * |
| 92 | * @param[in] padding Padding around the XY plane in number of elements. |
| 93 | * |
| 94 | * @return True if the strides, offset and total size have changed. |
| 95 | */ |
| 96 | virtual bool extend_padding(const PaddingSize &padding) = 0; |
| 97 | /** Return the size of the requested dimension |
| 98 | * |
| 99 | * @param[in] index Index of the dimension |
| 100 | * |
| 101 | * @return Dimension of the requested dimension |
| 102 | */ |
| 103 | virtual size_t dimension(size_t index) const = 0; |
| 104 | /** The strides in bytes for accessing each dimension of the tensor |
| 105 | * |
| 106 | * @return Strides in bytes for each tensor dimension |
| 107 | */ |
| 108 | virtual const Strides &strides_in_bytes() const = 0; |
| 109 | /** The offset from the beginning of the memory allocation to the first element of the tensor. |
| 110 | * This can be used to access efficiently elements in a 2D tensor |
| 111 | * |
| 112 | * @return The offset in bytes to access the first element of the tensor. |
| 113 | */ |
| 114 | virtual size_t offset_first_element_in_bytes() const = 0; |
| 115 | /** The offset in bytes from the beginning of the memory allocation to access the element at position (x, y, z ...) |
| 116 | * |
| 117 | * @param[in] pos Vector with the coordinates of the element to access. |
| 118 | * The size of this vector must be equal to the number of dimensions of the tensor |
| 119 | * |
| 120 | * @return Offset in bytes from the beginning of the memory allocation to access the element (x, y, z, ...) |
| 121 | */ |
| 122 | virtual size_t offset_element_in_bytes(const Coordinates &pos) const = 0; |
| 123 | /** Fixed point position used when the tensor data type is QS8 or QS16 |
| 124 | * |
| 125 | * @return The fixed point position that expresses the number of bits for the fractional part of the number |
| 126 | */ |
| 127 | virtual int fixed_point_position() const = 0; |
| 128 | /** Element size in bytes calculated as data_size() * num_channels() |
| 129 | * |
| 130 | * @return The size of one element in bytes |
| 131 | */ |
| 132 | virtual size_t element_size() const = 0; |
| 133 | /** The number of dimensions of the tensor (rank) |
| 134 | * |
| 135 | * @return The number of dimensions of the tensor (rank) |
| 136 | */ |
| 137 | virtual size_t num_dimensions() const = 0; |
| 138 | /** The number of channels for each tensor element |
| 139 | * |
| 140 | * @return The number of channels for each tensor element |
| 141 | */ |
| 142 | virtual size_t num_channels() const = 0; |
| 143 | /** Size for each dimension of the tensor |
| 144 | * |
| 145 | * @return A vector with the size for each dimension of the tensor |
| 146 | */ |
| 147 | virtual const TensorShape &tensor_shape() const = 0; |
| 148 | /** Data type used for each element of the tensor |
| 149 | * |
| 150 | * @return Tensor data type |
| 151 | */ |
| 152 | virtual DataType data_type() const = 0; |
| 153 | /** Colour format of the image |
| 154 | * |
| 155 | * @return Colour format of the image |
| 156 | */ |
| 157 | virtual Format format() const = 0; |
| 158 | /** Returns the total size of the tensor in bytes. |
| 159 | * |
| 160 | * @return Total size of the tensor in bytes. |
| 161 | */ |
| 162 | virtual size_t total_size() const = 0; |
| 163 | /** Padding of tensor. |
| 164 | * |
| 165 | * @return Padding. |
| 166 | */ |
| 167 | virtual PaddingSize padding() const = 0; |
| 168 | /** Checks if the tensor has been allocated with padding or not. |
| 169 | * |
| 170 | * @return True if padding is allocated in the tensor, otherwise false. |
| 171 | */ |
| 172 | virtual bool has_padding() const = 0; |
| 173 | /** Flag indicating whether the size of the tensor can be changed. |
| 174 | * |
| 175 | * @return True if the tensor size can be changed. |
| 176 | */ |
| 177 | virtual bool is_resizable() const = 0; |
| 178 | /** Set the flag whether the tensor size can be changed. |
| 179 | * |
| 180 | * @param[in] is_resizable Flag that marks the tensor if it can be changed or not. |
| 181 | */ |
| 182 | virtual void set_is_resizable(bool is_resizable) = 0; |
| 183 | /** Valid region of the tensor. All elements in the valid region have defined values, i.e. are not undefined. |
| 184 | * |
| 185 | * @return The valid region. |
| 186 | */ |
| 187 | virtual ValidRegion valid_region() const = 0; |
| 188 | /** Set the valid region of the tensor. |
| 189 | * |
| 190 | * @param[in] valid_region Valid region to set. |
| 191 | */ |
| 192 | virtual void set_valid_region(ValidRegion valid_region) = 0; |
| 193 | }; |
| 194 | } |
| 195 | #endif /*__ARM_COMPUTE_TENSORINFO_H__ */ |