From 9a1e28b4df4f5b49bb497c8463a8bc7cedaaf110 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Thu, 29 Jul 2021 16:24:36 +0100 Subject: Compilation issue: neon=1 armv8.2 on Android with NDKr18beta1 - The issue was related to the __fp16 specialization on the depthwise convolution layer (cpu) Resolves COMPMID-4741 Change-Id: I6072230c60df6659951db2a1adf611eca6ab7efe Signed-off-by: Gian Marco Iodice Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6026 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas --- .../arm_conv/depthwise/depthwise_depthfirst.hpp | 11 +------- .../depthwise/depthwise_depthfirst_generic.hpp | 11 +------- .../depthwise_depthfirst_generic_multiplier.hpp | 11 +------- src/core/NEON/kernels/arm_gemm/utils.hpp | 33 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst.hpp b/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst.hpp index a92817bb14..53ad5b5c6b 100644 --- a/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst.hpp +++ b/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst.hpp @@ -154,16 +154,7 @@ class DepthwiseDepthfirst : public DepthwiseCommon::is_integer) - { - activation_min = std::numeric_limits::min(); - activation_max = std::numeric_limits::max(); - } - else - { - activation_min = static_cast(-std::numeric_limits::infinity()); - activation_max = static_cast(std::numeric_limits::infinity()); - } + std::tie(activation_min, activation_max) = get_default_activation_values(); switch (this->m_args.activation.type) { diff --git a/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic.hpp b/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic.hpp index ee5ab84d14..f04f7751db 100644 --- a/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic.hpp +++ b/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic.hpp @@ -333,16 +333,7 @@ class DepthwiseDepthfirstGeneric : public DepthwiseDepthfirstGenericBase::is_integer) - { - activation_min = std::numeric_limits::min(); - activation_max = std::numeric_limits::max(); - } - else - { - activation_min = static_cast(-std::numeric_limits::infinity()); - activation_max = static_cast(std::numeric_limits::infinity()); - } + std::tie(activation_min, activation_max) = get_default_activation_values(); switch (this->m_args.activation.type) { diff --git a/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic_multiplier.hpp b/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic_multiplier.hpp index 31e5834366..bb580e605a 100644 --- a/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic_multiplier.hpp +++ b/src/core/NEON/kernels/arm_conv/depthwise/depthwise_depthfirst_generic_multiplier.hpp @@ -426,16 +426,7 @@ class DepthwiseDepthfirstGenericWithMultiplier : public DepthwiseDepthfirstGener // Compute activation values TAccum activation_min, activation_max; - if (std::numeric_limits::is_integer) - { - activation_min = std::numeric_limits::min(); - activation_max = std::numeric_limits::max(); - } - else - { - activation_min = static_cast(-std::numeric_limits::infinity()); - activation_max = static_cast(std::numeric_limits::infinity()); - } + std::tie(activation_min, activation_max) = get_default_activation_values(); switch (this->m_args.activation.type) { diff --git a/src/core/NEON/kernels/arm_gemm/utils.hpp b/src/core/NEON/kernels/arm_gemm/utils.hpp index 82464d2eff..2ae3db19ed 100644 --- a/src/core/NEON/kernels/arm_gemm/utils.hpp +++ b/src/core/NEON/kernels/arm_gemm/utils.hpp @@ -27,6 +27,7 @@ #include "arm_gemm.hpp" #include +#include // Macro for unreachable code (e.g. impossible default cases on switch) #define UNREACHABLE(why) __builtin_unreachable() @@ -202,6 +203,38 @@ inline unsigned long get_vector_length(VLType vl_type) { return 16 / sizeof(T); } } + +// get_default_activation_values(): Returns the default values for activation min and max for integer activation. +template +inline std::tuple get_default_activation_values() +{ + const T min = static_cast(std::numeric_limits::min()); + const T max = static_cast(std::numeric_limits::max()); + + return std::make_tuple(min, max); +} + +// get_default_activation_values(): Returns the default values for activation min and max for float activation. +template <> +inline std::tuple get_default_activation_values() +{ + const float min = static_cast(-std::numeric_limits::infinity()); + const float max = static_cast(std::numeric_limits::infinity()); + + return std::make_tuple(min, max); +} + +#if defined(__ARM_FP16_ARGS) +// get_default_activation_values(): Returns the default values for activation min and max for __fp16 activation. +template <> +inline std::tuple<__fp16, __fp16> get_default_activation_values() +{ + const __fp16 min = static_cast<__fp16>(-std::numeric_limits::infinity()); + const __fp16 max = static_cast<__fp16>(std::numeric_limits::infinity()); + + return std::make_tuple(min, max); +} +#endif // defined(__ARM_FP16_ARGS) } // utils namespace } // arm_gemm namespace -- cgit v1.2.1