Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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_SUBTENSORINFO_H__ |
| 25 | #define __ARM_COMPUTE_SUBTENSORINFO_H__ |
| 26 | |
| 27 | #include "arm_compute/core/ITensorInfo.h" |
| 28 | |
| 29 | #include "arm_compute/core/Coordinates.h" |
| 30 | #include "arm_compute/core/Strides.h" |
| 31 | #include "arm_compute/core/TensorInfo.h" |
| 32 | #include "arm_compute/core/TensorShape.h" |
| 33 | #include "arm_compute/core/Validate.h" |
| 34 | |
| 35 | #include <cstddef> |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | /** Store the sub tensor's metadata */ |
| 40 | class SubTensorInfo final : public ITensorInfo |
| 41 | { |
| 42 | public: |
| 43 | /** Default constructor */ |
| 44 | SubTensorInfo(); |
| 45 | /** Default constructor |
| 46 | * |
| 47 | * @param[in] parent Metadata of parent tensor. |
| 48 | * @param[in] tensor_shape Tensor shape. Shape must fit inside parent's shape. |
| 49 | * X and Y dimensions must match the parent's ones. |
| 50 | * @param[in] coords Coordinates of starting element inside parent tensor. |
| 51 | */ |
| 52 | SubTensorInfo(ITensorInfo *parent, const TensorShape &tensor_shape, const Coordinates &coords); |
| 53 | /** Default destructor */ |
| 54 | ~SubTensorInfo() = default; |
| 55 | /** Allow instances of this class to be copy constructed */ |
| 56 | SubTensorInfo(const SubTensorInfo &) = default; |
| 57 | /** Allow instances of this class to be copied */ |
| 58 | SubTensorInfo &operator=(const SubTensorInfo &) = default; |
| 59 | /** Allow instances of this class to be move constructed */ |
| 60 | SubTensorInfo(SubTensorInfo &&) = default; |
| 61 | /** Allow instances of this class to be moved */ |
| 62 | SubTensorInfo &operator=(SubTensorInfo &&) = default; |
| 63 | |
| 64 | // Inherited methods overridden: |
| 65 | void set_data_type(DataType data_type) override |
| 66 | { |
| 67 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 68 | _parent->set_data_type(data_type); |
| 69 | }; |
| 70 | void set_num_channels(int num_channels) override |
| 71 | { |
| 72 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 73 | _parent->set_num_channels(num_channels); |
| 74 | }; |
| 75 | void set_format(Format format) override |
| 76 | { |
| 77 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 78 | _parent->set_format(format); |
| 79 | }; |
| 80 | void set_fixed_point_position(int fixed_point_position) override |
| 81 | { |
| 82 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 83 | _parent->set_fixed_point_position(fixed_point_position); |
| 84 | }; |
| 85 | void set_tensor_shape(TensorShape shape) override; |
| 86 | bool auto_padding() override |
| 87 | { |
| 88 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 89 | return _parent->auto_padding(); |
| 90 | }; |
| 91 | bool extend_padding(const PaddingSize &padding) override; |
| 92 | size_t dimension(size_t index) const override |
| 93 | { |
| 94 | return _tensor_shape[index]; |
| 95 | } |
| 96 | const Strides &strides_in_bytes() const override |
| 97 | { |
| 98 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 99 | return _parent->strides_in_bytes(); |
| 100 | } |
| 101 | size_t offset_first_element_in_bytes() const override |
| 102 | { |
| 103 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 104 | return _parent->offset_element_in_bytes(_coords); |
| 105 | } |
| 106 | size_t offset_element_in_bytes(const Coordinates &pos) const override; |
| 107 | int fixed_point_position() const override |
| 108 | { |
| 109 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 110 | return _parent->fixed_point_position(); |
| 111 | } |
| 112 | size_t element_size() const override |
| 113 | { |
| 114 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 115 | return _parent->element_size(); |
| 116 | } |
| 117 | size_t num_dimensions() const override |
| 118 | { |
| 119 | return _tensor_shape.num_dimensions(); |
| 120 | } |
| 121 | size_t num_channels() const override |
| 122 | { |
| 123 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 124 | return _parent->num_channels(); |
| 125 | } |
| 126 | const TensorShape &tensor_shape() const override |
| 127 | { |
| 128 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 129 | return _tensor_shape; |
| 130 | } |
| 131 | DataType data_type() const override |
| 132 | { |
| 133 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 134 | return _parent->data_type(); |
| 135 | } |
| 136 | Format format() const override |
| 137 | { |
| 138 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 139 | return _parent->format(); |
| 140 | } |
| 141 | size_t total_size() const override |
| 142 | { |
| 143 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 144 | return _parent->total_size(); |
| 145 | } |
| 146 | PaddingSize padding() const override |
| 147 | { |
| 148 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 149 | return _parent->padding(); |
| 150 | } |
| 151 | bool has_padding() const override |
| 152 | { |
| 153 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 154 | return _parent->has_padding(); |
| 155 | } |
| 156 | bool is_resizable() const override |
| 157 | { |
| 158 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 159 | return _parent->is_resizable(); |
| 160 | } |
| 161 | void set_is_resizable(bool is_resizable) override |
| 162 | { |
| 163 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 164 | _parent->set_is_resizable(is_resizable); |
| 165 | } |
| 166 | ValidRegion valid_region() const override |
| 167 | { |
| 168 | return _valid_region; |
| 169 | } |
| 170 | void set_valid_region(ValidRegion valid_region) override |
| 171 | { |
| 172 | ARM_COMPUTE_ERROR_ON(_parent == nullptr); |
| 173 | ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(_parent->valid_region(), valid_region); |
| 174 | _valid_region = std::move(valid_region); |
| 175 | } |
| 176 | |
| 177 | private: |
| 178 | ITensorInfo *_parent; |
| 179 | TensorShape _tensor_shape; |
| 180 | Coordinates _coords; |
| 181 | ValidRegion _valid_region; |
| 182 | }; |
| 183 | } |
| 184 | #endif /*__ARM_COMPUTE_SUBTENSORINFO_H__ */ |