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