Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +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 | */ |
Jaroslaw Rzepecki | 0a878ae | 2017-11-22 17:16:39 +0000 | [diff] [blame] | 24 | |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 25 | #include "arm_compute/core/Utils.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Helpers.h" |
| 28 | #include "arm_compute/core/utils/StringUtils.h" |
SiCong Li | 9129549 | 2023-07-21 18:16:13 +0100 | [diff] [blame] | 29 | #include "arm_compute/function_info/ActivationLayerInfo.h" |
Jaroslaw Rzepecki | 0a878ae | 2017-11-22 17:16:39 +0000 | [diff] [blame] | 30 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | #include <cmath> |
| 33 | #include <cstdint> |
| 34 | #include <fstream> |
| 35 | #include <map> |
| 36 | #include <string> |
| 37 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
| 40 | std::string read_file(const std::string &filename, bool binary) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | { |
| 42 | std::string out; |
| 43 | std::ifstream fs; |
| 44 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 45 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | try |
| 47 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 48 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | fs.exceptions(std::ifstream::failbit | std::ifstream::badbit); |
| 50 | std::ios_base::openmode mode = std::ios::in; |
| 51 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 52 | if (binary) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | { |
| 54 | mode |= std::ios::binary; |
| 55 | } |
| 56 | |
| 57 | fs.open(filename, mode); |
| 58 | |
| 59 | // Go to the end of the file |
| 60 | fs.seekg(0, std::ios::end); |
| 61 | // Reserve the memory required to store the file's content |
| 62 | out.reserve(fs.tellg()); |
| 63 | // Go back to the beginning of the file |
| 64 | fs.seekg(0, std::ios::beg); |
| 65 | // Copy the content of the file |
| 66 | out.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>()); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 67 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 69 | catch (const std::ifstream::failure &e) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | { |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 71 | ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", filename.c_str(), e.what()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 73 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | |
| 75 | return out; |
| 76 | } |
| 77 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 78 | const std::string &string_from_channel(Channel channel) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 80 | static std::map<Channel, const std::string> channels_map = {{Channel::UNKNOWN, "UNKNOWN"}, |
| 81 | {Channel::R, "R"}, |
| 82 | {Channel::G, "G"}, |
| 83 | {Channel::B, "B"}, |
| 84 | {Channel::A, "A"}, |
| 85 | {Channel::Y, "Y"}, |
| 86 | {Channel::U, "U"}, |
| 87 | {Channel::V, "V"}, |
| 88 | {Channel::C0, "C0"}, |
| 89 | {Channel::C1, "C1"}, |
| 90 | {Channel::C2, "C2"}, |
| 91 | {Channel::C3, "C3"}}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | |
| 93 | return channels_map[channel]; |
| 94 | } |
| 95 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 96 | const std::string &string_from_border_mode(BorderMode border_mode) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 97 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 98 | static std::map<BorderMode, const std::string> border_mode_map = { |
| 99 | {BorderMode::UNDEFINED, "UNDEFINED"}, |
| 100 | {BorderMode::CONSTANT, "CONSTANT"}, |
| 101 | {BorderMode::REPLICATE, "REPLICATE"}, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | return border_mode_map[border_mode]; |
| 105 | } |
| 106 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 107 | const std::string &string_from_norm_type(NormType type) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 108 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 109 | static std::map<NormType, const std::string> norm_type_map = { |
| 110 | {NormType::IN_MAP_1D, "IN_MAP_1D"}, |
| 111 | {NormType::IN_MAP_2D, "IN_MAP_2D"}, |
| 112 | {NormType::CROSS_MAP, "CROSS_MAP"}, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | return norm_type_map[type]; |
| 116 | } |
| 117 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 118 | const std::string &string_from_pooling_type(PoolingType type) |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 119 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 120 | static std::map<PoolingType, const std::string> pool_type_map = { |
| 121 | {PoolingType::MAX, "MAX"}, |
| 122 | {PoolingType::AVG, "AVG"}, |
| 123 | {PoolingType::L2, "L2"}, |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | return pool_type_map[type]; |
| 127 | } |
| 128 | |
SiCongLi | c4270cf | 2021-12-22 11:22:40 +0000 | [diff] [blame] | 129 | bool is_pool_region_entirely_outside_input(const PoolingLayerInfo &info) |
| 130 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 131 | if (info.is_global_pooling || info.exclude_padding || info.pool_size.x() == 0 || info.pool_size.y() == 0) |
SiCongLi | c4270cf | 2021-12-22 11:22:40 +0000 | [diff] [blame] | 132 | { |
| 133 | return false; |
| 134 | } |
| 135 | const auto ps = info.pad_stride_info; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 136 | const auto pool_le_padding_x = info.pool_size.x() <= std::max({ps.pad_left(), ps.pad_right()}); |
| 137 | const auto pool_le_padding_y = info.pool_size.y() <= std::max({ps.pad_top(), ps.pad_bottom()}); |
SiCongLi | c4270cf | 2021-12-22 11:22:40 +0000 | [diff] [blame] | 138 | return pool_le_padding_x || pool_le_padding_y; |
| 139 | } |
| 140 | |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 141 | bool is_pool_3d_region_entirely_outside_input(const Pooling3dLayerInfo &info) |
| 142 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 143 | if (info.is_global_pooling || info.pool_size.x() == 0 || info.pool_size.y() == 0 || info.pool_size.z() == 0) |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 144 | { |
| 145 | return false; |
| 146 | } |
| 147 | const auto ps = info.padding; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 148 | const auto pool_le_padding_x = info.pool_size.x() <= std::max({ps.left, ps.right}); |
| 149 | const auto pool_le_padding_y = info.pool_size.y() <= std::max({ps.top, ps.bottom}); |
| 150 | const auto pool_le_padding_z = info.pool_size.z() <= std::max({ps.front, ps.back}); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 151 | return pool_le_padding_x || pool_le_padding_y || pool_le_padding_z; |
| 152 | } |
| 153 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 154 | const std::string &string_from_gemmlowp_output_stage(GEMMLowpOutputStageType output_stage) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 155 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 156 | static std::map<GEMMLowpOutputStageType, const std::string> output_stage_map = { |
| 157 | {GEMMLowpOutputStageType::NONE, ""}, |
| 158 | {GEMMLowpOutputStageType::QUANTIZE_DOWN, "quantize_down"}, |
| 159 | {GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, "quantize_down_fixedpoint"}, |
| 160 | {GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT, "quantize_down_float"}}; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 161 | |
| 162 | return output_stage_map[output_stage]; |
| 163 | } |
| 164 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 165 | std::string string_from_pixel_value(const PixelValue &value, const DataType data_type) |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 166 | { |
| 167 | std::stringstream ss; |
| 168 | std::string converted_string; |
| 169 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 170 | switch (data_type) |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 171 | { |
| 172 | case DataType::U8: |
| 173 | case DataType::QASYMM8: |
| 174 | // Needs conversion to 32 bit, otherwise interpreted as ASCII values |
| 175 | ss << uint32_t(value.get<uint8_t>()); |
| 176 | converted_string = ss.str(); |
| 177 | break; |
| 178 | case DataType::S8: |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 179 | case DataType::QASYMM8_SIGNED: |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 180 | case DataType::QSYMM8_PER_CHANNEL: |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 181 | // Needs conversion to 32 bit, otherwise interpreted as ASCII values |
| 182 | ss << int32_t(value.get<int8_t>()); |
| 183 | converted_string = ss.str(); |
| 184 | break; |
| 185 | case DataType::U16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 186 | case DataType::QASYMM16: |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 187 | ss << value.get<uint16_t>(); |
| 188 | converted_string = ss.str(); |
| 189 | break; |
| 190 | case DataType::S16: |
Manuel Bottini | 3689fcd | 2019-06-14 17:18:12 +0100 | [diff] [blame] | 191 | case DataType::QSYMM16: |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 192 | ss << value.get<int16_t>(); |
| 193 | converted_string = ss.str(); |
| 194 | break; |
| 195 | case DataType::U32: |
| 196 | ss << value.get<uint32_t>(); |
| 197 | converted_string = ss.str(); |
| 198 | break; |
| 199 | case DataType::S32: |
| 200 | ss << value.get<int32_t>(); |
| 201 | converted_string = ss.str(); |
| 202 | break; |
| 203 | case DataType::F32: |
| 204 | converted_string = float_to_string_with_full_precision(value.get<float>()); |
| 205 | break; |
| 206 | case DataType::F16: |
| 207 | static_assert(sizeof(half) == 2, "Half must be 16 bit"); |
| 208 | ss << value.get<half>(); |
| 209 | converted_string = ss.str(); |
| 210 | break; |
| 211 | default: |
| 212 | ARM_COMPUTE_ERROR("Not handled"); |
| 213 | } |
| 214 | |
| 215 | return converted_string; |
| 216 | } |
| 217 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 218 | PadStrideInfo calculate_same_pad(TensorShape input_shape, |
| 219 | TensorShape weights_shape, |
| 220 | PadStrideInfo conv_info, |
| 221 | DataLayout data_layout, |
| 222 | const Size2D &dilation, |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 223 | const DimensionRoundingType &rounding_type) |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 224 | { |
Sang-Hoon Park | 46023ed | 2019-11-12 16:26:26 +0000 | [diff] [blame] | 225 | const auto &strides = conv_info.stride(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 226 | ARM_COMPUTE_ERROR_ON_MSG((strides.first < 1 || strides.second < 1), |
| 227 | "Stride values should be greater than or equal to 1."); |
Sang-Hoon Park | 46023ed | 2019-11-12 16:26:26 +0000 | [diff] [blame] | 228 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 229 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 230 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 231 | const unsigned int in_width = input_shape[width_idx]; |
| 232 | const unsigned int in_height = input_shape[height_idx]; |
| 233 | const unsigned int kernel_width = weights_shape[width_idx]; |
| 234 | const unsigned int kernel_height = weights_shape[height_idx]; |
Georgios Pinitas | 4c75851 | 2019-07-10 19:49:11 +0100 | [diff] [blame] | 235 | |
| 236 | // Calculate output dimensions |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 237 | const auto is_ceil = static_cast<unsigned int>(rounding_type == DimensionRoundingType::CEIL); |
| 238 | const unsigned int out_width = ((in_width - is_ceil) + strides.first - 1) / strides.first + is_ceil; |
| 239 | const unsigned int out_height = ((in_height - is_ceil) + strides.second - 1) / strides.second + is_ceil; |
Georgios Pinitas | 4c75851 | 2019-07-10 19:49:11 +0100 | [diff] [blame] | 240 | |
| 241 | // Calculate effective weights sizes |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 242 | const int real_weight_width = (kernel_width - 1) * dilation.x() + 1; |
| 243 | const int real_weight_height = (kernel_height - 1) * dilation.y() + 1; |
Georgios Pinitas | 4c75851 | 2019-07-10 19:49:11 +0100 | [diff] [blame] | 244 | |
| 245 | // Calculate total pad |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 246 | const int pad_width = std::max(0, static_cast<int>((out_width - 1) * strides.first + real_weight_width - in_width)); |
| 247 | const int pad_height = |
| 248 | std::max(0, static_cast<int>((out_height - 1) * strides.second + real_weight_height - in_height)); |
Georgios Pinitas | 4c75851 | 2019-07-10 19:49:11 +0100 | [diff] [blame] | 249 | |
| 250 | // Calculate individual paddings |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 251 | const unsigned int pad_left = pad_width / 2; |
| 252 | const unsigned int pad_top = pad_height / 2; |
| 253 | const unsigned int pad_right = pad_width - pad_left; |
| 254 | const unsigned int pad_bottom = pad_height - pad_top; |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 255 | |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 256 | PadStrideInfo same_info(strides.first, strides.second, pad_left, pad_right, pad_top, pad_bottom, rounding_type); |
| 257 | |
| 258 | // Check for correctness of predicted output shape against the one calculated using the generated info |
| 259 | const auto out_dims = scaled_dimensions(in_width, in_height, kernel_width, kernel_height, same_info, dilation); |
| 260 | ARM_COMPUTE_ERROR_ON(out_dims.first != out_width || out_dims.second != out_height); |
| 261 | ARM_COMPUTE_UNUSED(out_dims); |
| 262 | |
| 263 | return same_info; |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 266 | std::pair<unsigned int, unsigned int> deconvolution_output_dimensions(unsigned int in_width, |
| 267 | unsigned int in_height, |
| 268 | unsigned int kernel_width, |
| 269 | unsigned int kernel_height, |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 270 | const PadStrideInfo &pad_stride_info) |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 271 | { |
Matthew Jackson | b9070a4 | 2019-08-22 16:13:27 +0100 | [diff] [blame] | 272 | const unsigned int pad_left = pad_stride_info.pad_left(); |
| 273 | const unsigned int pad_top = pad_stride_info.pad_top(); |
| 274 | const unsigned int pad_right = pad_stride_info.pad_right(); |
| 275 | const unsigned int pad_bottom = pad_stride_info.pad_bottom(); |
| 276 | const unsigned int stride_x = pad_stride_info.stride().first; |
| 277 | const unsigned int stride_y = pad_stride_info.stride().second; |
| 278 | |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 279 | ARM_COMPUTE_ERROR_ON(in_width < 1 || in_height < 1); |
Matthew Jackson | b9070a4 | 2019-08-22 16:13:27 +0100 | [diff] [blame] | 280 | ARM_COMPUTE_ERROR_ON(((in_width - 1) * stride_x + kernel_width) < (pad_left + pad_right)); |
| 281 | ARM_COMPUTE_ERROR_ON(((in_height - 1) * stride_y + kernel_height) < (pad_top + pad_bottom)); |
| 282 | const int w = stride_x * (in_width - 1) + kernel_width - (pad_left + pad_right); |
| 283 | const int h = stride_y * (in_height - 1) + kernel_height - (pad_top + pad_bottom); |
Michalis Spyrou | afbc5ff | 2018-10-03 14:18:19 +0100 | [diff] [blame] | 284 | |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 285 | return std::make_pair<unsigned int, unsigned int>(w, h); |
| 286 | } |
| 287 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 288 | std::pair<unsigned int, unsigned int> scaled_dimensions(int width, |
| 289 | int height, |
| 290 | int kernel_width, |
| 291 | int kernel_height, |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 292 | const PadStrideInfo &pad_stride_info, |
| 293 | const Size2D &dilation) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 294 | { |
Georgios Pinitas | 80838f1 | 2019-12-12 18:23:13 +0000 | [diff] [blame] | 295 | const int dilation_x = dilation.x(); |
| 296 | const int dilation_y = dilation.y(); |
| 297 | const int pad_left = pad_stride_info.pad_left(); |
| 298 | const int pad_top = pad_stride_info.pad_top(); |
| 299 | const int pad_right = pad_stride_info.pad_right(); |
| 300 | const int pad_bottom = pad_stride_info.pad_bottom(); |
| 301 | const int stride_x = pad_stride_info.stride().first; |
| 302 | const int stride_y = pad_stride_info.stride().second; |
| 303 | int w = 0; |
| 304 | int h = 0; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 305 | switch (pad_stride_info.round()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 306 | { |
| 307 | case DimensionRoundingType::FLOOR: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 308 | w = static_cast<int>(std::floor( |
| 309 | (static_cast<float>(width + pad_left + pad_right - (dilation_x * (kernel_width - 1) + 1)) / stride_x) + |
| 310 | 1)); |
| 311 | h = static_cast<int>( |
| 312 | std::floor((static_cast<float>(height + pad_top + pad_bottom - (dilation_y * (kernel_height - 1) + 1)) / |
| 313 | stride_y) + |
| 314 | 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 315 | break; |
| 316 | case DimensionRoundingType::CEIL: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 317 | w = static_cast<int>(std::ceil( |
| 318 | (static_cast<float>(width + pad_left + pad_right - (dilation_x * (kernel_width - 1) + 1)) / stride_x) + |
| 319 | 1)); |
| 320 | h = static_cast<int>( |
| 321 | std::ceil((static_cast<float>(height + pad_top + pad_bottom - (dilation_y * (kernel_height - 1) + 1)) / |
| 322 | stride_y) + |
| 323 | 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 324 | break; |
| 325 | default: |
| 326 | ARM_COMPUTE_ERROR("Unsupported rounding type"); |
| 327 | } |
| 328 | |
Georgios Pinitas | 80838f1 | 2019-12-12 18:23:13 +0000 | [diff] [blame] | 329 | w = std::max(1, w); |
| 330 | h = std::max(1, h); |
| 331 | return std::make_pair(static_cast<unsigned int>(w), static_cast<unsigned int>(h)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 334 | std::pair<int, int> scaled_dimensions_signed( |
| 335 | int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info) |
Freddie Liardet | afcbb8f | 2021-05-04 12:41:16 +0100 | [diff] [blame] | 336 | { |
| 337 | const int pad_left = pad_stride_info.pad_left(); |
| 338 | const int pad_top = pad_stride_info.pad_top(); |
| 339 | const int pad_right = pad_stride_info.pad_right(); |
| 340 | const int pad_bottom = pad_stride_info.pad_bottom(); |
| 341 | const int stride_x = pad_stride_info.stride().first; |
| 342 | const int stride_y = pad_stride_info.stride().second; |
| 343 | int w = 0; |
| 344 | int h = 0; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 345 | switch (pad_stride_info.round()) |
Freddie Liardet | afcbb8f | 2021-05-04 12:41:16 +0100 | [diff] [blame] | 346 | { |
| 347 | case DimensionRoundingType::FLOOR: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 348 | w = static_cast<int>( |
| 349 | std::floor((static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1)); |
| 350 | h = static_cast<int>( |
| 351 | std::floor((static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1)); |
Freddie Liardet | afcbb8f | 2021-05-04 12:41:16 +0100 | [diff] [blame] | 352 | break; |
| 353 | case DimensionRoundingType::CEIL: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 354 | w = static_cast<int>( |
| 355 | std::ceil((static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1)); |
| 356 | h = static_cast<int>( |
| 357 | std::ceil((static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1)); |
Freddie Liardet | afcbb8f | 2021-05-04 12:41:16 +0100 | [diff] [blame] | 358 | break; |
| 359 | default: |
| 360 | ARM_COMPUTE_ERROR("Unsupported rounding type"); |
| 361 | } |
| 362 | |
| 363 | return std::make_pair(static_cast<int>(w), static_cast<int>(h)); |
| 364 | } |
| 365 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 366 | std::tuple<int, int, int> scaled_3d_dimensions_signed(int width, |
| 367 | int height, |
| 368 | int depth, |
| 369 | int kernel_width, |
| 370 | int kernel_height, |
| 371 | int kernel_depth, |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 372 | const Pooling3dLayerInfo &pool3d_info) |
| 373 | { |
| 374 | const int pad_left = pool3d_info.padding.left; |
| 375 | const int pad_top = pool3d_info.padding.top; |
| 376 | const int pad_right = pool3d_info.padding.right; |
| 377 | const int pad_bottom = pool3d_info.padding.bottom; |
| 378 | const int pad_front = pool3d_info.padding.front; |
| 379 | const int pad_back = pool3d_info.padding.back; |
| 380 | const int stride_x = pool3d_info.stride.x(); |
| 381 | const int stride_y = pool3d_info.stride.y(); |
| 382 | const int stride_z = pool3d_info.stride.z(); |
| 383 | int w = 0; |
| 384 | int h = 0; |
| 385 | int d = 0; |
| 386 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 387 | switch (pool3d_info.round_type) |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 388 | { |
| 389 | case DimensionRoundingType::FLOOR: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 390 | w = static_cast<int>( |
| 391 | std::floor((static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1)); |
| 392 | h = static_cast<int>( |
| 393 | std::floor((static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1)); |
| 394 | d = static_cast<int>( |
| 395 | std::floor((static_cast<float>(depth + pad_front + pad_back - kernel_depth) / stride_z) + 1)); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 396 | break; |
| 397 | case DimensionRoundingType::CEIL: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 398 | w = static_cast<int>( |
| 399 | std::ceil((static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1)); |
| 400 | h = static_cast<int>( |
| 401 | std::ceil((static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1)); |
| 402 | d = static_cast<int>( |
| 403 | std::ceil((static_cast<float>(depth + pad_front + pad_back - kernel_depth) / stride_z) + 1)); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 404 | break; |
| 405 | default: |
| 406 | ARM_COMPUTE_ERROR("Unsupported rounding type"); |
| 407 | } |
| 408 | |
| 409 | return std::make_tuple(static_cast<int>(w), static_cast<int>(h), static_cast<int>(d)); |
| 410 | } |
| 411 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 412 | bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis) |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 413 | { |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 414 | const bool is_min_max = (op == ReductionOperation::MAX || op == ReductionOperation::MIN); |
| 415 | const bool is_quantized_type = is_data_type_quantized(dt); |
| 416 | const bool is_first_dim = (axis == 0); |
| 417 | |
Gunes Bayir | 338ef46 | 2023-07-18 15:57:23 +0100 | [diff] [blame] | 418 | return !is_first_dim || (is_quantized_type && !is_min_max); |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 419 | } |
| 420 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 421 | QuantizationInfo get_softmax_output_quantization_info(DataType input_type, bool is_log) |
Sang-Hoon Park | 0779fec | 2019-11-13 17:08:12 +0000 | [diff] [blame] | 422 | { |
| 423 | // Note: Output quantization info for softmax should always have |
| 424 | // * Softmax with QASYMM8: scale = 1/256, offset = 0 |
| 425 | // * Softmax with QASYMM8_SIGNED: scale = 1/256, offset = -128 |
| 426 | // * LogSoftmax with QASYMM8: scale = 1/256, offset = 0 |
| 427 | // * LogSoftmax with QASYMM8_SIGNED: scale = 16/256, offset = 127 |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 428 | if (is_data_type_quantized_asymmetric_signed(input_type)) |
Sang-Hoon Park | 0779fec | 2019-11-13 17:08:12 +0000 | [diff] [blame] | 429 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 430 | if (is_log) |
Sang-Hoon Park | 0779fec | 2019-11-13 17:08:12 +0000 | [diff] [blame] | 431 | { |
| 432 | return QuantizationInfo(16.f / 256, 127); |
| 433 | } |
| 434 | else |
| 435 | { |
| 436 | return QuantizationInfo(1.f / 256, -128); |
| 437 | } |
| 438 | } |
| 439 | return QuantizationInfo(1.f / 256, 0); |
| 440 | } |
| 441 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 442 | std::pair<int32_t, int32_t> get_quantized_activation_min_max(const ActivationLayerInfo &act_info, |
| 443 | DataType data_type, |
| 444 | UniformQuantizationInfo oq_info) |
Sang-Hoon Park | 4715cf9 | 2020-01-08 16:02:47 +0000 | [diff] [blame] | 445 | { |
| 446 | const bool is_qasymm8_signed = is_data_type_quantized_asymmetric_signed(data_type); |
| 447 | const auto a = act_info.a(); |
| 448 | const auto b = act_info.b(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 449 | const int a_int = is_qasymm8_signed ? quantize_qasymm8_signed(a, oq_info) : quantize_qasymm8(a, oq_info); |
| 450 | const int b_int = is_qasymm8_signed ? quantize_qasymm8_signed(b, oq_info) : quantize_qasymm8(b, oq_info); |
| 451 | const auto type_max_value = std::get<1>(get_min_max(data_type)).get<int32_t>(); |
Sang-Hoon Park | 4715cf9 | 2020-01-08 16:02:47 +0000 | [diff] [blame] | 452 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 453 | const int32_t min_activation = |
| 454 | act_info.activation() != ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU ? oq_info.offset : b_int; |
| 455 | const int32_t max_activation = |
| 456 | act_info.activation() == ActivationLayerInfo::ActivationFunction::RELU ? type_max_value : a_int; |
Sang-Hoon Park | 4715cf9 | 2020-01-08 16:02:47 +0000 | [diff] [blame] | 457 | |
| 458 | return std::make_pair(min_activation, max_activation); |
| 459 | } |
| 460 | |
Giorgio Arena | 4112eed | 2020-10-23 14:24:26 +0100 | [diff] [blame] | 461 | std::unordered_map<const ITensorInfo *, PaddingSize> get_padding_info(std::initializer_list<const ITensor *> tensors) |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 462 | { |
Giorgio Arena | 4112eed | 2020-10-23 14:24:26 +0100 | [diff] [blame] | 463 | std::unordered_map<const ITensorInfo *, PaddingSize> res; |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 464 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 465 | for (const ITensor *tensor : tensors) |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 466 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 467 | if (tensor) |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 468 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 469 | res.insert({tensor->info(), tensor->info()->padding()}); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | return res; |
| 474 | } |
| 475 | |
Giorgio Arena | 4112eed | 2020-10-23 14:24:26 +0100 | [diff] [blame] | 476 | std::unordered_map<const ITensorInfo *, PaddingSize> get_padding_info(std::initializer_list<const ITensorInfo *> infos) |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 477 | { |
Giorgio Arena | 4112eed | 2020-10-23 14:24:26 +0100 | [diff] [blame] | 478 | std::unordered_map<const ITensorInfo *, PaddingSize> res; |
| 479 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 480 | for (const ITensorInfo *info : infos) |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 481 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 482 | if (info) |
Giorgio Arena | 4112eed | 2020-10-23 14:24:26 +0100 | [diff] [blame] | 483 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 484 | res.insert({info, info->padding()}); |
Giorgio Arena | 4112eed | 2020-10-23 14:24:26 +0100 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
| 488 | return res; |
| 489 | } |
| 490 | |
| 491 | bool has_padding_changed(const std::unordered_map<const ITensorInfo *, PaddingSize> &padding_map) |
| 492 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 493 | return std::find_if(padding_map.begin(), padding_map.end(), |
| 494 | [](const std::pair<const ITensorInfo *, PaddingSize> &padding_info) |
| 495 | { return (padding_info.first->padding() != padding_info.second); }) != padding_map.end(); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 496 | } |
| 497 | |
giuros01 | edc21e4 | 2018-11-16 14:45:31 +0000 | [diff] [blame] | 498 | #ifdef ARM_COMPUTE_ASSERTS_ENABLED |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 499 | void print_consecutive_elements(std::ostream &s, |
| 500 | DataType dt, |
| 501 | const uint8_t *ptr, |
| 502 | unsigned int n, |
| 503 | int stream_width, |
| 504 | const std::string &element_delim) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 505 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 506 | switch (dt) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 507 | { |
| 508 | case DataType::U8: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 509 | case DataType::QASYMM8: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 510 | print_consecutive_elements_impl<uint8_t>(s, ptr, n, stream_width, element_delim); |
| 511 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 512 | case DataType::S8: |
Sang-Hoon Park | d5c020a | 2020-05-06 21:01:19 +0100 | [diff] [blame] | 513 | case DataType::QSYMM8: |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 514 | case DataType::QASYMM8_SIGNED: |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 515 | case DataType::QSYMM8_PER_CHANNEL: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 516 | print_consecutive_elements_impl<int8_t>(s, reinterpret_cast<const int8_t *>(ptr), n, stream_width, |
| 517 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 518 | break; |
| 519 | case DataType::U16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 520 | case DataType::QASYMM16: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 521 | print_consecutive_elements_impl<uint16_t>(s, reinterpret_cast<const uint16_t *>(ptr), n, stream_width, |
| 522 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 523 | break; |
| 524 | case DataType::S16: |
Manuel Bottini | 3689fcd | 2019-06-14 17:18:12 +0100 | [diff] [blame] | 525 | case DataType::QSYMM16: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 526 | print_consecutive_elements_impl<int16_t>(s, reinterpret_cast<const int16_t *>(ptr), n, stream_width, |
| 527 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 528 | break; |
| 529 | case DataType::U32: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 530 | print_consecutive_elements_impl<uint32_t>(s, reinterpret_cast<const uint32_t *>(ptr), n, stream_width, |
| 531 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 532 | break; |
| 533 | case DataType::S32: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 534 | print_consecutive_elements_impl<int32_t>(s, reinterpret_cast<const int32_t *>(ptr), n, stream_width, |
| 535 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 536 | break; |
Pablo Marquez Tello | 4a1c917 | 2023-07-18 14:51:24 +0100 | [diff] [blame] | 537 | case DataType::U64: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 538 | print_consecutive_elements_impl<uint64_t>(s, reinterpret_cast<const uint64_t *>(ptr), n, stream_width, |
| 539 | element_delim); |
Pablo Marquez Tello | 4a1c917 | 2023-07-18 14:51:24 +0100 | [diff] [blame] | 540 | break; |
| 541 | case DataType::S64: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 542 | print_consecutive_elements_impl<int64_t>(s, reinterpret_cast<const int64_t *>(ptr), n, stream_width, |
| 543 | element_delim); |
Pablo Marquez Tello | 4a1c917 | 2023-07-18 14:51:24 +0100 | [diff] [blame] | 544 | break; |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 545 | case DataType::BFLOAT16: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 546 | print_consecutive_elements_impl<bfloat16>(s, reinterpret_cast<const bfloat16 *>(ptr), n, stream_width, |
| 547 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 548 | break; |
| 549 | case DataType::F16: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 550 | print_consecutive_elements_impl<half>(s, reinterpret_cast<const half *>(ptr), n, stream_width, |
| 551 | element_delim); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 552 | break; |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 553 | case DataType::F32: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 554 | print_consecutive_elements_impl<float>(s, reinterpret_cast<const float *>(ptr), n, stream_width, |
| 555 | element_delim); |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 556 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 557 | default: |
| 558 | ARM_COMPUTE_ERROR("Undefined element size for given data type"); |
| 559 | } |
| 560 | } |
| 561 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 562 | int max_consecutive_elements_display_width(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 563 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 564 | switch (dt) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 565 | { |
| 566 | case DataType::U8: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 567 | case DataType::QASYMM8: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 568 | return max_consecutive_elements_display_width_impl<uint8_t>(s, ptr, n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 569 | case DataType::S8: |
Sang-Hoon Park | d5c020a | 2020-05-06 21:01:19 +0100 | [diff] [blame] | 570 | case DataType::QSYMM8: |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 571 | case DataType::QASYMM8_SIGNED: |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 572 | case DataType::QSYMM8_PER_CHANNEL: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 573 | return max_consecutive_elements_display_width_impl<int8_t>(s, reinterpret_cast<const int8_t *>(ptr), n); |
| 574 | case DataType::U16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 575 | case DataType::QASYMM16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 576 | return max_consecutive_elements_display_width_impl<uint16_t>(s, reinterpret_cast<const uint16_t *>(ptr), n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 577 | case DataType::S16: |
Manuel Bottini | 3689fcd | 2019-06-14 17:18:12 +0100 | [diff] [blame] | 578 | case DataType::QSYMM16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 579 | return max_consecutive_elements_display_width_impl<int16_t>(s, reinterpret_cast<const int16_t *>(ptr), n); |
| 580 | case DataType::U32: |
| 581 | return max_consecutive_elements_display_width_impl<uint32_t>(s, reinterpret_cast<const uint32_t *>(ptr), n); |
| 582 | case DataType::S32: |
| 583 | return max_consecutive_elements_display_width_impl<int32_t>(s, reinterpret_cast<const int32_t *>(ptr), n); |
Pablo Marquez Tello | 4a1c917 | 2023-07-18 14:51:24 +0100 | [diff] [blame] | 584 | case DataType::U64: |
| 585 | return max_consecutive_elements_display_width_impl<uint64_t>(s, reinterpret_cast<const uint64_t *>(ptr), n); |
| 586 | case DataType::S64: |
| 587 | return max_consecutive_elements_display_width_impl<int64_t>(s, reinterpret_cast<const int64_t *>(ptr), n); |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 588 | case DataType::BFLOAT16: |
| 589 | return max_consecutive_elements_display_width_impl<bfloat16>(s, reinterpret_cast<const bfloat16 *>(ptr), n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 590 | case DataType::F16: |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 591 | return max_consecutive_elements_display_width_impl<half>(s, reinterpret_cast<const half *>(ptr), n); |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 592 | case DataType::F32: |
| 593 | return max_consecutive_elements_display_width_impl<float>(s, reinterpret_cast<const float *>(ptr), n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 594 | default: |
| 595 | ARM_COMPUTE_ERROR("Undefined element size for given data type"); |
| 596 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 597 | return 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 598 | } |
giuros01 | edc21e4 | 2018-11-16 14:45:31 +0000 | [diff] [blame] | 599 | #endif /* ARM_COMPUTE_ASSERTS_ENABLED */ |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 600 | |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 601 | } // namespace arm_compute |