Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
giuros01 | edc21e4 | 2018-11-16 14:45:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 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 | #include "support/ToolchainSupport.h" |
| 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 | |
| 37 | using namespace arm_compute; |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 38 | #ifndef DOXYGEN_SKIP_THIS |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | std::string arm_compute::build_information() |
| 40 | { |
| 41 | static const std::string information = |
| 42 | #include "arm_compute_version.embed" |
| 43 | ; |
| 44 | return information; |
| 45 | } |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 46 | #endif /* DOXYGEN_SKIP_THIS */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | std::string arm_compute::read_file(const std::string &filename, bool binary) |
| 48 | { |
| 49 | std::string out; |
| 50 | std::ifstream fs; |
| 51 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 52 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | try |
| 54 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 55 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | fs.exceptions(std::ifstream::failbit | std::ifstream::badbit); |
| 57 | std::ios_base::openmode mode = std::ios::in; |
| 58 | |
| 59 | if(binary) |
| 60 | { |
| 61 | mode |= std::ios::binary; |
| 62 | } |
| 63 | |
| 64 | fs.open(filename, mode); |
| 65 | |
| 66 | // Go to the end of the file |
| 67 | fs.seekg(0, std::ios::end); |
| 68 | // Reserve the memory required to store the file's content |
| 69 | out.reserve(fs.tellg()); |
| 70 | // Go back to the beginning of the file |
| 71 | fs.seekg(0, std::ios::beg); |
| 72 | // Copy the content of the file |
| 73 | out.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>()); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 74 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | } |
| 76 | catch(const std::ifstream::failure &e) |
| 77 | { |
| 78 | ARM_COMPUTE_ERROR("Accessing %s: %s", filename.c_str(), e.what()); |
| 79 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 80 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 81 | |
| 82 | return out; |
| 83 | } |
| 84 | |
| 85 | const std::string &arm_compute::string_from_format(Format format) |
| 86 | { |
| 87 | static std::map<Format, const std::string> formats_map = |
| 88 | { |
| 89 | { Format::UNKNOWN, "UNKNOWN" }, |
| 90 | { Format::U8, "U8" }, |
| 91 | { Format::S16, "S16" }, |
| 92 | { Format::U16, "U16" }, |
| 93 | { Format::S32, "S32" }, |
| 94 | { Format::U32, "U32" }, |
| 95 | { Format::F16, "F16" }, |
| 96 | { Format::F32, "F32" }, |
| 97 | { Format::UV88, "UV88" }, |
| 98 | { Format::RGB888, "RGB888" }, |
| 99 | { Format::RGBA8888, "RGBA8888" }, |
| 100 | { Format::YUV444, "YUV444" }, |
| 101 | { Format::YUYV422, "YUYV422" }, |
| 102 | { Format::NV12, "NV12" }, |
| 103 | { Format::NV21, "NV21" }, |
| 104 | { Format::IYUV, "IYUV" }, |
| 105 | { Format::UYVY422, "UYVY422" } |
| 106 | }; |
| 107 | |
| 108 | return formats_map[format]; |
| 109 | } |
| 110 | |
| 111 | const std::string &arm_compute::string_from_channel(Channel channel) |
| 112 | { |
| 113 | static std::map<Channel, const std::string> channels_map = |
| 114 | { |
| 115 | { Channel::UNKNOWN, "UNKNOWN" }, |
| 116 | { Channel::R, "R" }, |
| 117 | { Channel::G, "G" }, |
| 118 | { Channel::B, "B" }, |
| 119 | { Channel::A, "A" }, |
| 120 | { Channel::Y, "Y" }, |
| 121 | { Channel::U, "U" }, |
| 122 | { Channel::V, "V" }, |
| 123 | { Channel::C0, "C0" }, |
| 124 | { Channel::C1, "C1" }, |
| 125 | { Channel::C2, "C2" }, |
| 126 | { Channel::C3, "C3" } |
| 127 | }; |
| 128 | |
| 129 | return channels_map[channel]; |
| 130 | } |
| 131 | |
Michele Di Giorgio | bf3c662 | 2018-03-08 11:52:27 +0000 | [diff] [blame] | 132 | const std::string &arm_compute::string_from_data_layout(DataLayout dl) |
| 133 | { |
| 134 | static std::map<DataLayout, const std::string> dl_map = |
| 135 | { |
| 136 | { DataLayout::UNKNOWN, "UNKNOWN" }, |
| 137 | { DataLayout::NCHW, "NCHW" }, |
| 138 | { DataLayout::NHWC, "NHWC" }, |
| 139 | }; |
| 140 | |
| 141 | return dl_map[dl]; |
| 142 | } |
| 143 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 144 | const std::string &arm_compute::string_from_data_type(DataType dt) |
| 145 | { |
| 146 | static std::map<DataType, const std::string> dt_map = |
| 147 | { |
| 148 | { DataType::UNKNOWN, "UNKNOWN" }, |
| 149 | { DataType::S8, "S8" }, |
| 150 | { DataType::U8, "U8" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 151 | { DataType::S16, "S16" }, |
| 152 | { DataType::U16, "U16" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 153 | { DataType::S32, "S32" }, |
| 154 | { DataType::U32, "U32" }, |
| 155 | { DataType::S64, "S64" }, |
| 156 | { DataType::U64, "U64" }, |
| 157 | { DataType::F16, "F16" }, |
| 158 | { DataType::F32, "F32" }, |
| 159 | { DataType::F64, "F64" }, |
| 160 | { DataType::SIZET, "SIZET" }, |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 161 | { DataType::QSYMM8, "QSYMM8" }, |
| 162 | { DataType::QSYMM8_PER_CHANNEL, "QSYMM8_PER_CHANNEL" }, |
Michalis Spyrou | c853021 | 2019-08-22 11:44:04 +0100 | [diff] [blame] | 163 | { DataType::QASYMM8_PER_CHANNEL, "QASYMM8_PER_CHANNEL" }, |
Isabella Gottardi | 01a214a | 2018-04-09 16:00:52 +0100 | [diff] [blame] | 164 | { DataType::QASYMM8, "QASYMM8" }, |
Manuel Bottini | 3689fcd | 2019-06-14 17:18:12 +0100 | [diff] [blame] | 165 | { DataType::QSYMM16, "QSYMM16" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | return dt_map[dt]; |
| 169 | } |
| 170 | |
| 171 | const std::string &arm_compute::string_from_activation_func(ActivationLayerInfo::ActivationFunction act) |
| 172 | { |
| 173 | static std::map<ActivationLayerInfo::ActivationFunction, const std::string> act_map = |
| 174 | { |
| 175 | { ActivationLayerInfo::ActivationFunction::ABS, "ABS" }, |
| 176 | { ActivationLayerInfo::ActivationFunction::LINEAR, "LINEAR" }, |
| 177 | { ActivationLayerInfo::ActivationFunction::LOGISTIC, "LOGISTIC" }, |
| 178 | { ActivationLayerInfo::ActivationFunction::RELU, "RELU" }, |
| 179 | { ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, "BRELU" }, |
Georgios Pinitas | 64ebe5b | 2017-09-01 17:44:24 +0100 | [diff] [blame] | 180 | { ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, "LU_BRELU" }, |
Georgios Pinitas | 579c049 | 2017-07-12 16:12:12 +0100 | [diff] [blame] | 181 | { ActivationLayerInfo::ActivationFunction::LEAKY_RELU, "LRELU" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 182 | { ActivationLayerInfo::ActivationFunction::SOFT_RELU, "SRELU" }, |
Georgios Pinitas | fb0fdcd | 2019-08-22 17:10:04 +0100 | [diff] [blame] | 183 | { ActivationLayerInfo::ActivationFunction::ELU, "ELU" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 184 | { ActivationLayerInfo::ActivationFunction::SQRT, "SQRT" }, |
| 185 | { ActivationLayerInfo::ActivationFunction::SQUARE, "SQUARE" }, |
| 186 | { ActivationLayerInfo::ActivationFunction::TANH, "TANH" }, |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 187 | { ActivationLayerInfo::ActivationFunction::IDENTITY, "IDENTITY" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | return act_map[act]; |
| 191 | } |
| 192 | |
| 193 | const std::string &arm_compute::string_from_matrix_pattern(MatrixPattern pattern) |
| 194 | { |
| 195 | static std::map<MatrixPattern, const std::string> pattern_map = |
| 196 | { |
| 197 | { MatrixPattern::BOX, "BOX" }, |
| 198 | { MatrixPattern::CROSS, "CROSS" }, |
| 199 | { MatrixPattern::DISK, "DISK" }, |
| 200 | { MatrixPattern::OTHER, "OTHER" }, |
| 201 | }; |
| 202 | |
| 203 | return pattern_map[pattern]; |
| 204 | } |
| 205 | |
| 206 | const std::string &arm_compute::string_from_non_linear_filter_function(NonLinearFilterFunction function) |
| 207 | { |
| 208 | static std::map<NonLinearFilterFunction, const std::string> func_map = |
| 209 | { |
| 210 | { NonLinearFilterFunction::MAX, "MAX" }, |
| 211 | { NonLinearFilterFunction::MEDIAN, "MEDIAN" }, |
| 212 | { NonLinearFilterFunction::MIN, "MIN" }, |
| 213 | }; |
| 214 | |
| 215 | return func_map[function]; |
| 216 | } |
| 217 | |
| 218 | const std::string &arm_compute::string_from_interpolation_policy(InterpolationPolicy policy) |
| 219 | { |
| 220 | static std::map<InterpolationPolicy, const std::string> interpolation_policy_map = |
| 221 | { |
| 222 | { InterpolationPolicy::AREA, "AREA" }, |
| 223 | { InterpolationPolicy::BILINEAR, "BILINEAR" }, |
| 224 | { InterpolationPolicy::NEAREST_NEIGHBOR, "NEAREST_NEIGHBOUR" }, |
| 225 | }; |
| 226 | |
| 227 | return interpolation_policy_map[policy]; |
| 228 | } |
| 229 | |
| 230 | const std::string &arm_compute::string_from_border_mode(BorderMode border_mode) |
| 231 | { |
| 232 | static std::map<BorderMode, const std::string> border_mode_map = |
| 233 | { |
| 234 | { BorderMode::UNDEFINED, "UNDEFINED" }, |
| 235 | { BorderMode::CONSTANT, "CONSTANT" }, |
| 236 | { BorderMode::REPLICATE, "REPLICATE" }, |
| 237 | }; |
| 238 | |
| 239 | return border_mode_map[border_mode]; |
| 240 | } |
| 241 | |
| 242 | const std::string &arm_compute::string_from_norm_type(NormType type) |
| 243 | { |
| 244 | static std::map<NormType, const std::string> norm_type_map = |
| 245 | { |
| 246 | { NormType::IN_MAP_1D, "IN_MAP_1D" }, |
| 247 | { NormType::IN_MAP_2D, "IN_MAP_2D" }, |
| 248 | { NormType::CROSS_MAP, "CROSS_MAP" }, |
| 249 | }; |
| 250 | |
| 251 | return norm_type_map[type]; |
| 252 | } |
| 253 | |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 254 | const std::string &arm_compute::string_from_pooling_type(PoolingType type) |
| 255 | { |
| 256 | static std::map<PoolingType, const std::string> pool_type_map = |
| 257 | { |
| 258 | { PoolingType::MAX, "MAX" }, |
| 259 | { PoolingType::AVG, "AVG" }, |
| 260 | { PoolingType::L2, "L2" }, |
| 261 | }; |
| 262 | |
| 263 | return pool_type_map[type]; |
| 264 | } |
| 265 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 266 | const std::string &arm_compute::string_from_gemmlowp_output_stage(GEMMLowpOutputStageType output_stage) |
| 267 | { |
| 268 | static std::map<GEMMLowpOutputStageType, const std::string> output_stage_map = |
| 269 | { |
| 270 | { GEMMLowpOutputStageType::NONE, "" }, |
| 271 | { GEMMLowpOutputStageType::QUANTIZE_DOWN, "quantize_down" }, |
| 272 | { GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, "quantize_down_fixedpoint" }, |
| 273 | { GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT, "quantize_down_float" } |
| 274 | }; |
| 275 | |
| 276 | return output_stage_map[output_stage]; |
| 277 | } |
| 278 | |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 279 | std::string arm_compute::string_from_pixel_value(const PixelValue &value, const DataType data_type) |
| 280 | { |
| 281 | std::stringstream ss; |
| 282 | std::string converted_string; |
| 283 | |
| 284 | switch(data_type) |
| 285 | { |
| 286 | case DataType::U8: |
| 287 | case DataType::QASYMM8: |
| 288 | // Needs conversion to 32 bit, otherwise interpreted as ASCII values |
| 289 | ss << uint32_t(value.get<uint8_t>()); |
| 290 | converted_string = ss.str(); |
| 291 | break; |
| 292 | case DataType::S8: |
| 293 | // Needs conversion to 32 bit, otherwise interpreted as ASCII values |
| 294 | ss << int32_t(value.get<int8_t>()); |
| 295 | converted_string = ss.str(); |
| 296 | break; |
| 297 | case DataType::U16: |
| 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 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 329 | std::string arm_compute::lower_string(const std::string &val) |
| 330 | { |
| 331 | std::string res = val; |
| 332 | std::transform(res.begin(), res.end(), res.begin(), ::tolower); |
| 333 | return res; |
| 334 | } |
| 335 | |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 336 | PadStrideInfo arm_compute::calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout, const Size2D &dilation, |
| 337 | const DimensionRoundingType &rounding_type) |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 338 | { |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 339 | const unsigned int width_idx = arm_compute::get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 340 | const unsigned int height_idx = arm_compute::get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 341 | const unsigned int in_width = input_shape[width_idx]; |
| 342 | const unsigned int in_height = input_shape[height_idx]; |
| 343 | const unsigned int kernel_width = weights_shape[width_idx]; |
| 344 | const unsigned int kernel_height = weights_shape[height_idx]; |
| 345 | const auto &strides = conv_info.stride(); |
Georgios Pinitas | 4c75851 | 2019-07-10 19:49:11 +0100 | [diff] [blame] | 346 | |
| 347 | // Calculate output dimensions |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 348 | const auto is_ceil = static_cast<unsigned int>(rounding_type == DimensionRoundingType::CEIL); |
| 349 | const unsigned int out_width = ((in_width - is_ceil) + strides.first - 1) / strides.first + is_ceil; |
| 350 | 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] | 351 | |
| 352 | // Calculate effective weights sizes |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 353 | const int real_weight_width = (kernel_width - 1) * dilation.x() + 1; |
| 354 | const int real_weight_height = (kernel_height - 1) * dilation.y() + 1; |
Georgios Pinitas | 4c75851 | 2019-07-10 19:49:11 +0100 | [diff] [blame] | 355 | |
| 356 | // Calculate total pad |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 357 | const int pad_width = std::max(0, static_cast<int>((out_width - 1) * strides.first + real_weight_width - in_width)); |
| 358 | 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] | 359 | |
| 360 | // Calculate individual paddings |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 361 | const unsigned int pad_left = pad_width / 2; |
| 362 | const unsigned int pad_top = pad_height / 2; |
| 363 | const unsigned int pad_right = pad_width - pad_left; |
| 364 | const unsigned int pad_bottom = pad_height - pad_top; |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 365 | |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 366 | PadStrideInfo same_info(strides.first, strides.second, pad_left, pad_right, pad_top, pad_bottom, rounding_type); |
| 367 | |
| 368 | // Check for correctness of predicted output shape against the one calculated using the generated info |
| 369 | const auto out_dims = scaled_dimensions(in_width, in_height, kernel_width, kernel_height, same_info, dilation); |
| 370 | ARM_COMPUTE_ERROR_ON(out_dims.first != out_width || out_dims.second != out_height); |
| 371 | ARM_COMPUTE_UNUSED(out_dims); |
| 372 | |
| 373 | return same_info; |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Pablo Tello | 01bbacb | 2019-04-30 10:32:42 +0100 | [diff] [blame] | 376 | std::pair<unsigned int, unsigned int> arm_compute::deconvolution_output_dimensions( |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 377 | unsigned int in_width, unsigned int in_height, unsigned int kernel_width, unsigned int kernel_height, unsigned int padx, unsigned int pady, |
Michalis Spyrou | afbc5ff | 2018-10-03 14:18:19 +0100 | [diff] [blame] | 378 | unsigned int stride_x, unsigned int stride_y) |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 379 | { |
| 380 | ARM_COMPUTE_ERROR_ON(in_width < 1 || in_height < 1); |
Michalis Spyrou | afbc5ff | 2018-10-03 14:18:19 +0100 | [diff] [blame] | 381 | ARM_COMPUTE_ERROR_ON(((in_width - 1) * stride_x + kernel_width) < 2 * padx); |
| 382 | ARM_COMPUTE_ERROR_ON(((in_height - 1) * stride_y + kernel_height) < 2 * pady); |
| 383 | const int w = stride_x * (in_width - 1) + kernel_width - 2 * padx; |
| 384 | const int h = stride_y * (in_height - 1) + kernel_height - 2 * pady; |
| 385 | |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 386 | return std::make_pair<unsigned int, unsigned int>(w, h); |
| 387 | } |
| 388 | |
Pablo Tello | 01bbacb | 2019-04-30 10:32:42 +0100 | [diff] [blame] | 389 | std::pair<unsigned int, unsigned int> arm_compute::scaled_dimensions(unsigned int width, unsigned int height, |
| 390 | unsigned int kernel_width, unsigned int kernel_height, |
| 391 | const PadStrideInfo &pad_stride_info, |
| 392 | const Size2D &dilation) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 393 | { |
Jaroslaw Rzepecki | a1ed41f | 2017-10-13 11:13:58 +0100 | [diff] [blame] | 394 | const unsigned int pad_left = pad_stride_info.pad_left(); |
| 395 | const unsigned int pad_top = pad_stride_info.pad_top(); |
| 396 | const unsigned int pad_right = pad_stride_info.pad_right(); |
| 397 | const unsigned int pad_bottom = pad_stride_info.pad_bottom(); |
| 398 | const unsigned int stride_x = pad_stride_info.stride().first; |
| 399 | const unsigned int stride_y = pad_stride_info.stride().second; |
| 400 | unsigned int w = 0; |
| 401 | unsigned int h = 0; |
Gian Marco Iodice | 4e28869 | 2017-06-27 11:41:59 +0100 | [diff] [blame] | 402 | switch(pad_stride_info.round()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 403 | { |
| 404 | case DimensionRoundingType::FLOOR: |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 405 | w = static_cast<unsigned int>(std::floor((static_cast<float>(width + pad_left + pad_right - (dilation.x() * (kernel_width - 1) + 1)) / stride_x) + 1)); |
| 406 | h = static_cast<unsigned 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] | 407 | break; |
| 408 | case DimensionRoundingType::CEIL: |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 409 | w = static_cast<unsigned int>(std::ceil((static_cast<float>(width + pad_left + pad_right - (dilation.x() * (kernel_width - 1) + 1)) / stride_x) + 1)); |
| 410 | h = static_cast<unsigned 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] | 411 | break; |
| 412 | default: |
| 413 | ARM_COMPUTE_ERROR("Unsupported rounding type"); |
| 414 | } |
| 415 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 416 | return std::make_pair(w, h); |
| 417 | } |
| 418 | |
giuros01 | edc21e4 | 2018-11-16 14:45:31 +0000 | [diff] [blame] | 419 | #ifdef ARM_COMPUTE_ASSERTS_ENABLED |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 420 | void arm_compute::print_consecutive_elements(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n, int stream_width, const std::string &element_delim) |
| 421 | { |
| 422 | switch(dt) |
| 423 | { |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 424 | case DataType::QASYMM8: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 425 | case DataType::U8: |
| 426 | print_consecutive_elements_impl<uint8_t>(s, ptr, n, stream_width, element_delim); |
| 427 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 428 | case DataType::S8: |
| 429 | print_consecutive_elements_impl<int8_t>(s, reinterpret_cast<const int8_t *>(ptr), n, stream_width, element_delim); |
| 430 | break; |
| 431 | case DataType::U16: |
| 432 | print_consecutive_elements_impl<uint16_t>(s, reinterpret_cast<const uint16_t *>(ptr), n, stream_width, element_delim); |
| 433 | break; |
| 434 | case DataType::S16: |
Manuel Bottini | 3689fcd | 2019-06-14 17:18:12 +0100 | [diff] [blame] | 435 | case DataType::QSYMM16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 436 | print_consecutive_elements_impl<int16_t>(s, reinterpret_cast<const int16_t *>(ptr), n, stream_width, element_delim); |
| 437 | break; |
| 438 | case DataType::U32: |
| 439 | print_consecutive_elements_impl<uint32_t>(s, reinterpret_cast<const uint32_t *>(ptr), n, stream_width, element_delim); |
| 440 | break; |
| 441 | case DataType::S32: |
| 442 | print_consecutive_elements_impl<int32_t>(s, reinterpret_cast<const int32_t *>(ptr), n, stream_width, element_delim); |
| 443 | break; |
| 444 | case DataType::F32: |
| 445 | print_consecutive_elements_impl<float>(s, reinterpret_cast<const float *>(ptr), n, stream_width, element_delim); |
| 446 | break; |
| 447 | case DataType::F16: |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 448 | 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] | 449 | break; |
| 450 | default: |
| 451 | ARM_COMPUTE_ERROR("Undefined element size for given data type"); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | int arm_compute::max_consecutive_elements_display_width(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n) |
| 456 | { |
| 457 | switch(dt) |
| 458 | { |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 459 | case DataType::QASYMM8: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 460 | case DataType::U8: |
| 461 | return max_consecutive_elements_display_width_impl<uint8_t>(s, ptr, n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 462 | case DataType::S8: |
| 463 | return max_consecutive_elements_display_width_impl<int8_t>(s, reinterpret_cast<const int8_t *>(ptr), n); |
| 464 | case DataType::U16: |
| 465 | 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] | 466 | case DataType::S16: |
Manuel Bottini | 3689fcd | 2019-06-14 17:18:12 +0100 | [diff] [blame] | 467 | case DataType::QSYMM16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 468 | return max_consecutive_elements_display_width_impl<int16_t>(s, reinterpret_cast<const int16_t *>(ptr), n); |
| 469 | case DataType::U32: |
| 470 | return max_consecutive_elements_display_width_impl<uint32_t>(s, reinterpret_cast<const uint32_t *>(ptr), n); |
| 471 | case DataType::S32: |
| 472 | return max_consecutive_elements_display_width_impl<int32_t>(s, reinterpret_cast<const int32_t *>(ptr), n); |
| 473 | case DataType::F32: |
| 474 | return max_consecutive_elements_display_width_impl<float>(s, reinterpret_cast<const float *>(ptr), n); |
| 475 | case DataType::F16: |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 476 | return max_consecutive_elements_display_width_impl<half>(s, reinterpret_cast<const half *>(ptr), n); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 477 | default: |
| 478 | ARM_COMPUTE_ERROR("Undefined element size for given data type"); |
| 479 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 480 | return 0; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 481 | } |
giuros01 | edc21e4 | 2018-11-16 14:45:31 +0000 | [diff] [blame] | 482 | #endif /* ARM_COMPUTE_ASSERTS_ENABLED */ |