blob: 3a88ebae5af5fc5a76d61cef952bb2cd65c2edef [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010030#include "arm_compute/core/Helpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/Strides.h"
32#include "arm_compute/core/TensorInfo.h"
33#include "arm_compute/core/TensorShape.h"
34#include "arm_compute/core/Validate.h"
35
36#include <cstddef>
37
38namespace arm_compute
39{
40/** Store the sub tensor's metadata */
41class SubTensorInfo final : public ITensorInfo
42{
43public:
44 /** Default constructor */
45 SubTensorInfo();
46 /** Default constructor
47 *
48 * @param[in] parent Metadata of parent tensor.
49 * @param[in] tensor_shape Tensor shape. Shape must fit inside parent's shape.
50 * X and Y dimensions must match the parent's ones.
51 * @param[in] coords Coordinates of starting element inside parent tensor.
52 */
53 SubTensorInfo(ITensorInfo *parent, const TensorShape &tensor_shape, const Coordinates &coords);
54 /** Default destructor */
55 ~SubTensorInfo() = default;
56 /** Allow instances of this class to be copy constructed */
57 SubTensorInfo(const SubTensorInfo &) = default;
58 /** Allow instances of this class to be copied */
59 SubTensorInfo &operator=(const SubTensorInfo &) = default;
60 /** Allow instances of this class to be move constructed */
61 SubTensorInfo(SubTensorInfo &&) = default;
62 /** Allow instances of this class to be moved */
63 SubTensorInfo &operator=(SubTensorInfo &&) = default;
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010064 /** Returns the coordinates of the sub-tensor inside the parent tensor
65 *
66 * @return Sub-tensor coordinates
67 */
68 Coordinates coords() const
69 {
70 return _coords;
71 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072
73 // Inherited methods overridden:
74 void set_data_type(DataType data_type) override
75 {
76 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
77 _parent->set_data_type(data_type);
78 };
79 void set_num_channels(int num_channels) override
80 {
81 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
82 _parent->set_num_channels(num_channels);
83 };
84 void set_format(Format format) override
85 {
86 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
87 _parent->set_format(format);
88 };
89 void set_fixed_point_position(int fixed_point_position) override
90 {
91 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
92 _parent->set_fixed_point_position(fixed_point_position);
93 };
94 void set_tensor_shape(TensorShape shape) override;
95 bool auto_padding() override
96 {
97 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
98 return _parent->auto_padding();
99 };
100 bool extend_padding(const PaddingSize &padding) override;
101 size_t dimension(size_t index) const override
102 {
103 return _tensor_shape[index];
104 }
105 const Strides &strides_in_bytes() const override
106 {
107 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
108 return _parent->strides_in_bytes();
109 }
110 size_t offset_first_element_in_bytes() const override
111 {
112 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
113 return _parent->offset_element_in_bytes(_coords);
114 }
115 size_t offset_element_in_bytes(const Coordinates &pos) const override;
116 int fixed_point_position() const override
117 {
118 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
119 return _parent->fixed_point_position();
120 }
121 size_t element_size() const override
122 {
123 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
124 return _parent->element_size();
125 }
126 size_t num_dimensions() const override
127 {
128 return _tensor_shape.num_dimensions();
129 }
130 size_t num_channels() const override
131 {
132 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
133 return _parent->num_channels();
134 }
135 const TensorShape &tensor_shape() const override
136 {
137 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
138 return _tensor_shape;
139 }
140 DataType data_type() const override
141 {
142 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
143 return _parent->data_type();
144 }
145 Format format() const override
146 {
147 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
148 return _parent->format();
149 }
150 size_t total_size() const override
151 {
152 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
153 return _parent->total_size();
154 }
155 PaddingSize padding() const override
156 {
157 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
158 return _parent->padding();
159 }
160 bool has_padding() const override
161 {
162 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
163 return _parent->has_padding();
164 }
165 bool is_resizable() const override
166 {
167 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
168 return _parent->is_resizable();
169 }
170 void set_is_resizable(bool is_resizable) override
171 {
172 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
173 _parent->set_is_resizable(is_resizable);
174 }
175 ValidRegion valid_region() const override
176 {
177 return _valid_region;
178 }
179 void set_valid_region(ValidRegion valid_region) override
180 {
181 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100182 // Check if subtensor is valid if parent is configured
183 if(_parent->tensor_shape().total_size() != 0)
184 {
185 ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(_parent->valid_region(), valid_region);
186 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 _valid_region = std::move(valid_region);
188 }
Michel Iwaniec00633802017-10-12 14:14:15 +0100189 QuantizationInfo quantization_info() const override
190 {
191 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
192 return _parent->quantization_info();
193 }
194 void set_quantization_info(QuantizationInfo quantization_info) override
195 {
196 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
197 _parent->set_quantization_info(quantization_info);
198 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199
200private:
201 ITensorInfo *_parent;
202 TensorShape _tensor_shape;
203 Coordinates _coords;
204 ValidRegion _valid_region;
205};
206}
207#endif /*__ARM_COMPUTE_SUBTENSORINFO_H__ */