Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 1 | /* |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [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 | #ifndef __ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H__ |
| 25 | #define __ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H__ |
| 26 | |
Georgios Pinitas | 9be0c5a | 2018-02-19 12:46:29 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Helpers.h" |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/ITensorInfo.h" |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Utils.h" |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 30 | |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/utils/helpers/tensor_transform.h" |
| 32 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 33 | #include <cmath> |
| 34 | |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace misc |
| 38 | { |
| 39 | namespace shape_calculator |
| 40 | { |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 41 | inline TensorShape compute_vector_to_tensor_output_shape(const TensorShape &input, size_t conv_w, size_t conv_h, const DataLayout &data_layout) |
| 42 | { |
| 43 | const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 44 | const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 45 | const size_t idx_c = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 46 | |
| 47 | TensorShape output_shape(input); |
| 48 | output_shape.set(idx_w, conv_w); |
| 49 | output_shape.set(idx_h, conv_h); |
| 50 | output_shape.set(idx_c, input.x() / (conv_w * conv_h)); |
| 51 | |
| 52 | return output_shape; |
| 53 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 54 | |
Pablo Tello | 00afd11 | 2018-01-04 10:34:24 +0000 | [diff] [blame] | 55 | inline TensorShape compute_permutation_output_shape(const ITensorInfo &input, const PermutationVector &perm) |
| 56 | { |
| 57 | TensorShape output_shape = input.tensor_shape(); |
| 58 | permute(output_shape, perm); |
| 59 | return output_shape; |
| 60 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 61 | |
Georgios Pinitas | aa6a04a | 2018-08-29 12:53:41 +0100 | [diff] [blame] | 62 | inline TensorShape compute_reorg_output_shape(const ITensorInfo &input, int32_t stride) |
| 63 | { |
Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +0100 | [diff] [blame] | 64 | const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH); |
| 65 | const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT); |
| 66 | const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL); |
Georgios Pinitas | aa6a04a | 2018-08-29 12:53:41 +0100 | [diff] [blame] | 67 | |
Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +0100 | [diff] [blame] | 68 | ARM_COMPUTE_ERROR_ON(stride <= 0); |
| 69 | ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_width] % stride != 0), "The width of the input tensor must be a multiple of stride"); |
| 70 | ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_height] % stride != 0), "The height of the input tensor must be a multiple of stride"); |
Georgios Pinitas | aa6a04a | 2018-08-29 12:53:41 +0100 | [diff] [blame] | 71 | |
| 72 | TensorShape output_shape{ input.tensor_shape() }; |
Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +0100 | [diff] [blame] | 73 | |
| 74 | output_shape.set(idx_width, output_shape[idx_width] / stride); |
| 75 | output_shape.set(idx_height, output_shape[idx_height] / stride); |
| 76 | output_shape.set(idx_channel, output_shape[idx_channel] * stride * stride); |
Georgios Pinitas | aa6a04a | 2018-08-29 12:53:41 +0100 | [diff] [blame] | 77 | |
| 78 | return output_shape; |
| 79 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 80 | |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 81 | inline TensorShape compute_weights_reshaped_shape(const ITensorInfo &weights, bool has_bias = false, unsigned int num_groups = 1) |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 82 | { |
Giorgio Arena | 088c2b0 | 2018-08-07 16:59:05 +0100 | [diff] [blame] | 83 | // Number of groups greater than one are only supported for NCHW data layout, and the number of weights must be a multiple of it. |
Giorgio Arena | c6aa49b | 2018-08-07 11:53:30 +0100 | [diff] [blame] | 84 | ARM_COMPUTE_ERROR_ON(num_groups == 0); |
Giorgio Arena | c6aa49b | 2018-08-07 11:53:30 +0100 | [diff] [blame] | 85 | ARM_COMPUTE_ERROR_ON(weights.data_layout() == DataLayout::NHWC && num_groups > 1); |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 86 | ARM_COMPUTE_ERROR_ON((weights.dimension(3) % num_groups) != 0); |
Giorgio Arena | c6aa49b | 2018-08-07 11:53:30 +0100 | [diff] [blame] | 87 | |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 88 | // Calculate output shape |
| 89 | TensorShape weights_reshaped{ weights.tensor_shape() }; |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 90 | weights_reshaped.set(3, weights_reshaped[3] / num_groups); |
| 91 | |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 92 | weights_reshaped.collapse(3); |
| 93 | const size_t tmp_dim = weights_reshaped[0]; |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 94 | weights_reshaped.set(0, weights_reshaped[1]); |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 95 | weights_reshaped.set(1, tmp_dim + (has_bias ? 1 : 0)); |
Giorgio Arena | c6aa49b | 2018-08-07 11:53:30 +0100 | [diff] [blame] | 96 | if(weights.num_dimensions() < 5) |
| 97 | { |
| 98 | weights_reshaped.set(2, num_groups); |
| 99 | } |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 100 | |
| 101 | return weights_reshaped; |
| 102 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 103 | |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 104 | inline TensorShape compute_lhs_reshaped_shape(const ITensorInfo &a, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d = false) |
| 105 | { |
| 106 | ARM_COMPUTE_ERROR_ON(lhs_info.m0 == 0); |
| 107 | ARM_COMPUTE_ERROR_ON(lhs_info.k0 == 0); |
| 108 | ARM_COMPUTE_ERROR_ON(lhs_info.v0 == 0); |
| 109 | |
| 110 | // Input width/height |
| 111 | const unsigned int input_width = a.dimension(0); |
| 112 | const unsigned int input_height = reinterpret_input_as_3d ? a.dimension(1) * a.dimension(2) : a.dimension(1); |
| 113 | |
| 114 | // Number of horizontal/vertical blocks in the input tensor |
| 115 | const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(lhs_info.k0)); |
| 116 | const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(lhs_info.m0)); |
| 117 | |
| 118 | // Block size |
| 119 | const unsigned int block_size = lhs_info.m0 * lhs_info.k0; |
| 120 | |
| 121 | // Output width/height |
| 122 | const unsigned int output_width = block_size * num_horiz_blocks * lhs_info.v0; |
| 123 | const unsigned int output_height = std::ceil(num_vert_blocks / static_cast<float>(lhs_info.v0)); |
| 124 | |
| 125 | TensorShape lhs_shape{ a.tensor_shape() }; |
| 126 | lhs_shape.set(0, output_width); |
| 127 | lhs_shape.set(1, output_height); |
| 128 | |
| 129 | if((reinterpret_input_as_3d) && (lhs_shape.num_dimensions() > 2)) |
| 130 | { |
| 131 | // When the data format is NHWC and the shapes are Nx1x1 |
| 132 | // the tensor shape num_dimensions is automatically set to 1 instead of 3. |
| 133 | // To avoid failures by removing a dimension that doesn't exist |
| 134 | // check if the number of dimensions is greater than 2. |
| 135 | lhs_shape.remove_dimension(2); |
| 136 | } |
| 137 | |
| 138 | return lhs_shape; |
| 139 | } |
| 140 | |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 141 | inline TensorShape compute_rhs_reshaped_shape(const ITensorInfo &a, const GEMMRHSMatrixInfo &rhs_info) |
| 142 | { |
| 143 | ARM_COMPUTE_ERROR_ON(rhs_info.n0 == 0); |
| 144 | ARM_COMPUTE_ERROR_ON(rhs_info.k0 == 0); |
| 145 | ARM_COMPUTE_ERROR_ON(rhs_info.h0 == 0); |
| 146 | |
| 147 | // Input width/height |
| 148 | const unsigned int input_width = a.dimension(0); |
| 149 | const unsigned int input_height = a.dimension(1); |
| 150 | |
| 151 | // Number of horizontal/vertical blocks in the input tensor |
| 152 | const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(rhs_info.n0)); |
| 153 | const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(rhs_info.k0)); |
| 154 | |
| 155 | // Block size |
| 156 | const unsigned int block_size = rhs_info.n0 * rhs_info.k0; |
| 157 | |
| 158 | // Output width/height |
| 159 | const unsigned int output_width = block_size * num_vert_blocks * rhs_info.h0; |
| 160 | const unsigned int output_height = std::ceil(num_horiz_blocks / static_cast<float>(rhs_info.h0)); |
| 161 | |
| 162 | TensorShape rhs_shape{ a.tensor_shape() }; |
| 163 | rhs_shape.set(0, output_width); |
| 164 | rhs_shape.set(1, output_height); |
| 165 | |
| 166 | return rhs_shape; |
| 167 | } |
| 168 | |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 169 | inline TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height = 1, bool reinterpret_input_as_3d = false) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 170 | { |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 171 | // The interleaved output matrix will have the following shape: [ a_height * W, ceil(a_width / W) ] where W = 4 * mult_interleave4x4_height |
| 172 | ARM_COMPUTE_ERROR_ON(mult_interleave4x4_height < 1); |
| 173 | const int interleave_width = 4 * mult_interleave4x4_height; |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 174 | TensorShape shape_interleaved_a{ a.tensor_shape() }; |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 175 | shape_interleaved_a.set(0, a.dimension(0) * interleave_width); |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 176 | if(reinterpret_input_as_3d) |
| 177 | { |
| 178 | const int M = a.dimension(1) * a.dimension(2); |
| 179 | const int height = std::ceil(M / static_cast<float>(interleave_width)); |
| 180 | shape_interleaved_a.set(1, height); |
Isabella Gottardi | 089695f | 2018-10-17 18:04:15 +0100 | [diff] [blame] | 181 | |
| 182 | // When the data format is NHWC and the shapes are Nx1x1 |
| 183 | // the tensor shape num_dimensions is automatically set to 1 instead of 3. |
| 184 | // To avoid failures by removing a dimension that doesn't exist |
| 185 | // check if the number of dimensions is greater than 2. |
| 186 | if(shape_interleaved_a.num_dimensions() > 2) |
| 187 | { |
| 188 | shape_interleaved_a.remove_dimension(2); |
| 189 | } |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 190 | } |
| 191 | else |
| 192 | { |
| 193 | shape_interleaved_a.set(1, std::ceil(a.dimension(1) / static_cast<float>(interleave_width))); |
| 194 | } |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 195 | |
| 196 | return shape_interleaved_a; |
| 197 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 198 | |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 199 | inline TensorShape compute_transpose1xW_shape(const ITensorInfo &b) |
| 200 | { |
| 201 | // The transpose1xW output matrix will have the following shape: [ b_height * 16, ceil(b_width / 16.0f) ] |
| 202 | TensorShape shape_transposed1xW_b{ b.tensor_shape() }; |
| 203 | shape_transposed1xW_b.set(0, b.dimension(1) * 16); |
| 204 | shape_transposed1xW_b.set(1, std::ceil(b.dimension(0) / 16.f)); |
| 205 | |
| 206 | return shape_transposed1xW_b; |
| 207 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 208 | |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 209 | inline TensorShape compute_transpose1xW_with_element_size_shape(const ITensorInfo &b, int mult_transpose1xW_width = 1) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 210 | { |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 211 | // Note: mult_transpose1xW_width expresses the number of chunks with size 1x(W) we want to store on the same row |
| 212 | // The transpose1xW output matrix will have the following shape: |
| 213 | // [ b_height * W, ceil(b_width / W) ] where W = (16 / element size of the tensor) * mult_transpose1xW_width |
| 214 | ARM_COMPUTE_ERROR_ON(mult_transpose1xW_width < 1); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 215 | TensorShape shape_transposed1xW_b{ b.tensor_shape() }; |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 216 | const size_t transpose_width = (16 / b.element_size()) * mult_transpose1xW_width; |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 217 | shape_transposed1xW_b.set(0, b.dimension(1) * transpose_width); |
| 218 | shape_transposed1xW_b.set(1, static_cast<size_t>(std::ceil(b.dimension(0) / static_cast<float>(transpose_width)))); |
| 219 | |
| 220 | return shape_transposed1xW_b; |
| 221 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 222 | |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 223 | inline TensorShape compute_reductionA_shape(const ITensorInfo &b) |
| 224 | { |
| 225 | TensorShape shape_vector_sum_col{ b.tensor_shape() }; |
| 226 | if(shape_vector_sum_col.num_dimensions() > 1) |
| 227 | { |
| 228 | shape_vector_sum_col.remove_dimension(1); |
| 229 | } |
| 230 | |
| 231 | return shape_vector_sum_col; |
| 232 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 233 | |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 234 | inline TensorShape compute_reductionB_shape(const ITensorInfo &a) |
| 235 | { |
| 236 | TensorShape shape_vector_sum_row{ a.tensor_shape() }; |
| 237 | shape_vector_sum_row.set(Window::DimX, a.dimension(1)); |
Georgios Pinitas | 932491f | 2018-09-21 16:33:15 +0100 | [diff] [blame] | 238 | if(shape_vector_sum_row.num_dimensions() > 1) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 239 | { |
| 240 | shape_vector_sum_row.remove_dimension(1); |
| 241 | } |
| 242 | |
| 243 | return shape_vector_sum_row; |
| 244 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 245 | |
Giorgio Arena | 226e4b9 | 2018-08-23 12:00:02 +0100 | [diff] [blame] | 246 | inline TensorShape compute_col2im_shape(const ITensorInfo &input, const Size2D &convolved_dims, bool batch_size_on_z, unsigned int num_groups = 1) |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 247 | { |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 248 | ARM_COMPUTE_ERROR_ON(num_groups == 0); |
Giorgio Arena | 226e4b9 | 2018-08-23 12:00:02 +0100 | [diff] [blame] | 249 | ARM_COMPUTE_ERROR_ON(input.tensor_shape()[1] != (convolved_dims.area())); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 250 | ARM_COMPUTE_ERROR_ON((num_groups > 1) && input.tensor_shape()[2] != num_groups); |
| 251 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 252 | const DataLayout data_layout = input.data_layout(); |
| 253 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 254 | const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 255 | const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 256 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 257 | TensorShape col2im_shape{ input.tensor_shape() }; |
| 258 | // If batches start on 3rd dimension shift dimensions right by 1 to retain upper tensor shape, |
| 259 | // as first three will be override by H,W,C data |
| 260 | if(batch_size_on_z && num_groups == 1) |
| 261 | { |
| 262 | col2im_shape.shift_right(1); |
| 263 | } |
| 264 | col2im_shape.set(width_idx, convolved_dims.width); |
| 265 | col2im_shape.set(height_idx, convolved_dims.height); |
| 266 | col2im_shape.set(channel_idx, input.tensor_shape()[0] * num_groups); |
Georgios Pinitas | 78c0090 | 2018-01-09 17:33:11 +0000 | [diff] [blame] | 267 | |
| 268 | return col2im_shape; |
| 269 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 270 | |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 271 | inline TensorShape compute_transposed_shape(const ITensorInfo &input) |
| 272 | { |
| 273 | TensorShape shape_transposed{ input.tensor_shape() }; |
| 274 | |
| 275 | shape_transposed.set(0, input.dimension(1)); |
| 276 | shape_transposed.set(1, input.dimension(0)); |
| 277 | |
| 278 | return shape_transposed; |
| 279 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 280 | |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 281 | inline TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info, unsigned int depth_multiplier) |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 282 | { |
| 283 | const TensorShape input_shape{ input.tensor_shape() }; |
| 284 | const TensorShape weights_shape{ weights.tensor_shape() }; |
| 285 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 286 | const DataLayout data_layout = input.data_layout(); |
| 287 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 288 | const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 289 | const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 290 | |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 291 | unsigned int output_width = 0; |
| 292 | unsigned int output_height = 0; |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 293 | std::tie(output_width, output_height) = scaled_dimensions(input_shape[width_idx], input_shape[height_idx], |
| 294 | weights_shape[width_idx], weights_shape[height_idx], |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 295 | conv_info); |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 296 | |
| 297 | TensorShape output_shape{ input_shape }; |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 298 | output_shape.set(width_idx, output_width); |
| 299 | output_shape.set(height_idx, output_height); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 300 | output_shape.set(channel_idx, input_shape[channel_idx] * depth_multiplier); |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 301 | |
| 302 | return output_shape; |
| 303 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 304 | |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 305 | inline TensorShape compute_deconvolution_upsampled_shape(const ITensorInfo &input, const ITensorInfo &weights, unsigned int sx, unsigned int sy, unsigned int inner_border_right, |
| 306 | unsigned int inner_border_top, |
| 307 | std::pair<unsigned int, unsigned int> &out_dims, unsigned int &padx, unsigned int &pady) |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 308 | { |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 309 | const DataLayout data_layout = input.data_layout(); |
| 310 | const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 311 | const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 312 | |
Michalis Spyrou | afbc5ff | 2018-10-03 14:18:19 +0100 | [diff] [blame] | 313 | // Find the upsampled dimensions |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 314 | unsigned int out_x = (input.dimension(idx_w) - 1) * sx + inner_border_right + 1; |
| 315 | unsigned int out_y = (input.dimension(idx_h) - 1) * sy + inner_border_top + 1; |
Michalis Spyrou | afbc5ff | 2018-10-03 14:18:19 +0100 | [diff] [blame] | 316 | |
| 317 | // Find the padding needed for the convolution with stride 1 in order to match output shape |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 318 | padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1); |
| 319 | pady = out_dims.second - (out_y - weights.dimension(idx_h) + 1); |
Michalis Spyrou | afbc5ff | 2018-10-03 14:18:19 +0100 | [diff] [blame] | 320 | out_x += padx; |
| 321 | out_y += pady; |
| 322 | |
| 323 | TensorShape scale_out_shape(input.tensor_shape()); |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 324 | scale_out_shape.set(idx_w, out_x); |
| 325 | scale_out_shape.set(idx_h, out_y); |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 326 | |
| 327 | return scale_out_shape; |
| 328 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 329 | |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 330 | inline TensorShape compute_deconvolution_output_shape(const std::pair<unsigned int, unsigned int> &out_dims, const ITensorInfo &input, const ITensorInfo &weights) |
| 331 | { |
| 332 | const TensorShape input_shape{ input.tensor_shape() }; |
| 333 | const TensorShape weights_shape{ weights.tensor_shape() }; |
| 334 | |
| 335 | const DataLayout data_layout = input.data_layout(); |
| 336 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 337 | const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 338 | const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 339 | const int batch_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
| 340 | |
| 341 | TensorShape out_shape{ input_shape }; |
| 342 | out_shape.set(width_idx, out_dims.first); |
| 343 | out_shape.set(height_idx, out_dims.second); |
| 344 | out_shape.set(channel_idx, weights_shape[batch_idx]); |
| 345 | return out_shape; |
| 346 | } |
| 347 | |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 348 | inline TensorShape compute_im2col_conv_shape(const ITensorInfo *input, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, bool batch_size_on_z, |
| 349 | unsigned int num_groups = 1) |
Giorgio Arena | 156fcf3 | 2018-03-09 15:30:43 +0000 | [diff] [blame] | 350 | { |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 351 | // The output shape will be the 3D shape [ out_channels * kernel_area, num_elems_per_out_channel, batches ] if batch_size_on_z == true |
| 352 | // or the 4D shape [ out_channels * kernel_area / num_groups, num_elems_per_out_channel, num_groups, batches ] if batch_size_on_z == false |
| 353 | |
| 354 | ARM_COMPUTE_ERROR_ON(num_groups == 0); |
| 355 | ARM_COMPUTE_ERROR_ON(num_groups > 1 && input->data_layout() != DataLayout::NCHW); |
| 356 | ARM_COMPUTE_ERROR_ON(num_groups > 1 && batch_size_on_z); |
Giorgio Arena | 156fcf3 | 2018-03-09 15:30:43 +0000 | [diff] [blame] | 357 | |
| 358 | TensorShape output_shape{ input->tensor_shape() }; |
| 359 | |
| 360 | const DataLayout data_layout = input->data_layout(); |
| 361 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 362 | const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 363 | const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 364 | |
| 365 | std::pair<unsigned int, unsigned int> out_dims = scaled_dimensions(output_shape[width_idx], output_shape[height_idx], kernel_dims.width, kernel_dims.height, conv_info, dilation); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 366 | output_shape.set(0, (output_shape[channel_idx] / num_groups * kernel_dims.area() + (has_bias ? 1 : 0))); // NOLINT |
Giorgio Arena | f485a10 | 2018-04-20 16:06:21 +0100 | [diff] [blame] | 367 | output_shape.set(1, (out_dims.first * out_dims.second)); |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 368 | if(batch_size_on_z && output_shape.num_dimensions() >= 3) |
| 369 | { |
| 370 | output_shape.remove_dimension(2); |
| 371 | } |
| 372 | else |
| 373 | { |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 374 | output_shape.set(2, num_groups); |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 375 | } |
Giorgio Arena | 156fcf3 | 2018-03-09 15:30:43 +0000 | [diff] [blame] | 376 | |
| 377 | return output_shape; |
| 378 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 379 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 380 | inline TensorShape compute_flatten_shape(const ITensorInfo *input) |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 381 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 382 | // The output shape will be the flatten version of the input (i.e. [ width * height * channels, num_batches, ... ] ). Used for FlattenLayer and FullyConnectedLayer. |
| 383 | |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 384 | TensorShape output_shape{ input->tensor_shape() }; |
| 385 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 386 | output_shape.collapse(3); |
Giorgio Arena | 156fcf3 | 2018-03-09 15:30:43 +0000 | [diff] [blame] | 387 | |
| 388 | return output_shape; |
| 389 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 390 | |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 391 | inline TensorShape compute_softmax_shape(const ITensorInfo *input, size_t axis = 1) |
| 392 | { |
| 393 | // The output shape will be a 2D version of the input. For instance: |
| 394 | // - [x,y,z] and axis 1 will return [x, y*z] |
| 395 | // - [x,y,z,w] and axis 2 will return [x*y, w*z] |
| 396 | // - [x,y,z,w] and axis 3 will return [x*y*z, w] |
| 397 | TensorShape shape2D = input->tensor_shape(); |
| 398 | |
| 399 | if(axis < input->num_dimensions()) |
| 400 | { |
| 401 | // Collapse from axis onward (this changes the shape) |
| 402 | shape2D.collapse_from(axis); |
| 403 | |
| 404 | // Collapse the rest (collapse is inclusive) |
| 405 | shape2D.collapse(shape2D.num_dimensions() - 1); |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | // Collapse everything |
| 410 | shape2D.collapse(shape2D.num_dimensions()); |
| 411 | } |
| 412 | |
| 413 | if(axis == 0) |
| 414 | { |
| 415 | // If axis is zero the first dim should be one. Since |
| 416 | // collapse is an inclusive operation we need to shift |
| 417 | shape2D.shift_right(1); |
| 418 | } |
| 419 | |
| 420 | return shape2D; |
| 421 | } |
| 422 | |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 423 | inline TensorShape compute_interleave_custom_shape(const TensorShape &input, const int x_interleave, const int y_interleave) |
| 424 | { |
| 425 | TensorShape output_shape{ input }; |
| 426 | |
| 427 | output_shape.set(0, output_shape.x() * x_interleave); |
| 428 | output_shape.set(1, std::ceil(output_shape.y() / static_cast<float>(y_interleave))); |
| 429 | |
| 430 | return output_shape; |
| 431 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 432 | |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 433 | inline TensorShape compute_fully_connected_reshaped_weights_shape(const ITensorInfo *input, bool transpose_weights, bool is_batched_fc_layer, const int interleave) |
| 434 | { |
| 435 | TensorShape output_shape{ input->tensor_shape() }; |
| 436 | |
| 437 | // Transpose weights if the user hasn't done it |
| 438 | if(transpose_weights) |
| 439 | { |
| 440 | output_shape = compute_transposed_shape(*input); |
| 441 | } |
| 442 | |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 443 | // If we run multiple batches we need 1xW transpose, too. |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 444 | if(is_batched_fc_layer) |
| 445 | { |
| 446 | output_shape = compute_transposed_shape(input->clone()->set_tensor_shape(output_shape)); |
| 447 | output_shape = compute_interleave_custom_shape(output_shape, interleave, interleave); |
| 448 | } |
| 449 | |
| 450 | return output_shape; |
| 451 | } |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 452 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 453 | inline TensorShape compute_winograd_filter_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info) |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 454 | { |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 455 | TensorShape tensor_shape{ input.tensor_shape() }; |
| 456 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 457 | const Size2D kernel_size = winograd_info.kernel_size; |
| 458 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 459 | const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1); |
Giorgio Arena | 2d9de0a | 2018-03-15 17:58:20 +0000 | [diff] [blame] | 460 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 461 | tensor_shape.remove_dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH)); |
| 462 | tensor_shape.set(Window::DimX, input.dimension(3)); |
| 463 | tensor_shape.set(Window::DimY, input.dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL))); |
| 464 | tensor_shape.set(Window::DimZ, input_tile_size.area()); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 465 | |
| 466 | return tensor_shape; |
| 467 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 468 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 469 | inline TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 470 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 471 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 472 | const Size2D kernel_size = winograd_info.kernel_size; |
| 473 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 474 | const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1); |
| 475 | |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 476 | const size_t idx_w = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH); |
| 477 | const size_t idx_h = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT); |
| 478 | const size_t idx_c = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 479 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 480 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
| 481 | const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(input.tensor_shape()[idx_w], input.tensor_shape()[idx_h]), |
| 482 | kernel_size, |
| 483 | output_tile_size, |
| 484 | conv_info); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 485 | |
| 486 | const unsigned int width = input.tensor_shape()[idx_c]; |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 487 | const unsigned int height = num_tiles.area(); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 488 | const unsigned int depth = input_tile_size.area(); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 489 | |
| 490 | TensorShape output_shape{ input.tensor_shape() }; |
| 491 | output_shape.set(0, width); |
| 492 | output_shape.set(1, height); |
| 493 | output_shape.set(2, depth); |
| 494 | |
| 495 | return output_shape; |
| 496 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 497 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 498 | inline TensorShape compute_winograd_output_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 499 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 500 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 501 | const Size2D kernel_size = winograd_info.kernel_size; |
| 502 | const Size2D input_dimensions = winograd_info.input_dimensions; |
| 503 | const DataLayout data_layout = winograd_info.output_data_layout; |
| 504 | |
| 505 | // Compute output shape |
| 506 | unsigned int output_width = 0; |
| 507 | unsigned int output_height = 0; |
| 508 | std::tie(output_width, output_height) = scaled_dimensions(input_dimensions.width, input_dimensions.height, |
| 509 | kernel_size.width, kernel_size.height, conv_info); |
| 510 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 511 | TensorShape tensor_shape{ input.tensor_shape() }; |
| 512 | |
| 513 | // Output dimension |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 514 | const unsigned int out_w = output_width; |
| 515 | const unsigned int out_h = output_height; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 516 | const unsigned int out_c = input.dimension(0); |
| 517 | |
| 518 | tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH), out_w); |
| 519 | tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT), out_h); |
| 520 | tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL), out_c); |
| 521 | |
| 522 | return tensor_shape; |
| 523 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 524 | |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 525 | inline TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info) |
| 526 | { |
| 527 | const TensorShape input_shape{ input.tensor_shape() }; |
| 528 | const TensorShape weights_shape{ weights.tensor_shape() }; |
| 529 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 530 | const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH); |
| 531 | const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT); |
| 532 | const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL); |
| 533 | |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 534 | const unsigned int input_width = input_shape[idx_width]; |
| 535 | const unsigned int input_height = input_shape[idx_height]; |
| 536 | const unsigned int weights_width = weights_shape[idx_width]; |
| 537 | const unsigned int weights_height = weights_shape[idx_height]; |
| 538 | const unsigned int weights_out_channel = weights_shape[3]; |
| 539 | unsigned int output_width = 0; |
| 540 | unsigned int output_height = 0; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 541 | std::tie(output_width, output_height) = scaled_dimensions(input_width, input_height, weights_width, weights_height, conv_info); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 542 | |
| 543 | TensorShape output_shape{ input_shape }; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 544 | output_shape.set(idx_width, output_width); |
| 545 | output_shape.set(idx_height, output_height); |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 546 | output_shape.set(idx_channel, weights_out_channel); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 547 | |
| 548 | return output_shape; |
| 549 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 550 | |
Alex Gilday | 60954c6 | 2018-03-05 16:22:48 +0000 | [diff] [blame] | 551 | inline TensorShape compute_min_max_shape(const ITensorInfo *input) |
| 552 | { |
| 553 | TensorShape output_shape{ input->tensor_shape() }; |
| 554 | output_shape.set(Window::DimX, 2); |
| 555 | output_shape.remove_dimension(1); |
| 556 | output_shape.remove_dimension(1); |
| 557 | |
| 558 | return output_shape; |
| 559 | } |
| 560 | |
Michalis Spyrou | e74b201 | 2018-04-18 09:49:16 +0100 | [diff] [blame] | 561 | inline TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info) |
| 562 | { |
| 563 | unsigned int pooled_w = 0; |
| 564 | unsigned int pooled_h = 0; |
| 565 | |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 566 | TensorShape output_shape{ input.tensor_shape() }; |
Michalis Spyrou | e74b201 | 2018-04-18 09:49:16 +0100 | [diff] [blame] | 567 | |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 568 | const bool is_global_pooling = pool_info.is_global_pooling(); |
| 569 | const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH); |
| 570 | const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT); |
| 571 | const unsigned int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size().width; |
| 572 | const unsigned int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size().height; |
| 573 | |
| 574 | std::tie(pooled_w, pooled_h) = scaled_dimensions(output_shape[idx_width], |
| 575 | output_shape[idx_height], |
Michalis Spyrou | e74b201 | 2018-04-18 09:49:16 +0100 | [diff] [blame] | 576 | pool_size_x, |
| 577 | pool_size_y, |
| 578 | pool_info.pad_stride_info()); |
| 579 | |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 580 | output_shape.set(idx_width, pooled_w); |
| 581 | output_shape.set(idx_height, pooled_h); |
Michalis Spyrou | e74b201 | 2018-04-18 09:49:16 +0100 | [diff] [blame] | 582 | |
| 583 | return output_shape; |
| 584 | } |
| 585 | |
Michalis Spyrou | 36a559e | 2018-03-20 10:30:58 +0000 | [diff] [blame] | 586 | inline TensorShape compute_rnn_shape(const ITensorInfo *input, const unsigned int batch_size) |
| 587 | { |
| 588 | TensorShape output_shape{ input->tensor_shape() }; |
| 589 | output_shape.set(1, batch_size); |
| 590 | |
| 591 | return output_shape; |
| 592 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 593 | |
Gian Marco Iodice | 750641d | 2018-05-08 12:01:57 +0100 | [diff] [blame] | 594 | inline TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo &input1, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info) |
| 595 | { |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 596 | ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4"); |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 597 | ARM_COMPUTE_ERROR_ON_MSG(is_interleaved_transposed && reshape_info.reinterpret_input_as_3d(), "The first input tensor cannot be reinterpreted as 3D if is_interleaved_transposed is true"); |
Gian Marco Iodice | 750641d | 2018-05-08 12:01:57 +0100 | [diff] [blame] | 598 | |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 599 | const bool reinterpret_input_as_3d = reshape_info.reinterpret_input_as_3d(); |
Gian Marco Iodice | 3139f03 | 2018-11-05 14:26:32 +0000 | [diff] [blame] | 600 | const bool reinterpret_output_as_3d = reshape_info.depth_output_gemm3d() != 0; |
| 601 | const int depth_output_gemm3d = reinterpret_output_as_3d ? reshape_info.depth_output_gemm3d() : 1; |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 602 | const int m = reshape_info.reinterpret_input_as_3d() ? input0.dimension(1) * input0.dimension(2) : input0.dimension(1); |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 603 | |
| 604 | // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third |
| 605 | // dimension of the output tensor |
| 606 | const int dim0 = is_interleaved_transposed ? reshape_info.n() : input1.dimension(0); |
Gian Marco Iodice | 3139f03 | 2018-11-05 14:26:32 +0000 | [diff] [blame] | 607 | const int dim1 = is_interleaved_transposed ? reshape_info.m() / depth_output_gemm3d : m / depth_output_gemm3d; |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 608 | const int dim2 = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2]; |
| 609 | const int dim3 = reinterpret_input_as_3d ? 1 : input0.tensor_shape()[3]; |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 610 | |
| 611 | TensorShape output_shape{ input0.tensor_shape() }; |
| 612 | |
| 613 | output_shape.set(0, dim0); |
| 614 | output_shape.set(1, dim1); |
Gian Marco Iodice | 3139f03 | 2018-11-05 14:26:32 +0000 | [diff] [blame] | 615 | output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2); |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 616 | output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3); |
| 617 | output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1); |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 618 | |
| 619 | return output_shape; |
Gian Marco Iodice | 750641d | 2018-05-08 12:01:57 +0100 | [diff] [blame] | 620 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 621 | |
Gian Marco Iodice | bf9731e | 2018-12-12 10:18:04 +0000 | [diff] [blame] | 622 | inline TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo &input1, const GEMMReshapeInfo &gemm_info) |
| 623 | { |
| 624 | ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4"); |
| 625 | |
| 626 | const bool reinterpret_output_as_3d = gemm_info.depth_output_gemm3d() != 0; |
| 627 | const int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.depth_output_gemm3d() : 1; |
| 628 | |
| 629 | // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third |
| 630 | // dimension of the output tensor |
| 631 | const int dim0 = gemm_info.n(); |
| 632 | const int dim1 = gemm_info.m() / depth_output_gemm3d; |
| 633 | const int dim2 = input0.tensor_shape()[2]; |
| 634 | const int dim3 = input0.tensor_shape()[3]; |
| 635 | |
| 636 | TensorShape output_shape{ input0.tensor_shape() }; |
| 637 | |
| 638 | output_shape.set(0, dim0); |
| 639 | output_shape.set(1, dim1); |
| 640 | output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2); |
| 641 | output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3); |
| 642 | output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1); |
| 643 | |
| 644 | return output_shape; |
| 645 | } |
| 646 | |
Georgios Pinitas | 932491f | 2018-09-21 16:33:15 +0100 | [diff] [blame] | 647 | inline TensorShape compute_output_stage_shape(const ITensorInfo &input, unsigned int gemm_3d_depth = 1, bool batch_size_on_z = false) |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 648 | { |
| 649 | ARM_COMPUTE_ERROR_ON(input.data_layout() != DataLayout::NHWC && gemm_3d_depth > 1); |
| 650 | |
| 651 | TensorShape output_shape = input.tensor_shape(); |
| 652 | if(gemm_3d_depth > 1) |
| 653 | { |
Georgios Pinitas | 932491f | 2018-09-21 16:33:15 +0100 | [diff] [blame] | 654 | if(batch_size_on_z) |
| 655 | { |
| 656 | output_shape.shift_right(1); |
| 657 | } |
Georgios Pinitas | 041f36d | 2018-09-18 18:38:37 +0100 | [diff] [blame] | 658 | output_shape.set(0, input.tensor_shape().x()); |
| 659 | output_shape.set(1, input.tensor_shape().y() / gemm_3d_depth); |
| 660 | output_shape.set(2, gemm_3d_depth); |
| 661 | } |
| 662 | |
| 663 | return output_shape; |
| 664 | } |
| 665 | |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 666 | inline TensorShape compute_strided_slice_shape(const ITensorInfo &input, |
| 667 | const Coordinates &starts, const Coordinates &ends, const Coordinates &strides, |
| 668 | int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask) |
| 669 | { |
| 670 | using namespace arm_compute::helpers::tensor_transform; |
Georgios Pinitas | b4af2c6 | 2018-12-10 18:45:35 +0000 | [diff] [blame^] | 671 | return compute_strided_slice_output_shape(input.tensor_shape(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); |
| 672 | } |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 673 | |
Georgios Pinitas | b4af2c6 | 2018-12-10 18:45:35 +0000 | [diff] [blame^] | 674 | inline TensorShape compute_slice_shape(const TensorShape &input_shape, const Coordinates &starts, const Coordinates &ends) |
| 675 | { |
| 676 | using namespace arm_compute::helpers::tensor_transform; |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 677 | |
Georgios Pinitas | b4af2c6 | 2018-12-10 18:45:35 +0000 | [diff] [blame^] | 678 | return compute_strided_slice_output_shape(input_shape, |
| 679 | starts, ends, BiStrides(), |
| 680 | 0, construct_slice_end_mask(ends), 0); |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 681 | } |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 682 | |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 683 | inline TensorShape compute_batch_to_space_shape(const ITensorInfo *input, const int block_x, const int block_y) |
| 684 | { |
| 685 | ARM_COMPUTE_ERROR_ON(block_x <= 0 || block_y <= 0); |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 686 | |
| 687 | const DataLayout data_layout = input->data_layout(); |
| 688 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 689 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Michalis Spyrou | 13a51e1 | 2018-09-18 13:09:30 +0100 | [diff] [blame] | 690 | const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 691 | |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 692 | TensorShape output_shape{ input->tensor_shape() }; |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 693 | output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x); |
| 694 | output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y); |
Michalis Spyrou | 13a51e1 | 2018-09-18 13:09:30 +0100 | [diff] [blame] | 695 | output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y)); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 696 | |
| 697 | return output_shape; |
| 698 | } |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 699 | |
Georgios Pinitas | e1a352c | 2018-09-03 12:42:19 +0100 | [diff] [blame] | 700 | inline TensorShape compute_split_shape(const ITensorInfo *input, unsigned int axis, unsigned int num_splits) |
| 701 | { |
| 702 | TensorShape empty_shape; |
| 703 | empty_shape.set(0, 0); |
| 704 | |
| 705 | TensorShape out_shape{ input->tensor_shape() }; |
| 706 | |
| 707 | // Return empty shape if axis is invalid |
| 708 | if(axis > input->tensor_shape().num_dimensions()) |
| 709 | { |
| 710 | return empty_shape; |
| 711 | } |
| 712 | |
| 713 | size_t axis_size = out_shape[axis]; |
| 714 | |
| 715 | // Return empty shape if num_split is not valid |
| 716 | if(axis_size % num_splits) |
| 717 | { |
| 718 | return empty_shape; |
| 719 | } |
| 720 | |
| 721 | out_shape[axis] = axis_size / num_splits; |
| 722 | return out_shape; |
| 723 | } |
| 724 | |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 725 | inline TensorShape compute_space_to_batch_shape(const ITensorInfo *input, const int block_x, const int block_y, const Size2D &padding_left, const Size2D &padding_right) |
| 726 | { |
| 727 | TensorShape output_shape{ input->tensor_shape() }; |
Michalis Spyrou | 13a51e1 | 2018-09-18 13:09:30 +0100 | [diff] [blame] | 728 | |
| 729 | const DataLayout data_layout = input->data_layout(); |
| 730 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 731 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 732 | const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
| 733 | |
| 734 | output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x + padding_left.x() + padding_right.x()); |
| 735 | output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y + padding_left.y() + padding_right.y()); |
| 736 | output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y)); |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 737 | |
| 738 | return output_shape; |
| 739 | } |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 740 | |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 741 | inline TensorShape compute_prior_box_shape(const ITensorInfo &input, const PriorBoxLayerInfo &info) |
| 742 | { |
| 743 | DataLayout data_layout = input.data_layout(); |
| 744 | const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 745 | const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 746 | const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size(); |
Michalis Spyrou | 6c7c38e | 2018-08-29 16:28:11 +0100 | [diff] [blame] | 747 | |
| 748 | TensorShape output_shape{}; |
| 749 | output_shape.set(0, input.dimension(idx_w) * input.dimension(idx_h) * num_priors * 4); |
| 750 | output_shape.set(1, 2); |
| 751 | |
| 752 | return output_shape; |
| 753 | } |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 754 | |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 755 | inline TensorShape compute_padded_shape(const TensorShape &input_shape, const PaddingList &padding) |
| 756 | { |
| 757 | TensorShape padded_shape = input_shape; |
| 758 | for(size_t dim = 0; dim < padding.size(); ++dim) |
| 759 | { |
| 760 | padded_shape.set(dim, padding[dim].first + input_shape[dim] + padding[dim].second); |
| 761 | } |
| 762 | return padded_shape; |
| 763 | } |
| 764 | |
giuros01 | 3175fcf | 2018-11-21 09:59:17 +0000 | [diff] [blame] | 765 | inline TensorShape compute_tiled_shape(const TensorShape &input_shape, const Multiples &multiples) |
| 766 | { |
| 767 | TensorShape tiled_shape = input_shape; |
| 768 | for(size_t dim = 0; dim < multiples.size(); ++dim) |
| 769 | { |
| 770 | tiled_shape.set(dim, input_shape[dim] * multiples[dim]); |
| 771 | } |
| 772 | return tiled_shape; |
| 773 | } |
| 774 | |
Michalis Spyrou | ceb889e | 2018-09-17 18:24:41 +0100 | [diff] [blame] | 775 | inline TensorShape compute_upsample_shape(const ITensorInfo &input, const Size2D &info) |
| 776 | { |
| 777 | const DataLayout data_layout = input.data_layout(); |
| 778 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 779 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 780 | |
| 781 | TensorShape scale_out_shape(input.tensor_shape()); |
| 782 | const unsigned int out_x = input.dimension(idx_width) * info.x(); |
| 783 | const unsigned int out_y = input.dimension(idx_height) * info.y(); |
| 784 | scale_out_shape.set(idx_width, out_x); |
| 785 | scale_out_shape.set(idx_height, out_y); |
| 786 | |
| 787 | return scale_out_shape; |
| 788 | } |
| 789 | |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 790 | template <typename T> |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 791 | inline TensorShape extract_shape(T *data) |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 792 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 793 | return data->info()->tensor_shape(); |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 794 | } |
| 795 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 796 | inline TensorShape extract_shape(ITensorInfo *data) |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 797 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 798 | return data->tensor_shape(); |
| 799 | } |
| 800 | |
| 801 | inline TensorShape extract_shape(const TensorShape *data) |
| 802 | { |
| 803 | return *data; |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | template <typename T> |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 807 | inline TensorShape calculate_depth_concatenate_shape(const std::vector<T *> &inputs_vector) |
| 808 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 809 | TensorShape out_shape = extract_shape(inputs_vector[0]); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 810 | |
| 811 | size_t max_x = 0; |
| 812 | size_t max_y = 0; |
| 813 | size_t depth = 0; |
| 814 | |
| 815 | for(const auto &tensor : inputs_vector) |
| 816 | { |
| 817 | ARM_COMPUTE_ERROR_ON(tensor == nullptr); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 818 | const TensorShape shape = extract_shape(tensor); |
Georgios Pinitas | e29acf1 | 2018-07-16 14:40:09 +0100 | [diff] [blame] | 819 | max_x = std::max(shape.x(), max_x); |
| 820 | max_y = std::max(shape.y(), max_y); |
| 821 | depth += shape.z(); |
| 822 | } |
| 823 | |
| 824 | out_shape.set(0, max_x); |
| 825 | out_shape.set(1, max_y); |
| 826 | out_shape.set(2, depth); |
| 827 | |
| 828 | return out_shape; |
| 829 | } |
| 830 | |
| 831 | template <typename T> |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 832 | inline TensorShape calculate_width_concatenate_shape(const std::vector<T *> &inputs_vector) |
| 833 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 834 | TensorShape out_shape = extract_shape(inputs_vector[0]); |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 835 | |
| 836 | size_t width = 0; |
| 837 | for(const auto &tensor : inputs_vector) |
| 838 | { |
| 839 | ARM_COMPUTE_ERROR_ON(tensor == nullptr); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 840 | const TensorShape shape = extract_shape(tensor); |
Michalis Spyrou | 55b3d12 | 2018-05-09 09:59:23 +0100 | [diff] [blame] | 841 | width += shape.x(); |
| 842 | } |
| 843 | |
| 844 | out_shape.set(0, width); |
| 845 | |
| 846 | return out_shape; |
| 847 | } |
Gian Marco Iodice | 8aa985e | 2018-11-27 15:58:08 +0000 | [diff] [blame] | 848 | |
| 849 | inline TensorShape compute_stack_shape(const ITensorInfo &a, unsigned int axis, unsigned int num_tensors) |
| 850 | { |
| 851 | ARM_COMPUTE_ERROR_ON(axis > a.num_dimensions()); |
| 852 | ARM_COMPUTE_ERROR_ON(a.num_dimensions() > 4); |
| 853 | |
| 854 | TensorShape shape_out{ a.tensor_shape() }; |
| 855 | shape_out.set(axis, num_tensors); |
| 856 | |
| 857 | unsigned int i_shift = 0; |
| 858 | |
| 859 | for(unsigned int i = 0; i < a.num_dimensions(); ++i) |
| 860 | { |
| 861 | if(i == axis) |
| 862 | { |
| 863 | i_shift++; |
| 864 | } |
| 865 | |
| 866 | shape_out.set(i + i_shift, a.tensor_shape()[i]); |
| 867 | } |
| 868 | return shape_out; |
| 869 | } |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 870 | } // namespace shape_calculator |
| 871 | } // namespace misc |
| 872 | } // namespace arm_compute |
| 873 | #endif /* __ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H__ */ |