aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/Helpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/validation/Helpers.h')
-rw-r--r--tests/validation/Helpers.h181
1 files changed, 106 insertions, 75 deletions
diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h
index 325cc0042e..e044620556 100644
--- a/tests/validation/Helpers.h
+++ b/tests/validation/Helpers.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2020 Arm Limited.
+ * Copyright (c) 2017-2023,2024 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,15 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifndef ARM_COMPUTE_TEST_VALIDATION_HELPERS_H
-#define ARM_COMPUTE_TEST_VALIDATION_HELPERS_H
+#ifndef ACL_TESTS_VALIDATION_HELPERS_H
+#define ACL_TESTS_VALIDATION_HELPERS_H
#include "arm_compute/core/Types.h"
#include "arm_compute/core/Utils.h"
+#include "arm_compute/function_info/ActivationLayerInfo.h"
+
#include "support/Half.h"
#include "tests/Globals.h"
#include "tests/SimpleTensor.h"
+#include <cmath>
+#include <cstdint>
#include <random>
#include <type_traits>
#include <utility>
@@ -49,6 +53,23 @@ template <>
struct is_floating_point<half> : public std::true_type
{
};
+template <>
+struct is_floating_point<bfloat16> : public std::true_type
+{
+};
+
+/** Helper struct to store the hints for
+ * - destination quantization info
+ * - minimum bias value
+ * - maximum bias value
+ * in quantized test construction.
+ */
+struct QuantizationHint
+{
+ QuantizationInfo q_info;
+ int32_t bias_min;
+ int32_t bias_max;
+};
/** Helper function to get the testing range for each activation layer.
*
@@ -62,13 +83,13 @@ std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::Activation
{
std::pair<T, T> bounds;
- switch(data_type)
+ switch (data_type)
{
case DataType::F16:
{
using namespace half_float::literal;
- switch(activation)
+ switch (activation)
{
case ActivationLayerInfo::ActivationFunction::TANH:
case ActivationLayerInfo::ActivationFunction::SQUARE:
@@ -88,7 +109,7 @@ std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::Activation
break;
}
case DataType::F32:
- switch(activation)
+ switch (activation)
{
case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
// Reduce range as exponent overflows
@@ -110,72 +131,6 @@ std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::Activation
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);
-
-/** Calculate output tensor shape for the concatenate operation along a given axis
- *
- * @param[in] input_shapes Shapes of the tensors to concatenate across width.
- * @param[in] axis Axis to use for the concatenate operation
- *
- * @return The shape of output concatenated tensor.
- */
-TensorShape calculate_concatenate_shape(const std::vector<TensorShape> &input_shapes, size_t axis);
-
-/** Parameters of Harris Corners algorithm. */
-struct HarrisCornersParameters
-{
- float threshold{ 0.f }; /**< Threshold */
- float sensitivity{ 0.f }; /**< Sensitivity */
- float min_dist{ 0.f }; /**< Minimum distance */
- uint8_t constant_border_value{ 0 }; /**< Border value */
-};
-
-/** Generate parameters for Harris Corners algorithm. */
-HarrisCornersParameters harris_corners_parameters();
-
-/** Parameters of Canny edge algorithm. */
-struct CannyEdgeParameters
-{
- int32_t upper_thresh{ 255 };
- int32_t lower_thresh{ 0 };
- uint8_t constant_border_value{ 0 };
-};
-
-/** Generate parameters for Canny edge algorithm. */
-CannyEdgeParameters canny_edge_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);
- }
-}
-
/** Convert an asymmetric quantized simple tensor into float using tensor quantization information.
*
* @param[in] src Quantized tensor.
@@ -190,6 +145,7 @@ SimpleTensor<float> convert_from_asymmetric(const SimpleTensor<T> &src);
* @param[in] src Float tensor.
* @param[in] quantization_info Quantification information.
*
+ * \relates arm_compute::test::SimpleTensor
* @return Quantized tensor.
*/
template <typename T>
@@ -208,7 +164,7 @@ SimpleTensor<float> convert_from_symmetric(const SimpleTensor<T> &src);
*
* @param[in] src Float tensor.
* @param[in] quantization_info Quantification information.
- *
+ * \relates arm_compute::test::SimpleTensor
* @return Quantized tensor.
*/
template <typename T>
@@ -276,8 +232,83 @@ std::pair<int, int> get_quantized_qasymm8_signed_bounds(const QuantizationInfo &
* @param[in] max Floating point maximum value to be quantized
* @param[in] channel_id Channel id for per channel quantization info.
*/
-std::pair<int, int> get_symm_quantized_per_channel_bounds(const QuantizationInfo &quant_info, float min, float max, size_t channel_id = 0);
+std::pair<int, int>
+get_symm_quantized_per_channel_bounds(const QuantizationInfo &quant_info, float min, float max, size_t channel_id = 0);
+
+/** Add random padding along the X axis (between 1 and 16 columns per side) to all the input tensors.
+ * This is used in our validation suite in order to simulate implicit padding addition after configuring, but before allocating.
+ *
+ * @param[in] tensors List of tensors to add padding to
+ * @param[in] data_layout (Optional) Data layout of the operator
+ * @param[in] only_right_pad (Optional) Only right padding testing, in case of cl image padding
+ *
+ * @note This function adds padding to the input tensors only if data_layout == DataLayout::NHWC
+ */
+void add_padding_x(std::initializer_list<ITensor *> tensors,
+ const DataLayout &data_layout = DataLayout::NHWC,
+ bool only_right_pad = false);
+
+/** For 2d convolution, given the Lhs/Rhs matrix quantization informations and the convolution dimension,
+ * calculate a suitable output quantization and suggested bias range for obtaining non-saturated outputs with high probability.
+ *
+ * @param[in] in_q_info Input matrix quantization info
+ * @param[in] weight_q_info Weights matrix quantization info
+ * @param[in] height Height of the weights tensor
+ * @param[in] width Width of the weights tensors
+ * @param[in] channels Number of input channels
+ * @param[in] data_type data type, only QASYMM8, QASYMM8_SIGNED are supported
+ * @param[in] bias_fraction see @ref suggest_mac_dst_q_info_and_bias() for explanation
+ *
+ * @return QuantizationHint object containing the suggested output quantization info and min/max bias range
+ */
+QuantizationHint suggest_conv_dst_q_info_and_bias(const QuantizationInfo &in_q_info,
+ const QuantizationInfo &weight_q_info,
+ int32_t height,
+ int32_t width,
+ int32_t channels,
+ DataType data_type,
+ float bias_fraction);
+
+/** For a matrix multiplication, given the Lhs/Rhs matrix quantization informations and the matrix multiplication dimensions,
+ * calculate a suitable output quantization and suggested bias range for obtaining non-saturated outputs with high probability.
+ *
+ * @param[in] lhs_q_info Lhs matrix quantization info
+ * @param[in] rhs_q_info Rhs matrix quantization info
+ * @param[in] m Number of rows of Lhs matrix
+ * @param[in] n Number of columns of Rhs Matrix
+ * @param[in] k Number of rows/columns of Rhs/Lhs Matrix
+ * @param[in] data_type data type, only QASYMM8, QASYMM8_SIGNED are supported
+ * @param[in] bias_fraction see @ref suggest_mac_dst_q_info_and_bias() for explanation
+ *
+ * @return QuantizationHint object containing the suggested output quantization info and min/max bias range
+ */
+QuantizationHint suggest_matmul_dst_q_info_and_bias(const QuantizationInfo &lhs_q_info,
+ const QuantizationInfo &rhs_q_info,
+ int32_t m,
+ int32_t n,
+ int32_t k,
+ DataType data_type,
+ float bias_fraction);
+
+/** For a multiply-accumulate (mac), given the Lhs/Rhs vector quantization informations and the dot product dimensions,
+ * calculate a suitable output quantization and suggested bias range for obtaining non-saturated outputs with high probability.
+ *
+ * @param[in] lhs_q_info Lhs matrix quantization info
+ * @param[in] rhs_q_info Rhs matrix quantization info
+ * @param[in] k number of accumulations taking place in the sum, i.e. c_k = sum_k(a_k * b_k)
+ * @param[in] data_type data type, only QASYMM8, QASYMM8_SIGNED are supported
+ * @param[in] bias_fraction the fraction of bias amplitude compared to integer accummulation.
+ * @param[in] num_sd (Optional) number of standard deviations we allow from the mean. Default value is 2.
+ *
+ * @return QuantizationHint object containing the suggested output quantization info and min/max bias range
+ */
+QuantizationHint suggest_mac_dst_q_info_and_bias(const QuantizationInfo &lhs_q_info,
+ const QuantizationInfo &rhs_q_info,
+ int32_t k,
+ DataType data_type,
+ float bias_fraction,
+ int num_sd = 2);
} // namespace validation
} // namespace test
} // namespace arm_compute
-#endif /* ARM_COMPUTE_TEST_VALIDATION_HELPERS_H */
+#endif // ACL_TESTS_VALIDATION_HELPERS_H