diff options
author | Pablo Marquez Tello <pablo.tello@arm.com> | 2022-05-26 14:19:39 +0100 |
---|---|---|
committer | Pablo Marquez Tello <pablo.tello@arm.com> | 2022-06-07 12:33:48 +0000 |
commit | d75cd8ac5de1a785712e2e23c735a0167d64dfa3 (patch) | |
tree | 4e07c3cb0b159e14596c5e47d677de5877ec6efc /arm_compute | |
parent | fe1b1f6d94c196f086122613277ff95062a7e834 (diff) | |
download | ComputeLibrary-d75cd8ac5de1a785712e2e23c735a0167d64dfa3.tar.gz |
Compute Hard-Swish with a Lookup table for qasymm8.
* Resolves COMPMID-5211
Change-Id: I5914f971d733174dae67e6b4c589f45c75733cf7
Signed-off-by: Pablo Marquez Tello <pablo.tello@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7654
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute')
-rw-r--r-- | arm_compute/core/QuantizationInfo.h | 12 | ||||
-rw-r--r-- | arm_compute/core/Types.h | 74 |
2 files changed, 59 insertions, 27 deletions
diff --git a/arm_compute/core/QuantizationInfo.h b/arm_compute/core/QuantizationInfo.h index b331f7d923..0bd0f21bc1 100644 --- a/arm_compute/core/QuantizationInfo.h +++ b/arm_compute/core/QuantizationInfo.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021 Arm Limited. + * Copyright (c) 2019-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -399,6 +399,16 @@ inline float dequantize_qsymm8(int8_t value, const UniformQuantizationInfo &qinf return value * qinfo.scale; } +inline qasymm8_t qasymm8_hard_swish(qasymm8_t in, + const UniformQuantizationInfo &qi_in, + const UniformQuantizationInfo &qi_out) +{ + float tmp_f = dequantize_qasymm8(in, qi_in); + tmp_f = tmp_f * ((std::min(std::max((tmp_f + 3), 0.0f), 6.0f)) * 0.166666667f); + const qasymm8_t tmp = quantize_qasymm8(tmp_f, qi_out); + return tmp; +} + /** Dequantize a value given a 8-bit symmetric quantization scheme * * @param[in] value Value to dequantize diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h index b1a1eb6f44..4524976d6b 100644 --- a/arm_compute/core/Types.h +++ b/arm_compute/core/Types.h @@ -774,10 +774,10 @@ public: private: std::pair<unsigned int, unsigned int> _stride; - unsigned int _pad_left; - unsigned int _pad_top; - unsigned int _pad_right; - unsigned int _pad_bottom; + unsigned int _pad_left; + unsigned int _pad_top; + unsigned int _pad_right; + unsigned int _pad_bottom; DimensionRoundingType _round_type; }; @@ -919,14 +919,14 @@ public: } private: - std::vector<float> _min_sizes; - std::vector<float> _variances; - float _offset; - bool _flip; - bool _clip; - std::vector<float> _max_sizes; - std::vector<float> _aspect_ratios; - Coordinates2D _img_size; + std::vector<float> _min_sizes; + std::vector<float> _variances; + float _offset; + bool _flip; + bool _clip; + std::vector<float> _max_sizes; + std::vector<float> _aspect_ratios; + Coordinates2D _img_size; std::array<float, 2> _steps; }; @@ -1171,15 +1171,15 @@ public: } private: - unsigned int _max_detections; - unsigned int _max_classes_per_detection; - float _nms_score_threshold; - float _iou_threshold; - unsigned int _num_classes; + unsigned int _max_detections; + unsigned int _max_classes_per_detection; + float _nms_score_threshold; + float _iou_threshold; + unsigned int _num_classes; std::array<float, 4> _scales_values; - bool _use_regular_nms; - unsigned int _detection_per_class; - bool _dequantize_scores; + bool _use_regular_nms; + unsigned int _detection_per_class; + bool _dequantize_scores; }; /** Pooling Layer Information struct*/ @@ -1612,13 +1612,13 @@ public: } private: - float _img_width; - float _img_height; - float _scale; - bool _apply_scale; - bool _correct_transform_coords; + float _img_width; + float _img_height; + float _scale; + bool _apply_scale; + bool _correct_transform_coords; std::array<float, 4> _weights; - float _bbox_xform_clip; + float _bbox_xform_clip; }; /** Activation Layer Information class */ @@ -1644,6 +1644,9 @@ public: HARD_SWISH /**< Hard-swish ( \f$ f(x) = (x * relu6(x+3))/6 \f$ ) */ }; + /** Lookup table */ + using LookupTable256 = std::array<qasymm8_t, 256>; + ActivationLayerInfo() = default; /** Default Constructor * @@ -1677,11 +1680,30 @@ public: return _enabled; } + const LookupTable256 &lut() const + { + return _lut; + } + + void init_lut(const UniformQuantizationInfo &qi_in, const UniformQuantizationInfo &qi_out) + { + qasymm8_hard_swish_populate_table(_lut, qi_in, qi_out); + } + private: ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::IDENTITY }; float _a = {}; float _b = {}; bool _enabled = { false }; + LookupTable256 _lut = {}; + + inline void qasymm8_hard_swish_populate_table(LookupTable256 &lut, const UniformQuantizationInfo &qi_in, const UniformQuantizationInfo &qi_out) + { + for(size_t i = 0; i < lut.size(); ++i) + { + lut[i] = qasymm8_hard_swish(i, qi_in, qi_out); + } + } }; /** Fully connected layer info */ |