diff options
author | Kaizen <kaizen@arm.com> | 2017-09-28 14:38:23 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2017-09-28 16:31:13 +0100 |
commit | 8938bd3f40ea62ff56d6ed4e2db0a8aee34dd64a (patch) | |
tree | c234331232f227e0cdfb567a54ecaa5460aaa064 /tests/validation/Helpers.h | |
parent | f4a254c2745aeaab6f7276a675147d707002fe7a (diff) | |
download | armcl-8938bd3f40ea62ff56d6ed4e2db0a8aee34dd64a.tar.gz armcl-8938bd3f40ea62ff56d6ed4e2db0a8aee34dd64a.tar.bz2 armcl-8938bd3f40ea62ff56d6ed4e2db0a8aee34dd64a.zip |
arm_compute v17.09
Change-Id: I4bf8f4e6e5f84ce0d5b6f5ba570d276879f42a81
Diffstat (limited to 'tests/validation/Helpers.h')
-rw-r--r-- | tests/validation/Helpers.h | 154 |
1 files changed, 119 insertions, 35 deletions
diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h index cbaea4b89..eecf976a1 100644 --- a/tests/validation/Helpers.h +++ b/tests/validation/Helpers.h @@ -24,8 +24,13 @@ #ifndef __ARM_COMPUTE_TEST_VALIDATION_HELPERS_H__ #define __ARM_COMPUTE_TEST_VALIDATION_HELPERS_H__ -#include "Types.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/Utils.h" +#include "support/Half.h" +#include "tests/Globals.h" +#include "tests/SimpleTensor.h" +#include <random> #include <type_traits> #include <utility> @@ -35,64 +40,143 @@ namespace test { namespace validation { +template <typename T> +struct is_floating_point : public std::is_floating_point<T> +{ +}; + +template <> +struct is_floating_point<half> : public std::true_type +{ +}; + /** Helper function to get the testing range for each activation layer. * * @param[in] activation Activation function to test. - * @param[in] fixed_point_position (Optional) Number of bits for the fractional part. Defaults to 1. + * @param[in] data_type Data type. + * @param[in] fixed_point_position Number of bits for the fractional part. Defaults to 1. * * @return A pair containing the lower upper testing bounds for a given function. */ template <typename T> -std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::ActivationFunction activation, int fixed_point_position = 1) +std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::ActivationFunction activation, DataType data_type, int fixed_point_position = 0) { - bool is_float = std::is_floating_point<T>::value; std::pair<T, T> bounds; - // Set initial values - if(is_float) + switch(data_type) { - bounds = std::make_pair(-255.f, 255.f); - } - else - { - bounds = std::make_pair(std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max()); - } + case DataType::F16: + { + using namespace half_float::literal; - // Reduce testing ranges - switch(activation) - { - case ActivationLayerInfo::ActivationFunction::LOGISTIC: - case ActivationLayerInfo::ActivationFunction::SOFT_RELU: - // Reduce range as exponent overflows - if(is_float) + switch(activation) { - bounds.first = -40.f; - bounds.second = 40.f; + case ActivationLayerInfo::ActivationFunction::SQUARE: + case ActivationLayerInfo::ActivationFunction::LOGISTIC: + case ActivationLayerInfo::ActivationFunction::SOFT_RELU: + // Reduce range as exponent overflows + bounds = std::make_pair(-10._h, 10._h); + break; + case ActivationLayerInfo::ActivationFunction::SQRT: + // Reduce range as sqrt should take a non-negative number + bounds = std::make_pair(0._h, 255._h); + break; + default: + bounds = std::make_pair(-255._h, 255._h); + break; } - else + break; + } + case DataType::F32: + switch(activation) { - bounds.first = -(1 << (fixed_point_position)); - bounds.second = 1 << (fixed_point_position); + case ActivationLayerInfo::ActivationFunction::LOGISTIC: + case ActivationLayerInfo::ActivationFunction::SOFT_RELU: + // Reduce range as exponent overflows + bounds = std::make_pair(-40.f, 40.f); + break; + case ActivationLayerInfo::ActivationFunction::SQRT: + // Reduce range as sqrt should take a non-negative number + bounds = std::make_pair(0.f, 255.f); + break; + default: + bounds = std::make_pair(-255.f, 255.f); + break; } break; - case ActivationLayerInfo::ActivationFunction::TANH: - // Reduce range as exponent overflows - if(!is_float) + case DataType::QS8: + case DataType::QS16: + switch(activation) { - bounds.first = -(1 << (fixed_point_position)); - bounds.second = 1 << (fixed_point_position); + case ActivationLayerInfo::ActivationFunction::LOGISTIC: + case ActivationLayerInfo::ActivationFunction::SOFT_RELU: + case ActivationLayerInfo::ActivationFunction::TANH: + // Reduce range as exponent overflows + bounds = std::make_pair(-(1 << fixed_point_position), 1 << fixed_point_position); + break; + case ActivationLayerInfo::ActivationFunction::SQRT: + // Reduce range as sqrt should take a non-negative number + // Can't be zero either as inv_sqrt is used in NEON. + bounds = std::make_pair(1, std::numeric_limits<T>::max()); + break; + default: + bounds = std::make_pair(std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max()); + break; } break; - case ActivationLayerInfo::ActivationFunction::SQRT: - // Reduce range as sqrt should take a non-negative number - bounds.first = (is_float) ? 0 : 1 << (fixed_point_position); - break; default: - break; + ARM_COMPUTE_ERROR("Unsupported data type"); } + return bounds; } +/** Fill mask with the corresponding given pattern. + * + * @param[in,out] mask Mask to be filled according to pattern + * @param[in] cols Columns (width) of mask + * @param[in] rows Rows (height) of mask + * @param[in] pattern Pattern to fill the mask according to + */ +void fill_mask_from_pattern(uint8_t *mask, int cols, int rows, MatrixPattern pattern); + +/** Calculate output tensor shape give a vector of input tensor to concatenate + * + * @param[in] input_shapes Shapes of the tensors to concatenate across depth. + * + * @return The shape of output concatenated tensor. + */ +TensorShape calculate_depth_concatenate_shape(const std::vector<TensorShape> &input_shapes); + +/** Parameters of Harris Corners algorithm. */ +struct HarrisCornersParameters +{ + float threshold{ 0.f }; + float sensitivity{ 0.f }; + float min_dist{ 0.f }; + uint8_t constant_border_value{ 0 }; +}; + +/** Generate parameters for Harris Corners algorithm. */ +HarrisCornersParameters harris_corners_parameters(); + +/** Helper function to fill the Lut random by a ILutAccessor. + * + * @param[in,out] table Accessor at the Lut. + * + */ +template <typename T> +void fill_lookuptable(T &&table) +{ + std::mt19937 generator(library->seed()); + std::uniform_int_distribution<typename T::value_type> distribution(std::numeric_limits<typename T::value_type>::min(), std::numeric_limits<typename T::value_type>::max()); + + for(int i = std::numeric_limits<typename T::value_type>::min(); i <= std::numeric_limits<typename T::value_type>::max(); i++) + { + table[i] = distribution(generator); + } +} + /** Helper function to get the testing range for batch normalization layer. * * @param[in] fixed_point_position (Optional) Number of bits for the fractional part. Defaults to 1. @@ -120,4 +204,4 @@ std::pair<T, T> get_batchnormalization_layer_test_bounds(int fixed_point_positio } // namespace validation } // namespace test } // namespace arm_compute -#endif //__ARM_COMPUTE_TEST_VALIDATION_HELPERS_H__ +#endif /* __ARM_COMPUTE_TEST_VALIDATION_HELPERS_H__ */ |