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