diff options
Diffstat (limited to 'tests/validation/reference')
242 files changed, 2378 insertions, 6409 deletions
diff --git a/tests/validation/reference/AbsoluteDifference.cpp b/tests/validation/reference/AbsoluteDifference.cpp index ea7685bc9e..a267b4bcb1 100644 --- a/tests/validation/reference/AbsoluteDifference.cpp +++ b/tests/validation/reference/AbsoluteDifference.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/AbsoluteDifference.h b/tests/validation/reference/AbsoluteDifference.h index 77849f87fb..7a2989ba6b 100644 --- a/tests/validation/reference/AbsoluteDifference.h +++ b/tests/validation/reference/AbsoluteDifference.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Accumulate.cpp b/tests/validation/reference/Accumulate.cpp index 2758577ef9..67754f0712 100644 --- a/tests/validation/reference/Accumulate.cpp +++ b/tests/validation/reference/Accumulate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Accumulate.h b/tests/validation/reference/Accumulate.h index 211314386a..70b2fdbc42 100644 --- a/tests/validation/reference/Accumulate.h +++ b/tests/validation/reference/Accumulate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ActivationLayer.cpp b/tests/validation/reference/ActivationLayer.cpp index 4aeefaaa79..2172362bdd 100644 --- a/tests/validation/reference/ActivationLayer.cpp +++ b/tests/validation/reference/ActivationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020,2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #include "ActivationLayer.h" #include "arm_compute/core/Types.h" + #include "tests/validation/Helpers.h" namespace arm_compute @@ -40,7 +41,7 @@ SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, ActivationLayerInfo ARM_COMPUTE_UNUSED(oq_info); // Create reference - SimpleTensor<T> dst{ src.shape(), src.data_type(), 1 }; + SimpleTensor<T> dst{src.shape(), src.data_type(), 1}; // Compute reference const T a(info.a()); @@ -48,7 +49,7 @@ SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, ActivationLayerInfo #if defined(_OPENMP) #pragma omp parallel for #endif /* _OPENMP */ - for(int i = 0; i < src.num_elements(); ++i) + for (int i = 0; i < src.num_elements(); ++i) { dst[i] = activate_float<T>(src[i], a, b, info.activation()); } @@ -57,7 +58,8 @@ SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, ActivationLayerInfo } template <> -SimpleTensor<uint8_t> activation_layer<uint8_t>(const SimpleTensor<uint8_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info) +SimpleTensor<uint8_t> +activation_layer<uint8_t>(const SimpleTensor<uint8_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info) { const QuantizationInfo dst_qinfo = oq_info.empty() ? src.quantization_info() : oq_info; @@ -68,7 +70,8 @@ SimpleTensor<uint8_t> activation_layer<uint8_t>(const SimpleTensor<uint8_t> &src } template <> -SimpleTensor<int8_t> activation_layer<int8_t>(const SimpleTensor<int8_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info) +SimpleTensor<int8_t> +activation_layer<int8_t>(const SimpleTensor<int8_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info) { const QuantizationInfo dst_qinfo = oq_info.empty() ? src.quantization_info() : oq_info; @@ -79,7 +82,8 @@ SimpleTensor<int8_t> activation_layer<int8_t>(const SimpleTensor<int8_t> &src, A } template <> -SimpleTensor<int16_t> activation_layer<int16_t>(const SimpleTensor<int16_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info) +SimpleTensor<int16_t> +activation_layer<int16_t>(const SimpleTensor<int16_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info) { const QuantizationInfo dst_qinfo = oq_info.empty() ? src.quantization_info() : oq_info; @@ -88,9 +92,14 @@ SimpleTensor<int16_t> activation_layer<int16_t>(const SimpleTensor<int16_t> &src SimpleTensor<int16_t> dst = convert_to_symmetric<int16_t>(dst_tmp, dst_qinfo); return dst; } -template SimpleTensor<int32_t> activation_layer(const SimpleTensor<int32_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); -template SimpleTensor<float> activation_layer(const SimpleTensor<float> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); -template SimpleTensor<half> activation_layer(const SimpleTensor<half> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); +template SimpleTensor<int32_t> +activation_layer(const SimpleTensor<int32_t> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); +template SimpleTensor<float> +activation_layer(const SimpleTensor<float> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); +template SimpleTensor<half> +activation_layer(const SimpleTensor<half> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); +template SimpleTensor<bfloat16> +activation_layer(const SimpleTensor<bfloat16> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/ActivationLayer.h b/tests/validation/reference/ActivationLayer.h index 4585a9db10..7f896bd696 100644 --- a/tests/validation/reference/ActivationLayer.h +++ b/tests/validation/reference/ActivationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020,2022,2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_ACTIVATION_LAYER_H -#define ARM_COMPUTE_TEST_ACTIVATION_LAYER_H +#ifndef ACL_TESTS_VALIDATION_REFERENCE_ACTIVATIONLAYER_H +#define ACL_TESTS_VALIDATION_REFERENCE_ACTIVATIONLAYER_H #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -40,7 +40,7 @@ inline T activate_float(T x, T a, T b, ActivationLayerInfo::ActivationFunction a { T ret; - switch(activation) + switch (activation) { case ActivationLayerInfo::ActivationFunction::ABS: ret = std::abs(x); @@ -61,13 +61,13 @@ inline T activate_float(T x, T a, T b, ActivationLayerInfo::ActivationFunction a ret = std::min<T>(a, std::max<T>(b, x)); break; case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: - ret = (x > 0) ? x : a * x; + ret = x > static_cast<T>(0) ? x : static_cast<T>(a * x); break; case ActivationLayerInfo::ActivationFunction::SOFT_RELU: - ret = std::log(static_cast<T>(1) + std::exp(x)); + ret = std::log(static_cast<T>(1) + std::exp(static_cast<double>(x))); break; case ActivationLayerInfo::ActivationFunction::ELU: - ret = (x > 0) ? x : a * (std::exp(x) - static_cast<T>(1)); + ret = x > static_cast<T>(0) ? x : static_cast<T>(a * (std::exp(x) - static_cast<T>(1))); break; case ActivationLayerInfo::ActivationFunction::SQRT: ret = std::sqrt(x); @@ -82,7 +82,14 @@ inline T activate_float(T x, T a, T b, ActivationLayerInfo::ActivationFunction a ret = x; break; case ActivationLayerInfo::ActivationFunction::HARD_SWISH: - ret = x * ((std::min(std::max(static_cast<T>(x + 3), static_cast<T>(0.0f)), static_cast<T>(6.0f))) * 0.166666667f); + ret = x * ((std::min(std::max(static_cast<T>(x + 3), static_cast<T>(0.0f)), static_cast<T>(6.0f))) * + 0.166666667f); + break; + case ActivationLayerInfo::ActivationFunction::SWISH: + ret = static_cast<T>(x) / (static_cast<T>(1) + std::exp(-a * x)); + break; + case ActivationLayerInfo::ActivationFunction::GELU: + ret = x * 0.5f * (1 + erf(x / std::sqrt(2.0f))); break; default: ARM_COMPUTE_ERROR("Unsupported activation function"); @@ -93,9 +100,11 @@ inline T activate_float(T x, T a, T b, ActivationLayerInfo::ActivationFunction a } template <typename T> -SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, ActivationLayerInfo info, const QuantizationInfo &oq_info = QuantizationInfo()); +SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, + ActivationLayerInfo info, + const QuantizationInfo &oq_info = QuantizationInfo()); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_ACTIVATION_LAYER_H */ +#endif // ACL_TESTS_VALIDATION_REFERENCE_ACTIVATIONLAYER_H diff --git a/tests/validation/reference/ArithmeticDivision.cpp b/tests/validation/reference/ArithmeticDivision.cpp index f86ee5e599..414d9b9eeb 100644 --- a/tests/validation/reference/ArithmeticDivision.cpp +++ b/tests/validation/reference/ArithmeticDivision.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ArithmeticDivision.h b/tests/validation/reference/ArithmeticDivision.h index f47c59f8ee..0363ffd60d 100644 --- a/tests/validation/reference/ArithmeticDivision.h +++ b/tests/validation/reference/ArithmeticDivision.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ArithmeticOperations.cpp b/tests/validation/reference/ArithmeticOperations.cpp index fd32f45cfa..ecf02f7e39 100644 --- a/tests/validation/reference/ArithmeticOperations.cpp +++ b/tests/validation/reference/ArithmeticOperations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -180,6 +180,7 @@ SimpleTensor<int16_t> arithmetic_operation(ArithmeticOperation op, const SimpleT } } +template SimpleTensor<int32_t> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<int32_t> &src1, const SimpleTensor<int32_t> &src2, SimpleTensor<int32_t> &dst, ConvertPolicy convert_policy); template SimpleTensor<half> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<half> &src1, const SimpleTensor<half> &src2, SimpleTensor<half> &dst, ConvertPolicy convert_policy); template SimpleTensor<float> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<float> &src1, const SimpleTensor<float> &src2, SimpleTensor<float> &dst, ConvertPolicy convert_policy); @@ -193,6 +194,7 @@ SimpleTensor<T> arithmetic_operation(ArithmeticOperation op, const SimpleTensor< return dst; } +template SimpleTensor<int32_t> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<int32_t> &src1, const SimpleTensor<int32_t> &src2, DataType dst_data_type, ConvertPolicy convert_policy); template SimpleTensor<int16_t> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<int16_t> &src1, const SimpleTensor<int16_t> &src2, DataType dst_data_type, ConvertPolicy convert_policy); template SimpleTensor<int8_t> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<int8_t> &src1, const SimpleTensor<int8_t> &src2, DataType dst_data_type, ConvertPolicy convert_policy); template SimpleTensor<half> arithmetic_operation(ArithmeticOperation op, const SimpleTensor<half> &src1, const SimpleTensor<half> &src2, DataType dst_data_type, ConvertPolicy convert_policy); diff --git a/tests/validation/reference/ArithmeticOperations.h b/tests/validation/reference/ArithmeticOperations.h index 53d4bbf9cd..e3a4f736c3 100644 --- a/tests/validation/reference/ArithmeticOperations.h +++ b/tests/validation/reference/ArithmeticOperations.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BatchNormalizationLayer.cpp b/tests/validation/reference/BatchNormalizationLayer.cpp index 6623b22e78..3406781132 100644 --- a/tests/validation/reference/BatchNormalizationLayer.cpp +++ b/tests/validation/reference/BatchNormalizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BatchNormalizationLayer.h b/tests/validation/reference/BatchNormalizationLayer.h index 89b18ff929..13a5eb2eeb 100644 --- a/tests/validation/reference/BatchNormalizationLayer.h +++ b/tests/validation/reference/BatchNormalizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BatchToSpaceLayer.cpp b/tests/validation/reference/BatchToSpaceLayer.cpp index 662a7070b8..63d121f59b 100644 --- a/tests/validation/reference/BatchToSpaceLayer.cpp +++ b/tests/validation/reference/BatchToSpaceLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -23,8 +23,10 @@ */ #include "BatchToSpaceLayer.h" +#include "arm_compute/core/Validate.h" #include "tests/validation/Helpers.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" namespace arm_compute { namespace test @@ -35,32 +37,37 @@ namespace reference { // Batch to Space template <typename T> -SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape) +SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape) { - ARM_COMPUTE_ERROR_ON(block_shape[0] <= 0); - ARM_COMPUTE_ERROR_ON(block_shape[1] <= 0); - SimpleTensor<T> result(dst_shape, src.data_type()); + ARM_COMPUTE_ERROR_ON(block_shape[0] < 1); + ARM_COMPUTE_ERROR_ON(block_shape[1] < 1); + const auto expected_dst_shape = misc::shape_calculator::compute_batch_to_space_shape(DataLayout::NCHW, src.shape(), block_shape[0], block_shape[1], crop_info); + ARM_COMPUTE_ERROR_ON(arm_compute::detail::have_different_dimensions(expected_dst_shape, dst_shape, 0)); + ARM_COMPUTE_UNUSED(expected_dst_shape); - int in_pos = 0; - const auto width_in = static_cast<int>(src.shape()[0]); - const auto height_in = static_cast<int>(src.shape()[1]); - const auto z_in = static_cast<int>(src.shape()[2]); - const auto batch_in = static_cast<int>(src.shape()[3]); + SimpleTensor<T> result(dst_shape, src.data_type()); + int out_pos = 0; + const auto width_out = static_cast<int>(dst_shape[0]); + const auto height_out = static_cast<int>(dst_shape[1]); + const auto z_out = static_cast<int>(dst_shape[2]); + const auto batch_out = static_cast<int>(dst_shape[3]); - for(int batch = 0; batch < batch_in; ++batch) + for(int batch = 0; batch < batch_out; ++batch) { - for(int z = 0; z < z_in; ++z) + for(int z = 0; z < z_out; ++z) { - for(int y = 0; y < height_in; ++y) + for(int y = 0; y < height_out; ++y) { - for(int x = 0; x < width_in; ++x) + for(int x = 0; x < width_out; ++x) { - const int r = src.shape()[3] / (block_shape[0] * block_shape[1]); - const int out_x = (block_shape[0] * x + (batch / r) % block_shape[0]); - const int out_y = (block_shape[1] * y + (batch / r) / block_shape[0]); - const int out_pos = out_x + dst_shape[0] * out_y + z * dst_shape[0] * dst_shape[1] + (batch % r) * dst_shape[0] * dst_shape[1] * dst_shape[2]; - result[out_pos] = src[in_pos]; - ++in_pos; + const int x_c = x + crop_info.left; + const int y_c = y + crop_info.top; + const int in_batch = batch + ((x_c % block_shape[0]) + (y_c % block_shape[1]) * (block_shape[0])) * dst_shape[3]; + const int in_x = x_c / block_shape[0]; + const int in_y = y_c / block_shape[1]; + const int in_pos = in_x + src.shape()[0] * in_y + z * src.shape()[0] * src.shape()[1] + in_batch * src.shape()[0] * src.shape()[1] * src.shape()[2]; + result[out_pos] = src[in_pos]; + ++out_pos; } } } @@ -68,8 +75,8 @@ SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const SimpleTensor<in return result; } -template SimpleTensor<float> batch_to_space(const SimpleTensor<float> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape); -template SimpleTensor<half> batch_to_space(const SimpleTensor<half> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape); +template SimpleTensor<float> batch_to_space(const SimpleTensor<float> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape); +template SimpleTensor<half> batch_to_space(const SimpleTensor<half> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/BatchToSpaceLayer.h b/tests/validation/reference/BatchToSpaceLayer.h index da8c1ef3aa..a37bfc3373 100644 --- a/tests/validation/reference/BatchToSpaceLayer.h +++ b/tests/validation/reference/BatchToSpaceLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #ifndef ARM_COMPUTE_TEST_BATCH_TO_SPACE_LAYER_H #define ARM_COMPUTE_TEST_BATCH_TO_SPACE_LAYER_H +#include "arm_compute/core/Types.h" #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -36,7 +37,7 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape); +SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/BitwiseAnd.cpp b/tests/validation/reference/BitwiseAnd.cpp index 356c27ee13..922f75ae4a 100644 --- a/tests/validation/reference/BitwiseAnd.cpp +++ b/tests/validation/reference/BitwiseAnd.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseAnd.h b/tests/validation/reference/BitwiseAnd.h index def8669957..f78be7383b 100644 --- a/tests/validation/reference/BitwiseAnd.h +++ b/tests/validation/reference/BitwiseAnd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseNot.cpp b/tests/validation/reference/BitwiseNot.cpp index 03578a3beb..d68a01075b 100644 --- a/tests/validation/reference/BitwiseNot.cpp +++ b/tests/validation/reference/BitwiseNot.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseNot.h b/tests/validation/reference/BitwiseNot.h index a617853970..f4294ee785 100644 --- a/tests/validation/reference/BitwiseNot.h +++ b/tests/validation/reference/BitwiseNot.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseOr.cpp b/tests/validation/reference/BitwiseOr.cpp index 11c0a932fe..d38ae46b34 100644 --- a/tests/validation/reference/BitwiseOr.cpp +++ b/tests/validation/reference/BitwiseOr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseOr.h b/tests/validation/reference/BitwiseOr.h index 9e9c3e1815..9f5c7cb52a 100644 --- a/tests/validation/reference/BitwiseOr.h +++ b/tests/validation/reference/BitwiseOr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseXor.cpp b/tests/validation/reference/BitwiseXor.cpp index afae032b1b..db5c9532c0 100644 --- a/tests/validation/reference/BitwiseXor.cpp +++ b/tests/validation/reference/BitwiseXor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BitwiseXor.h b/tests/validation/reference/BitwiseXor.h index 68478d0ea2..c1a4d6fe99 100644 --- a/tests/validation/reference/BitwiseXor.h +++ b/tests/validation/reference/BitwiseXor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BoundingBoxTransform.cpp b/tests/validation/reference/BoundingBoxTransform.cpp index 89182f1a9c..2abadd0f54 100644 --- a/tests/validation/reference/BoundingBoxTransform.cpp +++ b/tests/validation/reference/BoundingBoxTransform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/BoundingBoxTransform.h b/tests/validation/reference/BoundingBoxTransform.h index 6900f67afa..df243ef42f 100644 --- a/tests/validation/reference/BoundingBoxTransform.h +++ b/tests/validation/reference/BoundingBoxTransform.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Box3x3.cpp b/tests/validation/reference/Box3x3.cpp deleted file mode 100644 index 7ea3f1fe99..0000000000 --- a/tests/validation/reference/Box3x3.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Helpers.h" - -#include "Box3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> box3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const std::array<T, 9> filter{ { 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; - const float scale = 1.f / static_cast<float>(filter.size()); - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor<uint8_t> box3x3(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/CannyEdgeDetector.cpp b/tests/validation/reference/CannyEdgeDetector.cpp deleted file mode 100644 index a952ddedb0..0000000000 --- a/tests/validation/reference/CannyEdgeDetector.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "CannyEdgeDetector.h" - -#include "Utils.h" -#include "support/ToolchainSupport.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/Magnitude.h" -#include "tests/validation/reference/NonMaximaSuppression.h" -#include "tests/validation/reference/Phase.h" -#include "tests/validation/reference/Sobel.h" - -#include <cmath> -#include <stack> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const auto MARK_ZERO = 0u; -const auto MARK_MAYBE = 127u; -const auto MARK_EDGE = 255u; - -template <typename T> -void trace_edge(SimpleTensor<T> &dst, const ValidRegion &valid_region) -{ - std::stack<Coordinates> pixels_stack; - for(auto i = 0; i < dst.num_elements(); ++i) - { - if(dst[i] == MARK_EDGE) - { - pixels_stack.push(index2coord(dst.shape(), i)); - } - } - - while(!pixels_stack.empty()) - { - const Coordinates pixel_coord = pixels_stack.top(); - pixels_stack.pop(); - - std::array<Coordinates, 8> neighbours = - { - { - Coordinates(pixel_coord.x() - 1, pixel_coord.y() + 0), - Coordinates(pixel_coord.x() + 1, pixel_coord.y() + 0), - Coordinates(pixel_coord.x() - 1, pixel_coord.y() - 1), - Coordinates(pixel_coord.x() + 1, pixel_coord.y() + 1), - Coordinates(pixel_coord.x() + 0, pixel_coord.y() - 1), - Coordinates(pixel_coord.x() + 0, pixel_coord.y() + 1), - Coordinates(pixel_coord.x() + 1, pixel_coord.y() - 1), - Coordinates(pixel_coord.x() - 1, pixel_coord.y() + 1) - } - }; - - // Mark MAYBE neighbours as edges since they are next to an EDGE - std::for_each(neighbours.begin(), neighbours.end(), [&](Coordinates & coord) - { - if(is_in_valid_region(valid_region, coord)) - { - const size_t pixel_index = coord2index(dst.shape(), coord); - const T pixel = dst[pixel_index]; - if(pixel == MARK_MAYBE) - { - dst[pixel_index] = MARK_EDGE; - pixels_stack.push(coord); - } - } - }); - } - - // Mark all remaining MAYBE pixels as ZERO (not edges) - for(auto i = 0; i < dst.num_elements(); ++i) - { - if(dst[i] == MARK_MAYBE) - { - dst[i] = MARK_ZERO; - } - } -} - -template <typename U, typename T> -SimpleTensor<T> canny_edge_detector_impl(const SimpleTensor<T> &src, int32_t upper, int32_t lower, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, T constant_border_value) -{ - ARM_COMPUTE_ERROR_ON(gradient_size != 3 && gradient_size != 5 && gradient_size != 7); - ARM_COMPUTE_ERROR_ON(lower < 0 || lower >= upper); - - // Output: T == uint8_t - SimpleTensor<T> dst{ src.shape(), src.data_type() }; - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + 1)); - - // Sobel computation: U == int16_t or int32_t - SimpleTensor<U> gx{}; - SimpleTensor<U> gy{}; - std::tie(gx, gy) = sobel<U>(src, gradient_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - using unsigned_U = typename traits::make_unsigned_conditional_t<U>::type; - using promoted_U = typename common_promoted_signed_type<U>::intermediate_type; - - // Gradient magnitude and phase (edge direction) - const DataType mag_data_type = gx.data_type() == DataType::S16 ? DataType::U16 : DataType::U32; - SimpleTensor<unsigned_U> grad_mag{ gx.shape(), mag_data_type }; - SimpleTensor<uint8_t> grad_dir{ gy.shape(), DataType::U8 }; - - for(auto i = 0; i < grad_mag.num_elements(); ++i) - { - double mag = 0.f; - - if(norm_type == MagnitudeType::L2NORM) - { - mag = support::cpp11::round(std::sqrt(static_cast<promoted_U>(gx[i]) * gx[i] + static_cast<promoted_U>(gy[i]) * gy[i])); - } - else // MagnitudeType::L1NORM - { - mag = static_cast<promoted_U>(std::abs(gx[i])) + static_cast<promoted_U>(std::abs(gy[i])); - } - - float angle = 180.f * std::atan2(static_cast<float>(gy[i]), static_cast<float>(gx[i])) / M_PI; - grad_dir[i] = support::cpp11::round(angle < 0.f ? 180 + angle : angle); - grad_mag[i] = saturate_cast<unsigned_U>(mag); - } - - /* - Quantise the phase into 4 directions - 0° dir=0 0.0 <= p < 22.5 or 157.5 <= p < 180 - 45° dir=1 22.5 <= p < 67.5 - 90° dir=2 67.5 <= p < 112.5 - 135° dir=3 112.5 <= p < 157.5 - */ - for(auto i = 0; i < grad_dir.num_elements(); ++i) - { - const auto direction = std::fabs(grad_dir[i]); - grad_dir[i] = (direction < 22.5 || direction >= 157.5) ? 0 : (direction < 67.5) ? 1 : (direction < 112.5) ? 2 : 3; - } - - // Non-maximum suppression - std::vector<int> strong_edges; - const auto upper_thresh = static_cast<uint32_t>(upper); - const auto lower_thresh = static_cast<uint32_t>(lower); - - const auto pixel_at_offset = [&](const SimpleTensor<unsigned_U> &tensor, const Coordinates & coord, int xoffset, int yoffset) - { - return tensor_elem_at(tensor, Coordinates{ coord.x() + xoffset, coord.y() + yoffset }, border_mode, static_cast<unsigned_U>(constant_border_value)); - }; - - for(auto i = 0; i < dst.num_elements(); ++i) - { - const auto coord = index2coord(dst.shape(), i); - if(!is_in_valid_region(valid_region, coord) || grad_mag[i] <= lower_thresh) - { - dst[i] = MARK_ZERO; - continue; - } - - unsigned_U mag_90; - unsigned_U mag90; - switch(grad_dir[i]) - { - case 0: // North/South edge direction, compare against East/West pixels (left & right) - mag_90 = pixel_at_offset(grad_mag, coord, -1, 0); - mag90 = pixel_at_offset(grad_mag, coord, 1, 0); - break; - case 1: // NE/SW edge direction, compare against NW/SE pixels (top-left & bottom-right) - mag_90 = pixel_at_offset(grad_mag, coord, -1, -1); - mag90 = pixel_at_offset(grad_mag, coord, +1, +1); - break; - case 2: // East/West edge direction, compare against North/South pixels (top & bottom) - mag_90 = pixel_at_offset(grad_mag, coord, 0, -1); - mag90 = pixel_at_offset(grad_mag, coord, 0, +1); - break; - case 3: // NW/SE edge direction, compare against NE/SW pixels (top-right & bottom-left) - mag_90 = pixel_at_offset(grad_mag, coord, +1, -1); - mag90 = pixel_at_offset(grad_mag, coord, -1, +1); - break; - default: - ARM_COMPUTE_ERROR("Invalid gradient phase provided"); - break; - } - - // Potential edge if greater than both pixels at +/-90° on either side - if(grad_mag[i] > mag_90 && grad_mag[i] > mag90) - { - // Double thresholding and edge tracing - if(grad_mag[i] > upper_thresh) - { - dst[i] = MARK_EDGE; // Definite edge pixel - strong_edges.emplace_back(i); - } - else - { - dst[i] = MARK_MAYBE; - } - } - else - { - dst[i] = MARK_ZERO; // Since not greater than neighbours - } - } - - // Final edge tracing - trace_edge<T>(dst, valid_region); - return dst; -} -} // namespace - -template <typename T> -SimpleTensor<T> canny_edge_detector(const SimpleTensor<T> &src, - int32_t upper_thresh, int32_t lower_thresh, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, T constant_border_value) -{ - if(gradient_size < 7) - { - return canny_edge_detector_impl<int16_t>(src, upper_thresh, lower_thresh, gradient_size, norm_type, border_mode, constant_border_value); - } - else - { - return canny_edge_detector_impl<int32_t>(src, upper_thresh, lower_thresh, gradient_size, norm_type, border_mode, constant_border_value); - } -} - -template SimpleTensor<uint8_t> canny_edge_detector(const SimpleTensor<uint8_t> &src, - int32_t upper_thresh, int32_t lower_thresh, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/CannyEdgeDetector.h b/tests/validation/reference/CannyEdgeDetector.h deleted file mode 100644 index 664eab7432..0000000000 --- a/tests/validation/reference/CannyEdgeDetector.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_CANNY_EDGE_DETECTOR_H -#define ARM_COMPUTE_TEST_CANNY_EDGE_DETECTOR_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> canny_edge_detector(const SimpleTensor<T> &src, - int32_t upper_thresh, int32_t lower_thresh, int gradient_size, MagnitudeType norm_type, - BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CANNY_EDGE_DETECTOR_H */ diff --git a/tests/validation/reference/ChannelCombine.cpp b/tests/validation/reference/ChannelCombine.cpp deleted file mode 100644 index 2380b58583..0000000000 --- a/tests/validation/reference/ChannelCombine.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ChannelCombine.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape, Format format) -{ - TensorShape image_shape = adjust_odd_shape(shape, format); - - std::vector<SimpleTensor<T>> image_planes; - - switch(format) - { - case Format::RGB888: - case Format::RGBA8888: - case Format::YUYV422: - case Format::UYVY422: - { - image_planes.emplace_back(image_shape, format); - break; - } - case Format::NV12: - case Format::NV21: - { - TensorShape shape_uv88 = calculate_subsampled_shape(image_shape, Format::UV88); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_uv88, Format::UV88); - break; - } - case Format::IYUV: - { - TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, Format::IYUV); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - break; - } - case Format::YUV444: - { - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - - return image_planes; -} -} // namespace - -template <typename T> -std::vector<SimpleTensor<T>> channel_combine(const TensorShape &shape, const std::vector<SimpleTensor<T>> &image_planes, Format format) -{ - std::vector<SimpleTensor<T>> dst = create_image_planes<T>(shape, format); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(unsigned int plane_idx = 0; plane_idx < dst.size(); ++plane_idx) - { - SimpleTensor<T> &dst_tensor = dst[plane_idx]; - const uint32_t num_elements = dst_tensor.num_elements(); - - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - Coordinates coord = index2coord(dst_tensor.shape(), element_idx); - - switch(format) - { - case Format::RGB888: - case Format::RGBA8888: - { - // Copy R/G/B or A channel - for(int channel_idx = 0; channel_idx < dst_tensor.num_channels(); ++channel_idx) - { - const T &src_value = reinterpret_cast<const T *>(image_planes[channel_idx](coord))[0]; - T &dst_value = reinterpret_cast<T *>(dst_tensor(coord))[channel_idx]; - - dst_value = src_value; - } - break; - } - case Format::YUYV422: - case Format::UYVY422: - { - // Find coordinates of the sub-sampled pixel - const Coordinates coord_hori(coord.x() / 2, coord.y()); - - const T &src0 = reinterpret_cast<const T *>(image_planes[0](coord))[0]; - const T &src1 = reinterpret_cast<const T *>(image_planes[1](coord_hori))[0]; - - const int shift = (Format::YUYV422 == format) ? 1 : 0; - T &dst0 = reinterpret_cast<T *>(dst_tensor(coord))[1 - shift]; - T &dst1 = reinterpret_cast<T *>(dst_tensor(coord))[0 + shift]; - - dst0 = src0; - dst1 = src1; - - Coordinates coord2 = index2coord(dst_tensor.shape(), ++element_idx); - - const T &src2 = reinterpret_cast<const T *>(image_planes[0](coord2))[0]; - const T &src3 = reinterpret_cast<const T *>(image_planes[2](coord_hori))[0]; - - T &dst2 = reinterpret_cast<T *>(dst_tensor(coord2))[1 - shift]; - T &dst3 = reinterpret_cast<T *>(dst_tensor(coord2))[0 + shift]; - - dst2 = src2; - dst3 = src3; - - break; - } - case Format::NV12: - case Format::NV21: - { - if(0U == plane_idx) - { - // Get and combine Y channel from plane0 of destination multi-image - dst_tensor[element_idx] = image_planes[0][element_idx]; - } - else - { - const int shift = (Format::NV12 == format) ? 0 : 1; - - // Get U channel from plane1 and V channel from plane2 of the source - const T &src_u0 = reinterpret_cast<const T *>(image_planes[1](coord))[0]; - const T &src_v0 = reinterpret_cast<const T *>(image_planes[2](coord))[0]; - - // Get U and V channel from plane1 of destination multi-image - T &dst_u0 = reinterpret_cast<T *>(dst_tensor(coord))[0 + shift]; - T &dst_v0 = reinterpret_cast<T *>(dst_tensor(coord))[1 - shift]; - - // Combine channel U and V - dst_u0 = src_u0; - dst_v0 = src_v0; - } - - break; - } - case Format::IYUV: - case Format::YUV444: - { - // Get Y/U/V element - const T &src = reinterpret_cast<const T *>(image_planes[plane_idx](coord))[0]; - T &dst = reinterpret_cast<T *>(dst_tensor(coord))[0]; - - // Copy Y/U/V plane - dst = src; - - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - } - } - - return dst; -} - -template std::vector<SimpleTensor<uint8_t>> channel_combine(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &image_planes, Format format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ChannelExtract.cpp b/tests/validation/reference/ChannelExtract.cpp deleted file mode 100644 index 75d0a00604..0000000000 --- a/tests/validation/reference/ChannelExtract.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ChannelExtract.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel) -{ - // Find plane and channel index - const unsigned int plane_idx = plane_idx_from_channel(format, channel); - const unsigned int channel_idx = channel_idx_from_format(format, channel); - - // Create dst and get src tensor - SimpleTensor<T> src = tensor_planes[plane_idx]; - SimpleTensor<T> dst{ calculate_subsampled_shape(shape, format, channel), Format::U8 }; - - // Single planar formats with subsampling require a double horizontal step - const int step_x = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1; - const int width = dst.shape().x(); - const int height = dst.shape().y(); - - // Loop over each pixel and extract channel -#if defined(_OPENMP) - #pragma omp parallel for collapse(2) -#endif /* _OPENMP */ - for(int y = 0; y < height; ++y) - { - for(int x = 0; x < width; ++x) - { - const Coordinates src_coord{ x * step_x, y }; - const Coordinates dst_coord{ x, y }; - - const auto *src_pixel = reinterpret_cast<const T *>(src(src_coord)); - auto *dst_pixel = reinterpret_cast<T *>(dst(dst_coord)); - - dst_pixel[0] = src_pixel[channel_idx]; // NOLINT - } - } - - return dst; -} - -template SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format format, Channel channel); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ChannelShuffle.cpp b/tests/validation/reference/ChannelShuffle.cpp index 39d89e9f02..89ef080030 100644 --- a/tests/validation/reference/ChannelShuffle.cpp +++ b/tests/validation/reference/ChannelShuffle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ChannelShuffle.h b/tests/validation/reference/ChannelShuffle.h index 7c72977fbf..d83be362ca 100644 --- a/tests/validation/reference/ChannelShuffle.h +++ b/tests/validation/reference/ChannelShuffle.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Col2Im.cpp b/tests/validation/reference/Col2Im.cpp index f42582bbe8..04c4128a80 100644 --- a/tests/validation/reference/Col2Im.cpp +++ b/tests/validation/reference/Col2Im.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Col2Im.h b/tests/validation/reference/Col2Im.h index 6ca76d0763..57e93d9363 100644 --- a/tests/validation/reference/Col2Im.h +++ b/tests/validation/reference/Col2Im.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ColorConvert.cpp b/tests/validation/reference/ColorConvert.cpp deleted file mode 100644 index a759594cfa..0000000000 --- a/tests/validation/reference/ColorConvert.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ColorConvert.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/ColorConvertHelper.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape, Format format) -{ - TensorShape image_shape = adjust_odd_shape(shape, format); - - std::vector<SimpleTensor<T>> image_planes; - - switch(format) - { - case Format::U8: - case Format::RGB888: - case Format::RGBA8888: - case Format::YUYV422: - case Format::UYVY422: - { - image_planes.emplace_back(image_shape, format); - break; - } - case Format::NV12: - case Format::NV21: - { - TensorShape shape_uv88 = calculate_subsampled_shape(image_shape, Format::UV88); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_uv88, Format::UV88); - break; - } - case Format::IYUV: - { - TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, Format::IYUV); - - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - image_planes.emplace_back(shape_sub2, Format::U8); - break; - } - case Format::YUV444: - { - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - image_planes.emplace_back(image_shape, Format::U8); - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - - return image_planes; -} -} // namespace - -template <typename T> -std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format src_format, Format dst_format) -{ - std::vector<SimpleTensor<T>> dst = create_image_planes<T>(shape, dst_format); - - switch(src_format) - { - case Format::RGB888: - { - switch(dst_format) - { - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_rgb_to_rgbx(tensor_planes[0], dst[0]); - break; - case Format::U8: - colorconvert_helper::detail::colorconvert_rgb_to_u8(tensor_planes[0], dst[0]); - break; - case Format::NV12: - colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst); - break; - case Format::YUV444: - colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::RGBA8888: - { - switch(dst_format) - { - case Format::RGB888: - colorconvert_helper::detail::colorconvert_rgbx_to_rgb(tensor_planes[0], dst[0]); - break; - case Format::NV12: - colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst); - break; - case Format::YUV444: - colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::UYVY422: - case Format::YUYV422: - { - switch(dst_format) - { - case Format::RGB888: - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_yuyv_to_rgb(tensor_planes[0], src_format, dst[0]); - break; - case Format::NV12: - colorconvert_helper::detail::colorconvert_yuyv_to_nv12(tensor_planes[0], src_format, dst); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_yuyv_to_iyuv(tensor_planes[0], src_format, dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::IYUV: - { - switch(dst_format) - { - case Format::RGB888: - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_iyuv_to_rgb(tensor_planes, dst[0]); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - case Format::NV12: - case Format::NV21: - { - switch(dst_format) - { - case Format::RGB888: - case Format::RGBA8888: - colorconvert_helper::detail::colorconvert_nv12_to_rgb(src_format, tensor_planes, dst[0]); - break; - case Format::IYUV: - colorconvert_helper::detail::colorconvert_nv_to_iyuv(tensor_planes, src_format, dst); - break; - case Format::YUV444: - colorconvert_helper::detail::colorconvert_nv_to_yuv4(tensor_planes, src_format, dst); - break; - default: - ARM_COMPUTE_ERROR("Not Supported"); - break; - } - break; - } - default: - ARM_COMPUTE_ERROR("Not supported"); - break; - } - return dst; -} - -template std::vector<SimpleTensor<uint8_t>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format src_format, Format dst_format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ColorConvert.h b/tests/validation/reference/ColorConvert.h deleted file mode 100644 index 75efeb2aca..0000000000 --- a/tests/validation/reference/ColorConvert.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_COLOR_CONVERT_H -#define ARM_COMPUTE_TEST_COLOR_CONVERT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format src_format, Format dst_format); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_COLOR_CONVERT_H */ diff --git a/tests/validation/reference/ColorConvertHelper.h b/tests/validation/reference/ColorConvertHelper.h index f3865dd947..8ab58409a7 100644 --- a/tests/validation/reference/ColorConvertHelper.h +++ b/tests/validation/reference/ColorConvertHelper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -614,9 +614,7 @@ inline void colorconvert_rgb_to_yuv4(const SimpleTensor<T> src, std::vector<Simp rgb_to_yuv_calculation(rvec, gvec, bvec, dst[0], uvec_top, uvec_bottom, vvec_top, vvec_bottom); - int uvec_coord_x = 0; - int uvec_coord_y = 0; - Coordinates uvec_coord{ uvec_coord_x, uvec_coord_y }; + Coordinates uvec_coord{ 0, 0 }; for(int y = 0; y < height; y++) { for(int x = 0; x < width; x += 2) @@ -638,7 +636,7 @@ inline void colorconvert_rgb_to_yuv4(const SimpleTensor<T> src, std::vector<Simp plane_2_pixel[0] = vvec_top_val; plane_2_pixel[1] = vvec_bottom_val; - uvec_coord.set(0, ++uvec_coord_x); + uvec_coord.increment(0); } } } diff --git a/tests/validation/reference/Comparisons.cpp b/tests/validation/reference/Comparisons.cpp index 2313d9b022..6b18e90d28 100644 --- a/tests/validation/reference/Comparisons.cpp +++ b/tests/validation/reference/Comparisons.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Comparisons.h b/tests/validation/reference/Comparisons.h index 262f4b7b16..f0867a8ae4 100644 --- a/tests/validation/reference/Comparisons.h +++ b/tests/validation/reference/Comparisons.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ComputeAllAnchors.cpp b/tests/validation/reference/ComputeAllAnchors.cpp index 9654da2ea3..8715a5aa74 100644 --- a/tests/validation/reference/ComputeAllAnchors.cpp +++ b/tests/validation/reference/ComputeAllAnchors.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ComputeAllAnchors.h b/tests/validation/reference/ComputeAllAnchors.h index 7dfa268747..838d780f25 100644 --- a/tests/validation/reference/ComputeAllAnchors.h +++ b/tests/validation/reference/ComputeAllAnchors.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ConcatenateLayer.cpp b/tests/validation/reference/ConcatenateLayer.cpp index 266dae1c27..8910f481da 100644 --- a/tests/validation/reference/ConcatenateLayer.cpp +++ b/tests/validation/reference/ConcatenateLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ConcatenateLayer.h b/tests/validation/reference/ConcatenateLayer.h index a85a66e355..b773221041 100644 --- a/tests/validation/reference/ConcatenateLayer.h +++ b/tests/validation/reference/ConcatenateLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Conv3D.cpp b/tests/validation/reference/Conv3D.cpp new file mode 100644 index 0000000000..e4010a507a --- /dev/null +++ b/tests/validation/reference/Conv3D.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2021, 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "Conv3D.h" + +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "arm_compute/core/utils/quantization/AsymmHelpers.h" +#include "support/AclRequires.h" +#include "tests/validation/reference/UtilsQuantizedAsymm.h" + +// Source/Destination Tensor shape indices (N D H W C) +constexpr unsigned int batch_dim = 4u; +constexpr unsigned int depth_dim = 3u; +constexpr unsigned int height_dim = 2u; +constexpr unsigned int width_dim = 1u; +constexpr unsigned int channel_dim = 0u; + +// Weight tensor shape indices (D H W Cin Cout) +constexpr unsigned int weights_depth_dim = 4u; +constexpr unsigned int weights_height_dim = 3u; +constexpr unsigned int weights_width_dim = 2u; +constexpr unsigned int weights_CHin_dim = 1u; +constexpr unsigned int weights_CHout_dim = 0u; + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +inline bool is_valid_pixel(int i, int min, int max) +{ + return (i >= min && i < max); +} + +// Evaluate the weights against an element in a given tensor. +template < typename T, typename TB, typename std::enable_if < validation::is_floating_point<T>::value &&validation::is_floating_point<TB>::value, int >::type = 0 > +T calculate_conv3d(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, const Size3D &dilation, int batch, + int z_start, int y_start, int x_start, int ch_out, UniformQuantizationInfo oq_info) +{ + ARM_COMPUTE_UNUSED(oq_info); + + const unsigned int weights_width = weights.shape()[weights_width_dim]; + const unsigned int weights_height = weights.shape()[weights_height_dim]; + const unsigned int weights_depth = weights.shape()[weights_depth_dim]; + + const unsigned int src_channels = src.shape()[channel_dim]; + const unsigned int src_width = src.shape()[width_dim]; + const unsigned int src_height = src.shape()[height_dim]; + const unsigned int src_depth = src.shape()[depth_dim]; + + T total(0); + for(unsigned int weight_d = 0; weight_d < weights_depth; ++weight_d) + { + const int idx_z = z_start + dilation.depth * weight_d; + for(unsigned int weight_y = 0; weight_y < weights_height; ++weight_y) + { + const int idx_y = y_start + dilation.height * weight_y; + for(unsigned int weight_x = 0; weight_x < weights_width; ++weight_x) + { + const int idx_x = x_start + dilation.width * weight_x; + + //Check if the point is within padding + const bool is_x_valid = is_valid_pixel(idx_x, 0, src_width); + const bool is_y_valid = is_valid_pixel(idx_y, 0, src_height); + const bool is_z_valid = is_valid_pixel(idx_z, 0, src_depth); + const bool is_invalid_pixel = !(is_x_valid && is_y_valid && is_z_valid); + if(is_invalid_pixel) + { + continue; + } + + for(unsigned int ch_in = 0; ch_in < src_channels; ++ch_in) + { + const T *in_ptr = src.data(); + const T *w_ptr = weights.data(); + + const int in_offset = coord2index(src.shape(), Coordinates{ ch_in, idx_x, idx_y, idx_z, batch }); + const int weight_offset = coord2index(weights.shape(), Coordinates{ ch_out, ch_in, weight_x, weight_y, weight_d }); + T input_value = in_ptr[in_offset]; + T weight_value = w_ptr[weight_offset]; + total += (input_value * weight_value); + } + } + } + } + + const TB *b_ptr = bias.data(); + TB bias_value = b_ptr[ch_out]; + + return total + bias_value; +} + +template < typename T, typename TB, ARM_COMPUTE_REQUIRES_TA(std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value) > +T calculate_conv3d(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, const Size3D &dilation, int batch, + int z_start, int y_start, int x_start, int ch_out, UniformQuantizationInfo oq_info) +{ + const unsigned int weights_width = weights.shape()[weights_width_dim]; + const unsigned int weights_height = weights.shape()[weights_height_dim]; + const unsigned int weights_depth = weights.shape()[weights_depth_dim]; + + const unsigned int src_channels = src.shape()[channel_dim]; + const unsigned int src_width = src.shape()[width_dim]; + const unsigned int src_height = src.shape()[height_dim]; + const unsigned int src_depth = src.shape()[depth_dim]; + + const UniformQuantizationInfo iq_info = src.quantization_info().uniform(); + const UniformQuantizationInfo wq_info = weights.quantization_info().uniform(); + + const int input_offset = -iq_info.offset; + const float input_scale = iq_info.scale; + int weights_offset = -wq_info.offset; + float weights_scale = wq_info.scale; + const int output_offset = oq_info.offset; + const float output_scale = oq_info.scale; + + int output_multiplier = 0; + int output_shift = 0; + const float multiplier = input_scale * weights_scale / output_scale; + arm_compute::quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); + + int32_t total(0); + for(unsigned int weight_d = 0; weight_d < weights_depth; ++weight_d) + { + const int idx_z = z_start + dilation.depth * weight_d; + for(unsigned int weight_y = 0; weight_y < weights_height; ++weight_y) + { + const int idx_y = y_start + dilation.height * weight_y; + for(unsigned int weight_x = 0; weight_x < weights_width; ++weight_x) + { + const int idx_x = x_start + dilation.width * weight_x; + + //Check if the point is within padding + const bool is_x_valid = is_valid_pixel(idx_x, 0, src_width); + const bool is_y_valid = is_valid_pixel(idx_y, 0, src_height); + const bool is_z_valid = is_valid_pixel(idx_z, 0, src_depth); + const bool is_invalid_pixel = !(is_x_valid && is_y_valid && is_z_valid); + if(is_invalid_pixel) + { + continue; + } + + for(unsigned int ch_in = 0; ch_in < src_channels; ++ch_in) + { + const T *in_ptr = src.data(); + const T *w_ptr = weights.data(); + + const int in_offset = coord2index(src.shape(), Coordinates{ ch_in, idx_x, idx_y, idx_z, batch }); + const int weight_offset = coord2index(weights.shape(), Coordinates{ ch_out, ch_in, weight_x, weight_y, weight_d }); + T input_value = in_ptr[in_offset]; + T weight_value = w_ptr[weight_offset]; + total += ((input_value + input_offset) * (weight_value + weights_offset)); + } + } + } + } + + const TB *b_ptr = bias.data(); + TB bias_value = b_ptr[ch_out]; + + total += bias_value; + + return validation::quantize_down_scale_by_fixedpoint(total, output_multiplier, output_shift, output_offset, + std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max()); +} +} // namespace + +template <typename T, typename TB> +SimpleTensor<T> conv3d(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, SimpleTensor<T> &dst, const Conv3dInfo &conv3d_info) +{ + // Compute reference + const unsigned int batch_size = src.shape()[batch_dim]; + const unsigned int dst_width = dst.shape()[width_dim]; + const unsigned int dst_height = dst.shape()[height_dim]; + const unsigned int dst_depth = dst.shape()[depth_dim]; + const unsigned int src_channels = src.shape()[channel_dim]; + const unsigned int weights_out_ch = weights.shape()[weights_CHout_dim]; + const unsigned int dst_channels = dst.shape()[channel_dim]; + const size_t pad_left = conv3d_info.padding.left; + const size_t pad_top = conv3d_info.padding.top; + const size_t pad_front = conv3d_info.padding.front; + const size_t stride_x = conv3d_info.stride.x(); + const size_t stride_y = conv3d_info.stride.y(); + const size_t stride_z = conv3d_info.stride.z(); + + const TensorShape dst_shape = arm_compute::misc::shape_calculator::compute_conv3d_shape(src.shape(), weights.shape(), conv3d_info); + + ARM_COMPUTE_UNUSED(src_channels, weights_out_ch, dst_channels, dst_shape, weights_CHin_dim); + // Number of batches of source and destination tensors must match. + ARM_COMPUTE_ERROR_ON(src.shape()[batch_dim] != dst.shape()[batch_dim]); + // Input channels in the source and weights must match. + ARM_COMPUTE_ERROR_ON(src_channels != weights.shape()[weights_CHin_dim]); + // Weight channels in the destination and weights must match. + ARM_COMPUTE_ERROR_ON(weights_out_ch != dst_channels); + // Bias must match the number of destination channels. + ARM_COMPUTE_ERROR_ON(bias.shape()[0] != dst_channels); + // Compare given dst tensor shape with expected shape. + ARM_COMPUTE_ERROR_ON(dst.shape() != dst_shape); + + for(unsigned int batch = 0; batch < batch_size; ++batch) + { + for(unsigned int z_out = 0; z_out < dst_depth; ++z_out) + { + const int z_start = (z_out * stride_z) - pad_front; + for(unsigned int y_out = 0; y_out < dst_height; ++y_out) + { + const int y_start = (y_out * stride_y) - pad_top; + for(unsigned int x_out = 0; x_out < dst_width; ++x_out) + { + const int x_start = (x_out * stride_x) - pad_left; + for(unsigned int ch_out = 0; ch_out < dst_channels; ++ch_out) + { + T *out_ptr = dst.data(); + + const int out_offset = coord2index(dst.shape(), Coordinates{ ch_out, x_out, y_out, z_out, batch }); + out_ptr[out_offset] = calculate_conv3d<T, TB>(src, weights, bias, conv3d_info.dilation, batch, z_start, y_start, x_start, ch_out, dst.quantization_info().uniform()); + } + } + } + } + } + return dst; +} + +template SimpleTensor<float> conv3d(const SimpleTensor<float> &src, const SimpleTensor<float> &weights, const SimpleTensor<float> &bias, SimpleTensor<float> &dst, + const Conv3dInfo &conv3d_info); +template SimpleTensor<half> conv3d(const SimpleTensor<half> &src, const SimpleTensor<half> &weights, const SimpleTensor<half> &bias, SimpleTensor<half> &dst, + const Conv3dInfo &conv3d_info); +template SimpleTensor<uint8_t> conv3d(const SimpleTensor<uint8_t> &src, const SimpleTensor<uint8_t> &weights, const SimpleTensor<int32_t> &bias, SimpleTensor<uint8_t> &dst, + const Conv3dInfo &conv3d_info); +template SimpleTensor<int8_t> conv3d(const SimpleTensor<int8_t> &src, const SimpleTensor<int8_t> &weights, const SimpleTensor<int32_t> &bias, SimpleTensor<int8_t> &dst, + const Conv3dInfo &conv3d_info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/LocallyConnected.h b/tests/validation/reference/Conv3D.h index 97df45e047..e3674f4bfb 100644 --- a/tests/validation/reference/LocallyConnected.h +++ b/tests/validation/reference/Conv3D.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,9 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_LOCALLY_CONNECTED_H -#define ARM_COMPUTE_TEST_LOCALLY_CONNECTED_H +#ifndef ARM_COMPUTE_TEST_CONV3D_LAYER_H +#define ARM_COMPUTE_TEST_CONV3D_LAYER_H +#include "Utils.h" +#include "arm_compute/runtime/FunctionDescriptors.h" #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -36,9 +38,10 @@ namespace validation namespace reference { template <typename T, typename TB> -SimpleTensor<T> locally_connected(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, const TensorShape &output_shape, const PadStrideInfo &info); +SimpleTensor<T> conv3d(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, SimpleTensor<T> &dst, + const Conv3dInfo &conv3d_info); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_LOCALLY_CONNECTED_H */ +#endif /* ARM_COMPUTE_TEST_CONV3D_LAYER_H */ diff --git a/tests/validation/reference/ConvertFullyConnectedWeights.cpp b/tests/validation/reference/ConvertFullyConnectedWeights.cpp index 710644a4e5..0bb65fc9c1 100644 --- a/tests/validation/reference/ConvertFullyConnectedWeights.cpp +++ b/tests/validation/reference/ConvertFullyConnectedWeights.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ConvertFullyConnectedWeights.h b/tests/validation/reference/ConvertFullyConnectedWeights.h index daeba0e87d..615987380b 100644 --- a/tests/validation/reference/ConvertFullyConnectedWeights.h +++ b/tests/validation/reference/ConvertFullyConnectedWeights.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Convolution.cpp b/tests/validation/reference/Convolution.cpp deleted file mode 100644 index ad93b3077a..0000000000 --- a/tests/validation/reference/Convolution.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Helpers.h" - -#include "Convolution.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value, - const unsigned int width, - const unsigned int height) -{ - ARM_COMPUTE_ERROR_ON(scale == 0); - ARM_COMPUTE_ERROR_ON(scale >= static_cast<unsigned int>(std::numeric_limits<int32_t>::max())); - - SimpleTensor<T> dst(src.shape(), output_data_type); - SimpleTensor<int32_t> sum(src.shape(), output_data_type); - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, sum, TensorShape(width, height), conv, 1, border_mode, constant_border_value); - dst[element_idx] = saturate_cast<T>(tensor_elem_at<int32_t>(sum, id, border_mode, constant_border_value) / static_cast<int>(scale)); - } - - return dst; -} - -template SimpleTensor<uint8_t> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value, - const unsigned int widht, const unsigned int height); -template SimpleTensor<int16_t> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value, - const unsigned int widht, const unsigned int height); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Convolution.h b/tests/validation/reference/Convolution.h deleted file mode 100644 index ae6650ead3..0000000000 --- a/tests/validation/reference/Convolution.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_CONVOLUTION_H -#define ARM_COMPUTE_TEST_CONVOLUTION_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value, - const unsigned int width, - const unsigned int height); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CONVOLUTION_H */ diff --git a/tests/validation/reference/Convolution3d.h b/tests/validation/reference/Convolution3d.h index 6168f10741..b67e88e839 100644 --- a/tests/validation/reference/Convolution3d.h +++ b/tests/validation/reference/Convolution3d.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2021, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,8 +24,8 @@ #ifndef ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H #define ARM_COMPUTE_TEST_VALIDATION_CONVOLUTION_H -#include "arm_compute/core/utils/misc/Requires.h" #include "arm_compute/core/utils/quantization/AsymmHelpers.h" +#include "support/AclRequires.h" #include "tests/validation/Helpers.h" #include "tests/validation/reference/UtilsQuantizedAsymm.h" @@ -95,8 +95,8 @@ inline void convolution3d(const SimpleTensor<T> &in, const SimpleTensor<TW> &wei } // 3D convolution for QASYMM8 type -template < typename T, typename TW, typename TB, REQUIRES_TA((std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value) &&(std::is_same<TW, uint8_t>::value - || std::is_same<TW, int8_t>::value)) > +template < typename T, typename TW, typename TB, ARM_COMPUTE_REQUIRES_TA((std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value) &&(std::is_same<TW, uint8_t>::value + || std::is_same<TW, int8_t>::value)) > inline void convolution3d(const SimpleTensor<T> &in, const SimpleTensor<TW> &weights, const SimpleTensor<TB> &bias, SimpleTensor<T> &out, int i_offset, int w_offset, int b_offset, int o_offset, int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights, int dilation_x = 1, int dilation_y = 1, int filter_id = 0) diff --git a/tests/validation/reference/ConvolutionLayer.cpp b/tests/validation/reference/ConvolutionLayer.cpp index 9675901542..8eb855315b 100644 --- a/tests/validation/reference/ConvolutionLayer.cpp +++ b/tests/validation/reference/ConvolutionLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ConvolutionLayer.h b/tests/validation/reference/ConvolutionLayer.h index 61733d53e6..40d235ad2b 100644 --- a/tests/validation/reference/ConvolutionLayer.h +++ b/tests/validation/reference/ConvolutionLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Copy.cpp b/tests/validation/reference/Copy.cpp index dc519a4e45..181d85e3b3 100644 --- a/tests/validation/reference/Copy.cpp +++ b/tests/validation/reference/Copy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Copy.h b/tests/validation/reference/Copy.h index 10a3a61f53..1998b9e286 100644 --- a/tests/validation/reference/Copy.h +++ b/tests/validation/reference/Copy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/CropResize.cpp b/tests/validation/reference/CropResize.cpp index f1b49f6673..4126790d31 100644 --- a/tests/validation/reference/CropResize.cpp +++ b/tests/validation/reference/CropResize.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/CropResize.h b/tests/validation/reference/CropResize.h index 6c073064f4..2f88ad68d5 100644 --- a/tests/validation/reference/CropResize.h +++ b/tests/validation/reference/CropResize.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DFT.cpp b/tests/validation/reference/DFT.cpp index 7221312641..2b03c270ac 100644 --- a/tests/validation/reference/DFT.cpp +++ b/tests/validation/reference/DFT.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -27,6 +27,7 @@ #include "Permute.h" #include "Reverse.h" #include "SliceOperations.h" +#include "support/ToolchainSupport.h" #include <cmath> @@ -267,8 +268,9 @@ SimpleTensor<T> complex_mul_and_reduce(const SimpleTensor<T> &input, const Simpl output_shape.set(2, Co); SimpleTensor<T> dst(output_shape, input.data_type(), input.num_channels()); - // MemSet dst memory to zero - std::memset(dst.data(), 0, dst.size()); + // dst memory to zero + const auto total_element_count = dst.num_channels() * dst.num_elements(); + std::fill_n(dst.data(), total_element_count, 0); for(uint32_t b = 0; b < N; ++b) { @@ -318,7 +320,7 @@ SimpleTensor<T> ridft_1d(const SimpleTensor<T> &src, bool is_odd) { auto dst = rdft_1d_core(src, FFTDirection::Inverse, is_odd); - const T scaling_factor = dst.shape()[0]; + const T scaling_factor = T(dst.shape()[0]); scale(dst, scaling_factor); return dst; @@ -330,7 +332,7 @@ SimpleTensor<T> dft_1d(const SimpleTensor<T> &src, FFTDirection direction) auto dst = dft_1d_core(src, direction); if(direction == FFTDirection::Inverse) { - const T scaling_factor = dst.shape()[0]; + const T scaling_factor = T(dst.shape()[0]); scale(dst, scaling_factor); } return dst; @@ -359,7 +361,7 @@ SimpleTensor<T> ridft_2d(const SimpleTensor<T> &src, bool is_odd) auto transposed_2 = permute(first_pass, PermutationVector(1U, 0U)); auto dst = rdft_1d_core(transposed_2, direction, is_odd); - const T scaling_factor = dst.shape()[0] * dst.shape()[1]; + const T scaling_factor = T(dst.shape()[0] * dst.shape()[1]); scale(dst, scaling_factor); return dst; } @@ -383,7 +385,7 @@ SimpleTensor<T> dft_2d(const SimpleTensor<T> &src, FFTDirection direction) auto transposed_2 = permute(first_pass, PermutationVector(1U, 0U)); auto dst = dft_1d_core(transposed_2, direction); - const T scaling_factor = dst.shape()[0] * dst.shape()[1]; + const T scaling_factor = T(dst.shape()[0] * dst.shape()[1]); scale(dst, scaling_factor); return dst; @@ -398,10 +400,10 @@ SimpleTensor<T> conv2d_dft(const SimpleTensor<T> &src, const SimpleTensor<T> &w, auto padded_src = pad_layer(src, padding_in); // Flip weights - std::vector<uint32_t> axis_v = { 0, 1 }; - SimpleTensor<uint32_t> axis{ TensorShape(2U), DataType::U32 }; + std::vector<uint32_t> axis_v = { 0, 1 }; + SimpleTensor<int32_t> axis{ TensorShape(2U), DataType::S32 }; std::copy(axis_v.begin(), axis_v.begin() + axis.shape().x(), axis.data()); - auto flipped_w = reverse(w, axis); + auto flipped_w = reverse(w, axis, /* use_inverted_axis */ false); // Pad weights to have the same size as input const PaddingList paddings_w = { { 0, src.shape()[0] - 1 }, { 0, src.shape()[1] - 1 } }; @@ -425,6 +427,7 @@ SimpleTensor<T> conv2d_dft(const SimpleTensor<T> &src, const SimpleTensor<T> &w, return slice(conv_res, Coordinates(start_left, start_top), Coordinates(end_right, end_botton)); } +// FP32 template SimpleTensor<float> rdft_1d(const SimpleTensor<float> &src); template SimpleTensor<float> ridft_1d(const SimpleTensor<float> &src, bool is_odd); template SimpleTensor<float> dft_1d(const SimpleTensor<float> &src, FFTDirection direction); @@ -434,6 +437,17 @@ template SimpleTensor<float> ridft_2d(const SimpleTensor<float> &src, bool is_od template SimpleTensor<float> dft_2d(const SimpleTensor<float> &src, FFTDirection direction); template SimpleTensor<float> conv2d_dft(const SimpleTensor<float> &src, const SimpleTensor<float> &w, const PadStrideInfo &conv_info); + +// FP16 +template SimpleTensor<half> rdft_1d(const SimpleTensor<half> &src); +template SimpleTensor<half> ridft_1d(const SimpleTensor<half> &src, bool is_odd); +template SimpleTensor<half> dft_1d(const SimpleTensor<half> &src, FFTDirection direction); + +template SimpleTensor<half> rdft_2d(const SimpleTensor<half> &src); +template SimpleTensor<half> ridft_2d(const SimpleTensor<half> &src, bool is_odd); +template SimpleTensor<half> dft_2d(const SimpleTensor<half> &src, FFTDirection direction); + +template SimpleTensor<half> conv2d_dft(const SimpleTensor<half> &src, const SimpleTensor<half> &w, const PadStrideInfo &conv_info); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/DFT.h b/tests/validation/reference/DFT.h index 997343cdf2..5b12e4935b 100644 --- a/tests/validation/reference/DFT.h +++ b/tests/validation/reference/DFT.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DeconvolutionLayer.cpp b/tests/validation/reference/DeconvolutionLayer.cpp index 3cfbfae163..eeb25fcbe3 100644 --- a/tests/validation/reference/DeconvolutionLayer.cpp +++ b/tests/validation/reference/DeconvolutionLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -33,8 +33,8 @@ namespace validation { namespace reference { -template <typename T, typename TB> -SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, const TensorShape &output_shape, +template <typename T, typename TW, typename TB> +SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTensor<TW> &weights, const SimpleTensor<TB> &bias, const TensorShape &output_shape, const PadStrideInfo &info, QuantizationInfo out_qinfo) { // Create reference @@ -99,7 +99,7 @@ SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTens } // Flip weights by 180 degrees - SimpleTensor<T> weights_flipped{ weights.shape(), weights.data_type(), 1, weights.quantization_info() }; + SimpleTensor<TW> weights_flipped{ weights.shape(), weights.data_type(), 1, weights.quantization_info(), weights.data_layout() }; #if defined(_OPENMP) #pragma omp parallel for #endif /* _OPENMP */ @@ -143,6 +143,8 @@ SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTens template SimpleTensor<uint8_t> deconvolution_layer(const SimpleTensor<uint8_t> &src, const SimpleTensor<uint8_t> &weights, const SimpleTensor<int32_t> &bias, const TensorShape &output_shape, const PadStrideInfo &info, QuantizationInfo out_quant_info); +template SimpleTensor<uint8_t> deconvolution_layer(const SimpleTensor<uint8_t> &src, const SimpleTensor<int8_t> &weights, const SimpleTensor<int32_t> &bias, const TensorShape &output_shape, + const PadStrideInfo &info, QuantizationInfo out_quant_info); template SimpleTensor<int8_t> deconvolution_layer(const SimpleTensor<int8_t> &src, const SimpleTensor<int8_t> &weights, const SimpleTensor<int32_t> &bias, const TensorShape &output_shape, const PadStrideInfo &info, QuantizationInfo out_quant_info); template SimpleTensor<float> deconvolution_layer(const SimpleTensor<float> &src, const SimpleTensor<float> &weights, const SimpleTensor<float> &bias, const TensorShape &output_shape, diff --git a/tests/validation/reference/DeconvolutionLayer.h b/tests/validation/reference/DeconvolutionLayer.h index fff529a719..16f0d9ae59 100644 --- a/tests/validation/reference/DeconvolutionLayer.h +++ b/tests/validation/reference/DeconvolutionLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -39,16 +39,16 @@ namespace reference * * src Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. * Data types supported: QASYMM8/QASYMM8_SIGNED/F32/F16. - * weights The 4d weights with dimensions [width, height, OFM, IFM]. Data type supported: Same as @p input. + * weights The 4d weights with dimensions [width, height, OFM, IFM]. Data type supported: Same as @p input, also could be QSYMM8_PER_CHANNEL if input is QASYMM8/QASYMM8_SIGNED. * bias Optional, ignored if NULL. The biases have one dimension. - * Data type supported: Same as @p input, except for input of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type + * Data type supported: Same as @p input, except for input of QASYMM8/QASYMM8_SIGNED types where biases should be of S32 type * output_shape Output tensor shape. The output has the same number of dimensions as the @p input. * info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo. * a The number of zeros added to right and top edges of the input. * */ -template <typename T, typename TB> -SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, const TensorShape &output_shape, const PadStrideInfo &info, +template <typename T, typename TW, typename TB> +SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTensor<TW> &weights, const SimpleTensor<TB> &bias, const TensorShape &output_shape, const PadStrideInfo &info, QuantizationInfo out_qinfo = QuantizationInfo()); } // namespace reference } // namespace validation diff --git a/tests/validation/reference/DepthConcatenateLayer.cpp b/tests/validation/reference/DepthConcatenateLayer.cpp index 2c93e7060a..54226a4fa6 100644 --- a/tests/validation/reference/DepthConcatenateLayer.cpp +++ b/tests/validation/reference/DepthConcatenateLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthConcatenateLayer.h b/tests/validation/reference/DepthConcatenateLayer.h index 264d8d05e8..56f9aba28f 100644 --- a/tests/validation/reference/DepthConcatenateLayer.h +++ b/tests/validation/reference/DepthConcatenateLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthConvertLayer.cpp b/tests/validation/reference/DepthConvertLayer.cpp index 9c6a9aa76c..3f88897f8e 100644 --- a/tests/validation/reference/DepthConvertLayer.cpp +++ b/tests/validation/reference/DepthConvertLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2023-2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,8 +25,8 @@ #include "tests/validation/Helpers.h" -#include "arm_compute/core/utils/misc/Rounding.h" -#include "arm_compute/core/utils/misc/SaturateCast.h" +#include "support/Rounding.h" +#include "support/SaturateCast.h" #include "tests/Types.h" @@ -165,7 +165,7 @@ template SimpleTensor<half> depth_convert(const SimpleTensor<int32_t> &src, Data template SimpleTensor<float> depth_convert(const SimpleTensor<int32_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); // BFLOAT16 -template SimpleTensor<float> depth_convert(const SimpleTensor<bfloat16> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<bfloat16> depth_convert(const SimpleTensor<bfloat16> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); // F16 template SimpleTensor<uint8_t> depth_convert(const SimpleTensor<half> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); @@ -186,6 +186,25 @@ template SimpleTensor<int32_t> depth_convert(const SimpleTensor<float> &src, Dat template SimpleTensor<half> depth_convert(const SimpleTensor<float> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); template SimpleTensor<bfloat16> depth_convert(const SimpleTensor<float> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +// S64 +template SimpleTensor<uint8_t> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<int8_t> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<uint16_t> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<int16_t> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<uint32_t> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<int32_t> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<half> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<float> depth_convert(const SimpleTensor<int64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); + +// U64 +template SimpleTensor<uint8_t> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<int8_t> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<uint16_t> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<int16_t> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<uint32_t> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<int32_t> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<half> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); +template SimpleTensor<float> depth_convert(const SimpleTensor<uint64_t> &src, DataType dt_out, ConvertPolicy policy, uint32_t shift); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/DepthConvertLayer.h b/tests/validation/reference/DepthConvertLayer.h index 9513d07c34..a9c750079c 100644 --- a/tests/validation/reference/DepthConvertLayer.h +++ b/tests/validation/reference/DepthConvertLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthToSpaceLayer.cpp b/tests/validation/reference/DepthToSpaceLayer.cpp index e2329ed60b..29a30750e4 100644 --- a/tests/validation/reference/DepthToSpaceLayer.cpp +++ b/tests/validation/reference/DepthToSpaceLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthToSpaceLayer.h b/tests/validation/reference/DepthToSpaceLayer.h index 6c83342ac5..6c63a11244 100644 --- a/tests/validation/reference/DepthToSpaceLayer.h +++ b/tests/validation/reference/DepthToSpaceLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp index 7bba98a0c6..e24b5b4ea7 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.cpp +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.h b/tests/validation/reference/DepthwiseConvolutionLayer.h index d0dabb919b..1b93acf42a 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.h +++ b/tests/validation/reference/DepthwiseConvolutionLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h b/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h index 6165fafe2f..b831f6abc3 100644 --- a/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h +++ b/tests/validation/reference/DepthwiseSeparableConvolutionLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/DequantizationLayer.cpp b/tests/validation/reference/DequantizationLayer.cpp index 7dec988b18..67d69c2c38 100644 --- a/tests/validation/reference/DequantizationLayer.cpp +++ b/tests/validation/reference/DequantizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -59,6 +59,12 @@ TOut dequantize(int16_t val, const UniformQuantizationInfo qinfo, DataType dt) ARM_COMPUTE_UNUSED(dt); return static_cast<TOut>(dequantize_qsymm16(val, qinfo)); } +template <typename TOut> +TOut dequantize(int32_t val, const UniformQuantizationInfo qinfo, DataType dt) +{ + ARM_COMPUTE_UNUSED(dt); + return static_cast<TOut>(dequantize_s32(val, qinfo)); +} } // namespace template <typename TOut, typename TIn> SimpleTensor<TOut> dequantization_layer(const SimpleTensor<TIn> &src) @@ -115,6 +121,7 @@ template SimpleTensor<half> dequantization_layer(const SimpleTensor<int8_t> &src template SimpleTensor<float> dequantization_layer(const SimpleTensor<int8_t> &src); template SimpleTensor<half> dequantization_layer(const SimpleTensor<int16_t> &src); template SimpleTensor<float> dequantization_layer(const SimpleTensor<int16_t> &src); +template SimpleTensor<float> dequantization_layer(const SimpleTensor<int32_t> &src); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/DequantizationLayer.h b/tests/validation/reference/DequantizationLayer.h index 0bf10a232e..a0a83ae23b 100644 --- a/tests/validation/reference/DequantizationLayer.h +++ b/tests/validation/reference/DequantizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Derivative.cpp b/tests/validation/reference/Derivative.cpp deleted file mode 100644 index f4c2934728..0000000000 --- a/tests/validation/reference/Derivative.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Derivative.h" - -#include "Utils.h" -#include "tests/Types.h" - -#include <array> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array<int8_t, 9> derivative_3_x{ { 0, 0, 0, -1, 0, 1, 0, 0, 0 } }; -const std::array<int8_t, 9> derivative_3_y{ { 0, -1, 0, 0, 0, 0, 0, 1, 0 } }; - -template <typename T> -struct data_type; - -template <> -struct data_type<int16_t> -{ - const static DataType value = DataType::S16; -}; -} // namespace - -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> derivative(const SimpleTensor<U> &src, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - const unsigned int filter_size = 3; - - SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); - SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ filter_size, filter_size }, derivative_3_x.data(), 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ filter_size, filter_size }, derivative_3_y.data(), 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ filter_size, filter_size }, derivative_3_x.data(), 1.f, border_mode, - constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ filter_size, filter_size }, derivative_3_y.data(), 1.f, border_mode, - constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> derivative(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Derivative.h b/tests/validation/reference/Derivative.h deleted file mode 100644 index 829d2eeb3c..0000000000 --- a/tests/validation/reference/Derivative.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_DERIVATIVE_H -#define ARM_COMPUTE_TEST_DERIVATIVE_H - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> derivative(const SimpleTensor<U> &src, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_DERIVATIVE_H */ diff --git a/tests/validation/reference/Dilate.cpp b/tests/validation/reference/Dilate.cpp deleted file mode 100644 index cba9af127f..0000000000 --- a/tests/validation/reference/Dilate.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Dilate.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <algorithm> -#include <array> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> dilate(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - /* - -1 x +1 - -1 [tl][tc][tr] -1 - y [ml][xy][mr] y - +1 [bl][bc][br] +1 - -1 x +1 - dilate: - dst(x, y) = max[ src(x', y') for x-1<=x'<=x+1, y-1<=y'<=y+1 ] = max({tl, tc, tr, ml, xy, mr, bl, bc, br}) - */ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const uint32_t num_elements = src.num_elements(); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - const int x = coord.x(); - const int y = coord.y(); - - std::array<T, 9> neighbours = { { 0 } }; - for(int row = y - 1, j = 0; row <= y + 1; ++row) - { - for(int col = x - 1; col <= x + 1; ++col, ++j) - { - coord.set(0, col); - coord.set(1, row); - neighbours[j] = tensor_elem_at(src, coord, border_mode, constant_border_value); - } - } - - dst[i] = *std::max_element(neighbours.cbegin(), neighbours.cend()); - } - - return dst; -} - -template SimpleTensor<uint8_t> dilate(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Dilate.h b/tests/validation/reference/Dilate.h deleted file mode 100644 index 6755f02fb4..0000000000 --- a/tests/validation/reference/Dilate.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_DILATE_H -#define ARM_COMPUTE_TEST_DILATE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> dilate(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_DILATE_H */ diff --git a/tests/validation/reference/ElementWiseUnary.cpp b/tests/validation/reference/ElementWiseUnary.cpp deleted file mode 100644 index f1bb7c783c..0000000000 --- a/tests/validation/reference/ElementWiseUnary.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2018-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ElementWiseUnary.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> elementwise_unary(const SimpleTensor<T> &src, ElementWiseUnary op) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - for(int i = 0; i < src.num_elements(); ++i) - { - switch(op) - { - case ElementWiseUnary::RSQRT: - dst[i] = 1.f / std::sqrt(src[i]); - break; - case ElementWiseUnary::EXP: - dst[i] = std::exp(src[i]); - break; - case ElementWiseUnary::NEG: - dst[i] = -src[i]; - break; - case ElementWiseUnary::LOG: - dst[i] = std::log(src[i]); - break; - case ElementWiseUnary::ABS: - dst[i] = std::abs(src[i]); - break; - case ElementWiseUnary::SIN: - dst[i] = std::sin(src[i]); - break; - case ElementWiseUnary::ROUND: - dst[i] = arm_compute::support::cpp11::nearbyint(src[i]); - break; - default: - ARM_COMPUTE_ERROR("Not implemented"); - } - } - - return dst; -} - -template SimpleTensor<float> elementwise_unary(const SimpleTensor<float> &src, ElementWiseUnary op); -template SimpleTensor<half> elementwise_unary(const SimpleTensor<half> &src, ElementWiseUnary op); -template SimpleTensor<int32_t> elementwise_unary(const SimpleTensor<int32_t> &src, ElementWiseUnary op); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/ElementwiseOperations.cpp b/tests/validation/reference/ElementwiseOperations.cpp index 2a76b316d8..edbbab8600 100644 --- a/tests/validation/reference/ElementwiseOperations.cpp +++ b/tests/validation/reference/ElementwiseOperations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2020, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ElementwiseOperations.h b/tests/validation/reference/ElementwiseOperations.h index 912fe1aa62..79d00420e1 100644 --- a/tests/validation/reference/ElementwiseOperations.h +++ b/tests/validation/reference/ElementwiseOperations.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ElementwiseUnary.cpp b/tests/validation/reference/ElementwiseUnary.cpp new file mode 100644 index 0000000000..558f9d24fc --- /dev/null +++ b/tests/validation/reference/ElementwiseUnary.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2018-2020, 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "ElementwiseUnary.h" +#include "tests/validation/Helpers.h" +#include "utils/TypePrinter.h" +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> elementwise_unary(const SimpleTensor<T> &src, SimpleTensor<T> &dst, ElementWiseUnary op) +{ + for(int i = 0; i < src.num_elements(); ++i) + { + switch(op) + { + case ElementWiseUnary::RSQRT: + dst[i] = 1.f / std::sqrt(src[i]); + break; + case ElementWiseUnary::EXP: + dst[i] = std::exp(src[i]); + break; + case ElementWiseUnary::NEG: + dst[i] = -src[i]; + break; + case ElementWiseUnary::LOG: + dst[i] = std::log(src[i]); + break; + case ElementWiseUnary::ABS: + dst[i] = std::abs(src[i]); + break; + case ElementWiseUnary::SIN: + dst[i] = std::sin(src[i]); + break; + case ElementWiseUnary::ROUND: + dst[i] = arm_compute::support::cpp11::nearbyint(src[i]); + break; + default: + ARM_COMPUTE_ERROR("Not implemented"); + } + } + return dst; +} +template <> +SimpleTensor<int8_t> elementwise_unary(const SimpleTensor<int8_t> &src, SimpleTensor<int8_t> &dst, ElementWiseUnary op) +{ + if(dst.data_type() == DataType::QASYMM8_SIGNED) + { + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp(src.shape(), DataType::F32); + for(int i = 0; i < src.num_elements(); ++i) + { + switch(op) + { + case ElementWiseUnary::RSQRT: + if(src_tmp[i] != 0) + { + dst_tmp[i] = 1.f / std::sqrt(src_tmp[i]); + } + else + { + // rsqrt(0) give 'inf' so set to the maximum in int8: 127 + dst_tmp[i] = (127.0f - dst.quantization_info().uniform().offset) * dst.quantization_info().uniform().scale ; + } + break; + + case ElementWiseUnary::LOG: + if(src_tmp[i] != 0) + { + dst_tmp[i] = std::log(src_tmp[i]); + } + else + { + dst_tmp[i] = (-128.0f - dst.quantization_info().uniform().offset) * dst.quantization_info().uniform().scale ; + } + break; + + default: + elementwise_unary(src_tmp, dst_tmp, op); + break; + } + } + dst = convert_to_asymmetric<int8_t>(dst_tmp, dst.quantization_info()); + } + else + { + ARM_COMPUTE_ERROR("Not implemented"); + } + return dst; +} +template <> +SimpleTensor<uint8_t> elementwise_unary(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &dst, ElementWiseUnary op) +{ + if(dst.data_type() == DataType::QASYMM8) + { + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp(src.shape(), DataType::F32); + for(int i = 0; i < src.num_elements(); ++i) + { + switch(op) + { + case ElementWiseUnary::RSQRT: + if(src_tmp[i] != 0) + { + dst_tmp[i] = 1.f / std::sqrt(src_tmp[i]); + } + else + { + // rsqrt(0) give 'inf' so set to the maximum in uint8: 255 + dst_tmp[i] = (255.0f - dst.quantization_info().uniform().offset)* dst.quantization_info().uniform().scale; + } + break; + + case ElementWiseUnary::LOG: + if(src_tmp[i] != 0) + { + dst_tmp[i] = std::log(src_tmp[i]); + } + else + { + dst_tmp[i] = -dst.quantization_info().uniform().offset * dst.quantization_info().uniform().scale; + } + break; + + default: + elementwise_unary(src_tmp, dst_tmp, op); + break; + } + } + dst = convert_to_asymmetric<uint8_t>(dst_tmp, dst.quantization_info()); + } + else + { + ARM_COMPUTE_ERROR("Not implemented"); + } + return dst; +} + +template SimpleTensor<float> elementwise_unary(const SimpleTensor<float> &src, SimpleTensor<float> &dst, ElementWiseUnary op); +template SimpleTensor<half> elementwise_unary(const SimpleTensor<half> &src, SimpleTensor<half> &dst, ElementWiseUnary op); +template SimpleTensor<int32_t> elementwise_unary(const SimpleTensor<int32_t> &src, SimpleTensor<int32_t> &dst, ElementWiseUnary op); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ElementWiseUnary.h b/tests/validation/reference/ElementwiseUnary.h index a8bed197ad..ae7a49bce4 100644 --- a/tests/validation/reference/ElementWiseUnary.h +++ b/tests/validation/reference/ElementwiseUnary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -35,7 +35,7 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> elementwise_unary(const SimpleTensor<T> &src, ElementWiseUnary op); +SimpleTensor<T> elementwise_unary(const SimpleTensor<T> &src, SimpleTensor<T> &dst, ElementWiseUnary op); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/EqualizeHistogram.cpp b/tests/validation/reference/EqualizeHistogram.cpp deleted file mode 100644 index 34e7c397bf..0000000000 --- a/tests/validation/reference/EqualizeHistogram.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "EqualizeHistogram.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> equalize_histogram(const SimpleTensor<T> &src) -{ - const size_t num_bins = 256; // 0-255 inclusive - - std::vector<T> lut(num_bins); - std::vector<uint32_t> hist(num_bins); - std::vector<uint32_t> cd(num_bins); // cumulative distribution - - SimpleTensor<T> dst(src.shape(), src.data_type()); - - // Create the histogram - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - hist[src[element_idx]]++; - } - - // Calculate cumulative distribution - std::partial_sum(hist.begin(), hist.end(), cd.begin()); - - // Get the number of pixels that have the lowest non-zero value - const uint32_t cd_min = *std::find_if(hist.begin(), hist.end(), [](const uint32_t &x) - { - return x > 0; - }); - - const size_t total_num_pixels = cd.back(); - - // Single color - create linear distribution - if(total_num_pixels == cd_min) - { - std::iota(lut.begin(), lut.end(), 0); - } - else - { - const float diff = total_num_pixels - cd_min; - - for(size_t i = 0; i < num_bins; ++i) - { - lut[i] = lround((cd[i] - cd_min) / diff * 255.f); - } - } - - // Fill output tensor with equalized values -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = lut[src[i]]; - } - - return dst; -} - -template SimpleTensor<uint8_t> equalize_histogram(const SimpleTensor<uint8_t> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/EqualizeHistogram.h b/tests/validation/reference/EqualizeHistogram.h deleted file mode 100644 index 5d22cbb943..0000000000 --- a/tests/validation/reference/EqualizeHistogram.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_EQUALIZE_HISTOGRAM_H -#define ARM_COMPUTE_TEST_EQUALIZE_HISTOGRAM_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> equalize_histogram(const SimpleTensor<T> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_EQUALIZE_HISTOGRAM_H */ diff --git a/tests/validation/reference/Erode.cpp b/tests/validation/reference/Erode.cpp index 0964c3d4b2..0413eb5cef 100644 --- a/tests/validation/reference/Erode.cpp +++ b/tests/validation/reference/Erode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Erode.h b/tests/validation/reference/Erode.h index 4ec06d7c93..a809be856d 100644 --- a/tests/validation/reference/Erode.h +++ b/tests/validation/reference/Erode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/FastCorners.cpp b/tests/validation/reference/FastCorners.cpp deleted file mode 100644 index 32b911573b..0000000000 --- a/tests/validation/reference/FastCorners.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "FastCorners.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/NonMaximaSuppression.h" - -#include "tests/framework/Asserts.h" -#include <iomanip> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -constexpr unsigned int bresenham_radius = 3; -constexpr unsigned int bresenham_count = 16; - -/* - Offsets of the 16 pixels in the Bresenham circle of radius 3 centered on P - . . . . . . . . . - . . . F 0 1 . . . - . . E . . . 2 . . - . D . . . . . 3 . - . C . . P . . 4 . - . B . . . . . 5 . - . . A . . . 6 . . - . . . 9 8 7 . . . - . . . . . . . . . -*/ -const std::array<std::array<int, 2>, 16> circle_offsets = -{ - { - { { 0, -3 } }, // 0 - pixel #1 - { { 1, -3 } }, // 1 - pixel #2 - { { 2, -2 } }, // 2 - pixel #3 - { { 3, -1 } }, // 3 - pixel #4 - { { 3, 0 } }, // 4 - pixel #5 - { { 3, 1 } }, // 5 - pixel #6 - { { 2, 2 } }, // 6 - pixel #7 - { { 1, 3 } }, // 7 - pixel #8 - { { 0, 3 } }, // 8 - pixel #9 - { { -1, 3 } }, // 9 - pixel #10 - { { -2, 2 } }, // A - pixel #11 - { { -3, 1 } }, // B - pixel #12 - { { -3, 0 } }, // C - pixel #13 - { { -3, -1 } }, // D - pixel #14 - { { -2, -2 } }, // E - pixel #15 - { { -1, -3 } } // F - pixel #16 - } -}; - -/* - FAST-9 bit masks for consecutive points surrounding a corner candidate - Rejection of non-corners is expedited by checking pixels 1, 9, then 5, 13... -*/ -const std::array<uint16_t, 16> fast9_masks = -{ - { - 0x01FF, // 0000 0001 1111 1111 - 0x03FE, // 0000 0011 1111 1110 - 0x07FC, // 0000 0111 1111 1100 - 0x0FF8, // 0000 1111 1111 1000 - 0x1FF0, // 0001 1111 1111 0000 - 0x3FE0, // 0011 1111 1110 0000 - 0x7FC0, // 0111 1111 1100 0000 - 0xFF80, // 1111 1111 1000 0000 - 0xFF01, // 1111 1111 0000 0001 - 0xFE03, // 1111 1110 0000 0011 - 0xFC07, // 1111 1100 0000 0111 - 0xF80F, // 1111 1000 0000 1111 - 0xF01F, // 1111 0000 0001 1111 - 0xE03F, // 1110 0000 0011 1111 - 0xC07F, // 1100 0000 0111 1111 - 0x80FF // 1000 0000 1111 1111 - } -}; - -inline bool in_range(const uint8_t low, const uint8_t high, const uint8_t val) -{ - return low <= val && val <= high; -} - -template <typename T, typename F> -bool is_a_corner(const Coordinates &candidate, const SimpleTensor<T> &src, uint8_t threshold, BorderMode border_mode, T constant_border_value, F intensity_at) -{ - const auto intensity_p = tensor_elem_at(src, candidate, border_mode, constant_border_value); - const auto thresh_bright = intensity_p + threshold; - const auto thresh_dark = intensity_p - threshold; - - // Quicker rejection of non-corner points by checking pixels 1, 9 then 5, 13 around the candidate - const auto p1 = intensity_at(candidate, 0); - const auto p9 = intensity_at(candidate, 8); - const auto p5 = intensity_at(candidate, 4); - const auto p13 = intensity_at(candidate, 12); - - if((in_range(thresh_dark, thresh_bright, p1) && in_range(thresh_dark, thresh_bright, p9)) - || (in_range(thresh_dark, thresh_bright, p5) && in_range(thresh_dark, thresh_bright, p13))) - { - return false; - } - - uint16_t mask_bright = 0; - uint16_t mask_dark = 0; - - // Set bits of the brighter/darker pixels mask accordingly - for(unsigned int n = 0; n < bresenham_count; ++n) - { - T intensity_n = intensity_at(candidate, n); - mask_bright |= (intensity_n > thresh_bright) << n; - mask_dark |= (intensity_n < thresh_dark) << n; - } - - // Mark as corner candidate if brighter/darker pixel sequence satisfies any one of the FAST-9 masks - const auto found = std::find_if(fast9_masks.begin(), fast9_masks.end(), [&](decltype(fast9_masks[0]) mask) - { - return (mask_bright & mask) == mask || (mask_dark & mask) == mask; - }); - - return found != fast9_masks.end(); -} -} // namespace - -template <typename T> -std::vector<KeyPoint> fast_corners(const SimpleTensor<T> &src, float input_thresh, bool suppress_nonmax, BorderMode border_mode, T constant_border_value) -{ - // Get intensity of pixel at given index on the Bresenham circle around a candidate point - const auto intensity_at = [&](const Coordinates & point, const unsigned int idx) - { - const auto offset = circle_offsets[idx]; - Coordinates px{ point.x() + offset[0], point.y() + offset[1] }; - return tensor_elem_at(src, px, border_mode, constant_border_value); - }; - - const auto threshold = static_cast<uint8_t>(input_thresh); - std::vector<KeyPoint> corners; - - // 1. Detect potential corners (the segment test) - std::vector<Coordinates> corner_candidates; - SimpleTensor<uint8_t> scores(src.shape(), DataType::U8); - ValidRegion valid_region = shape_to_valid_region(src.shape(), BorderMode::UNDEFINED == border_mode, BorderSize(bresenham_radius)); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates candidate = index2coord(src.shape(), i); - scores[i] = 0; - if(!is_in_valid_region(valid_region, candidate)) - { - continue; - } - - if(is_a_corner(candidate, src, threshold, border_mode, constant_border_value, intensity_at)) - { - corner_candidates.emplace_back(candidate); - scores[i] = 1; - } - } - - // 2. Calculate corner scores if necessary - if(suppress_nonmax) - { - for(const auto &candidate : corner_candidates) - { - const auto index = coord2index(scores.shape(), candidate); - uint8_t thresh_max = UINT8_MAX; - uint8_t thresh_min = threshold; - uint8_t response = (thresh_min + thresh_max) / 2; - - // Corner score (response) is the largest threshold for which the pixel remains a corner - while(thresh_max - thresh_min > 1) - { - response = (thresh_min + thresh_max) / 2; - if(is_a_corner(candidate, src, response, border_mode, constant_border_value, intensity_at)) - { - thresh_min = response; // raise threshold - } - else - { - thresh_max = response; // lower threshold - } - } - scores[index] = thresh_min; - } - - scores = non_maxima_suppression(scores, border_mode, constant_border_value); - valid_region = shape_to_valid_region(scores.shape(), BorderMode::UNDEFINED == border_mode, BorderSize(bresenham_radius + 1)); - } - - for(const auto &candidate : corner_candidates) - { - const auto index = coord2index(scores.shape(), candidate); - if(scores[index] > 0.f && is_in_valid_region(valid_region, candidate)) - { - KeyPoint corner; - corner.x = candidate.x(); - corner.y = candidate.y(); - corner.strength = scores[index]; - corner.tracking_status = 1; - corner.scale = 0.f; - corner.orientation = 0.f; - corner.error = 0.f; - corners.emplace_back(corner); - } - } - - return corners; -} - -template std::vector<KeyPoint> fast_corners(const SimpleTensor<uint8_t> &src, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/FastCorners.h b/tests/validation/reference/FastCorners.h deleted file mode 100644 index 00ee736359..0000000000 --- a/tests/validation/reference/FastCorners.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_FAST_CORNERS_H -#define ARM_COMPUTE_TEST_FAST_CORNERS_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<KeyPoint> fast_corners(const SimpleTensor<T> &src, float input_thresh, bool suppress_nonmax, BorderMode border_mode, T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_FAST_CORNERS_H */ diff --git a/tests/validation/reference/FlattenLayer.cpp b/tests/validation/reference/FlattenLayer.cpp index 381ce37051..145b41aedf 100644 --- a/tests/validation/reference/FlattenLayer.cpp +++ b/tests/validation/reference/FlattenLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/FlattenLayer.h b/tests/validation/reference/FlattenLayer.h index 2b8083a847..212bb087cc 100644 --- a/tests/validation/reference/FlattenLayer.h +++ b/tests/validation/reference/FlattenLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Floor.cpp b/tests/validation/reference/Floor.cpp index 21fa1c9932..8a3fb24222 100644 --- a/tests/validation/reference/Floor.cpp +++ b/tests/validation/reference/Floor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Floor.h b/tests/validation/reference/Floor.h index e0f09c990c..b197f15d10 100644 --- a/tests/validation/reference/Floor.h +++ b/tests/validation/reference/Floor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/FullyConnectedLayer.cpp b/tests/validation/reference/FullyConnectedLayer.cpp index 908c583161..af30e9ee54 100644 --- a/tests/validation/reference/FullyConnectedLayer.cpp +++ b/tests/validation/reference/FullyConnectedLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -123,7 +123,7 @@ SimpleTensor<T> fully_connected_layer(const SimpleTensor<T> &src, const SimpleTe // Create reference SimpleTensor<T> dst{ TensorShape{ dst_shape }, src.data_type(), 1, out_quant_info }; - // Sanity checks + // Health checks const int num_batch_dimensions = std::max(0, static_cast<int>(dst_shape.num_dimensions()) - 1); const int num_input_dimensions = src.shape().num_dimensions() - num_batch_dimensions; const unsigned int linear_input_size = src.shape().total_size_lower(num_input_dimensions); diff --git a/tests/validation/reference/FullyConnectedLayer.h b/tests/validation/reference/FullyConnectedLayer.h index 0afffc311d..c807e06a2d 100644 --- a/tests/validation/reference/FullyConnectedLayer.h +++ b/tests/validation/reference/FullyConnectedLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/FuseBatchNormalization.cpp b/tests/validation/reference/FuseBatchNormalization.cpp index cb5003874b..08e94a36d4 100644 --- a/tests/validation/reference/FuseBatchNormalization.cpp +++ b/tests/validation/reference/FuseBatchNormalization.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/FuseBatchNormalization.h b/tests/validation/reference/FuseBatchNormalization.h index d741bf38c8..9c9f9ace2d 100644 --- a/tests/validation/reference/FuseBatchNormalization.h +++ b/tests/validation/reference/FuseBatchNormalization.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMM.cpp b/tests/validation/reference/GEMM.cpp index f7a1718fad..d513343796 100644 --- a/tests/validation/reference/GEMM.cpp +++ b/tests/validation/reference/GEMM.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ #include "arm_compute/core/Helpers.h" #include "arm_compute/core/Types.h" +#include "tests/validation/reference/ArithmeticOperations.h" namespace arm_compute { @@ -35,10 +36,11 @@ namespace validation namespace reference { template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> gemm(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta) +SimpleTensor<T> +gemm(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta) { // Create reference - SimpleTensor<T> dst{ c.shape(), c.data_type(), 1 }; + SimpleTensor<T> dst{c.shape(), c.data_type(), 1}; // Compute reference const int M = a.shape().y(); @@ -50,30 +52,47 @@ SimpleTensor<T> gemm(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const S const int a_stride_z = K * M; const int a_stride_w = K * M * D; - const int b_stride_z = b.shape().num_dimensions() > 2 ? N * K : 0; // Do not slide the matrix B along the 3th dimension in case matrix B has less than 3 dimensions - const int b_stride_w = b.shape().num_dimensions() > 3 ? K * N * D : 0; // Do not slide the matrix B along the 4th dimension in case matrix B has less than 4 dimensions + const int b_stride_z = + b.shape().num_dimensions() > 2 + ? N * K + : 0; // Do not slide the matrix B along the 3th dimension in case matrix B has less than 3 dimensions + int b_stride_w = + b.shape().num_dimensions() > 3 + ? K * N * D + : 0; // Do not slide the matrix B along the 4th dimension in case matrix B has less than 4 dimensions + + // Note: There are 3 gemm types: batched-gemm, multi-gemm, and batched of multi-gemms. The third dimension of tensor b is overloaded when tensor b has exactly 3 dimensions: + // it can be either number of batches or multis. Batched-GEMM computation is detected only when the third dimension of "a" and "c" tensors is 1 and the number of dimensions is 4 + const bool is_batched_gemm = b.shape().num_dimensions() == 3 && a.shape().num_dimensions() == 4 && + c.shape().num_dimensions() == 4 && a.shape()[2] == 1 && c.shape()[2] == 1; + + // Batched-GEMM + if (is_batched_gemm) + { + b_stride_w = b_stride_z; + } const int c_stride_z = N * M; const int c_stride_w = N * M * D; -#if defined(_OPENMP) && !( defined(__arm__) && defined(__ANDROID__)) +#if defined(_OPENMP) && !(defined(__arm__) && defined(__ANDROID__)) #pragma omp parallel for collapse(2) #endif /* _OPENMP */ - for(int w = 0; w < W; ++w) + for (int w = 0; w < W; ++w) { - for(int depth = 0; depth < D; ++depth) + for (int depth = 0; depth < D; ++depth) { const int base_addr_a = depth * a_stride_z + w * a_stride_w; const int base_addr_b = depth * b_stride_z + w * b_stride_w; const int base_addr_c = depth * c_stride_z + w * c_stride_w; - for(int row = 0; row < M; ++row) + for (int row = 0; row < M; ++row) { - for(int col = 0; col < N; ++col) + for (int col = 0; col < N; ++col) { T acc(0); - for(int k = 0; k < K; ++k) + for (int k = 0; k < K; ++k) { acc += a[base_addr_a + k + row * K] * b[base_addr_b + col + k * N]; } @@ -89,11 +108,12 @@ SimpleTensor<T> gemm(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const S } template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> gemm_mixed_precision(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta) +SimpleTensor<T> gemm_mixed_precision( + const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta) { // GEMM mixed-precision combines F32 accumulators with F16 multiplications // Create reference - SimpleTensor<T> dst{ c.shape(), c.data_type(), 1 }; + SimpleTensor<T> dst{c.shape(), c.data_type(), 1}; // Compute reference const int M = a.shape().y(); @@ -105,36 +125,54 @@ SimpleTensor<T> gemm_mixed_precision(const SimpleTensor<T> &a, const SimpleTenso const int a_stride_z = K * M; const int a_stride_w = K * M * D; - const int b_stride_z = b.shape().num_dimensions() > 2 ? N * K : 0; // Do not slide the matrix B along the 3th dimension in case matrix B has less than 3 dimensions - const int b_stride_w = b.shape().num_dimensions() > 3 ? K * N * D : 0; // Do not slide the matrix B along the 4th dimension in case matrix B has less than 4 dimensions + const int b_stride_z = + b.shape().num_dimensions() > 2 + ? N * K + : 0; // Do not slide the matrix B along the 3th dimension in case matrix B has less than 3 dimensions + int b_stride_w = + b.shape().num_dimensions() > 3 + ? K * N * D + : 0; // Do not slide the matrix B along the 4th dimension in case matrix B has less than 4 dimensions + + // Note: There are 3 gemm types: batched-gemm, multi-gemm, and batched of multi-gemms. The third dimension of tensor b is overloaded when tensor b has exactly 3 dimensions: + // it can be either number of batches or multis. Batched-GEMM computation is detected only when the third dimension of "a" and "c" tensors is 1 and the number of dimensions is 4 + const bool is_batched_gemm = b.shape().num_dimensions() == 3 && a.shape().num_dimensions() == 4 && + c.shape().num_dimensions() == 4 && a.shape()[2] == 1 && c.shape()[2] == 1; + + // Batched-GEMM + if (is_batched_gemm) + { + b_stride_w = b_stride_z; + } const int c_stride_z = N * M; const int c_stride_w = N * M * D; -#if defined(_OPENMP) && !( defined(__arm__) && defined(__ANDROID__)) +#if defined(_OPENMP) && !(defined(__arm__) && defined(__ANDROID__)) #pragma omp parallel for collapse(2) #endif /* _OPENMP */ - for(int w = 0; w < W; ++w) + for (int w = 0; w < W; ++w) { - for(int depth = 0; depth < D; ++depth) + for (int depth = 0; depth < D; ++depth) { const int base_addr_a = depth * a_stride_z + w * a_stride_w; const int base_addr_b = depth * b_stride_z + w * b_stride_w; const int base_addr_c = depth * c_stride_z + w * c_stride_w; - for(int row = 0; row < M; ++row) + for (int row = 0; row < M; ++row) { - for(int col = 0; col < N; ++col) + for (int col = 0; col < N; ++col) { float acc(0); - for(int k = 0; k < K; ++k) + for (int k = 0; k < K; ++k) { acc += static_cast<float>(a[base_addr_a + k + row * K] * b[base_addr_b + col + k * N]); } // Finalize the result: alpha * A * B + beta * C - dst[base_addr_c + col + row * N] = static_cast<T>(alpha * acc + beta * c[base_addr_c + col + row * N]); + dst[base_addr_c + col + row * N] = + static_cast<T>(alpha * acc + beta * c[base_addr_c + col + row * N]); } } } @@ -143,8 +181,21 @@ SimpleTensor<T> gemm_mixed_precision(const SimpleTensor<T> &a, const SimpleTenso return dst; } +template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> +void gemm_accumulate(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta, SimpleTensor<T> &dst) +{ + // Compute reference + SimpleTensor<T> dst_gemm = gemm(a, b, c, alpha, beta); + reference::arithmetic_operation<T>(reference::ArithmeticOperation::ADD, dst, dst_gemm, dst, ConvertPolicy::SATURATE); +} + +template SimpleTensor<bfloat16> gemm(const SimpleTensor<bfloat16> &a, const SimpleTensor<bfloat16> &b, const SimpleTensor<bfloat16> &c, float alpha, float beta); template SimpleTensor<float> gemm(const SimpleTensor<float> &a, const SimpleTensor<float> &b, const SimpleTensor<float> &c, float alpha, float beta); template SimpleTensor<half> gemm(const SimpleTensor<half> &a, const SimpleTensor<half> &b, const SimpleTensor<half> &c, float alpha, float beta); + +template void gemm_accumulate(const SimpleTensor<float> &a, const SimpleTensor<float> &b, const SimpleTensor<float> &c, float alpha, float beta, SimpleTensor<float> &dst); +template void gemm_accumulate(const SimpleTensor<half> &a, const SimpleTensor<half> &b, const SimpleTensor<half> &c, float alpha, float beta, SimpleTensor<half> &dst); + template SimpleTensor<half> gemm_mixed_precision(const SimpleTensor<half> &a, const SimpleTensor<half> &b, const SimpleTensor<half> &c, float alpha, float beta); } // namespace reference } // namespace validation diff --git a/tests/validation/reference/GEMM.h b/tests/validation/reference/GEMM.h index 9d82818601..1b97570122 100644 --- a/tests/validation/reference/GEMM.h +++ b/tests/validation/reference/GEMM.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_GEMM_H -#define ARM_COMPUTE_TEST_GEMM_H +#ifndef ACL_TESTS_VALIDATION_REFERENCE_GEMM_H +#define ACL_TESTS_VALIDATION_REFERENCE_GEMM_H #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -41,8 +41,11 @@ SimpleTensor<T> gemm(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const S template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> SimpleTensor<T> gemm_mixed_precision(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta); +template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> +void gemm_accumulate(const SimpleTensor<T> &a, const SimpleTensor<T> &b, const SimpleTensor<T> &c, float alpha, float beta, SimpleTensor<T> &dst); + } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GEMM_H */ +#endif // ACL_TESTS_VALIDATION_REFERENCE_GEMM_H diff --git a/tests/validation/reference/GEMMInterleave4x4.h b/tests/validation/reference/GEMMInterleave4x4.h index e3d72d91aa..3493355626 100644 --- a/tests/validation/reference/GEMMInterleave4x4.h +++ b/tests/validation/reference/GEMMInterleave4x4.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMMInterleaveBlocked.h b/tests/validation/reference/GEMMInterleaveBlocked.h index d649a512e3..0e75d2bb0c 100644 --- a/tests/validation/reference/GEMMInterleaveBlocked.h +++ b/tests/validation/reference/GEMMInterleaveBlocked.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMMLowp.cpp b/tests/validation/reference/GEMMLowp.cpp index 85a98e4a76..30c577d850 100644 --- a/tests/validation/reference/GEMMLowp.cpp +++ b/tests/validation/reference/GEMMLowp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #include "GEMMLowp.h" #include "arm_compute/core/Types.h" +#include "tests/validation/reference/ArithmeticOperations.h" #include "tests/validation/reference/UtilsQuantizedAsymm.h" #include "support/ToolchainSupport.h" @@ -230,6 +231,13 @@ SimpleTensor<T_out> gemmlowp_matrix_multiply_core(const SimpleTensor<T_in> &a, c return c; } +template <typename T_out, typename T_in, typename T_in_1> +void gemmlowp_matrix_multiply_core_accumulate(const SimpleTensor<T_in> &a, const SimpleTensor<T_in_1> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset, SimpleTensor<T_out> &dst) +{ + SimpleTensor<T_out> dst_gemm = gemmlowp_matrix_multiply_core<T_out, T_in, T_in_1>(a, b, shape_c, a_offset, b_offset); + reference::arithmetic_operation<T_out>(reference::ArithmeticOperation::ADD, dst, dst_gemm, dst, ConvertPolicy::SATURATE); +} + // used to validate assembly kernels which don't know anything about offsets template <typename T1, typename T2, typename T3> SimpleTensor<T1> gemmlowp(const SimpleTensor<T2> &a, const SimpleTensor<T3> &b, TensorShape shape_c) @@ -336,6 +344,8 @@ template SimpleTensor<int8_t> gemmlowp_quantize_down_scale(const SimpleTensor<in std::vector<int32_t> result_shift, int32_t min, int32_t max); template SimpleTensor<int32_t> gemmlowp_matrix_multiply_core(const SimpleTensor<int8_t> &a, const SimpleTensor<int8_t> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset); template SimpleTensor<int32_t> gemmlowp_matrix_multiply_core(const SimpleTensor<uint8_t> &a, const SimpleTensor<uint8_t> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset); +template void gemmlowp_matrix_multiply_core_accumulate(const SimpleTensor<int8_t> &a, const SimpleTensor<int8_t> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset, SimpleTensor<int32_t> &dst); +template void gemmlowp_matrix_multiply_core_accumulate(const SimpleTensor<uint8_t> &a, const SimpleTensor<uint8_t> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset, SimpleTensor<int32_t> &dst); template SimpleTensor<int32_t> gemmlowp<int32_t, int8_t, int8_t>(const SimpleTensor<int8_t> &a, const SimpleTensor<int8_t> &b, TensorShape shape_c); template SimpleTensor<int32_t> gemmlowp<int32_t, uint8_t, uint8_t>(const SimpleTensor<uint8_t> &a, const SimpleTensor<uint8_t> &b, TensorShape shape_c); template SimpleTensor<int32_t> gemmlowp<int32_t, uint8_t, int8_t>(const SimpleTensor<uint8_t> &a, const SimpleTensor<int8_t> &b, TensorShape shape_c); diff --git a/tests/validation/reference/GEMMLowp.h b/tests/validation/reference/GEMMLowp.h index 5de48dab52..6e471fdad1 100644 --- a/tests/validation/reference/GEMMLowp.h +++ b/tests/validation/reference/GEMMLowp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_GEMMLOWP_H -#define ARM_COMPUTE_TEST_GEMMLOWP_H +#ifndef ACL_TESTS_VALIDATION_REFERENCE_GEMMLOWP_H +#define ACL_TESTS_VALIDATION_REFERENCE_GEMMLOWP_H #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -38,6 +38,9 @@ namespace reference template <typename T1, typename T2, typename T3> SimpleTensor<T1> gemmlowp_matrix_multiply_core(const SimpleTensor<T2> &a, const SimpleTensor<T3> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset); +template <typename T1, typename T2, typename T3> +void gemmlowp_matrix_multiply_core_accumulate(const SimpleTensor<T2> &a, const SimpleTensor<T3> &b, TensorShape shape_c, int32_t a_offset, int32_t b_offset, SimpleTensor<T1> &dst_); + template <typename T1, typename T2, typename T3 = T2> SimpleTensor<T1> gemmlowp(const SimpleTensor<T2> &a, const SimpleTensor<T3> &b, TensorShape shape_c); @@ -71,4 +74,4 @@ SimpleTensor<TOut> gemmlowp_quantize_down_scale_by_float(const SimpleTensor<TIn> } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GEMMLOWP_H */ +#endif // ACL_TESTS_VALIDATION_REFERENCE_GEMMLOWP_H diff --git a/tests/validation/reference/GEMMReshapeLHSMatrix.cpp b/tests/validation/reference/GEMMReshapeLHSMatrix.cpp index f21fe50e58..ab50e3d1a4 100644 --- a/tests/validation/reference/GEMMReshapeLHSMatrix.cpp +++ b/tests/validation/reference/GEMMReshapeLHSMatrix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMMReshapeLHSMatrix.h b/tests/validation/reference/GEMMReshapeLHSMatrix.h index 35fff91103..fefa946ee2 100644 --- a/tests/validation/reference/GEMMReshapeLHSMatrix.h +++ b/tests/validation/reference/GEMMReshapeLHSMatrix.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMMReshapeRHSMatrix.cpp b/tests/validation/reference/GEMMReshapeRHSMatrix.cpp index ebb6f856d2..d691338ef2 100644 --- a/tests/validation/reference/GEMMReshapeRHSMatrix.cpp +++ b/tests/validation/reference/GEMMReshapeRHSMatrix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMMReshapeRHSMatrix.h b/tests/validation/reference/GEMMReshapeRHSMatrix.h index 4be0cde03b..89e360e0ce 100644 --- a/tests/validation/reference/GEMMReshapeRHSMatrix.h +++ b/tests/validation/reference/GEMMReshapeRHSMatrix.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/GEMMTranspose1xW.h b/tests/validation/reference/GEMMTranspose1xW.h index 6ec70b1067..14add1e01e 100644 --- a/tests/validation/reference/GEMMTranspose1xW.h +++ b/tests/validation/reference/GEMMTranspose1xW.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Gather.cpp b/tests/validation/reference/Gather.cpp index ab5ea2f92e..c90c04f8cc 100644 --- a/tests/validation/reference/Gather.cpp +++ b/tests/validation/reference/Gather.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019, 2022-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -39,27 +39,56 @@ namespace reference template <typename T> SimpleTensor<T> gather(const SimpleTensor<T> &src, const SimpleTensor<uint32_t> &indices, uint32_t actual_axis) { - const auto *indices_ptr = static_cast<const uint32_t *>(indices.data()); const TensorShape dst_shape = arm_compute::misc::shape_calculator::compute_gather_shape(src.shape(), indices.shape(), actual_axis); SimpleTensor<T> dst(dst_shape, src.data_type()); + const auto src_ptr = static_cast<const T *>(src.data()); + const auto indices_ptr = static_cast<const uint32_t *>(indices.data()); + const auto dst_ptr = static_cast<T *>(dst.data()); + + const uint32_t index_limit = src.shape()[actual_axis]; + Window win; win.use_tensor_dimensions(dst_shape); - execute_window_loop(win, [&](const Coordinates & id) - { - Coordinates offset; - for(unsigned int dim = 0; dim < id.num_dimensions(); ++dim) + + execute_window_loop(win, [&](const Coordinates &dst_coords) { + const auto dst_addr = coords2index(dst.shape(), dst_coords); + + // Calculate the coordinates of the index value. + Coordinates idx_coords; + + for(size_t i = 0; i < indices.shape().num_dimensions(); ++i) { - if(dim == actual_axis) + idx_coords.set(i, dst_coords[i + actual_axis]); + } + + const auto index = indices_ptr[coords2index(indices.shape(), idx_coords)]; + + if(index < index_limit) + { + // Calculate the coordinates of the source data. + Coordinates src_coords; + + for(size_t i = 0; i < actual_axis; ++i) { - offset.set(dim, indices_ptr[id[dim]]); + src_coords.set(i, dst_coords[i]); } - else + + src_coords.set(actual_axis, index); + + for(size_t i = actual_axis + 1; i < src.shape().num_dimensions(); ++i) { - offset.set(dim, id[dim]); + src_coords.set(i, dst_coords[i + indices.shape().num_dimensions() - 1]); } + + // Copy the data. + const auto src_addr = coords2index(src.shape(), src_coords); + dst_ptr[dst_addr] = src_ptr[src_addr]; + } + else + { + dst_ptr[dst_addr] = 0; } - *reinterpret_cast<T *>(dst(id)) = *reinterpret_cast<const T *>(src(offset)); }); return dst; @@ -72,4 +101,4 @@ template SimpleTensor<uint8_t> gather(const SimpleTensor<uint8_t> &src, const Si } // namespace reference } // namespace validation } // namespace test -} // namespace arm_compute
\ No newline at end of file +} // namespace arm_compute diff --git a/tests/validation/reference/Gather.h b/tests/validation/reference/Gather.h index 40fac10e37..67b7dca0ae 100644 --- a/tests/validation/reference/Gather.h +++ b/tests/validation/reference/Gather.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Gaussian3x3.cpp b/tests/validation/reference/Gaussian3x3.cpp deleted file mode 100644 index f2ac134f17..0000000000 --- a/tests/validation/reference/Gaussian3x3.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Helpers.h" - -#include "Gaussian3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const std::array<T, 9> filter{ { 1, 2, 1, 2, 4, 2, 1, 2, 1 } }; - const float scale = 1.f / 16.f; - const uint32_t num_elements = src.num_elements(); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor<uint8_t> gaussian3x3(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Gaussian3x3.h b/tests/validation/reference/Gaussian3x3.h deleted file mode 100644 index 8a9c0a3fa6..0000000000 --- a/tests/validation/reference/Gaussian3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_GAUSSIAN3X3_H -#define ARM_COMPUTE_TEST_GAUSSIAN3X3_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GAUSSIAN3X3_H */ diff --git a/tests/validation/reference/Gaussian5x5.cpp b/tests/validation/reference/Gaussian5x5.cpp deleted file mode 100644 index 426e66647c..0000000000 --- a/tests/validation/reference/Gaussian5x5.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Helpers.h" - -#include "Gaussian5x5.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian5x5(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const std::array<T, 25> filter{ { - 1, 4, 6, 4, 1, - 4, 16, 24, 16, 4, - 6, 24, 36, 24, 6, - 4, 16, 24, 16, 4, - 1, 4, 6, 4, 1 - } }; - const float scale = 1.f / 256.f; - const uint32_t num_elements = src.num_elements(); - -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, dst, TensorShape(5U, 5U), filter.data(), scale, border_mode, constant_border_value); - } - return dst; -} - -template SimpleTensor<uint8_t> gaussian5x5(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Gaussian5x5.h b/tests/validation/reference/Gaussian5x5.h deleted file mode 100644 index 9a644172da..0000000000 --- a/tests/validation/reference/Gaussian5x5.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_GAUSSIAN5X5_H -#define ARM_COMPUTE_TEST_GAUSSIAN5X5_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> gaussian5x5(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GAUSSIAN5X5_H */ diff --git a/tests/validation/reference/GaussianPyramidHalf.cpp b/tests/validation/reference/GaussianPyramidHalf.cpp deleted file mode 100644 index 7d5eb07512..0000000000 --- a/tests/validation/reference/GaussianPyramidHalf.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "GaussianPyramidHalf.h" - -#include "arm_compute/core/Helpers.h" - -#include "Gaussian5x5.h" -#include "Scale.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> gaussian_pyramid_half(const SimpleTensor<T> &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels) -{ - std::vector<SimpleTensor<T>> dst; - - // Level0 is equal to src - dst.push_back(src); - - for(size_t i = 1; i < num_levels; ++i) - { - // Gaussian Filter - const SimpleTensor<T> out_gaus5x5 = reference::gaussian5x5(dst[i - 1], border_mode, constant_border_value); - - // Scale down by 2 with nearest interpolation - const SimpleTensor<T> out = reference::scale(out_gaus5x5, SCALE_PYRAMID_HALF, SCALE_PYRAMID_HALF, InterpolationPolicy::NEAREST_NEIGHBOR, border_mode, constant_border_value, SamplingPolicy::CENTER, - true); - - dst.push_back(out); - } - - return dst; -} - -template std::vector<SimpleTensor<uint8_t>> gaussian_pyramid_half(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/GaussianPyramidHalf.h b/tests/validation/reference/GaussianPyramidHalf.h deleted file mode 100644 index 03a4bd4a86..0000000000 --- a/tests/validation/reference/GaussianPyramidHalf.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H -#define ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<SimpleTensor<T>> gaussian_pyramid_half(const SimpleTensor<T> &src, BorderMode border_mode, uint8_t constant_border_value, size_t num_levels); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_GAUSSIAN_PYRAMID_HALF_H */
\ No newline at end of file diff --git a/tests/validation/reference/HOGDescriptor.cpp b/tests/validation/reference/HOGDescriptor.cpp deleted file mode 100644 index f0f573a471..0000000000 --- a/tests/validation/reference/HOGDescriptor.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "HOGDescriptor.h" - -#include "Derivative.h" -#include "Magnitude.h" -#include "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -void hog_orientation_compute(const SimpleTensor<T> &mag, const SimpleTensor<T> &phase, std::vector<T> &bins, const HOGInfo &hog_info) -{ - const Size2D &cell_size = hog_info.cell_size(); - const size_t num_bins = hog_info.num_bins(); - - float phase_scale = (PhaseType::SIGNED == hog_info.phase_type() ? num_bins / 360.0f : num_bins / 180.0f); - phase_scale *= (PhaseType::SIGNED == hog_info.phase_type() ? 360.0f / 255.0f : 1.0f); - - int row_idx = 0; - for(size_t yc = 0; yc < cell_size.height; ++yc) - { - for(size_t xc = 0; xc < cell_size.width; xc++) - { - const float mag_value = mag[(row_idx + xc)]; - const float phase_value = phase[(row_idx + xc)] * phase_scale + 0.5f; - const float w1 = phase_value - floor(phase_value); - - // The quantised phase is the histogram index [0, num_bins - 1] - // Check limit of histogram index. If hidx == num_bins, hidx = 0 - const auto hidx = static_cast<unsigned int>(phase_value) % num_bins; - - // Weighted vote between 2 bins - bins[hidx] += mag_value * (1.0f - w1); - bins[(hidx + 1) % num_bins] += mag_value * w1; - } - - row_idx += cell_size.width; - } -} - -template <typename T> -void hog_block_normalization_compute(SimpleTensor<T> &block, SimpleTensor<T> &desc, const HOGInfo &hog_info, uint32_t block_idx) -{ - const int num_bins_per_block = desc.num_channels(); - const HOGNormType norm_type = hog_info.normalization_type(); - const Coordinates id = index2coord(desc.shape(), block_idx); - - float sum = 0.0f; - - // Calculate sum - for(int i = 0; i < num_bins_per_block; ++i) - { - const float val = block[i]; - sum += (norm_type == HOGNormType::L1_NORM) ? std::fabs(val) : val * val; - } - - // Calculate normalization scale - float scale = 1.0f / (std::sqrt(sum) + num_bins_per_block * 0.1f); - - if(norm_type == HOGNormType::L2HYS_NORM) - { - // Reset sum - sum = 0.0f; - for(int i = 0; i < num_bins_per_block; ++i) - { - float val = block[i] * scale; - - // Clip scaled input_value if over l2_hyst_threshold - val = fmin(val, hog_info.l2_hyst_threshold()); - sum += val * val; - block[i] = val; - } - - // We use the same constants of OpenCV - scale = 1.0f / (std::sqrt(sum) + 1e-3f); - } - - for(int i = 0; i < num_bins_per_block; ++i) - { - block[i] *= scale; - reinterpret_cast<float *>(desc(id))[i] = block[i]; - } -} -} // namespace - -template <typename T, typename U, typename V> -void hog_orientation_binning(const SimpleTensor<T> &mag, const SimpleTensor<U> &phase, SimpleTensor<V> &hog_space, const HOGInfo &hog_info) -{ - const Size2D &cell_size = hog_info.cell_size(); - - const size_t num_bins = hog_info.num_bins(); - const size_t shape_width = hog_space.shape().x() * hog_info.cell_size().width; - const size_t shape_height = hog_space.shape().y() * hog_info.cell_size().height; - - TensorShape cell_shape(cell_size.width, cell_size.height); - - SimpleTensor<V> mag_cell(cell_shape, DataType::F32); - SimpleTensor<V> phase_cell(cell_shape, DataType::F32); - - int cell_idx = 0; - int y_offset = 0; - - // Traverse shape - for(auto sy = cell_size.height; sy <= shape_height; sy += cell_size.height) - { - int x_offset = 0; - for(auto sx = cell_size.width; sx <= shape_width; sx += cell_size.width) - { - int row_idx = 0; - int elem_idx = 0; - - // Traverse cell - for(auto y = 0u; y < cell_size.height; ++y) - { - for(auto x = 0u; x < cell_size.width; ++x) - { - int shape_idx = x + row_idx + x_offset + y_offset; - mag_cell[elem_idx] = mag[shape_idx]; - phase_cell[elem_idx] = phase[shape_idx]; - elem_idx++; - } - - row_idx += shape_width; - } - - // Partition magnitude values into bins based on phase values - std::vector<V> bins(num_bins); - hog_orientation_compute(mag_cell, phase_cell, bins, hog_info); - - for(size_t i = 0; i < num_bins; ++i) - { - hog_space[cell_idx * num_bins + i] = bins[i]; - } - - x_offset += cell_size.width; - cell_idx++; - } - - y_offset += (cell_size.height * shape_width); - } -} - -template <typename T> -void hog_block_normalization(SimpleTensor<T> &desc, const SimpleTensor<T> &hog_space, const HOGInfo &hog_info) -{ - const Size2D cells_per_block = hog_info.num_cells_per_block(); - const Size2D cells_per_block_stride = hog_info.num_cells_per_block_stride(); - const Size2D &block_size = hog_info.block_size(); - const Size2D &block_stride = hog_info.block_stride(); - const size_t num_bins = hog_info.num_bins(); - - const size_t shape_width = hog_space.shape().x() * hog_info.cell_size().width; - const size_t shape_height = hog_space.shape().y() * hog_info.cell_size().height; - const size_t num_bins_per_block_x = cells_per_block.width * num_bins; - - // Tensor representing single block - SimpleTensor<T> block(TensorShape{ 1u, 1u }, DataType::F32, cells_per_block.area() * num_bins); - - uint32_t block_idx = 0; - int block_y_offset = 0; - - // Traverse shape - for(auto sy = block_size.height; sy <= shape_height; sy += block_stride.height) - { - int block_x_offset = 0; - for(auto sx = block_size.width; sx <= shape_width; sx += block_stride.width) - { - int cell_y_offset = 0; - int elem_idx = 0; - - // Traverse block - for(auto y = 0u; y < cells_per_block.height; ++y) - { - for(auto x = 0u; x < num_bins_per_block_x; ++x) - { - int idx = x + cell_y_offset + block_x_offset + block_y_offset; - block[elem_idx] = hog_space[idx]; - elem_idx++; - } - - cell_y_offset += hog_space.shape().x() * num_bins; - } - - // Normalize block and write to descriptor - hog_block_normalization_compute(block, desc, hog_info, block_idx); - - block_x_offset += cells_per_block_stride.width * num_bins; - block_idx++; - } - - block_y_offset += cells_per_block_stride.height * num_bins * hog_space.shape().x(); - } -} - -template <typename T, typename U> -SimpleTensor<T> hog_descriptor(const SimpleTensor<U> &src, BorderMode border_mode, U constant_border_value, const HOGInfo &hog_info) -{ - SimpleTensor<int16_t> grad_x; - SimpleTensor<int16_t> grad_y; - - // Create tensor info for HOG descriptor - TensorInfo desc_info(hog_info, src.shape().x(), src.shape().y()); - SimpleTensor<T> desc(desc_info.tensor_shape(), DataType::F32, desc_info.num_channels()); - - // Create HOG space tensor (num_cells_x, num_cells_y) - TensorShape hog_space_shape(src.shape().x() / hog_info.cell_size().width, - src.shape().y() / hog_info.cell_size().height); - - // For each cell a histogram with a num_bins is created - TensorInfo info_hog_space(hog_space_shape, hog_info.num_bins(), DataType::F32); - SimpleTensor<T> hog_space(info_hog_space.tensor_shape(), DataType::F32, info_hog_space.num_channels()); - - // Calculate derivative - std::tie(grad_x, grad_y) = derivative<int16_t>(src, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - // For each cell create histogram based on magnitude and phase - hog_orientation_binning(magnitude(grad_x, grad_y, MagnitudeType::L2NORM), - phase(grad_x, grad_y, hog_info.phase_type()), - hog_space, - hog_info); - - // Normalize histograms based on block size - hog_block_normalization(desc, hog_space, hog_info); - - return desc; -} - -template void hog_orientation_binning(const SimpleTensor<int16_t> &mag, const SimpleTensor<uint8_t> &phase, SimpleTensor<float> &hog_space, const HOGInfo &hog_info); -template void hog_block_normalization(SimpleTensor<float> &desc, const SimpleTensor<float> &hog_space, const HOGInfo &hog_info); -template SimpleTensor<float> hog_descriptor(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, const HOGInfo &hog_info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HOGDetector.cpp b/tests/validation/reference/HOGDetector.cpp deleted file mode 100644 index 8ca1b0c204..0000000000 --- a/tests/validation/reference/HOGDetector.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2018-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "HOGDetector.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -/** Computes the number of detection windows to iterate over in the feature vector. */ -Size2D num_detection_windows(const TensorShape &shape, const Size2D &window_step, const HOGInfo &hog_info) -{ - const size_t num_block_strides_width = hog_info.detection_window_size().width / hog_info.block_stride().width; - const size_t num_block_strides_height = hog_info.detection_window_size().height / hog_info.block_stride().height; - - return Size2D{ floor_to_multiple(shape.x() - num_block_strides_width, window_step.width) + window_step.width, - floor_to_multiple(shape.y() - num_block_strides_height, window_step.height) + window_step.height }; -} -} // namespace - -template <typename T> -std::vector<DetectionWindow> hog_detector(const SimpleTensor<T> &src, const std::vector<T> &descriptor, unsigned int max_num_detection_windows, - const HOGInfo &hog_info, const Size2D &detection_window_stride, float threshold, uint16_t idx_class) -{ - ARM_COMPUTE_ERROR_ON_MSG((detection_window_stride.width % hog_info.block_stride().width != 0), - "Detection window stride width must be multiple of block stride width"); - ARM_COMPUTE_ERROR_ON_MSG((detection_window_stride.height % hog_info.block_stride().height != 0), - "Detection window stride height must be multiple of block stride height"); - - // Create vector for identifying each detection window - std::vector<DetectionWindow> windows; - - // Calculate detection window step - const Size2D window_step(detection_window_stride.width / hog_info.block_stride().width, - detection_window_stride.height / hog_info.block_stride().height); - - // Calculate number of detection windows - const Size2D num_windows = num_detection_windows(src.shape(), window_step, hog_info); - - // Calculate detection window and row offsets in feature vector - const size_t src_offset_x = window_step.width * hog_info.num_bins() * hog_info.num_cells_per_block().area(); - const size_t src_offset_y = window_step.height * hog_info.num_bins() * hog_info.num_cells_per_block().area() * src.shape().x(); - const size_t src_offset_row = src.num_channels() * src.shape().x(); - - // Calculate detection window attributes - const Size2D num_block_positions_per_detection_window = hog_info.num_block_positions_per_image(hog_info.detection_window_size()); - const unsigned int num_bins_per_descriptor_x = num_block_positions_per_detection_window.width * src.num_channels(); - const unsigned int num_blocks_per_descriptor_y = num_block_positions_per_detection_window.height; - - ARM_COMPUTE_ERROR_ON((num_bins_per_descriptor_x * num_blocks_per_descriptor_y + 1) != hog_info.descriptor_size()); - - size_t win_id = 0; - - // Traverse feature vector in detection window steps - for(auto win_y = 0u, offset_y = 0u; win_y < num_windows.height; win_y += window_step.height, offset_y += src_offset_y) - { - for(auto win_x = 0u, offset_x = 0u; win_x < num_windows.width; win_x += window_step.width, offset_x += src_offset_x) - { - // Reset the score - float score = 0.0f; - - // Traverse detection window - for(auto y = 0u, offset_row = 0u; y < num_blocks_per_descriptor_y; ++y, offset_row += src_offset_row) - { - const int bin_offset = y * num_bins_per_descriptor_x; - - for(auto x = 0u; x < num_bins_per_descriptor_x; ++x) - { - // Compute Linear SVM - const float a = src[x + offset_x + offset_y + offset_row]; - const float b = descriptor[x + bin_offset]; - score += a * b; - } - } - - // Add the bias. The bias is located at the position (descriptor_size() - 1) - score += descriptor[num_bins_per_descriptor_x * num_blocks_per_descriptor_y]; - - if(score > threshold) - { - DetectionWindow window; - - if(win_id++ < max_num_detection_windows) - { - window.x = win_x * hog_info.block_stride().width; - window.y = win_y * hog_info.block_stride().height; - window.width = hog_info.detection_window_size().width; - window.height = hog_info.detection_window_size().height; - window.idx_class = idx_class; - window.score = score; - - windows.push_back(window); - } - } - } - } - - return windows; -} - -template std::vector<DetectionWindow> hog_detector(const SimpleTensor<float> &src, const std::vector<float> &descriptor, unsigned int max_num_detection_windows, - const HOGInfo &hog_info, const Size2D &detection_window_stride, float threshold, uint16_t idx_class); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HOGDetector.h b/tests/validation/reference/HOGDetector.h deleted file mode 100644 index 86f45b4910..0000000000 --- a/tests/validation/reference/HOGDetector.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_HOG_DETECTOR_H -#define ARM_COMPUTE_TEST_HOG_DETECTOR_H - -#include "arm_compute/core/Types.h" -#include "arm_compute/core/Utils.h" -#include "tests/SimpleTensor.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<DetectionWindow> hog_detector(const SimpleTensor<T> &src, const std::vector<T> &descriptor, unsigned int max_num_detection_windows, - const HOGInfo &hog_info, const Size2D &detection_window_stride, float threshold = 0.0f, uint16_t idx_class = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HOG_DETECTOR_H */ diff --git a/tests/validation/reference/HOGMultiDetection.cpp b/tests/validation/reference/HOGMultiDetection.cpp deleted file mode 100644 index 2f5e4395a0..0000000000 --- a/tests/validation/reference/HOGMultiDetection.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "HOGMultiDetection.h" - -#include "Derivative.h" -#include "HOGDescriptor.h" -#include "HOGDetector.h" -#include "Magnitude.h" -#include "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -void validate_models(const std::vector<HOGInfo> &models) -{ - ARM_COMPUTE_ERROR_ON(0 == models.size()); - - for(size_t i = 1; i < models.size(); ++i) - { - ARM_COMPUTE_ERROR_ON_MSG(models[0].phase_type() != models[i].phase_type(), - "All HOG parameters must have the same phase type"); - - ARM_COMPUTE_ERROR_ON_MSG(models[0].normalization_type() != models[i].normalization_type(), - "All HOG parameters must have the same normalization_type"); - - ARM_COMPUTE_ERROR_ON_MSG((models[0].l2_hyst_threshold() != models[i].l2_hyst_threshold()) && (models[0].normalization_type() == arm_compute::HOGNormType::L2HYS_NORM), - "All HOG parameters must have the same l2 hysteresis threshold if you use L2 hysteresis normalization type"); - } -} -} // namespace - -void detection_windows_non_maxima_suppression(std::vector<DetectionWindow> &multi_windows, float min_distance) -{ - const size_t num_candidates = multi_windows.size(); - size_t num_detections = 0; - - // Sort by idx_class first and by score second - std::sort(multi_windows.begin(), multi_windows.end(), [](const DetectionWindow & lhs, const DetectionWindow & rhs) - { - if(lhs.idx_class < rhs.idx_class) - { - return true; - } - if(rhs.idx_class < lhs.idx_class) - { - return false; - } - - // idx_classes are equal so compare by score - if(lhs.score > rhs.score) - { - return true; - } - if(rhs.score > lhs.score) - { - return false; - } - - return false; - }); - - const float min_distance_pow2 = min_distance * min_distance; - - // Euclidean distance - for(size_t i = 0; i < num_candidates; ++i) - { - if(0.0f != multi_windows.at(i).score) - { - DetectionWindow cur; - cur.x = multi_windows.at(i).x; - cur.y = multi_windows.at(i).y; - cur.width = multi_windows.at(i).width; - cur.height = multi_windows.at(i).height; - cur.idx_class = multi_windows.at(i).idx_class; - cur.score = multi_windows.at(i).score; - - // Store window - multi_windows.at(num_detections) = cur; - ++num_detections; - - const float xc = cur.x + cur.width * 0.5f; - const float yc = cur.y + cur.height * 0.5f; - - for(size_t k = i + 1; k < (num_candidates) && (cur.idx_class == multi_windows.at(k).idx_class); ++k) - { - const float xn = multi_windows.at(k).x + multi_windows.at(k).width * 0.5f; - const float yn = multi_windows.at(k).y + multi_windows.at(k).height * 0.5f; - - const float dx = std::fabs(xn - xc); - const float dy = std::fabs(yn - yc); - - if(dx < min_distance && dy < min_distance) - { - const float d = dx * dx + dy * dy; - - if(d < min_distance_pow2) - { - // Invalidate detection window - multi_windows.at(k).score = 0.0f; - } - } - } - } - } - - multi_windows.resize(num_detections); -} - -template <typename T> -std::vector<DetectionWindow> hog_multi_detection(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value, - const std::vector<HOGInfo> &models, std::vector<std::vector<float>> descriptors, - unsigned int max_num_detection_windows, float threshold, bool non_maxima_suppression, float min_distance) -{ - ARM_COMPUTE_ERROR_ON(descriptors.size() != models.size()); - validate_models(models); - - const size_t width = src.shape().x(); - const size_t height = src.shape().y(); - const size_t num_models = models.size(); - - // Initialize previous values - size_t prev_num_bins = models[0].num_bins(); - Size2D prev_cell_size = models[0].cell_size(); - Size2D prev_block_size = models[0].block_size(); - Size2D prev_block_stride = models[0].block_stride(); - - std::vector<size_t> input_orient_bin; - std::vector<size_t> input_hog_detect; - std::vector<std::pair<size_t, size_t>> input_block_norm; - - input_orient_bin.push_back(0); - input_hog_detect.push_back(0); - input_block_norm.emplace_back(0, 0); - - // Iterate through the number of models and check if orientation binning - // and block normalization steps can be skipped - for(size_t i = 1; i < num_models; ++i) - { - size_t cur_num_bins = models[i].num_bins(); - Size2D cur_cell_size = models[i].cell_size(); - Size2D cur_block_size = models[i].block_size(); - Size2D cur_block_stride = models[i].block_stride(); - - // Check if binning and normalization steps are required - if((cur_num_bins != prev_num_bins) || (cur_cell_size.width != prev_cell_size.width) || (cur_cell_size.height != prev_cell_size.height)) - { - prev_num_bins = cur_num_bins; - prev_cell_size = cur_cell_size; - prev_block_size = cur_block_size; - prev_block_stride = cur_block_stride; - - // Compute orientation binning and block normalization. Update input to process - input_orient_bin.push_back(i); - input_block_norm.emplace_back(i, input_orient_bin.size() - 1); - } - else if((cur_block_size.width != prev_block_size.width) || (cur_block_size.height != prev_block_size.height) || (cur_block_stride.width != prev_block_stride.width) - || (cur_block_stride.height != prev_block_stride.height)) - { - prev_block_size = cur_block_size; - prev_block_stride = cur_block_stride; - - // Compute block normalization. Update input to process - input_block_norm.emplace_back(i, input_orient_bin.size() - 1); - } - - // Update input to process for hog detector - input_hog_detect.push_back(input_block_norm.size() - 1); - } - - size_t num_orient_bin = input_orient_bin.size(); - size_t num_block_norm = input_block_norm.size(); - size_t num_hog_detect = input_hog_detect.size(); - - std::vector<SimpleTensor<float>> hog_spaces(num_orient_bin); - std::vector<SimpleTensor<float>> hog_norm_spaces(num_block_norm); - - // Calculate derivative - SimpleTensor<int16_t> grad_x; - SimpleTensor<int16_t> grad_y; - std::tie(grad_x, grad_y) = derivative<int16_t>(src, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - // Calculate magnitude and phase - SimpleTensor<int16_t> _mag = magnitude(grad_x, grad_y, MagnitudeType::L2NORM); - SimpleTensor<uint8_t> _phase = phase(grad_x, grad_y, models[0].phase_type()); - - // Calculate Tensors for the HOG space and orientation binning - for(size_t i = 0; i < num_orient_bin; ++i) - { - const size_t idx_multi_hog = input_orient_bin[i]; - - const size_t num_bins = models[idx_multi_hog].num_bins(); - const size_t num_cells_x = width / models[idx_multi_hog].cell_size().width; - const size_t num_cells_y = height / models[idx_multi_hog].cell_size().height; - - // TensorShape of hog space - TensorShape hog_space_shape(num_cells_x, num_cells_y); - - // Initialise HOG space - TensorInfo info_hog_space(hog_space_shape, num_bins, DataType::F32); - hog_spaces.at(i) = SimpleTensor<float>(info_hog_space.tensor_shape(), DataType::F32, info_hog_space.num_channels()); - - // For each cell create histogram based on magnitude and phase - hog_orientation_binning(_mag, _phase, hog_spaces[i], models[idx_multi_hog]); - } - - // Calculate Tensors for the normalized HOG space and block normalization - for(size_t i = 0; i < num_block_norm; ++i) - { - const size_t idx_multi_hog = input_block_norm[i].first; - const size_t idx_orient_bin = input_block_norm[i].second; - - // Create tensor info for HOG descriptor - TensorInfo tensor_info(models[idx_multi_hog], src.shape().x(), src.shape().y()); - hog_norm_spaces.at(i) = SimpleTensor<float>(tensor_info.tensor_shape(), DataType::F32, tensor_info.num_channels()); - - // Normalize histograms based on block size - hog_block_normalization(hog_norm_spaces[i], hog_spaces[idx_orient_bin], models[idx_multi_hog]); - } - - std::vector<DetectionWindow> multi_windows; - - // Calculate Detection Windows for HOG detector - for(size_t i = 0; i < num_hog_detect; ++i) - { - const size_t idx_block_norm = input_hog_detect[i]; - - // NOTE: Detection window stride fixed to block stride - const Size2D detection_window_stride = models[i].block_stride(); - - std::vector<DetectionWindow> windows = hog_detector(hog_norm_spaces[idx_block_norm], descriptors[i], - max_num_detection_windows, models[i], detection_window_stride, threshold, i); - - multi_windows.insert(multi_windows.end(), windows.begin(), windows.end()); - } - - // Suppress Non-maxima detection windows - if(non_maxima_suppression) - { - detection_windows_non_maxima_suppression(multi_windows, min_distance); - } - - return multi_windows; -} - -template std::vector<DetectionWindow> hog_multi_detection(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value, - const std::vector<HOGInfo> &models, std::vector<std::vector<float>> descriptors, - unsigned int max_num_detection_windows, float threshold, bool non_maxima_suppression, float min_distance); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/HOGMultiDetection.h b/tests/validation/reference/HOGMultiDetection.h deleted file mode 100644 index 2b38aae7c9..0000000000 --- a/tests/validation/reference/HOGMultiDetection.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_HOG_MULTI_DETECTION_H -#define ARM_COMPUTE_TEST_HOG_MULTI_DETECTION_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<DetectionWindow> hog_multi_detection(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value, - const std::vector<HOGInfo> &models, std::vector<std::vector<float>> descriptors, - unsigned int max_num_detection_windows, float threshold = 0.0f, bool non_maxima_suppression = false, float min_distance = 1.0f); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HOG_MULTI_DETECTION_H */ diff --git a/tests/validation/reference/HarrisCornerDetector.cpp b/tests/validation/reference/HarrisCornerDetector.cpp deleted file mode 100644 index 442f6a18b5..0000000000 --- a/tests/validation/reference/HarrisCornerDetector.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "HarrisCornerDetector.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/NonMaximaSuppression.h" -#include "tests/validation/reference/Sobel.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -template <typename T> -std::tuple<SimpleTensor<T>, SimpleTensor<T>, float> compute_sobel(const SimpleTensor<uint8_t> &src, int gradient_size, int block_size, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor<T> grad_x; - SimpleTensor<T> grad_y; - float norm_factor = 0.f; - - std::tie(grad_x, grad_y) = sobel<T>(src, gradient_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - switch(gradient_size) - { - case 3: - norm_factor = 1.f / (4 * 255 * block_size); - break; - case 5: - norm_factor = 1.f / (16 * 255 * block_size); - break; - case 7: - norm_factor = 1.f / (64 * 255 * block_size); - break; - default: - ARM_COMPUTE_ERROR("Gradient size not supported."); - } - - return std::make_tuple(grad_x, grad_y, norm_factor); -} - -template <typename T, typename U> -std::vector<KeyPoint> harris_corner_detector_impl(const SimpleTensor<U> &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - U constant_border_value) -{ - ARM_COMPUTE_ERROR_ON(block_size != 3 && block_size != 5 && block_size != 7); - - SimpleTensor<T> grad_x; - SimpleTensor<T> grad_y; - float norm_factor = 0.f; - - // Sobel - std::tie(grad_x, grad_y, norm_factor) = compute_sobel<T>(src, gradient_size, block_size, border_mode, constant_border_value); - - SimpleTensor<float> scores(src.shape(), DataType::F32); - ValidRegion scores_region = shape_to_valid_region(scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2)); - - // Calculate scores - for(int i = 0; i < scores.num_elements(); ++i) - { - Coordinates src_coord = index2coord(src.shape(), i); - Coordinates block_top_left{ src_coord.x() - block_size / 2, src_coord.y() - block_size / 2 }; - Coordinates block_bottom_right{ src_coord.x() + block_size / 2, src_coord.y() + block_size / 2 }; - - if(!is_in_valid_region(scores_region, src_coord)) - { - scores[i] = 0.f; - continue; - } - - float Gx2 = 0.f; - float Gy2 = 0.f; - float Gxy = 0.f; - - // Calculate Gx^2, Gy^2 and Gxy within the given window - for(int y = block_top_left.y(); y <= block_bottom_right.y(); ++y) - { - for(int x = block_top_left.x(); x <= block_bottom_right.x(); ++x) - { - Coordinates block_coord(x, y); - - const float norm_x = tensor_elem_at(grad_x, block_coord, border_mode, static_cast<T>(constant_border_value)) * norm_factor; - const float norm_y = tensor_elem_at(grad_y, block_coord, border_mode, static_cast<T>(constant_border_value)) * norm_factor; - - Gx2 += std::pow(norm_x, 2); - Gy2 += std::pow(norm_y, 2); - Gxy += norm_x * norm_y; - } - } - - const float trace2 = std::pow(Gx2 + Gy2, 2); - const float det = Gx2 * Gy2 - std::pow(Gxy, 2); - const float response = det - sensitivity * trace2; - - if(response > threshold) - { - scores[i] = response; - } - else - { - scores[i] = 0.f; - } - } - - // Suppress non-maxima candidates - SimpleTensor<float> suppressed_scores = non_maxima_suppression(scores, border_mode != BorderMode::UNDEFINED ? BorderMode::CONSTANT : BorderMode::UNDEFINED, 0.f); - ValidRegion suppressed_scores_region = shape_to_valid_region(suppressed_scores.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(gradient_size / 2 + block_size / 2 + 1)); - - // Create vector of candidate corners - std::vector<KeyPoint> corner_candidates; - - for(int i = 0; i < suppressed_scores.num_elements(); ++i) - { - Coordinates coord = index2coord(suppressed_scores.shape(), i); - - if(is_in_valid_region(suppressed_scores_region, coord) && suppressed_scores[i] != 0.f) - { - KeyPoint corner; - corner.x = coord.x(); - corner.y = coord.y(); - corner.tracking_status = 1; - corner.strength = suppressed_scores[i]; - corner.scale = 0.f; - corner.orientation = 0.f; - corner.error = 0.f; - - corner_candidates.emplace_back(corner); - } - } - - // Sort descending by strength - std::sort(corner_candidates.begin(), corner_candidates.end(), [](const KeyPoint & a, const KeyPoint & b) - { - return a.strength > b.strength; - }); - - std::vector<KeyPoint> corners; - corners.reserve(corner_candidates.size()); - - // Only add corner if there is no stronger within min_dist - for(const KeyPoint &point : corner_candidates) - { - const auto strongest = std::find_if(corners.begin(), corners.end(), [&](const KeyPoint & other) - { - return std::sqrt((std::pow(point.x - other.x, 2) + std::pow(point.y - other.y, 2))) < min_dist; - }); - - if(strongest == corners.end()) - { - corners.emplace_back(point); - } - } - - corners.shrink_to_fit(); - - return corners; -} -} // namespace - -template <typename T> -std::vector<KeyPoint> harris_corner_detector(const SimpleTensor<T> &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - T constant_border_value) -{ - if(gradient_size < 7) - { - return harris_corner_detector_impl<int16_t>(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); - } - else - { - return harris_corner_detector_impl<int32_t>(src, threshold, min_dist, sensitivity, gradient_size, block_size, border_mode, constant_border_value); - } -} - -template std::vector<KeyPoint> harris_corner_detector(const SimpleTensor<uint8_t> &src, float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Histogram.cpp b/tests/validation/reference/Histogram.cpp deleted file mode 100644 index 594c4fb81f..0000000000 --- a/tests/validation/reference/Histogram.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Histogram.h" - -#include "Utils.h" -#include "arm_compute/core/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> histogram(const SimpleTensor<T> &src, size_t num_bins, int32_t offset, uint32_t range) -{ - SimpleTensor<uint32_t> dst(TensorShape(num_bins), DataType::U32); - - // Clear the distribution - for(size_t element_idx = 0; element_idx < num_bins; ++element_idx) - { - dst[element_idx] = 0; - } - - // Create the histogram - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - if((offset <= src[element_idx]) && (src[element_idx] < (offset + range))) - { - const int index = (src[element_idx] - offset) * num_bins / range; - dst[index]++; - } - } - - return dst; -} - -template SimpleTensor<uint32_t> histogram(const SimpleTensor<uint8_t> &src, size_t num_bins, int32_t offset, uint32_t range); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Histogram.h b/tests/validation/reference/Histogram.h deleted file mode 100644 index 60fa7588af..0000000000 --- a/tests/validation/reference/Histogram.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_HISTOGRAM_H -#define ARM_COMPUTE_TEST_HISTOGRAM_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> histogram(const SimpleTensor<T> &src, size_t num_bins, int32_t offset, uint32_t range); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HISTOGRAM_H */ diff --git a/tests/validation/reference/Im2Col.cpp b/tests/validation/reference/Im2Col.cpp index a3dcf07273..91544a4a15 100644 --- a/tests/validation/reference/Im2Col.cpp +++ b/tests/validation/reference/Im2Col.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Im2Col.h b/tests/validation/reference/Im2Col.h index 68c1c07044..db0f2b44ff 100644 --- a/tests/validation/reference/Im2Col.h +++ b/tests/validation/reference/Im2Col.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/IndirectConv2dAddressPrecalculation.cpp b/tests/validation/reference/IndirectConv2dAddressPrecalculation.cpp new file mode 100644 index 0000000000..7500560c91 --- /dev/null +++ b/tests/validation/reference/IndirectConv2dAddressPrecalculation.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "IndirectConv2dAddressPrecalculation.h" + +#include "arm_compute/core/Types.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +SimpleTensor<int32_t> indirect_conv2d_addr_precalculation(const TensorShape &shape_conv_src, const TensorShape &shape_conv_wei, const TensorShape &shape_conv_dst, const TensorShape &shape_dst, + const PadStrideInfo &conv_info) +{ + SimpleTensor<int32_t> out{ shape_dst, DataType::S32 }; + + constexpr unsigned int width_idx = 1; + constexpr unsigned int heigh_idx = 2; + + const int src_conv_width = static_cast<int32_t>(shape_conv_src[width_idx]); // NHWC + const int src_conv_height = static_cast<int32_t>(shape_conv_src[heigh_idx]); // NHWC + const int dst_conv_width = static_cast<int32_t>(shape_conv_dst[width_idx]); // NHWC + const int wei_conv_width = static_cast<int32_t>(shape_conv_wei[width_idx]); // NHWC + const int wei_conv_height = static_cast<int32_t>(shape_conv_wei[heigh_idx]); // NHWC + const int dst_width = static_cast<int32_t>(shape_dst[0]); + const int dst_height = static_cast<int32_t>(shape_dst[1]); + const int dst_batch = static_cast<int32_t>(shape_dst[2]); + const int ks = wei_conv_width * wei_conv_height; + const int stride_x = static_cast<int32_t>(conv_info.stride().first); + const int stride_y = static_cast<int32_t>(conv_info.stride().second); + const int pad_left = static_cast<int32_t>(conv_info.pad_left()); + const int pad_top = static_cast<int32_t>(conv_info.pad_top()); + + const int m0 = dst_width / ks; + + for(int z = 0; z < dst_batch; ++z) + { + for(int y = 0; y < dst_height; ++y) + { + const int mout = y * m0; + for(int ki = 0; ki < ks; ++ki) + { + const int xk = ki % wei_conv_width; + const int yk = ki / wei_conv_width; + for(int mi = 0; mi < m0; ++mi) + { + int xi = ((mout + mi) % dst_conv_width) * stride_x; + int yi = ((mout + mi) / dst_conv_width) * stride_y; + xi -= pad_left; + yi -= pad_top; + const int x_s = xi + xk; + const int y_s = yi + yk; + int my = x_s + y_s * src_conv_width; + my = my + z * src_conv_width * src_conv_height; + my = x_s >= 0 ? my : -1; + my = x_s < src_conv_width ? my : -1; + my = y_s >= 0 ? my : -1; + my = y_s < src_conv_height ? my : -1; + + const unsigned int addr_out = mi + ki * m0 + y * (dst_width) + z * (dst_width * dst_height); + out[addr_out] = my; + } + } + } + } + + return out; +} +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute
\ No newline at end of file diff --git a/tests/validation/reference/YOLOLayer.h b/tests/validation/reference/IndirectConv2dAddressPrecalculation.h index 6347845ffa..f4a90dfd9f 100644 --- a/tests/validation/reference/YOLOLayer.h +++ b/tests/validation/reference/IndirectConv2dAddressPrecalculation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_YOLO_LAYER_H -#define ARM_COMPUTE_TEST_YOLO_LAYER_H +#ifndef ARM_COMPUTE_TEST_INDIRECT_CONV2D_ADDRESS_PRECALCULATION_H +#define ARM_COMPUTE_TEST_INDIRECT_CONV2D_ADDRESS_PRECALCULATION_H #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -35,13 +35,10 @@ namespace validation { namespace reference { -template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> -SimpleTensor<T> yolo_layer(const SimpleTensor<T> &src, const ActivationLayerInfo &info, int32_t num_classes); - -template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0> -SimpleTensor<T> yolo_layer(const SimpleTensor<T> &src, const ActivationLayerInfo &info, int32_t num_classes); +SimpleTensor<int32_t> indirect_conv2d_addr_precalculation(const TensorShape &shape_conv_src, const TensorShape &shape_conv_wei, const TensorShape &shape_conv_out, const TensorShape &shape_out, + const PadStrideInfo &conv_info); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_YOLO_LAYER_H */ +#endif /* ARM_COMPUTE_TEST_INDIRECT_CONV2D_ADDRESS_PRECALCULATION_H */
\ No newline at end of file diff --git a/tests/validation/reference/InstanceNormalizationLayer.cpp b/tests/validation/reference/InstanceNormalizationLayer.cpp index 339549723d..8a5757bc78 100644 --- a/tests/validation/reference/InstanceNormalizationLayer.cpp +++ b/tests/validation/reference/InstanceNormalizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/InstanceNormalizationLayer.h b/tests/validation/reference/InstanceNormalizationLayer.h index 5c4ee6d3e6..5f9ea8b956 100644 --- a/tests/validation/reference/InstanceNormalizationLayer.h +++ b/tests/validation/reference/InstanceNormalizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/IntegralImage.cpp b/tests/validation/reference/IntegralImage.cpp deleted file mode 100644 index 8d07e995b5..0000000000 --- a/tests/validation/reference/IntegralImage.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "IntegralImage.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> integral_image(const SimpleTensor<T> &src) -{ - SimpleTensor<uint32_t> dst(src.shape(), DataType::U32); - - // Length of dimensions - const size_t width = src.shape().x(); - const size_t height = src.shape().y(); - const size_t depth = src.shape().total_size_upper(2); - - const size_t image_size = width * height; - - for(size_t z = 0; z < depth; ++z) - { - size_t current_image = z * image_size; - - //First element of each image - dst[current_image] = src[current_image]; - - // First row of each image (add only pixel on the left) - for(size_t x = 1; x < width; ++x) - { - dst[current_image + x] = static_cast<uint32_t>(src[current_image + x]) + dst[current_image + x - 1]; - } - - // Subsequent rows - for(size_t y = 1; y < height; ++y) - { - size_t current_row = current_image + (width * y); - - // First element of each row (add only pixel up) - dst[current_row] = static_cast<uint32_t>(src[current_row]) + dst[current_row - width]; - - // Following row elements - for(size_t x = 1; x < width; ++x) - { - size_t current_pixel = current_row + x; - - // out = in + up(out) + left(out) - up_left(out) - dst[current_pixel] = static_cast<uint32_t>(src[current_pixel]) + dst[current_pixel - 1] - + dst[current_pixel - width] - dst[current_pixel - width - 1]; - } - } - } - - return dst; -} - -template SimpleTensor<uint32_t> integral_image(const SimpleTensor<uint8_t> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/IntegralImage.h b/tests/validation/reference/IntegralImage.h deleted file mode 100644 index 0d2314c46a..0000000000 --- a/tests/validation/reference/IntegralImage.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H -#define ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint32_t> integral_image(const SimpleTensor<T> &src); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_INTEGRAL_IMAGE_H */ diff --git a/tests/validation/reference/L2NormalizeLayer.cpp b/tests/validation/reference/L2NormalizeLayer.cpp index 43885b29e2..265820d35a 100644 --- a/tests/validation/reference/L2NormalizeLayer.cpp +++ b/tests/validation/reference/L2NormalizeLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/L2NormalizeLayer.h b/tests/validation/reference/L2NormalizeLayer.h index 41817c83bd..29af6cc441 100644 --- a/tests/validation/reference/L2NormalizeLayer.h +++ b/tests/validation/reference/L2NormalizeLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/LaplacianPyramid.cpp b/tests/validation/reference/LaplacianPyramid.cpp deleted file mode 100644 index 21ddc1e48e..0000000000 --- a/tests/validation/reference/LaplacianPyramid.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "LaplacianPyramid.h" - -#include "tests/validation/reference/ArithmeticOperations.h" -#include "tests/validation/reference/DepthConvertLayer.h" -#include "tests/validation/reference/Gaussian5x5.h" -#include "tests/validation/reference/GaussianPyramidHalf.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::vector<SimpleTensor<U>> laplacian_pyramid(const SimpleTensor<T> &src, SimpleTensor<U> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value) -{ - std::vector<SimpleTensor<T>> pyramid_conv; - std::vector<SimpleTensor<U>> pyramid_dst; - - // First, a Gaussian pyramid with SCALE_PYRAMID_HALF is created - std::vector<SimpleTensor<T>> gaussian_level_pyramid = reference::gaussian_pyramid_half(src, border_mode, constant_border_value, num_levels); - - // For each level i, the corresponding image Ii is blurred with Gaussian 5x5 - // filter, and the difference between the two images is the corresponding - // level Li of the Laplacian pyramid - for(size_t i = 0; i < num_levels; ++i) - { - const SimpleTensor<T> level_filtered = reference::gaussian5x5(gaussian_level_pyramid[i], border_mode, constant_border_value); - pyramid_conv.push_back(level_filtered); - - const SimpleTensor<U> level_filtered_converted = depth_convert<T, U>(level_filtered, DataType::S16, ConvertPolicy::WRAP, 0); - const SimpleTensor<U> gaussian_level_converted = depth_convert<T, U>(gaussian_level_pyramid[i], DataType::S16, ConvertPolicy::WRAP, 0); - - const SimpleTensor<U> level_sub = reference::arithmetic_operation<U>(reference::ArithmeticOperation::SUB, gaussian_level_converted, level_filtered_converted, dst.data_type(), ConvertPolicy::WRAP); - pyramid_dst.push_back(level_sub); - } - - // Return the lowest resolution image and the pyramid - dst = depth_convert<T, U>(pyramid_conv[num_levels - 1], DataType::S16, ConvertPolicy::WRAP, 0); - - return pyramid_dst; -} - -template std::vector<SimpleTensor<int16_t>> laplacian_pyramid(const SimpleTensor<uint8_t> &src, SimpleTensor<int16_t> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/LaplacianPyramid.h b/tests/validation/reference/LaplacianPyramid.h deleted file mode 100644 index d9f4ef0294..0000000000 --- a/tests/validation/reference/LaplacianPyramid.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H -#define ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::vector<SimpleTensor<U>> laplacian_pyramid(const SimpleTensor<T> &src, SimpleTensor<U> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H */ diff --git a/tests/validation/reference/LaplacianReconstruct.cpp b/tests/validation/reference/LaplacianReconstruct.cpp deleted file mode 100644 index ef14355bc8..0000000000 --- a/tests/validation/reference/LaplacianReconstruct.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "LaplacianReconstruct.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/reference/ArithmeticOperations.h" -#include "tests/validation/reference/DepthConvertLayer.h" -#include "tests/validation/reference/Scale.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -SimpleTensor<U> laplacian_reconstruct(const std::vector<SimpleTensor<T>> &pyramid, const SimpleTensor<T> &low_res, BorderMode border_mode, T constant_border_value) -{ - std::vector<SimpleTensor<T>> tmp_pyramid(pyramid); - - const size_t last_level = pyramid.size() - 1; - const DataType data_type = low_res.data_type(); - - // input + L(n-1) - tmp_pyramid[last_level] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, low_res, pyramid[last_level], data_type, ConvertPolicy::SATURATE); - - // Scale levels n-1 to 1, and add levels n-2 to 0 - for(size_t i = last_level; i-- > 0;) - { - const float scale_x = static_cast<float>(tmp_pyramid[i].shape().x()) / tmp_pyramid[i + 1].shape().x(); - const float scale_y = static_cast<float>(tmp_pyramid[i].shape().y()) / tmp_pyramid[i + 1].shape().y(); - - tmp_pyramid[i] = reference::scale(tmp_pyramid[i + 1], scale_x, scale_y, InterpolationPolicy::NEAREST_NEIGHBOR, - border_mode, constant_border_value, SamplingPolicy::CENTER, false); - - tmp_pyramid[i] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, tmp_pyramid[i], pyramid[i], data_type, ConvertPolicy::SATURATE); - } - - return reference::depth_convert<T, U>(tmp_pyramid[0], DataType::U8, ConvertPolicy::SATURATE, 0); -} - -template SimpleTensor<uint8_t> laplacian_reconstruct(const std::vector<SimpleTensor<int16_t>> &pyramid, const SimpleTensor<int16_t> &low_res, BorderMode border_mode, int16_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/LaplacianReconstruct.h b/tests/validation/reference/LaplacianReconstruct.h deleted file mode 100644 index 24efc1bf8c..0000000000 --- a/tests/validation/reference/LaplacianReconstruct.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_H -#define ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -SimpleTensor<U> laplacian_reconstruct(const std::vector<SimpleTensor<T>> &pyramid, const SimpleTensor<T> &low_res, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_H */ diff --git a/tests/validation/reference/LocallyConnected.cpp b/tests/validation/reference/LocallyConnected.cpp deleted file mode 100644 index ecc582b181..0000000000 --- a/tests/validation/reference/LocallyConnected.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "LocallyConnected.h" - -#include "tests/validation/Helpers.h" -#include "tests/validation/reference/Convolution3d.h" -#include "tests/validation/reference/Utils.h" - -#include "tests/framework/Asserts.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename TB> -SimpleTensor<T> locally_connected(const SimpleTensor<T> &src, const SimpleTensor<T> &weights, const SimpleTensor<TB> &bias, const TensorShape &output_shape, const PadStrideInfo &info) -{ - // Create reference - SimpleTensor<T> dst{ output_shape, src.data_type(), 1, src.quantization_info() }; - - // Compute reference - const int width_in = src.shape().x(); - const int height_in = src.shape().y(); - const int depth_in = src.shape().z(); - - const int width_out = dst.shape().x(); - const int height_out = dst.shape().y(); - const int depth_out = dst.shape().z(); - - const int width_weights = weights.shape().x(); - const int height_weights = weights.shape().y(); - const int depth_weights = weights.shape().z(); - - const int pad_left = info.pad_left(); - const int pad_top = info.pad_top(); - const int stride_xi = info.stride().first; - const int stride_yi = info.stride().second; - - auto output_wh = scaled_dimensions(width_in, height_in, width_weights, height_weights, info); - - const int start_xi = width_weights / 2 - pad_left; - const int start_yi = height_weights / 2 - pad_top; - const int end_xi = output_wh.first * stride_xi; - const int end_yi = output_wh.second * stride_yi; - const int num_batches = src.shape().total_size() / (width_in * height_in * depth_in); - - for(int r = 0; r < num_batches; ++r) - { - int count = 0; - for(int yi = start_yi; yi < start_yi + end_yi; yi += stride_yi) - { - for(int xi = start_xi; xi < start_xi + end_xi; xi += stride_xi) - { - for(int ofm = 0; ofm < depth_out; ++ofm) - { - // Compute input and output offsets - const int offset_in = r * width_in * height_in * depth_in; - const int xo = (xi - start_xi) / stride_xi; - const int yo = (yi - start_yi) / stride_yi; - const int offset_out = xo + yo * width_out + ofm * width_out * height_out + r * width_out * height_out * depth_out; - - ARM_COMPUTE_ASSERT(xo < width_out); - ARM_COMPUTE_ASSERT(yo < height_out); - - // Compute 3D convolution - convolution_3d::detail::convolution3d(src, weights, bias, dst, - offset_in, count * width_weights * height_weights * depth_weights, count, offset_out, - xi, yi, - width_in, height_in, depth_in, - width_weights, height_weights); - count++; - } - } - } - } - - return dst; -} - -// Locally Connected only supports F32 -template SimpleTensor<float> locally_connected(const SimpleTensor<float> &src, const SimpleTensor<float> &weights, const SimpleTensor<float> &bias, const TensorShape &output_shape, - const PadStrideInfo &info); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/LogSoftmaxLayer.cpp b/tests/validation/reference/LogSoftmaxLayer.cpp deleted file mode 100644 index edb208e6ae..0000000000 --- a/tests/validation/reference/LogSoftmaxLayer.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2019-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "LogSoftmaxLayer.h" -#include "SoftmaxLayer.h" - -#include "arm_compute/core/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> log_softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis) -{ - return softmax_layer_generic<T>(src, beta, axis, true); -} - -template < typename T, typename std::enable_if < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int >::type > -SimpleTensor<T> log_softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis) -{ - const QuantizationInfo output_quantization_info = arm_compute::get_softmax_output_quantization_info(src.data_type(), true); - - SimpleTensor<float> src_tmp = convert_from_asymmetric(src); - SimpleTensor<float> dst_tmp = log_softmax_layer<float>(src_tmp, beta, axis); - SimpleTensor<T> dst = convert_to_asymmetric<T>(dst_tmp, output_quantization_info); - return dst; -} - -template SimpleTensor<float> log_softmax_layer(const SimpleTensor<float> &src, float beta, int32_t axis); -template SimpleTensor<half> log_softmax_layer(const SimpleTensor<half> &src, float beta, int32_t axis); -template SimpleTensor<uint8_t> log_softmax_layer(const SimpleTensor<uint8_t> &src, float beta, int32_t axis); -template SimpleTensor<int8_t> log_softmax_layer(const SimpleTensor<int8_t> &src, float beta, int32_t axis); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/LogSoftmaxLayer.h b/tests/validation/reference/LogSoftmaxLayer.h deleted file mode 100644 index 48ffdcfbcc..0000000000 --- a/tests/validation/reference/LogSoftmaxLayer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2019-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_LOG_SOFTMAX_LAYER_H -#define ARM_COMPUTE_TEST_LOG_SOFTMAX_LAYER_H - -#include "tests/SimpleTensor.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> -SimpleTensor<T> log_softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis = -1); - -template < typename T, typename std::enable_if < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int >::type = 0 > -SimpleTensor<T> log_softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis = -1); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_SOFTMAX_LAYER_H */ diff --git a/tests/validation/reference/Logical.cpp b/tests/validation/reference/Logical.cpp new file mode 100644 index 0000000000..aab57d9118 --- /dev/null +++ b/tests/validation/reference/Logical.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2020-2021 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "tests/validation/reference/Logical.h" +#include "src/core/KernelTypes.h" +#include "tests/framework/Asserts.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +T logical_binary_op(arm_compute::LogicalOperation op, T src1, T src2) +{ + switch(op) + { + case arm_compute::LogicalOperation::And: + return src1 && src2; + case arm_compute::LogicalOperation::Or: + return src1 || src2; + // The following operators are either invalid or not binary operator + case arm_compute::LogicalOperation::Not: + // fall through + case arm_compute::LogicalOperation::Unknown: + // fall through + default: + ARM_COMPUTE_ASSERT(true); + } + return T{}; +} + +template <size_t dim> +struct BroadcastUnroll +{ + template <typename T> + static void unroll(arm_compute::LogicalOperation op, const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, SimpleTensor<T> &dst, + Coordinates &id_src1, Coordinates &id_src2, Coordinates &id_dst) + { + const bool src1_is_broadcast = (src1.shape()[dim - 1] != dst.shape()[dim - 1]); + const bool src2_is_broadcast = (src2.shape()[dim - 1] != dst.shape()[dim - 1]); + + id_src1.set(dim - 1, 0); + id_src2.set(dim - 1, 0); + id_dst.set(dim - 1, 0); +#if defined(_OPENMP) + #pragma omp parallel for +#endif /* _OPENMP */ + for(size_t i = 0; i < dst.shape()[dim - 1]; ++i) + { + BroadcastUnroll < dim - 1 >::unroll(op, src1, src2, dst, id_src1, id_src2, id_dst); + + id_src1[dim - 1] += !src1_is_broadcast; + id_src2[dim - 1] += !src2_is_broadcast; + ++id_dst[dim - 1]; + } + } +}; + +template <> +struct BroadcastUnroll<0> +{ + template <typename T> + static void unroll(arm_compute::LogicalOperation op, const SimpleTensor<T> &src1, const SimpleTensor<T> &src2, SimpleTensor<T> &dst, + Coordinates &id_src1, Coordinates &id_src2, Coordinates &id_dst) + { + dst[coord2index(dst.shape(), id_dst)] = logical_binary_op(op, src1[coord2index(src1.shape(), id_src1)], src2[coord2index(src2.shape(), id_src2)]); + } +}; + +template <typename T> +SimpleTensor<T> logical_or(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2) +{ + Coordinates id_src1{}; + Coordinates id_src2{}; + Coordinates id_dst{}; + SimpleTensor<T> dst{ TensorShape::broadcast_shape(src1.shape(), src2.shape()), src1.data_type() }; + + BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(arm_compute::LogicalOperation::Or, src1, src2, dst, id_src1, id_src2, id_dst); + + return dst; +} + +template <typename T> +SimpleTensor<T> logical_and(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2) +{ + Coordinates id_src1{}; + Coordinates id_src2{}; + Coordinates id_dst{}; + SimpleTensor<T> dst{ TensorShape::broadcast_shape(src1.shape(), src2.shape()), src1.data_type() }; + + BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(arm_compute::LogicalOperation::And, src1, src2, dst, id_src1, id_src2, id_dst); + + return dst; +} + +template <typename T> +SimpleTensor<T> logical_not(const SimpleTensor<T> &src) +{ + SimpleTensor<T> dst(src.shape(), src.data_type()); +#if defined(_OPENMP) + #pragma omp parallel for +#endif /* _OPENMP */ + for(int i = 0; i < src.num_elements(); ++i) + { + dst[i] = !src[i]; + } + + return dst; +} + +template SimpleTensor<uint8_t> logical_or(const SimpleTensor<uint8_t> &src1, const SimpleTensor<uint8_t> &src2); +template SimpleTensor<uint8_t> logical_and(const SimpleTensor<uint8_t> &src1, const SimpleTensor<uint8_t> &src2); +template SimpleTensor<uint8_t> logical_not(const SimpleTensor<uint8_t> &src1); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Box3x3.h b/tests/validation/reference/Logical.h index 64820dc3c9..0d2bef9a43 100644 --- a/tests/validation/reference/Box3x3.h +++ b/tests/validation/reference/Logical.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_BOX3X3_H -#define ARM_COMPUTE_TEST_BOX3X3_H +#ifndef ARM_COMPUTE_TEST_LOGICAL_H +#define ARM_COMPUTE_TEST_LOGICAL_H #include "tests/SimpleTensor.h" @@ -35,9 +35,13 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> box3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); +SimpleTensor<T> logical_or(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2); +template <typename T> +SimpleTensor<T> logical_and(const SimpleTensor<T> &src1, const SimpleTensor<T> &src2); +template <typename T> +SimpleTensor<T> logical_not(const SimpleTensor<T> &src1); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_BOX3X3_H */ +#endif /* ARM_COMPUTE_TEST_LOGICAL_H */ diff --git a/tests/validation/reference/Magnitude.cpp b/tests/validation/reference/Magnitude.cpp deleted file mode 100644 index f0002bfb33..0000000000 --- a/tests/validation/reference/Magnitude.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Magnitude.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> magnitude(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, MagnitudeType magnitude_type) -{ - SimpleTensor<T> mag(gx.shape(), gx.data_type()); - - using intermediate_type = typename common_promoted_unsigned_type<T>::intermediate_type; - - for(int i = 0; i < gx.num_elements(); ++i) - { - double val = 0.f; - - if(magnitude_type == MagnitudeType::L1NORM) - { - val = static_cast<intermediate_type>(std::abs(gx[i])) + static_cast<intermediate_type>(std::abs(gy[i])); - } - else // MagnitudeType::L2NORM - { - // Note: kernel saturates to uint32_t instead of intermediate_type for S32 format - auto sum = static_cast<uint32_t>(gx[i] * gx[i]) + static_cast<uint32_t>(gy[i] * gy[i]); - val = std::sqrt(sum) + 0.5f; - } - - mag[i] = saturate_cast<T>(val); - } - - return mag; -} - -template SimpleTensor<int16_t> magnitude(const SimpleTensor<int16_t> &gx, const SimpleTensor<int16_t> &gy, MagnitudeType magnitude_type); -template SimpleTensor<int32_t> magnitude(const SimpleTensor<int32_t> &gx, const SimpleTensor<int32_t> &gy, MagnitudeType magnitude_type); -template SimpleTensor<half_float::half> magnitude(const SimpleTensor<half_float::half> &gx, const SimpleTensor<half_float::half> &gy, MagnitudeType magnitude_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Magnitude.h b/tests/validation/reference/Magnitude.h deleted file mode 100644 index 870ea28905..0000000000 --- a/tests/validation/reference/Magnitude.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_MAGNITUDE_H -#define ARM_COMPUTE_TEST_MAGNITUDE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> magnitude(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, MagnitudeType magnitude_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_MAGNITUDE_H */ diff --git a/tests/validation/reference/MaxUnpoolingLayer.cpp b/tests/validation/reference/MaxUnpoolingLayer.cpp new file mode 100644 index 0000000000..880018e99f --- /dev/null +++ b/tests/validation/reference/MaxUnpoolingLayer.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "MaxUnpoolingLayer.h" + +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +using namespace arm_compute::misc::shape_calculator; + +template <typename T> +SimpleTensor<T> max_unpooling_layer_internal(const SimpleTensor<T> &src, const PoolingLayerInfo &info, + const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> &indices, + TensorShape output_shape, DataLayout data_layout) +{ + ARM_COMPUTE_UNUSED(info); + ARM_COMPUTE_UNUSED(output_qinfo); + ARM_COMPUTE_UNUSED(data_layout); + // Create reference + SimpleTensor<T> dst{ output_shape, src.data_type(), 1 }; + ARM_COMPUTE_ERROR_ON(indices.shape().total_size() == 0); + std::fill_n(dst.data(), dst.num_elements(), 0); + const auto w_indices = static_cast<int>(indices.shape()[0]); + const auto h_indices = static_cast<int>(indices.shape()[1]); + const auto z_indices = static_cast<int>(indices.shape()[2]); + const auto b_indices = static_cast<int>(indices.shape()[3]); + const auto w_dst = static_cast<int>(dst.shape()[0]); + const auto h_dst = static_cast<int>(dst.shape()[1]); + const auto z_dst = static_cast<int>(dst.shape()[2]); + for(int b = 0; b < b_indices; ++b) + { + for(int r = 0; r < z_indices; ++r) + { + for(int h = 0; h < h_indices; ++h) + { + for(int w = 0; w < w_indices; ++w) + { + const uint32_t index_into_dst = indices[b * z_indices * h_indices * w_indices + r * h_indices * w_indices + h * w_indices + w]; + const auto input_val = src[b * z_indices * h_indices * w_indices + r * h_indices * w_indices + h * w_indices + w]; + auto *ptr = &dst[b * z_dst * h_dst * w_dst]; + ptr[index_into_dst] = input_val; + } + } + } + } + return dst; +} + +template <> +SimpleTensor<uint8_t> max_unpooling_layer<uint8_t>( + const SimpleTensor<uint8_t> &src, const PoolingLayerInfo &info, + const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> &indices, + TensorShape output_shape, DataLayout data_layout) + +{ + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp = max_unpooling_layer_internal<float>(src_tmp, info, output_qinfo, indices, output_shape, data_layout); + SimpleTensor<uint8_t> dst = convert_to_asymmetric<uint8_t>(dst_tmp, output_qinfo); + return dst; +} + +template <typename T> +SimpleTensor<T> max_unpooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info, + const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> &indices, + TensorShape output_shape, DataLayout data_layout) +{ + return max_unpooling_layer_internal<T>(src, info, output_qinfo, indices, output_shape, data_layout); +} + +template SimpleTensor<float> max_unpooling_layer(const SimpleTensor<float> &src, const PoolingLayerInfo &info, + const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> &indices, + TensorShape output_shape, DataLayout data_layout); +template SimpleTensor<half> max_unpooling_layer(const SimpleTensor<half> &src, const PoolingLayerInfo &info, + const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> &indices, + TensorShape output_shape, DataLayout data_layout); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ChannelCombine.h b/tests/validation/reference/MaxUnpoolingLayer.h index 7f870aa838..9b00a3a53a 100644 --- a/tests/validation/reference/ChannelCombine.h +++ b/tests/validation/reference/MaxUnpoolingLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,10 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_CHANNEL_COMBINE_H -#define ARM_COMPUTE_TEST_CHANNEL_COMBINE_H +#ifndef ARM_COMPUTE_TEST_MAXUNPOOLING_LAYER_H +#define ARM_COMPUTE_TEST_MAXUNPOOLING_LAYER_H #include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" namespace arm_compute { @@ -35,9 +36,11 @@ namespace validation namespace reference { template <typename T> -std::vector<SimpleTensor<T>> channel_combine(const TensorShape &shape, const std::vector<SimpleTensor<T>> &image_planes, Format format); +SimpleTensor<T> max_unpooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> &indices, + TensorShape output_shape, DataLayout data_layout = DataLayout::NCHW); + } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CHANNEL_COMBINE_H */ +#endif /* ARM_COMPUTE_TEST_MAXUNPOOLING_LAYER_H */ diff --git a/tests/validation/reference/MeanStdDev.cpp b/tests/validation/reference/MeanStdDev.cpp index f48fcb11d2..f6f5cb275b 100644 --- a/tests/validation/reference/MeanStdDev.cpp +++ b/tests/validation/reference/MeanStdDev.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/MeanStdDev.h b/tests/validation/reference/MeanStdDev.h index 96e04e953d..2552147f99 100644 --- a/tests/validation/reference/MeanStdDev.h +++ b/tests/validation/reference/MeanStdDev.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/MeanStdDevNormalizationLayer.cpp b/tests/validation/reference/MeanStdDevNormalizationLayer.cpp index c44c983888..a7c8a784d9 100644 --- a/tests/validation/reference/MeanStdDevNormalizationLayer.cpp +++ b/tests/validation/reference/MeanStdDevNormalizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019, 2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -63,6 +63,15 @@ SimpleTensor<T> mean_std_normalization_layer(const SimpleTensor<T> &src, float e return dst; } +template <> +SimpleTensor<uint8_t> mean_std_normalization_layer(const SimpleTensor<uint8_t> &src, float epsilon) +{ + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp = mean_std_normalization_layer<float>(src_tmp, epsilon); + SimpleTensor<uint8_t> dst = convert_to_asymmetric<uint8_t>(dst_tmp, src.quantization_info()); + return dst; +} + template SimpleTensor<float> mean_std_normalization_layer(const SimpleTensor<float> &src, float epsilon); template SimpleTensor<half> mean_std_normalization_layer(const SimpleTensor<half> &src, float epsilon); } // namespace reference diff --git a/tests/validation/reference/MeanStdDevNormalizationLayer.h b/tests/validation/reference/MeanStdDevNormalizationLayer.h index fb2d30bb0d..968cdc722e 100644 --- a/tests/validation/reference/MeanStdDevNormalizationLayer.h +++ b/tests/validation/reference/MeanStdDevNormalizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Median3x3.cpp b/tests/validation/reference/Median3x3.cpp deleted file mode 100644 index 314bbe38e6..0000000000 --- a/tests/validation/reference/Median3x3.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Helpers.h" - -#include "Median3x3.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -constexpr unsigned int filter_size = 3; /* Size of the kernel/filter in number of elements. */ -constexpr BorderSize border_size(filter_size / 2); /* Border size of the kernel/filter around its central element. */ -} // namespace - -template <typename T> -SimpleTensor<T> median3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - const int size_tot_filter = filter_size * filter_size; - const uint32_t num_elements = src.num_elements(); - - for(uint32_t src_idx = 0; src_idx < num_elements; ++src_idx) - { - std::array<T, size_tot_filter> filter_elems = { { 0 } }; - Coordinates id = index2coord(src.shape(), src_idx); - const int x = id.x(); - const int y = id.y(); - - for(int j = y - static_cast<int>(border_size.top), index = 0; j <= y + static_cast<int>(border_size.bottom); ++j) - { - for(int i = x - static_cast<int>(border_size.left); i <= x + static_cast<int>(border_size.right); ++i, ++index) - { - id.set(0, i); - id.set(1, j); - filter_elems[index] = tensor_elem_at(src, id, border_mode, constant_border_value); - } - } - std::sort(filter_elems.begin(), filter_elems.end()); - dst[src_idx] = filter_elems[size_tot_filter / 2]; - } - - return dst; -} - -template SimpleTensor<uint8_t> median3x3(const SimpleTensor<uint8_t> &src, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Median3x3.h b/tests/validation/reference/Median3x3.h deleted file mode 100644 index 2778269cd0..0000000000 --- a/tests/validation/reference/Median3x3.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_MEDIAN3X3_H -#define ARM_COMPUTE_TEST_MEDIAN3X3_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> median3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_MEDIAN3X3_H */ diff --git a/tests/validation/reference/MinMaxLocation.cpp b/tests/validation/reference/MinMaxLocation.cpp index 427adebc61..b8771ba3a5 100644 --- a/tests/validation/reference/MinMaxLocation.cpp +++ b/tests/validation/reference/MinMaxLocation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/MinMaxLocation.h b/tests/validation/reference/MinMaxLocation.h index 42ededfb58..d6ba932e61 100644 --- a/tests/validation/reference/MinMaxLocation.h +++ b/tests/validation/reference/MinMaxLocation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NonLinearFilter.cpp b/tests/validation/reference/NonLinearFilter.cpp deleted file mode 100644 index 72433ebe54..0000000000 --- a/tests/validation/reference/NonLinearFilter.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NonLinearFilter.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> non_linear_filter(const SimpleTensor<T> &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, - uint8_t constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - ARM_COMPUTE_ERROR_ON(pattern == MatrixPattern::OTHER && mask == nullptr); - ARM_COMPUTE_UNUSED(pattern); - - using intermediate_type = typename common_promoted_signed_type<T>::intermediate_type; - - const int sq_mask_size = mask_size * mask_size; - const int half_mask_size = mask_size / 2; - std::vector<intermediate_type> vals(sq_mask_size); - intermediate_type current_value = 0; - - const ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(half_mask_size)); - const uint32_t num_elements = src.num_elements(); - - for(uint32_t element_idx = 0, count = 0, index = 0; element_idx < num_elements; ++element_idx, count = 0, index = 0) - { - Coordinates id = index2coord(src.shape(), element_idx); - if(is_in_valid_region(valid_region, id)) - { - int idx = id.x(); - int idy = id.y(); - for(int y = idy - half_mask_size; y <= idy + half_mask_size; ++y) - { - for(int x = idx - half_mask_size; x <= idx + half_mask_size; ++x, ++index) - { - id.set(0, x); - id.set(1, y); - current_value = tensor_elem_at(src, id, border_mode, constant_border_value); - - if(mask[index] == 255) - { - vals[count] = static_cast<intermediate_type>(current_value); - ++count; - } - } - } - std::sort(vals.begin(), vals.begin() + count); - - ARM_COMPUTE_ERROR_ON(count == 0); - - switch(function) - { - case NonLinearFilterFunction::MIN: - dst[element_idx] = saturate_cast<T>(vals[0]); - break; - case NonLinearFilterFunction::MAX: - dst[element_idx] = saturate_cast<T>(vals[count - 1]); - break; - case NonLinearFilterFunction::MEDIAN: - dst[element_idx] = saturate_cast<T>(vals[count / 2]); - break; - default: - ARM_COMPUTE_ERROR("Unsupported NonLinearFilter function."); - } - } - } - - return dst; -} - -template SimpleTensor<uint8_t> non_linear_filter(const SimpleTensor<uint8_t> &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/NonLinearFilter.h b/tests/validation/reference/NonLinearFilter.h deleted file mode 100644 index 7f1c4fa7aa..0000000000 --- a/tests/validation/reference/NonLinearFilter.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_BITWISE_NOT_H -#define ARM_COMPUTE_TEST_BITWISE_NOT_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> non_linear_filter(const SimpleTensor<T> &src, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_BITWISE_NOT_H */ diff --git a/tests/validation/reference/NonMaxSuppression.cpp b/tests/validation/reference/NonMaxSuppression.cpp index 9a638ce042..0c76a3f16d 100644 --- a/tests/validation/reference/NonMaxSuppression.cpp +++ b/tests/validation/reference/NonMaxSuppression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 ARM Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NonMaxSuppression.h b/tests/validation/reference/NonMaxSuppression.h index ca63394a19..d0c9bf7b30 100644 --- a/tests/validation/reference/NonMaxSuppression.h +++ b/tests/validation/reference/NonMaxSuppression.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NonMaximaSuppression.cpp b/tests/validation/reference/NonMaximaSuppression.cpp index 45ce67f699..1132e65456 100644 --- a/tests/validation/reference/NonMaximaSuppression.cpp +++ b/tests/validation/reference/NonMaximaSuppression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NonMaximaSuppression.h b/tests/validation/reference/NonMaximaSuppression.h index f2ac95f33d..c5f8195ee0 100644 --- a/tests/validation/reference/NonMaximaSuppression.h +++ b/tests/validation/reference/NonMaximaSuppression.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NormalizationLayer.cpp b/tests/validation/reference/NormalizationLayer.cpp index d57e6f15a9..044a8b32ab 100644 --- a/tests/validation/reference/NormalizationLayer.cpp +++ b/tests/validation/reference/NormalizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NormalizationLayer.h b/tests/validation/reference/NormalizationLayer.h index ebdf765024..9d7bc57b23 100644 --- a/tests/validation/reference/NormalizationLayer.h +++ b/tests/validation/reference/NormalizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.cpp b/tests/validation/reference/NormalizePlanarYUVLayer.cpp index d2d29cc682..5e72e4a2e5 100644 --- a/tests/validation/reference/NormalizePlanarYUVLayer.cpp +++ b/tests/validation/reference/NormalizePlanarYUVLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.h b/tests/validation/reference/NormalizePlanarYUVLayer.h index f7420e9346..1a14e31130 100644 --- a/tests/validation/reference/NormalizePlanarYUVLayer.h +++ b/tests/validation/reference/NormalizePlanarYUVLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/OpticalFlow.cpp b/tests/validation/reference/OpticalFlow.cpp deleted file mode 100644 index da0b9f9f94..0000000000 --- a/tests/validation/reference/OpticalFlow.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (c) 2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "OpticalFlow.h" - -#include "GaussianPyramidHalf.h" -#include "Scharr.h" -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -using KeyPointArray = std::vector<KeyPoint>; -using InternalKeyPointArray = std::vector<InternalKeyPoint>; - -// Constants used for Lucas-Kanade Algorithm -constexpr int W_BITS = 14; -constexpr float D0 = 1 << W_BITS; -constexpr float DETERMINANT_THRESHOLD = 1.0e-07f; -constexpr float EIGENVALUE_THRESHOLD = 1.0e-04f; -constexpr float FLT_SCALE = 1.0f / (1 << 20); - -// Creates an InternalKeyPointArray for tracking non-integral pixel coordinates -InternalKeyPointArray create_internal_keypoints(const KeyPointArray &keypoints) -{ - InternalKeyPointArray internal_keypoints; - - for(auto keypoint : keypoints) - { - InternalKeyPoint internal_keypoint; - - internal_keypoint.x = static_cast<float>(keypoint.x); - internal_keypoint.y = static_cast<float>(keypoint.y); - internal_keypoint.tracking_status = static_cast<bool>(keypoint.tracking_status); - - internal_keypoints.push_back(internal_keypoint); - } - - return internal_keypoints; -} - -// Scale tracked points based on Pyramid level -void scale_tracked_points(size_t level, size_t num_levels, bool use_initial_estimate, - InternalKeyPointArray &old_points_internal, InternalKeyPointArray &new_points_internal, - const KeyPointArray &old_points, const KeyPointArray &new_points_estimates) -{ - if(level == num_levels - 1) // lowest resolution - { - const float scale = std::pow(SCALE_PYRAMID_HALF, level); - - for(size_t i = 0; i < old_points.size(); ++i) - { - old_points_internal.at(i).x = old_points.at(i).x * scale; - old_points_internal.at(i).y = old_points.at(i).y * scale; - old_points_internal.at(i).tracking_status = true; - - InternalKeyPoint keypoint_to_track; - - if(use_initial_estimate) - { - keypoint_to_track.x = new_points_estimates.at(i).x * scale; - keypoint_to_track.y = new_points_estimates.at(i).y * scale; - keypoint_to_track.tracking_status = (new_points_estimates.at(i).tracking_status == 1); - } - else - { - keypoint_to_track.x = old_points_internal.at(i).x; - keypoint_to_track.y = old_points_internal.at(i).y; - keypoint_to_track.tracking_status = true; - } - - new_points_internal.at(i) = keypoint_to_track; - } - } - else - { - for(size_t i = 0; i < old_points.size(); ++i) - { - old_points_internal.at(i).x /= SCALE_PYRAMID_HALF; - old_points_internal.at(i).y /= SCALE_PYRAMID_HALF; - new_points_internal.at(i).x /= SCALE_PYRAMID_HALF; - new_points_internal.at(i).y /= SCALE_PYRAMID_HALF; - } - } -} - -bool is_invalid_keypoint(const InternalKeyPoint &keypoint, const ValidRegion &valid_region, size_t window_dimension) -{ - const int half_window = window_dimension / 2; - const int x = std::floor(keypoint.x); - const int y = std::floor(keypoint.y); - - return (x - half_window < valid_region.start(0)) || (x + half_window >= valid_region.end(0) - 1) || (y - half_window < valid_region.start(1)) || (y + half_window >= valid_region.end(1) - 1); -} - -template <typename T> -constexpr int INT_ROUND(T x, int n) -{ - return (x + (1 << (n - 1))) >> n; -} - -// Return the bilinear value at a specified coordinate with different border modes -template <typename T> -int bilinear_interpolate(const SimpleTensor<T> &in, Coordinates id, float wx, float wy, BorderMode border_mode, T constant_border_value, int scale) -{ - const int level = id.x(); - const int idy = id.y(); - - const float dx = wx; - const float dy = wy; - const float dx_1 = 1.0f - dx; - const float dy_1 = 1.0f - dy; - - const T border_value = constant_border_value; - - id.set(0, level); - id.set(1, idy); - const T tl = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, level + 1); - id.set(1, idy); - const T tr = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, level); - id.set(1, idy + 1); - const T bl = tensor_elem_at(in, id, border_mode, border_value); - id.set(0, level + 1); - id.set(1, idy + 1); - const T br = tensor_elem_at(in, id, border_mode, border_value); - - // weights - const int w00 = roundf(dx_1 * dy_1 * D0); - const int w01 = roundf(dx * dy_1 * D0); - const int w10 = roundf(dx_1 * dy * D0); - const int w11 = D0 - w00 - w01 - w10; - - return static_cast<int>(INT_ROUND(tl * w00 + tr * w01 + bl * w10 + br * w11, scale)); -} - -template <typename T> -std::vector<int> compute_derivative(const SimpleTensor<T> &input, const InternalKeyPoint &keypoint, - BorderMode border_mode, uint8_t constant_border_value, size_t window_dimension, int scale) -{ - std::vector<int> bilinear_values; - - const int half_window = window_dimension / 2; - - float keypoint_int_x = 0; - float keypoint_int_y = 0; - - const float wx = std::modf(keypoint.x, &keypoint_int_x); - const float wy = std::modf(keypoint.y, &keypoint_int_y); - - Coordinates tl_window(static_cast<int>(keypoint_int_x) - half_window, static_cast<int>(keypoint_int_y) - half_window); - Coordinates br_window(static_cast<int>(keypoint_int_x) + half_window, static_cast<int>(keypoint_int_y) + half_window); - - for(int y = tl_window.y(); y <= br_window.y(); ++y) - { - for(int x = tl_window.x(); x <= br_window.x(); ++x) - { - bilinear_values.push_back(bilinear_interpolate(input, Coordinates(x, y), wx, wy, border_mode, static_cast<T>(constant_border_value), scale)); - } - } - - return bilinear_values; -} - -std::tuple<float, float, float> compute_spatial_gradient_matrix(const std::vector<int> &bilinear_ix, const std::vector<int> &bilinear_iy) -{ - ARM_COMPUTE_ERROR_ON(bilinear_ix.size() != bilinear_iy.size()); - - int iA11 = 0; - int iA12 = 0; - int iA22 = 0; - - for(size_t i = 0; i < bilinear_ix.size(); ++i) - { - int ixval = bilinear_ix[i]; - int iyval = bilinear_iy[i]; - - iA11 += ixval * ixval; - iA12 += ixval * iyval; - iA22 += iyval * iyval; - } - - return std::make_tuple(iA11 * FLT_SCALE, iA12 * FLT_SCALE, iA22 * FLT_SCALE); -} - -std::tuple<double, double> compute_temporal_gradient_vector(const std::vector<int> &bilinear_it_old, - const std::vector<int> &bilinear_it_new, - const std::vector<int> &bilinear_ix, - const std::vector<int> &bilinear_iy) -{ - ARM_COMPUTE_ERROR_ON(bilinear_ix.size() != bilinear_iy.size()); - ARM_COMPUTE_ERROR_ON(bilinear_it_old.size() != bilinear_it_new.size()); - - int ib1 = 0; - int ib2 = 0; - - for(size_t i = 0; i < bilinear_ix.size(); ++i) - { - int ixval = bilinear_ix[i]; - int iyval = bilinear_iy[i]; - int ival = bilinear_it_old[i]; - int jval = bilinear_it_new[i]; - - const int diff = jval - ival; - - ib1 += diff * ixval; - ib2 += diff * iyval; - } - - const double b1 = ib1 * FLT_SCALE; - const double b2 = ib2 * FLT_SCALE; - - return std::make_tuple(b1, b2); -} -} // namespace - -template <typename T> -std::vector<KeyPoint> optical_flow(const SimpleTensor<T> &old_input, const SimpleTensor<T> &new_input, - const OpticalFlowParameters ¶ms, size_t num_levels, - const std::vector<KeyPoint> &old_points, const std::vector<KeyPoint> &new_points_estimates, - BorderMode border_mode, uint8_t constant_border_value) -{ - const int filter_size = 3; // scharr filter size - const size_t max_iterations = 1000; // fixed by kernel - const size_t window_dimension = params.window_dimension; - const size_t num_iterations = (params.termination == Termination::TERM_CRITERIA_EPSILON) ? max_iterations : params.num_iterations; - - KeyPointArray new_points(old_points.size()); - - InternalKeyPointArray old_points_internal = create_internal_keypoints(old_points); - InternalKeyPointArray new_points_internal = create_internal_keypoints(new_points_estimates); - - SimpleTensor<int16_t> scharr_gx; - SimpleTensor<int16_t> scharr_gy; - - // Create pyramids - std::vector<SimpleTensor<T>> old_pyramid = gaussian_pyramid_half(old_input, border_mode, constant_border_value, num_levels); - std::vector<SimpleTensor<T>> new_pyramid = gaussian_pyramid_half(new_input, border_mode, constant_border_value, num_levels); - - // Iterate over each level of the pyramid - for(size_t idx = num_levels; idx > 0; --idx) - { - const size_t level = idx - 1; - - // Calculate scharr gradients - std::tie(scharr_gx, scharr_gy) = scharr<int16_t, T>(old_pyramid[level], filter_size, border_mode, constant_border_value, GradientDimension::GRAD_XY); - - scale_tracked_points(level, num_levels, params.use_initial_estimate, old_points_internal, new_points_internal, old_points, new_points_estimates); - - // Calculate valid region based on image dimensions of current pyramid level - const ValidRegion valid_region = shape_to_valid_region(old_pyramid[level].shape(), (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2)); - - for(size_t i = 0; i < old_points.size(); ++i) - { - InternalKeyPoint &old_keypoint = old_points_internal.at(i); - InternalKeyPoint &new_keypoint = new_points_internal.at(i); - - // Helper function for untracking keypoints when on the lowest pyramid level (high resolution) - const auto untrack_keypoint = [&](bool predicate) - { - if(predicate && (level == 0)) - { - new_keypoint.tracking_status = false; - return true; - } - return predicate; - }; - - if(!old_keypoint.tracking_status) - { - continue; - } - - // Check if tracked coordinate is outside image coordinate - if(untrack_keypoint(is_invalid_keypoint(old_keypoint, valid_region, window_dimension))) - { - continue; - } - - // Compute spatial derivative - std::vector<int> bilinear_ix = compute_derivative(scharr_gx, old_keypoint, border_mode, constant_border_value, window_dimension, W_BITS); - std::vector<int> bilinear_iy = compute_derivative(scharr_gy, old_keypoint, border_mode, constant_border_value, window_dimension, W_BITS); - - float A11 = 0.f; - float A12 = 0.f; - float A22 = 0.f; - std::tie(A11, A12, A22) = compute_spatial_gradient_matrix(bilinear_ix, bilinear_iy); - - // Calculate criteria for lost tracking : Matrix A is invertible - // 1. The determinant of the matrix is less than DETERMINANT_THRESHOLD - // 2. The minimum eigenvalue of the matrix is less than EIGENVALUE_THRESHOLD - const float trace_A = A11 + A22; - const float determinant = A11 * A22 - A12 * A12; - const float discriminant = (trace_A * trace_A) - 4.0f * (determinant); - const float eigenvalue_A = (trace_A - std::sqrt(discriminant)) / 2.0f; - - // Divide by window_dimension squared to reduce the floating point accummulation error - const float eigenvalue = eigenvalue_A / (window_dimension * window_dimension); - - // Check if it is a good point to track - if(untrack_keypoint(eigenvalue < EIGENVALUE_THRESHOLD || determinant < DETERMINANT_THRESHOLD)) - { - continue; - } - - float prev_delta_x = 0.f; - float prev_delta_y = 0.f; - - for(size_t j = 0; j < num_iterations; ++j) - { - // Check if tracked coordinate is outside image coordinate - if(untrack_keypoint(is_invalid_keypoint(new_keypoint, valid_region, window_dimension))) - { - break; - } - - // Compute temporal derivative - std::vector<int> bilinear_it_old = compute_derivative(old_pyramid[level], old_keypoint, border_mode, constant_border_value, window_dimension, W_BITS - 5); - std::vector<int> bilinear_it_new = compute_derivative(new_pyramid[level], new_keypoint, border_mode, constant_border_value, window_dimension, W_BITS - 5); - - double b1 = 0.f; - double b2 = 0.f; - std::tie(b1, b2) = compute_temporal_gradient_vector(bilinear_it_old, bilinear_it_new, bilinear_ix, bilinear_iy); - - // Compute motion vector -> A^-1 * -b - const float delta_x = (A12 * b2 - A22 * b1) / determinant; - const float delta_y = (A12 * b1 - A11 * b2) / determinant; - - // Update the new position - new_keypoint.x += delta_x; - new_keypoint.y += delta_y; - - const float magnitude_squared = delta_x * delta_x + delta_y * delta_y; - - // Check if termination criteria is EPSILON and if it is satisfied - if(magnitude_squared <= params.epsilon && (params.termination == Termination::TERM_CRITERIA_EPSILON || params.termination == Termination::TERM_CRITERIA_BOTH)) - { - break; - } - - // Check convergence analyzing the previous delta - if(j > 0 && (std::fabs(delta_x + prev_delta_x) < 0.01f && std::fabs(delta_y + prev_delta_y) < 0.01f)) - { - new_keypoint.x -= delta_x * SCALE_PYRAMID_HALF; - new_keypoint.y -= delta_y * SCALE_PYRAMID_HALF; - - break; - } - - prev_delta_x = delta_x; - prev_delta_y = delta_y; - } - } - } - - // Copy optical flow coordinates to output vector - for(size_t i = 0; i < old_points.size(); ++i) - { - const InternalKeyPoint &new_keypoint = new_points_internal.at(i); - - new_points.at(i).x = roundf(new_keypoint.x); - new_points.at(i).y = roundf(new_keypoint.y); - new_points.at(i).tracking_status = new_keypoint.tracking_status ? 1 : 0; - } - - return new_points; -} - -template std::vector<KeyPoint> optical_flow(const SimpleTensor<uint8_t> &old_input, const SimpleTensor<uint8_t> &new_input, - const OpticalFlowParameters ¶ms, size_t num_levels, - const std::vector<KeyPoint> &old_points, const std::vector<KeyPoint> &new_points_estimates, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/OpticalFlow.h b/tests/validation/reference/OpticalFlow.h deleted file mode 100644 index 42f2abe3d6..0000000000 --- a/tests/validation/reference/OpticalFlow.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_OPTICAL_FLOW_H -#define ARM_COMPUTE_TEST_OPTICAL_FLOW_H - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -#include <vector> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -std::vector<KeyPoint> optical_flow(const SimpleTensor<T> &old_input, const SimpleTensor<T> &new_input, - const OpticalFlowParameters ¶ms, size_t num_levels, - const std::vector<KeyPoint> &old_points, const std::vector<KeyPoint> &new_points_estimates, - BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_OPTICAL_FLOW_H */ diff --git a/tests/validation/reference/PadLayer.cpp b/tests/validation/reference/PadLayer.cpp index 182c16fb4e..f5ba33dd5d 100644 --- a/tests/validation/reference/PadLayer.cpp +++ b/tests/validation/reference/PadLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/PadLayer.h b/tests/validation/reference/PadLayer.h index 9b049d4866..1441dbe8eb 100644 --- a/tests/validation/reference/PadLayer.h +++ b/tests/validation/reference/PadLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Permute.cpp b/tests/validation/reference/Permute.cpp index 36b07dc277..7aa3011d8f 100644 --- a/tests/validation/reference/Permute.cpp +++ b/tests/validation/reference/Permute.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019,2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #include "Permute.h" #include "arm_compute/core/Types.h" + #include "tests/validation/Helpers.h" namespace arm_compute @@ -42,11 +43,11 @@ SimpleTensor<T> permute(const SimpleTensor<T> &src, PermutationVector perm) permute(dst_shape, perm); // Create reference - SimpleTensor<T> dst{ dst_shape, src.data_type(), src.num_channels(), src.quantization_info() }; + SimpleTensor<T> dst{dst_shape, src.data_type(), src.num_channels(), src.quantization_info()}; // Compute reference const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) + for (uint32_t i = 0; i < num_elements; ++i) { const Coordinates src_coords = index2coord(src.shape(), i); Coordinates dst_coords = src_coords; @@ -58,13 +59,14 @@ SimpleTensor<T> permute(const SimpleTensor<T> &src, PermutationVector perm) return dst; } -template SimpleTensor<int8_t> permute(const SimpleTensor<int8_t> &src, PermutationVector perm); -template SimpleTensor<uint8_t> permute(const SimpleTensor<uint8_t> &src, PermutationVector perm); -template SimpleTensor<int16_t> permute(const SimpleTensor<int16_t> &src, PermutationVector perm); +template SimpleTensor<int8_t> permute(const SimpleTensor<int8_t> &src, PermutationVector perm); +template SimpleTensor<uint8_t> permute(const SimpleTensor<uint8_t> &src, PermutationVector perm); +template SimpleTensor<int16_t> permute(const SimpleTensor<int16_t> &src, PermutationVector perm); template SimpleTensor<uint16_t> permute(const SimpleTensor<uint16_t> &src, PermutationVector perm); template SimpleTensor<uint32_t> permute(const SimpleTensor<uint32_t> &src, PermutationVector perm); -template SimpleTensor<float> permute(const SimpleTensor<float> &src, PermutationVector perm); -template SimpleTensor<half> permute(const SimpleTensor<half> &src, PermutationVector perm); +template SimpleTensor<float> permute(const SimpleTensor<float> &src, PermutationVector perm); +template SimpleTensor<half> permute(const SimpleTensor<half> &src, PermutationVector perm); +template SimpleTensor<bfloat16> permute(const SimpleTensor<bfloat16> &src, PermutationVector perm); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/Permute.h b/tests/validation/reference/Permute.h index 3de22b60a7..895c08c8a3 100644 --- a/tests/validation/reference/Permute.h +++ b/tests/validation/reference/Permute.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Phase.cpp b/tests/validation/reference/Phase.cpp deleted file mode 100644 index 7827cd2989..0000000000 --- a/tests/validation/reference/Phase.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Phase.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> phase(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, PhaseType phase_type) -{ - const float PI = std::atan(1) * 4; - SimpleTensor<uint8_t> phase(gx.shape(), DataType::U8); - - if(phase_type == PhaseType::UNSIGNED) // unsigned: map to [0-255) - { - for(int i = 0; i < gx.num_elements(); ++i) - { - float angle_deg = (std::atan2(float(gy[i]), float(gx[i])) / PI) * 180.0f; - phase[i] = (angle_deg < 0.0f) ? 180.f + angle_deg : angle_deg; - } - } - else // signed: map to [0-180) degrees - { - for(int i = 0; i < gx.num_elements(); ++i) - { - float angle_pi = std::atan2(gy[i], gx[i]) / PI; - angle_pi = (angle_pi < 0.0f) ? 2 + angle_pi : angle_pi; - phase[i] = lround(angle_pi * 128) & 0xFFu; - } - } - - return phase; -} - -template SimpleTensor<uint8_t> phase(const SimpleTensor<int16_t> &gx, const SimpleTensor<int16_t> &gy, PhaseType phase_type); -template SimpleTensor<uint8_t> phase(const SimpleTensor<int32_t> &gx, const SimpleTensor<int32_t> &gy, PhaseType phase_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Phase.h b/tests/validation/reference/Phase.h deleted file mode 100644 index 93845fc9eb..0000000000 --- a/tests/validation/reference/Phase.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_PHASE_H -#define ARM_COMPUTE_TEST_PHASE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<uint8_t> phase(const SimpleTensor<T> &gx, const SimpleTensor<T> &gy, PhaseType phase_type); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_PHASE_H */ diff --git a/tests/validation/reference/PixelWiseMultiplication.cpp b/tests/validation/reference/PixelWiseMultiplication.cpp index 3e21fca72a..0450991f61 100644 --- a/tests/validation/reference/PixelWiseMultiplication.cpp +++ b/tests/validation/reference/PixelWiseMultiplication.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -43,6 +43,8 @@ struct is_floating_point namespace { +constexpr float scale1_constant = 1.f; + /** Compute the result of `src1 * src2 * scale`. The result type always matches the type of @p src2. * * @param[in] src1 An input value. Data types supported: U8/S16/F16/F32. @@ -89,6 +91,90 @@ T3 mul(const T1 src1, const T2 src2, float scale, ConvertPolicy convert_policy, } } +template <> +int32_t mul(const int32_t src1, const int32_t src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) +{ + const int64_t intermediate_val = static_cast<int64_t>(src1) * static_cast<int64_t>(src2); + + if(std::abs(scale - scale1_constant) < 0.00001f) + { + // Use bit-accurate integer arithmetic for scale == 1 + // Apply conversion + if(convert_policy == ConvertPolicy::SATURATE) + { + return saturate_cast<int32_t>(intermediate_val); + } + else + { + // Correct wrapping behaviour for int32_t + const auto i32_hi = static_cast<int64_t>(std::numeric_limits<int32_t>::max()); + const auto i32_lo = static_cast<int64_t>(std::numeric_limits<int32_t>::lowest()); + const auto i32_wi = static_cast<int64_t>(1) << 32; + int64_t wrapped_rounded_val = intermediate_val - i32_wi * static_cast<int64_t>(support::cpp11::trunc(static_cast<double>(intermediate_val) / i32_wi)); + if(wrapped_rounded_val <= i32_hi) + { + return static_cast<int32_t>(wrapped_rounded_val); + } + else + { + // Values beyond i32_hi wrap around to negatives + return static_cast<int32_t>((wrapped_rounded_val - i32_hi) + i32_lo - 1); + } + } + } + else + { + // Use double arithmetic for scale != 1; may not be bit-accurate + // Apply scaling + // scale == 1 / 2^scale_exponent + int scale_exponent = 0; + std::frexp(scale, &scale_exponent); + // Store the positive exponent. We know that we compute 1/2^n + // Additionally we need to subtract 1 to compensate that frexp used a mantissa of 0.5 + scale_exponent = std::abs(scale_exponent - 1); + const double scale_inv = static_cast<int64_t>(1) << scale_exponent; + const double val = intermediate_val / scale_inv; + // Apply rounding + double rounded_val = 0; + switch(rounding_policy) + { + case(RoundingPolicy::TO_ZERO): + rounded_val = support::cpp11::trunc(val); + break; + case(RoundingPolicy::TO_NEAREST_UP): + rounded_val = round_half_up(val); + break; + case(RoundingPolicy::TO_NEAREST_EVEN): + rounded_val = round_half_even(val); + break; + default: + ARM_COMPUTE_ERROR("Unsupported rounding policy"); + } + // Apply conversion + if(convert_policy == ConvertPolicy::SATURATE) + { + return saturate_cast<int32_t>(rounded_val); + } + else + { + // Correct wrapping behaviour for int32_t + const auto i32_hi = static_cast<double>(std::numeric_limits<int32_t>::max()); + const auto i32_lo = static_cast<double>(std::numeric_limits<int32_t>::lowest()); + const auto i32_wi = static_cast<double>(static_cast<int64_t>(1) << 32); + double wrapped_rounded_val = rounded_val - i32_wi * std::floor(rounded_val / i32_wi); + if(wrapped_rounded_val <= i32_hi) + { + return static_cast<int32_t>(wrapped_rounded_val); + } + else + { + // Values beyond i32_hi wrap around to negatives + return static_cast<int32_t>((wrapped_rounded_val - i32_hi) + i32_lo - 1); + } + } + } +} + template <size_t dim> struct BroadcastUnroll { @@ -178,6 +264,34 @@ SimpleTensor<uint8_t> pixel_wise_multiplication(const SimpleTensor<uint8_t> &src } template <> +SimpleTensor<int16_t> pixel_wise_multiplication(const SimpleTensor<uint8_t> &src1, const SimpleTensor<uint8_t> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, + DataType dt_out, const QuantizationInfo &qout) +{ + SimpleTensor<int16_t> dst(TensorShape::broadcast_shape(src1.shape(), src2.shape()), dt_out, 1, qout); + + if(src1.data_type() == DataType::QASYMM8 && src2.data_type() == DataType::QASYMM8) + { + SimpleTensor<float> src1_tmp = convert_from_asymmetric(src1); + SimpleTensor<float> src2_tmp = convert_from_asymmetric(src2); + SimpleTensor<float> dst_tmp = pixel_wise_multiplication<float, float, float>(src1_tmp, src2_tmp, scale, convert_policy, rounding_policy, DataType::F32, qout); + dst = convert_to_symmetric<int16_t>(dst_tmp, qout); + } + else + { + if(scale < 0) + { + ARM_COMPUTE_ERROR("Scale of pixel-wise multiplication must be non-negative"); + } + + Coordinates id_src1{}; + Coordinates id_src2{}; + Coordinates id_dst{}; + BroadcastUnroll<Coordinates::num_max_dimensions>::unroll(src1, src2, dst, scale, convert_policy, rounding_policy, id_src1, id_src2, id_dst); + } + return dst; +} + +template <> SimpleTensor<int8_t> pixel_wise_multiplication(const SimpleTensor<int8_t> &src1, const SimpleTensor<int8_t> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, DataType dt_out, const QuantizationInfo &qout) { @@ -236,6 +350,7 @@ SimpleTensor<int16_t> pixel_wise_multiplication(const SimpleTensor<int16_t> &src // clang-format off template SimpleTensor<int16_t> pixel_wise_multiplication(const SimpleTensor<uint8_t> &src1, const SimpleTensor<int16_t> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, DataType dt_out, const QuantizationInfo &qout); template SimpleTensor<int32_t> pixel_wise_multiplication(const SimpleTensor<int16_t> &src1, const SimpleTensor<int16_t> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, DataType dt_out, const QuantizationInfo &qout); +template SimpleTensor<int32_t> pixel_wise_multiplication(const SimpleTensor<int32_t> &src1, const SimpleTensor<int32_t> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, DataType dt_out, const QuantizationInfo &qout); template SimpleTensor<float> pixel_wise_multiplication(const SimpleTensor<float> &src1, const SimpleTensor<float> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, DataType dt_out, const QuantizationInfo &qout); template SimpleTensor<half_float::half> pixel_wise_multiplication(const SimpleTensor<half_float::half> &src1, const SimpleTensor<half_float::half> &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, DataType dt_out, const QuantizationInfo &qout); // clang-format on diff --git a/tests/validation/reference/PixelWiseMultiplication.h b/tests/validation/reference/PixelWiseMultiplication.h index f8afa0384b..d61e6c7ba8 100644 --- a/tests/validation/reference/PixelWiseMultiplication.h +++ b/tests/validation/reference/PixelWiseMultiplication.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Pooling3dLayer.cpp b/tests/validation/reference/Pooling3dLayer.cpp new file mode 100644 index 0000000000..2e8f3a0b92 --- /dev/null +++ b/tests/validation/reference/Pooling3dLayer.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "Pooling3dLayer.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +using namespace arm_compute::misc::shape_calculator; + +template <typename T> +SimpleTensor<T> pooling_3d_layer_internal(const SimpleTensor<T> &src, const Pooling3dLayerInfo &pool3d_info, SimpleTensor<uint32_t> *indices) +{ + TensorShape pooled_shape = compute_pool3d_shape(src.shape(), pool3d_info); + SimpleTensor<T> dst{ pooled_shape, src.data_type(), 1 }; + + if(indices != nullptr) + { + *indices = SimpleTensor<uint32_t> { pooled_shape, DataType::U32, 1 }; + } + + const int idx_channel = 0; + const int idx_width = 1; + const int idx_height = 2; + const int idx_depth = 3; + const int idx_batch = 4; + + const int pool_size_width = pool3d_info.is_global_pooling ? src.shape()[idx_width] : pool3d_info.pool_size.width; + const int pool_size_height = pool3d_info.is_global_pooling ? src.shape()[idx_height] : pool3d_info.pool_size.height; + const int pool_size_depth = pool3d_info.is_global_pooling ? src.shape()[idx_depth] : pool3d_info.pool_size.depth; + + const int pool_stride_width = static_cast<int>(pool3d_info.stride.width); + const int pool_stride_height = static_cast<int>(pool3d_info.stride.height); + const int pool_stride_depth = static_cast<int>(pool3d_info.stride.depth); + + const int pad_left = static_cast<int>(pool3d_info.padding.left); + const int pad_top = static_cast<int>(pool3d_info.padding.top); + const int pad_front = static_cast<int>(pool3d_info.padding.front); + + const int pad_right = static_cast<int>(pool3d_info.padding.right); + const int pad_bottom = static_cast<int>(pool3d_info.padding.bottom); + const int pad_back = static_cast<int>(pool3d_info.padding.back); + + const int num_channels = static_cast<int>(src.shape()[idx_channel]); + const int num_batches = static_cast<int>(src.shape()[idx_batch]); + + ARM_COMPUTE_ERROR_ON(num_channels != static_cast<int>(dst.shape()[idx_channel])); + ARM_COMPUTE_ERROR_ON(num_batches != static_cast<int>(dst.shape()[idx_batch])); + + const int w_src = static_cast<int>(src.shape()[idx_width]); + const int h_src = static_cast<int>(src.shape()[idx_height]); + const int d_src = static_cast<int>(src.shape()[idx_depth]); + const int w_dst = static_cast<int>(dst.shape()[idx_width]); + const int h_dst = static_cast<int>(dst.shape()[idx_height]); + const int d_dst = static_cast<int>(dst.shape()[idx_depth]); + + const bool exclude_padding = pool3d_info.exclude_padding; + + const int height_stride_src = num_channels * w_src; + const int depth_stride_src = height_stride_src * h_src; + const int batch_stride_src = depth_stride_src * d_src; + const int height_stride_dst = num_channels * w_dst; + const int depth_stride_dst = height_stride_dst * h_dst; + const int batch_stride_dst = depth_stride_dst * d_dst; + + for(int b = 0; b < num_batches; ++b) + { + const int batch_offset_dst = b * batch_stride_dst; + const int batch_offset_src = b * batch_stride_src; + for(int c = 0; c < num_channels; ++c) + { + for(int d = 0; d < d_dst; ++d) + { + const int depth_offset_dst = d * depth_stride_dst; + for(int h = 0; h < h_dst; ++h) + { + const int height_offset_dst = h * height_stride_dst; + for(int w = 0; w < w_dst; ++w) + { + int wstart = w * pool_stride_width - pad_left; + int hstart = h * pool_stride_height - pad_top; + int dstart = d * pool_stride_depth - pad_front; + int wend = std::min(wstart + pool_size_width, w_src + pad_right); + int hend = std::min(hstart + pool_size_height, h_src + pad_bottom); + int dend = std::min(dstart + pool_size_depth, d_src + pad_back); + + // this may not be equal to pool_w * pool_h * pool_d because of + // DimensionRoundingType choice (CEIL) + int pool_size = (dend - dstart) * (hend - hstart) * (wend - wstart); + + // limit [start, end) to [0, w_src) + wstart = std::max(wstart, 0); + hstart = std::max(hstart, 0); + dstart = std::max(dstart, 0); + wend = std::min(wend, w_src); + hend = std::min(hend, h_src); + dend = std::min(dend, d_src); + + auto max_val = -std::numeric_limits<T>::infinity(); + int max_index{ 0 }; + T avg_val = static_cast<T>(0.f); + T l2_val = static_cast<T>(0.f); + + if(exclude_padding) + { + pool_size = (dend - dstart) * (hend - hstart) * (wend - wstart); + } + + for(int z = dstart; z < dend; ++z) + { + const int depth_offset_src = z * depth_stride_src; + for(int y = hstart; y < hend; ++y) + { + const int height_offset_src = y * height_stride_src; + for(int x = wstart; x < wend; ++x) + { + const auto val = static_cast<T>( + src[batch_offset_src + depth_offset_src + height_offset_src + x * num_channels + c]); + if(val > max_val) + { + max_val = val; + max_index = coord2index(src.shape(), Coordinates(c, x, y, z, 0)); + } + + avg_val += val; + l2_val += val * val; + } + } + } + + avg_val /= pool_size; + l2_val = static_cast<T>(std::sqrt(l2_val / pool_size)); + + int dst_index = batch_offset_dst + depth_offset_dst + height_offset_dst + w * num_channels + c; + switch(pool3d_info.pool_type) + { + case PoolingType::MAX: + dst[dst_index] = static_cast<T>(max_val); + break; + case PoolingType::AVG: + dst[dst_index] = static_cast<T>(avg_val); + break; + case PoolingType::L2: + dst[dst_index] = static_cast<T>(l2_val); + break; + default: + ARM_COMPUTE_ERROR("Pooling Type should be either MAX, AVG or L2"); + } + + if(indices != nullptr) + { + (*indices)[dst_index] = max_index; + } + } + } + } + } + } + + return dst; +} + +template SimpleTensor<float> pooling_3d_layer(const SimpleTensor<float> &src, const Pooling3dLayerInfo &pool3d_info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices); +template SimpleTensor<half> pooling_3d_layer(const SimpleTensor<half> &src, const Pooling3dLayerInfo &pool3d_info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices); + +template <typename T> +SimpleTensor<T> pooling_3d_layer(const SimpleTensor<T> &src, const Pooling3dLayerInfo &pool3d_info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +{ + ARM_COMPUTE_UNUSED(output_qinfo); + return pooling_3d_layer_internal<T>(src, pool3d_info, indices); +} + +template <> +SimpleTensor<int8_t> pooling_3d_layer<int8_t>(const SimpleTensor<int8_t> &src, const Pooling3dLayerInfo &pool3d_info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +{ + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp = pooling_3d_layer_internal<float>(src_tmp, pool3d_info, indices); + return convert_to_asymmetric<int8_t>(dst_tmp, output_qinfo); +} + +template <> +SimpleTensor<uint8_t> pooling_3d_layer<uint8_t>(const SimpleTensor<uint8_t> &src, const Pooling3dLayerInfo &pool3d_info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +{ + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp = pooling_3d_layer_internal<float>(src_tmp, pool3d_info, indices); + return convert_to_asymmetric<uint8_t>(dst_tmp, output_qinfo); +} + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/HarrisCornerDetector.h b/tests/validation/reference/Pooling3dLayer.h index 590e9ff2fe..481a0d3024 100644 --- a/tests/validation/reference/HarrisCornerDetector.h +++ b/tests/validation/reference/Pooling3dLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,13 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H -#define ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H +#ifndef ARM_COMPUTE_TEST_POOL3D_LAYER_H +#define ARM_COMPUTE_TEST_POOL3D_LAYER_H +#include "Utils.h" #include "arm_compute/core/Types.h" #include "tests/SimpleTensor.h" - -#include <vector> +#include "tests/validation/Helpers.h" namespace arm_compute { @@ -38,11 +38,13 @@ namespace validation namespace reference { template <typename T> -std::vector<KeyPoint> harris_corner_detector(const SimpleTensor<T> &src, - float threshold, float min_dist, float sensitivity, int gradient_size, int block_size, - BorderMode border_mode, T constant_border_value = 0); +SimpleTensor<T> pooling_3d_layer_internal(const SimpleTensor<T> &src, const Pooling3dLayerInfo &pool3d_info, SimpleTensor<uint32_t> *indices = nullptr); + +template <typename T> +SimpleTensor<T> pooling_3d_layer(const SimpleTensor<T> &src, const Pooling3dLayerInfo &pool3d_info, const QuantizationInfo &output_qinfo = QuantizationInfo(), + SimpleTensor<uint32_t> *indices = nullptr); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HARRIS_CORNER_DETECTOR_H */ +#endif /* ARM_COMPUTE_TEST_POOL3D_LAYER_H */ diff --git a/tests/validation/reference/PoolingLayer.cpp b/tests/validation/reference/PoolingLayer.cpp index 778e28d7c1..bf7bd0c1df 100644 --- a/tests/validation/reference/PoolingLayer.cpp +++ b/tests/validation/reference/PoolingLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -40,12 +40,12 @@ using namespace arm_compute::misc::shape_calculator; template <typename T, typename ACC_T, typename std::enable_if<is_floating_point<T>::value, int>::type> SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices, DataLayout data_layout) { - ARM_COMPUTE_ERROR_ON(info.is_global_pooling && (src.shape().x() != src.shape().y())); // Create reference SimpleTensor<T> dst{ compute_pool_shape(TensorInfo(src.shape(), 1, src.data_type()), info), src.data_type(), 1 }; + auto pooled_shape = compute_pool_shape(TensorInfo(src.shape(), 1, src.data_type()), info); if(indices) { - *indices = SimpleTensor<uint32_t> { compute_pool_shape(TensorInfo(src.shape(), 1, src.data_type()), info), DataType::U32, 1 }; + *indices = SimpleTensor<uint32_t> { pooled_shape, DataType::U32, 1 }; } const int pool_size_x = info.is_global_pooling ? src.shape().x() : info.pool_size.width; const int pool_size_y = info.is_global_pooling ? src.shape().y() : info.pool_size.height; @@ -58,56 +58,70 @@ SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const Pooling int pad_bottom = info.pad_stride_info.pad_bottom(); bool exclude_padding = info.exclude_padding; - const auto w_src = static_cast<int>(src.shape()[0]); - const auto h_src = static_cast<int>(src.shape()[1]); - const int upper_dims = src.shape().total_size() / (w_src * h_src); + const auto w_src = static_cast<int>(src.shape()[0]); + const auto h_src = static_cast<int>(src.shape()[1]); + const auto z_src = static_cast<int>(src.shape()[2]); + const auto b_src = static_cast<int>(src.shape()[3]); + + const int upper_dims = src.shape().total_size() / (w_src * h_src); + + const auto w_dst = static_cast<int>(dst.shape()[0]); + const auto h_dst = static_cast<int>(dst.shape()[1]); + const auto z_dst = static_cast<int>(dst.shape()[2]); - const auto w_dst = static_cast<int>(dst.shape()[0]); - const auto h_dst = static_cast<int>(dst.shape()[1]); TensorShape shape_nhwc(src.shape()); permute(shape_nhwc, PermutationVector(2U, 0U, 1U)); - if(type == PoolingType::MAX) { - for(int r = 0; r < upper_dims; ++r) + for(int b = 0; b < b_src; ++b) { - for(int h = 0; h < h_dst; ++h) + for(int r = 0; r < z_src; ++r) { - for(int w = 0; w < w_dst; ++w) + for(int h = 0; h < h_dst; ++h) { - int wstart = w * pool_stride_x - pad_left; - int hstart = h * pool_stride_y - pad_top; - int wend = std::min(wstart + pool_size_x, w_src); - int hend = std::min(hstart + pool_size_y, h_src); - wstart = std::max(wstart, 0); - hstart = std::max(hstart, 0); - - auto max_val = std::numeric_limits<ACC_T>::lowest(); - int max_index{ 0 }; - for(int y = hstart; y < hend; ++y) + for(int w = 0; w < w_dst; ++w) { - for(int x = wstart; x < wend; ++x) + int wstart = w * pool_stride_x - pad_left; + int hstart = h * pool_stride_y - pad_top; + + // Used to calculate kernel indices + int kh_start = std::max(0, -hstart); + int kw_start = std::max(0, -wstart); + int max_ker_index{ 0 }; + + int wend = std::min(wstart + pool_size_x, w_src); + int hend = std::min(hstart + pool_size_y, h_src); + wstart = std::max(wstart, 0); + hstart = std::max(hstart, 0); + auto max_val = info.use_inf_as_limit ? -std::numeric_limits<ACC_T>::infinity() : std::numeric_limits<ACC_T>::lowest(); + int max_index{ 0 }; + + for(int y = hstart, kh = kh_start; y < hend; ++y, ++kh) { - const auto val = static_cast<ACC_T>(src[r * h_src * w_src + y * w_src + x]); - if(val > max_val) + for(int x = wstart, kw = kw_start; x < wend; ++x, ++kw) { - max_val = val; - if(data_layout == DataLayout::NCHW) + const auto val = static_cast<ACC_T>(src[b * z_src * h_src * w_src + r * h_src * w_src + y * w_src + x]); + if(val > max_val) { - max_index = coord2index(src.shape(), Coordinates(x, y, r)); - } - else - { - max_index = coord2index(shape_nhwc, Coordinates(r, x, y)); + max_val = val; + max_ker_index = pool_size_x * (kh) + (kw); + if(data_layout == DataLayout::NCHW) + { + max_index = coord2index(src.shape(), Coordinates(x, y, r, 0)); + } + else + { + max_index = coord2index(shape_nhwc, Coordinates(r, x, y, 0)); + } } } } - } - dst[r * h_dst * w_dst + h * w_dst + w] = static_cast<T>(max_val); - if(indices) - { - (*indices)[r * h_dst * w_dst + h * w_dst + w] = max_index; + dst[b * z_dst * h_dst * w_dst + r * h_dst * w_dst + h * w_dst + w] = static_cast<T>(max_val); + if(indices) + { + (*indices)[b * z_dst * h_dst * w_dst + r * h_dst * w_dst + h * w_dst + w] = (info.use_kernel_indices) ? max_ker_index : max_index; + } } } } @@ -164,7 +178,6 @@ SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const Pooling } } } - return dst; } @@ -209,7 +222,7 @@ SimpleTensor<half> pooling_layer(const SimpleTensor<half> &src, const PoolingLay return pooling_layer_internal<half, float>(src, info, indices, data_layout); } - return pooling_layer_internal<half>(src, info, indices); + return pooling_layer_internal<half>(src, info, indices, data_layout); } template SimpleTensor<float> pooling_layer(const SimpleTensor<float> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, DataLayout data_layout); diff --git a/tests/validation/reference/PoolingLayer.h b/tests/validation/reference/PoolingLayer.h index 346f1c0c9f..6ce8c846f6 100644 --- a/tests/validation/reference/PoolingLayer.h +++ b/tests/validation/reference/PoolingLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/PriorBoxLayer.cpp b/tests/validation/reference/PriorBoxLayer.cpp index 0fd4a8aa48..4745df87be 100644 --- a/tests/validation/reference/PriorBoxLayer.cpp +++ b/tests/validation/reference/PriorBoxLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/PriorBoxLayer.h b/tests/validation/reference/PriorBoxLayer.h index ee9ad05597..eea3a3a1e7 100644 --- a/tests/validation/reference/PriorBoxLayer.h +++ b/tests/validation/reference/PriorBoxLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/QLSTMLayerNormalization.cpp b/tests/validation/reference/QLSTMLayerNormalization.cpp index dd6517f81f..1a9bdc921e 100644 --- a/tests/validation/reference/QLSTMLayerNormalization.cpp +++ b/tests/validation/reference/QLSTMLayerNormalization.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 ARM Limited. + * Copyright (c) 2020-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -27,7 +27,7 @@ #include "MeanStdDevNormalizationLayer.h" #include "PixelWiseMultiplication.h" #include "arm_compute/core/utils/misc/Utility.h" -#include "src/core/utils/quantization/AsymmHelpers.cpp" +#include "arm_compute/core/utils/quantization/AsymmHelpers.h" namespace arm_compute { diff --git a/tests/validation/reference/QLSTMLayerNormalization.h b/tests/validation/reference/QLSTMLayerNormalization.h index c35aa2a867..f0514937d5 100644 --- a/tests/validation/reference/QLSTMLayerNormalization.h +++ b/tests/validation/reference/QLSTMLayerNormalization.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 ARM Limited. + * Copyright (c) 2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/QuantizationLayer.cpp b/tests/validation/reference/QuantizationLayer.cpp index a70523d7da..ad7ba7ac43 100644 --- a/tests/validation/reference/QuantizationLayer.cpp +++ b/tests/validation/reference/QuantizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2024 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/QuantizationLayer.h b/tests/validation/reference/QuantizationLayer.h index 08501b7e18..a8f1ac2a65 100644 --- a/tests/validation/reference/QuantizationLayer.h +++ b/tests/validation/reference/QuantizationLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ROIAlignLayer.cpp b/tests/validation/reference/ROIAlignLayer.cpp index 8b2cd21ca6..2c176de407 100644 --- a/tests/validation/reference/ROIAlignLayer.cpp +++ b/tests/validation/reference/ROIAlignLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -40,21 +40,20 @@ namespace reference namespace { /** Average pooling over an aligned window */ -template <typename T> -inline T roi_align_1x1(const T *input, TensorShape input_shape, - float region_start_x, - float bin_size_x, - int grid_size_x, - float region_end_x, - float region_start_y, - float bin_size_y, - int grid_size_y, - float region_end_y, - int pz) +inline float roi_align_1x1(const float *input, TensorShape input_shape, + float region_start_x, + float bin_size_x, + int grid_size_x, + float region_end_x, + float region_start_y, + float bin_size_y, + int grid_size_y, + float region_end_y, + int pz) { if((region_end_x <= region_start_x) || (region_end_y <= region_start_y)) { - return T(0); + return 0; } else { @@ -85,16 +84,16 @@ inline T roi_align_1x1(const T *input, TensorShape input_shape, const float w4 = ly * lx; const size_t idx1 = coord2index(input_shape, Coordinates(x_low, y_low, pz)); - T data1 = input[idx1]; + float data1 = input[idx1]; const size_t idx2 = coord2index(input_shape, Coordinates(x_high, y_low, pz)); - T data2 = input[idx2]; + float data2 = input[idx2]; const size_t idx3 = coord2index(input_shape, Coordinates(x_low, y_high, pz)); - T data3 = input[idx3]; + float data3 = input[idx3]; const size_t idx4 = coord2index(input_shape, Coordinates(x_high, y_high, pz)); - T data4 = input[idx4]; + float data4 = input[idx4]; avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4; } @@ -102,15 +101,22 @@ inline T roi_align_1x1(const T *input, TensorShape input_shape, avg /= grid_size_x * grid_size_y; - return T(avg); + return avg; } } -/** Clamp the value between lower and upper */ -template <typename T> -T clamp(T value, T lower, T upper) +template <typename TI, typename TO> +SimpleTensor<TO> float_converter(const SimpleTensor<TI> &tensor, DataType dst_dt) { - return std::max(lower, std::min(value, upper)); + SimpleTensor<TO> dst{ tensor.shape(), dst_dt, 1, QuantizationInfo(), tensor.data_layout() }; +#if defined(_OPENMP) + #pragma omp parallel for +#endif /* _OPENMP */ + for(int i = 0; i < tensor.num_elements(); ++i) + { + dst[i] = tensor[i]; + } + return dst; } SimpleTensor<float> convert_rois_from_asymmetric(SimpleTensor<uint16_t> rois) @@ -129,8 +135,9 @@ SimpleTensor<float> convert_rois_from_asymmetric(SimpleTensor<uint16_t> rois) return dst; } } // namespace -template <typename T, typename TRois> -SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<TRois> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo) + +template <> +SimpleTensor<float> roi_align_layer(const SimpleTensor<float> &src, const SimpleTensor<float> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo) { ARM_COMPUTE_UNUSED(output_qinfo); @@ -138,11 +145,11 @@ SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<T const size_t num_rois = rois.shape()[1]; DataType dst_data_type = src.data_type(); - const auto *rois_ptr = static_cast<const TRois *>(rois.data()); + const auto *rois_ptr = static_cast<const float *>(rois.data()); - TensorShape input_shape = src.shape(); - TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), src.shape()[2], num_rois); - SimpleTensor<T> dst(output_shape, dst_data_type); + TensorShape input_shape = src.shape(); + TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), src.shape()[2], num_rois); + SimpleTensor<float> dst(output_shape, dst_data_type); // Iterate over every pixel of the input image for(size_t px = 0; px < pool_info.pooled_width(); ++px) @@ -169,10 +176,10 @@ SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<T float region_end_x = (px + 1) * bin_size_x + roi_anchor_x; float region_end_y = (py + 1) * bin_size_y + roi_anchor_y; - region_start_x = clamp(region_start_x, 0.0f, float(input_shape[0])); - region_start_y = clamp(region_start_y, 0.0f, float(input_shape[1])); - region_end_x = clamp(region_end_x, 0.0f, float(input_shape[0])); - region_end_y = clamp(region_end_y, 0.0f, float(input_shape[1])); + region_start_x = utility::clamp(region_start_x, 0.0f, float(input_shape[0])); + region_start_y = utility::clamp(region_start_y, 0.0f, float(input_shape[1])); + region_end_x = utility::clamp(region_end_x, 0.0f, float(input_shape[0])); + region_end_y = utility::clamp(region_end_y, 0.0f, float(input_shape[1])); const int roi_bin_grid_x = (pool_info.sampling_ratio() > 0) ? pool_info.sampling_ratio() : int(ceil(bin_size_x)); const int roi_bin_grid_y = (pool_info.sampling_ratio() > 0) ? pool_info.sampling_ratio() : int(ceil(bin_size_y)); @@ -180,8 +187,8 @@ SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<T // Move input and output pointer across the fourth dimension const size_t input_stride_w = input_shape[0] * input_shape[1] * input_shape[2]; const size_t output_stride_w = output_shape[0] * output_shape[1] * output_shape[2]; - const T *input_ptr = src.data() + roi_batch * input_stride_w; - T *output_ptr = dst.data() + px + py * output_shape[0] + pw * output_stride_w; + const float *input_ptr = src.data() + roi_batch * input_stride_w; + float *output_ptr = dst.data() + px + py * output_shape[0] + pw * output_stride_w; for(int pz = 0; pz < int(input_shape[2]); ++pz) { @@ -202,8 +209,15 @@ SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<T return dst; } -template SimpleTensor<float> roi_align_layer(const SimpleTensor<float> &src, const SimpleTensor<float> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo); -template SimpleTensor<half> roi_align_layer(const SimpleTensor<half> &src, const SimpleTensor<half> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo); +template <> +SimpleTensor<half> roi_align_layer(const SimpleTensor<half> &src, const SimpleTensor<half> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo) +{ + SimpleTensor<float> src_tmp = float_converter<half, float>(src, DataType::F32); + SimpleTensor<float> rois_tmp = float_converter<half, float>(rois, DataType::F32); + SimpleTensor<float> dst_tmp = roi_align_layer<float, float>(src_tmp, rois_tmp, pool_info, output_qinfo); + SimpleTensor<half> dst = float_converter<float, half>(dst_tmp, DataType::F16); + return dst; +} template <> SimpleTensor<uint8_t> roi_align_layer(const SimpleTensor<uint8_t> &src, const SimpleTensor<uint16_t> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo) diff --git a/tests/validation/reference/ROIAlignLayer.h b/tests/validation/reference/ROIAlignLayer.h index f3fb51616f..bb4a49af80 100644 --- a/tests/validation/reference/ROIAlignLayer.h +++ b/tests/validation/reference/ROIAlignLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ROIPoolingLayer.cpp b/tests/validation/reference/ROIPoolingLayer.cpp new file mode 100644 index 0000000000..8dc3014763 --- /dev/null +++ b/tests/validation/reference/ROIPoolingLayer.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2021 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "ROIPoolingLayer.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "tests/validation/Helpers.h" +#include <algorithm> + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <> +SimpleTensor<float> roi_pool_layer(const SimpleTensor<float> &src, const SimpleTensor<uint16_t> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo) +{ + ARM_COMPUTE_UNUSED(output_qinfo); + + const size_t num_rois = rois.shape()[1]; + const size_t values_per_roi = rois.shape()[0]; + DataType output_data_type = src.data_type(); + + TensorShape input_shape = src.shape(); + TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), src.shape()[2], num_rois); + SimpleTensor<float> output(output_shape, output_data_type); + + const int pooled_w = pool_info.pooled_width(); + const int pooled_h = pool_info.pooled_height(); + const float spatial_scale = pool_info.spatial_scale(); + + // get sizes of x and y dimensions in src tensor + const int width = src.shape()[0]; + const int height = src.shape()[1]; + + // Move pointer across the fourth dimension + const size_t input_stride_w = input_shape[0] * input_shape[1] * input_shape[2]; + const size_t output_stride_w = output_shape[0] * output_shape[1] * output_shape[2]; + + const auto *rois_ptr = reinterpret_cast<const uint16_t *>(rois.data()); + + // Iterate through pixel width (X-Axis) + for(size_t pw = 0; pw < num_rois; ++pw) + { + const unsigned int roi_batch = rois_ptr[values_per_roi * pw]; + const auto x1 = rois_ptr[values_per_roi * pw + 1]; + const auto y1 = rois_ptr[values_per_roi * pw + 2]; + const auto x2 = rois_ptr[values_per_roi * pw + 3]; + const auto y2 = rois_ptr[values_per_roi * pw + 4]; + + //Iterate through pixel height (Y-Axis) + for(size_t fm = 0; fm < input_shape[2]; ++fm) + { + // Iterate through regions of interest index + for(size_t py = 0; py < pool_info.pooled_height(); ++py) + { + // Scale ROI + const int roi_anchor_x = support::cpp11::round(x1 * spatial_scale); + const int roi_anchor_y = support::cpp11::round(y1 * spatial_scale); + const int roi_width = std::max(support::cpp11::round((x2 - x1) * spatial_scale), 1.f); + const int roi_height = std::max(support::cpp11::round((y2 - y1) * spatial_scale), 1.f); + + // Iterate over feature map (Z axis) + for(size_t px = 0; px < pool_info.pooled_width(); ++px) + { + auto region_start_x = static_cast<int>(std::floor((static_cast<float>(px) / pooled_w) * roi_width)); + auto region_end_x = static_cast<int>(std::floor((static_cast<float>(px + 1) / pooled_w) * roi_width)); + auto region_start_y = static_cast<int>(std::floor((static_cast<float>(py) / pooled_h) * roi_height)); + auto region_end_y = static_cast<int>(std::floor((static_cast<float>(py + 1) / pooled_h) * roi_height)); + + region_start_x = std::min(std::max(region_start_x + roi_anchor_x, 0), width); + region_end_x = std::min(std::max(region_end_x + roi_anchor_x, 0), width); + region_start_y = std::min(std::max(region_start_y + roi_anchor_y, 0), height); + region_end_y = std::min(std::max(region_end_y + roi_anchor_y, 0), height); + + // Iterate through the pooling region + if((region_end_x <= region_start_x) || (region_end_y <= region_start_y)) + { + /* Assign element in tensor 'output' at coordinates px, py, fm, roi_indx, to 0 */ + auto out_ptr = output.data() + px + py * output_shape[0] + fm * output_shape[0] * output_shape[1] + pw * output_stride_w; + *out_ptr = 0; + } + else + { + float curr_max = -std::numeric_limits<float>::max(); + for(int j = region_start_y; j < region_end_y; ++j) + { + for(int i = region_start_x; i < region_end_x; ++i) + { + /* Retrieve element from input tensor at coordinates(i, j, fm, roi_batch) */ + float in_element = *(src.data() + i + j * input_shape[0] + fm * input_shape[0] * input_shape[1] + roi_batch * input_stride_w); + curr_max = std::max(in_element, curr_max); + } + } + + /* Assign element in tensor 'output' at coordinates px, py, fm, roi_indx, to curr_max */ + auto out_ptr = output.data() + px + py * output_shape[0] + fm * output_shape[0] * output_shape[1] + pw * output_stride_w; + *out_ptr = curr_max; + } + } + } + } + } + + return output; +} + +/* + Template genericised method to allow calling of roi_pooling_layer with quantized 8 bit datatype +*/ +template <> +SimpleTensor<uint8_t> roi_pool_layer(const SimpleTensor<uint8_t> &src, const SimpleTensor<uint16_t> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo) +{ + const SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + SimpleTensor<float> dst_tmp = roi_pool_layer<float>(src_tmp, rois, pool_info, output_qinfo); + SimpleTensor<uint8_t> dst = convert_to_asymmetric<uint8_t>(dst_tmp, output_qinfo); + return dst; +} + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute
\ No newline at end of file diff --git a/tests/validation/reference/UpsampleLayer.h b/tests/validation/reference/ROIPoolingLayer.h index 1aad44c79c..ddbaee2d5e 100644 --- a/tests/validation/reference/UpsampleLayer.h +++ b/tests/validation/reference/ROIPoolingLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,9 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_UPSAMPLE_LAYER_H -#define ARM_COMPUTE_TEST_UPSAMPLE_LAYER_H +#ifndef ARM_COMPUTE_TEST_ROIPOOLLAYER_H +#define ARM_COMPUTE_TEST_ROIPOOLLAYER_H +#include "arm_compute/core/Types.h" #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -36,10 +37,10 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> upsample_layer(const SimpleTensor<T> &src, - const Size2D &info, const InterpolationPolicy policy); +SimpleTensor<T> roi_pool_layer(const SimpleTensor<T> &src, const SimpleTensor<uint16_t> &rois, const ROIPoolingLayerInfo &pool_info, const QuantizationInfo &output_qinfo); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_UPSAMPLE_LAYER_H */ + +#endif /* ARM_COMPUTE_TEST_ROIPOOLLAYER_H */
\ No newline at end of file diff --git a/tests/validation/reference/Range.cpp b/tests/validation/reference/Range.cpp index ad1345425a..7d7dcbfe2f 100644 --- a/tests/validation/reference/Range.cpp +++ b/tests/validation/reference/Range.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Range.h b/tests/validation/reference/Range.h index d0f63c07f8..e361a32034 100644 --- a/tests/validation/reference/Range.h +++ b/tests/validation/reference/Range.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ReductionOperation.cpp b/tests/validation/reference/ReductionOperation.cpp index 68352cc645..c189bc2d47 100644 --- a/tests/validation/reference/ReductionOperation.cpp +++ b/tests/validation/reference/ReductionOperation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -22,7 +22,6 @@ * SOFTWARE. */ #include "ReductionOperation.h" - #include "tests/validation/Helpers.h" #include <algorithm> @@ -39,7 +38,7 @@ namespace reference namespace { template <typename T, typename OT> -OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, int stride) +OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, int stride, RoundingPolicy policy) { using type = typename std::remove_cv<OT>::type; T res; @@ -99,7 +98,14 @@ OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, in } if(op == ReductionOperation::MEAN_SUM && reduce_elements > 0) { - int_res /= reduce_elements; + // Only use rounding in aarch64 to be consistent with kernel +#ifdef __aarch64__ + // Divide in float format, then rounded to nearest and implicitly cast back to int + int_res = round(static_cast<float>(int_res) / static_cast<float>(reduce_elements), policy); +#else // defined(__aarch64__) + ARM_COMPUTE_UNUSED(policy); + int_res /= reduce_elements; // Legacy compatibility +#endif // __aarch64 } res = static_cast<type>(int_res); } @@ -175,12 +181,12 @@ OT reduce_operation_arg_min_max(const T *ptr, int reduce_elements, ReductionOper } // namespace template <typename T, typename OT> -SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) +SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type, RoundingPolicy policy) { // Create reference - const bool is_arg_min_max = (op == ReductionOperation::ARG_IDX_MIN || op == ReductionOperation::ARG_IDX_MAX); - DataType output_data_type = is_arg_min_max ? DataType::S32 : src.data_type(); - SimpleTensor<OT> dst{ dst_shape, output_data_type, 1, src.quantization_info() }; + const bool is_arg_min_max = (op == ReductionOperation::ARG_IDX_MIN || op == ReductionOperation::ARG_IDX_MAX); + SimpleTensor<OT> dst{ dst_shape, output_type, 1, src.quantization_info() }; const unsigned int src_width = src.shape().x(); const unsigned int src_height = src.shape().y(); const unsigned int src_depth = src.shape().z(); @@ -197,7 +203,7 @@ SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const T const T *src_row_ptr = src.data() + du * reduce_elems; dst[du] = is_arg_min_max ? reduce_operation_arg_min_max<T, OT>(src_row_ptr, reduce_elems, op, 1) : - reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, 1); + reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, 1, policy); } } break; @@ -213,7 +219,7 @@ SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const T const T *src_row_ptr = src.data() + in_offset; dst[out_offset] = is_arg_min_max ? reduce_operation_arg_min_max<T, OT>(src_row_ptr, reduce_elems, op, src_width) : - reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, src_width); + reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, src_width, policy); } } } @@ -232,7 +238,7 @@ SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const T const T *src_row_ptr = src.data() + in_offset; dst[out_offset] = is_arg_min_max ? reduce_operation_arg_min_max<T, OT>(src_row_ptr, reduce_elems, op, src_width * src_height) : - reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, src_width * src_height); + reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, src_width * src_height, policy); } } } @@ -254,7 +260,7 @@ SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const T const T *src_row_ptr = src.data() + in_offset; dst[out_offset] = is_arg_min_max ? reduce_operation_arg_min_max<T, OT>(src_row_ptr, reduce_elems, op, src_width * src_height * src_depth) : - reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, src_width * src_height * src_depth); + reduce_operation<T, OT>(src_row_ptr, reduce_elems, op, src_width * src_height * src_depth, policy); } } } @@ -269,66 +275,89 @@ SimpleTensor<OT> compute_reduction_operation(const SimpleTensor<T> &src, const T } template <typename T, typename OT> -SimpleTensor<OT> reduction_operation(const SimpleTensor<T> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) +SimpleTensor<OT> reduction_operation(const SimpleTensor<T> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type, QuantizationInfo quantization_info_output, RoundingPolicy policy) { - return compute_reduction_operation<T, OT>(src, dst_shape, axis, op); + ARM_COMPUTE_UNUSED(quantization_info_output); + return compute_reduction_operation<T, OT>(src, dst_shape, axis, op, output_type, policy); } template <> -SimpleTensor<uint8_t> reduction_operation(const SimpleTensor<uint8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) +SimpleTensor<uint8_t> reduction_operation(const SimpleTensor<uint8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type, QuantizationInfo quantization_info_output, RoundingPolicy policy) { if(src.data_type() == DataType::QASYMM8) { // If the operation is MEAN_SUM, we can directly use the uint8 implementation without taking into account scale and offset - if(op == ReductionOperation::MEAN_SUM) + if(op == ReductionOperation::MEAN_SUM && src.quantization_info() == quantization_info_output) { - return compute_reduction_operation<uint8_t, uint8_t>(src, dst_shape, axis, op); + return compute_reduction_operation<uint8_t, uint8_t>(src, dst_shape, axis, op, output_type, policy); } else { SimpleTensor<float> src_f = convert_from_asymmetric(src); - SimpleTensor<float> dst_f = reference::reduction_operation<float, float>(src_f, dst_shape, axis, op); - return convert_to_asymmetric<uint8_t>(dst_f, src.quantization_info()); + SimpleTensor<float> dst_f = reference::reduction_operation<float, float>(src_f, dst_shape, axis, op, output_type); + return convert_to_asymmetric<uint8_t>(dst_f, quantization_info_output); } } else { - return compute_reduction_operation<uint8_t, uint8_t>(src, dst_shape, axis, op); + return compute_reduction_operation<uint8_t, uint8_t>(src, dst_shape, axis, op, output_type, policy); } } template <> -SimpleTensor<int8_t> reduction_operation(const SimpleTensor<int8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) +SimpleTensor<int8_t> reduction_operation(const SimpleTensor<int8_t> &src, const TensorShape &dst_shape, unsigned int axis, + ReductionOperation op, DataType output_type, QuantizationInfo quantization_info_output, RoundingPolicy policy) { if(src.data_type() == DataType::QASYMM8_SIGNED) { // If the operation is MEAN_SUM, we can directly use the int8 implementation without taking into account scale and offset - if(op == ReductionOperation::MEAN_SUM) + if(op == ReductionOperation::MEAN_SUM && src.quantization_info() == quantization_info_output) { - return compute_reduction_operation<int8_t, int8_t>(src, dst_shape, axis, op); + return compute_reduction_operation<int8_t, int8_t>(src, dst_shape, axis, op, output_type, policy); } else { SimpleTensor<float> src_f = convert_from_asymmetric(src); - SimpleTensor<float> dst_f = reference::reduction_operation<float, float>(src_f, dst_shape, axis, op); - return convert_to_asymmetric<int8_t>(dst_f, src.quantization_info()); + SimpleTensor<float> dst_f = reference::reduction_operation<float, float>(src_f, dst_shape, axis, op, output_type); + return convert_to_asymmetric<int8_t>(dst_f, quantization_info_output); } } else { - return compute_reduction_operation<int8_t, int8_t>(src, dst_shape, axis, op); + return compute_reduction_operation<int8_t, int8_t>(src, dst_shape, axis, op, output_type, policy); } } -template SimpleTensor<float> reduction_operation(const SimpleTensor<float> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -template SimpleTensor<half> reduction_operation(const SimpleTensor<half> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); +template SimpleTensor<float> reduction_operation(const SimpleTensor<float> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, QuantizationInfo quantization_info_output = QuantizationInfo(), + RoundingPolicy policy = RoundingPolicy::TO_ZERO); + +template SimpleTensor<half> reduction_operation(const SimpleTensor<half> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); + +template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<float> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); -template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<float> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<int32_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<half> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<uint8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<int8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); +template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<int32_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); +template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<half> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); +template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<uint8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); +template SimpleTensor<int32_t> reduction_operation(const SimpleTensor<int8_t> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); +template SimpleTensor<int64_t> reduction_operation(const SimpleTensor<float> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, + DataType output_type = DataType::S32, QuantizationInfo quantization_info_output = QuantizationInfo(), + RoundingPolicy policy = RoundingPolicy::TO_ZERO); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/ReductionOperation.h b/tests/validation/reference/ReductionOperation.h index d7c77a6b68..fb2e7a7093 100644 --- a/tests/validation/reference/ReductionOperation.h +++ b/tests/validation/reference/ReductionOperation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2020, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #ifndef ARM_COMPUTE_TEST_REDUCTION_OPERATION_H #define ARM_COMPUTE_TEST_REDUCTION_OPERATION_H +#include "arm_compute/core/Rounding.h" #include "tests/SimpleTensor.h" #include "tests/validation/Helpers.h" @@ -36,7 +37,8 @@ namespace validation namespace reference { template <typename T, typename OT> -SimpleTensor<OT> reduction_operation(const SimpleTensor<T> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); +SimpleTensor<OT> reduction_operation(const SimpleTensor<T> &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op, DataType output_type = DataType::S32, + QuantizationInfo quantization_info_output = QuantizationInfo(), RoundingPolicy policy = RoundingPolicy::TO_ZERO); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/Remap.cpp b/tests/validation/reference/Remap.cpp deleted file mode 100644 index a7352eb3a3..0000000000 --- a/tests/validation/reference/Remap.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Remap.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <algorithm> -#include <array> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> remap(const SimpleTensor<T> &in, SimpleTensor<float> &map_x, SimpleTensor<float> &map_y, SimpleTensor<T> &valid_mask, InterpolationPolicy policy, BorderMode border_mode, - T constant_border_value) -{ - ARM_COMPUTE_ERROR_ON_MSG(border_mode == BorderMode::REPLICATE, "BorderMode not supported"); - SimpleTensor<T> out(in.shape(), in.data_type()); - ARM_COMPUTE_ERROR_ON(out.num_elements() != map_x.num_elements()); - const int width = in.shape().x(); - const int height = in.shape().y(); - const uint32_t num_elements = out.num_elements(); - for(uint32_t idx = 0; idx < num_elements; idx++) - { - const Coordinates id_out = index2coord(out.shape(), idx); - valid_mask[idx] = 1; - Coordinates src_idx = id_out; // need to setup all coordinates and not just xy - src_idx.set(0, static_cast<int>(std::floor(map_x[idx]))); - src_idx.set(1, static_cast<int>(std::floor(map_y[idx]))); - if((0 <= map_y[idx]) && (map_y[idx] < height) && (0 <= map_x[idx]) && (map_x[idx] < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - { - out[idx] = tensor_elem_at(in, src_idx, border_mode, constant_border_value); - break; - } - case InterpolationPolicy::BILINEAR: - { - (valid_bilinear_policy(map_x[idx], map_y[idx], width, height, border_mode)) ? - out[idx] = bilinear_policy(in, src_idx, map_x[idx], map_y[idx], border_mode, constant_border_value) : - valid_mask[idx] = 0; - break; - } - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - out[idx] = constant_border_value; - break; - case InterpolationPolicy::BILINEAR: - out[idx] = bilinear_policy(in, src_idx, map_x[idx], map_y[idx], border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - break; - } - } - } - } - - return out; -} - -template SimpleTensor<uint8_t> remap(const SimpleTensor<uint8_t> &src, SimpleTensor<float> &map_x, SimpleTensor<float> &map_y, SimpleTensor<uint8_t> &valid_mask, InterpolationPolicy policy, - BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Remap.h b/tests/validation/reference/Remap.h deleted file mode 100644 index f24a16b66f..0000000000 --- a/tests/validation/reference/Remap.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_REMAP_H -#define ARM_COMPUTE_TEST_REMAP_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> remap(const SimpleTensor<T> &in, SimpleTensor<float> &map_x, SimpleTensor<float> &map_y, SimpleTensor<T> &valid_mask, InterpolationPolicy policy, BorderMode border_mode, - T constant_border_value = 0); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_REMAP_H */ diff --git a/tests/validation/reference/Reorder.cpp b/tests/validation/reference/Reorder.cpp new file mode 100644 index 0000000000..8abb372596 --- /dev/null +++ b/tests/validation/reference/Reorder.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "Reorder.h" +#include "src/core/NEON/kernels/arm_gemm/utils.hpp" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ + +/* + * Generic transform. + * + * Assuming the untransposed case, this works by first reading <BlockBy> + * consecutive values from the first input row. This same number of values + * are then read from the next <IntBy-1> rows. Now return to the first + * input row and repeat. + * + * Need to cope with the work requested in either dimension not actually + * being a multiple of the block sizes. + */ +template <unsigned int tIntBy, unsigned int BlockBy, bool Transposed, size_t TOutSize, size_t TInSize, typename d_type, arm_gemm::VLType vlt> +struct Transform_ref +{ + template <typename TOut, typename TIn> + static void Transform(TOut &out, const TIn in, const int stride, + const int y0, const int ymax, const int x0, const int xmax) + { + // NOTE: This code is disabled to avoid the call to get_vector_length(), so templated transforms will not be + // correct for SVE. This is not an issue as we have specializations for all SVE cases. + // For SVE cases we multiply the interleave factor by the vector length. + // const unsigned int IntBy = tIntBy * (vlt == VLType::SVE ? get_vector_length<TOut>() / BlockBy : 1); + const unsigned int IntBy = tIntBy; + int out_index = 0; + + const int n_whole_y_blocks = (ymax - y0) / IntBy; + const int y_remainders = (ymax - y0) % IntBy; + const int n_y_blocks = n_whole_y_blocks + (y_remainders ? 1 : 0); + + const int n_whole_x_blocks = (xmax - x0) / BlockBy; + const int x_remainders = (xmax - x0) % BlockBy; + const int n_x_blocks = n_whole_x_blocks + (x_remainders ? 1 : 0); + + // "Y" loop: advance down the rows of the source IntBy rows at a time. + // Set up fill_rows to show the number rows to copy from, and blank_rows + // for the number of blank rows to add. + for(int y_block = 0; y_block < n_y_blocks; y_block++) + { + const int fill_rows = (y_block < n_whole_y_blocks) ? IntBy : y_remainders; + const int blank_rows = IntBy - fill_rows; + + const int y_base = y0 + (y_block * IntBy); + + // So now advance along this block of rows, BlockBy columns at a time. + for(int x_block = 0; x_block < n_x_blocks; x_block++) + { + const int fill_cols = (x_block < n_whole_x_blocks) ? BlockBy : x_remainders; + const int blank_cols = BlockBy - fill_cols; + + const int x_base = x0 + (x_block * BlockBy); + + for(int row = 0; row < fill_rows; row++) + { + for(int col = 0; col < fill_cols; col++) + { + // In-range copy. If it's transposed, we reverse the sense of rows and columns here. + if(Transposed) + { + out[out_index] = in[(x_base + col) * stride + y_base + row]; + out_index++; + } + else + { + out[out_index] = in[(y_base + row) * stride + x_base + col]; + out_index++; + } + } + // "col" tail - row is in range but column is out of range. + for(int col = 0; col < blank_cols; col++) + { + out[out_index] = 0; + out_index++; + } + } + // "row" tail - row is out of range so fill with zeros always. + const d_type zeroval = 0; + const int pads = blank_rows * (fill_cols + blank_cols); + + for(int i = 0; i < pads; i++) + { + out[out_index] = zeroval; + } + + out_index += pads; + } + } + } +}; + +template <typename T> +SimpleTensor<T> reorder_layer(const SimpleTensor<T> &src, const TensorShape &output_shape, WeightFormat output_wf) +{ + SimpleTensor<T> dst{ output_shape, src.data_type() }; + const int cols = src.shape()[0]; + const int rows = src.shape()[1]; + + switch(output_wf) + { + case WeightFormat::OHWIo4: + { + Transform_ref<4, 1, true, sizeof(float), sizeof(float), float, arm_gemm::VLType::None>::Transform<SimpleTensor<T> &, SimpleTensor<T>>(dst, src, rows, 0, rows, 0, cols); + break; + } + case WeightFormat::OHWIo8: + { + Transform_ref<8, 1, true, sizeof(float), sizeof(float), float, arm_gemm::VLType::None>::Transform<SimpleTensor<T> &, SimpleTensor<T>>(dst, src, rows, 0, rows, 0, cols); + break; + } + default: + break; + } + + return dst; +} + +template SimpleTensor<float> reorder_layer(const SimpleTensor<float> &src, const TensorShape &output_shape, WeightFormat output_wf); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ChannelExtract.h b/tests/validation/reference/Reorder.h index fd34908e58..94ee5078f8 100644 --- a/tests/validation/reference/ChannelExtract.h +++ b/tests/validation/reference/Reorder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,10 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H -#define ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H +#ifndef ACL_TESTS_VALIDATION_REFERENCE_REORDER +#define ACL_TESTS_VALIDATION_REFERENCE_REORDER #include "tests/SimpleTensor.h" +#include "tests/Types.h" namespace arm_compute { @@ -35,9 +36,9 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel); +SimpleTensor<T> reorder_layer(const SimpleTensor<T> &src, const TensorShape &output_shape, WeightFormat output_wf); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H */ +#endif /* ACL_TESTS_VALIDATION_REFERENCE_REORDER */ diff --git a/tests/validation/reference/ReorgLayer.cpp b/tests/validation/reference/ReorgLayer.cpp index 9f087d06cb..0508ebe5b0 100644 --- a/tests/validation/reference/ReorgLayer.cpp +++ b/tests/validation/reference/ReorgLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ReorgLayer.h b/tests/validation/reference/ReorgLayer.h index 47db7f357d..25b5556758 100644 --- a/tests/validation/reference/ReorgLayer.h +++ b/tests/validation/reference/ReorgLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/ReshapeLayer.cpp b/tests/validation/reference/ReshapeLayer.cpp index 85bf3fcb76..30a58dd65b 100644 --- a/tests/validation/reference/ReshapeLayer.cpp +++ b/tests/validation/reference/ReshapeLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017,2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -44,14 +44,15 @@ SimpleTensor<T> reshape_layer(const SimpleTensor<T> &src, const TensorShape &out return dst; } -template SimpleTensor<uint8_t> reshape_layer(const SimpleTensor<uint8_t> &src, const TensorShape &output_shape); -template SimpleTensor<int8_t> reshape_layer(const SimpleTensor<int8_t> &src, const TensorShape &output_shape); +template SimpleTensor<uint8_t> reshape_layer(const SimpleTensor<uint8_t> &src, const TensorShape &output_shape); +template SimpleTensor<int8_t> reshape_layer(const SimpleTensor<int8_t> &src, const TensorShape &output_shape); template SimpleTensor<uint16_t> reshape_layer(const SimpleTensor<uint16_t> &src, const TensorShape &output_shape); -template SimpleTensor<int16_t> reshape_layer(const SimpleTensor<int16_t> &src, const TensorShape &output_shape); +template SimpleTensor<int16_t> reshape_layer(const SimpleTensor<int16_t> &src, const TensorShape &output_shape); template SimpleTensor<uint32_t> reshape_layer(const SimpleTensor<uint32_t> &src, const TensorShape &output_shape); -template SimpleTensor<int32_t> reshape_layer(const SimpleTensor<int32_t> &src, const TensorShape &output_shape); -template SimpleTensor<half> reshape_layer(const SimpleTensor<half> &src, const TensorShape &output_shape); -template SimpleTensor<float> reshape_layer(const SimpleTensor<float> &src, const TensorShape &output_shape); +template SimpleTensor<int32_t> reshape_layer(const SimpleTensor<int32_t> &src, const TensorShape &output_shape); +template SimpleTensor<half> reshape_layer(const SimpleTensor<half> &src, const TensorShape &output_shape); +template SimpleTensor<float> reshape_layer(const SimpleTensor<float> &src, const TensorShape &output_shape); +template SimpleTensor<bfloat16> reshape_layer(const SimpleTensor<bfloat16> &src, const TensorShape &output_shape); /** [ReshapeLayer] **/ } // namespace reference } // namespace validation diff --git a/tests/validation/reference/ReshapeLayer.h b/tests/validation/reference/ReshapeLayer.h index a68bbb34b9..26e357fec8 100644 --- a/tests/validation/reference/ReshapeLayer.h +++ b/tests/validation/reference/ReshapeLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Reverse.cpp b/tests/validation/reference/Reverse.cpp index f5630b9a40..7924f900d1 100644 --- a/tests/validation/reference/Reverse.cpp +++ b/tests/validation/reference/Reverse.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -35,8 +35,9 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> reverse(const SimpleTensor<T> &src, const SimpleTensor<uint32_t> &axis) +SimpleTensor<T> reverse(const SimpleTensor<T> &src, const SimpleTensor<int32_t> &axis, bool use_inverted_axis) { + ARM_COMPUTE_ERROR_ON(src.shape().num_dimensions() > 4); ARM_COMPUTE_ERROR_ON(axis.shape().num_dimensions() > 1); ARM_COMPUTE_ERROR_ON(axis.shape().x() > 4); @@ -48,10 +49,32 @@ SimpleTensor<T> reverse(const SimpleTensor<T> &src, const SimpleTensor<uint32_t> const unsigned int depth = src.shape()[2]; const unsigned int batches = src.shape()[3]; + const int rank = src.shape().num_dimensions(); + std::array<bool, 4> to_reverse = { { false, false, false, false } }; for(int i = 0; i < axis.num_elements(); ++i) { - to_reverse[axis[i]] = true; + int axis_i = axis[i]; + + // The values of axis tensor must be between [-rank, rank-1]. + if((axis_i < -rank) || (axis_i >= rank)) + { + ARM_COMPUTE_ERROR("the values of the axis tensor must be within [-rank, rank-1]."); + } + + // In case of negative axis value i.e targeted axis(i) = rank + axis(i) + if(axis_i < 0) + { + axis_i = rank + axis_i; + } + + // Reverse ACL axis indices convention i.e. (inverted)axis = (tensor_rank - 1) - axis + if(use_inverted_axis) + { + axis_i = (rank - 1) - axis_i; + } + + to_reverse[axis_i] = true; } const uint32_t num_elements = src.num_elements(); @@ -73,9 +96,9 @@ SimpleTensor<T> reverse(const SimpleTensor<T> &src, const SimpleTensor<uint32_t> return dst; } -template SimpleTensor<uint8_t> reverse(const SimpleTensor<uint8_t> &src, const SimpleTensor<uint32_t> &axis); -template SimpleTensor<half> reverse(const SimpleTensor<half> &src, const SimpleTensor<uint32_t> &axis); -template SimpleTensor<float> reverse(const SimpleTensor<float> &src, const SimpleTensor<uint32_t> &axis); +template SimpleTensor<uint8_t> reverse(const SimpleTensor<uint8_t> &src, const SimpleTensor<int32_t> &axis, bool use_inverted_axis); +template SimpleTensor<half> reverse(const SimpleTensor<half> &src, const SimpleTensor<int32_t> &axis, bool use_inverted_axis); +template SimpleTensor<float> reverse(const SimpleTensor<float> &src, const SimpleTensor<int32_t> &axis, bool use_inverted_axis); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/Reverse.h b/tests/validation/reference/Reverse.h index cc46807893..30926b05a5 100644 --- a/tests/validation/reference/Reverse.h +++ b/tests/validation/reference/Reverse.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_REVERSE_H -#define ARM_COMPUTE_TEST_REVERSE_H +#ifndef ACL_TESTS_VALIDATION_REFERENCE_REVERSE_H +#define ACL_TESTS_VALIDATION_REFERENCE_REVERSE_H #include "tests/SimpleTensor.h" @@ -35,9 +35,9 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> reverse(const SimpleTensor<T> &src, const SimpleTensor<uint32_t> &axis); +SimpleTensor<T> reverse(const SimpleTensor<T> &src, const SimpleTensor<int32_t> &axis, bool use_inverted_axis = false); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_REVERSE_H */ +#endif // ACL_TESTS_VALIDATION_REFERENCE_REVERSE_H diff --git a/tests/validation/reference/Scale.cpp b/tests/validation/reference/Scale.cpp index 73fe21cbf1..2f429cb29b 100644 --- a/tests/validation/reference/Scale.cpp +++ b/tests/validation/reference/Scale.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,7 +25,8 @@ #include "Scale.h" #include "Utils.h" -#include "arm_compute/core/utils/misc/Utility.h" +#include "src/core/utils/ScaleUtils.h" +#include "support/Rounding.h" namespace arm_compute { @@ -42,17 +43,13 @@ SimpleTensor<T> scale_core(const SimpleTensor<T> &in, float scale_x, float scale // Add 1 if ceil_policy_scale is true const size_t round_value = ceil_policy_scale ? 1U : 0U; TensorShape shape_scaled(in.shape()); - shape_scaled.set(0, (in.shape()[0] + round_value) * scale_x); - shape_scaled.set(1, (in.shape()[1] + round_value) * scale_y); + shape_scaled.set(0, (in.shape()[0] + round_value) * scale_x, /* apply_dim_correction = */ false); + shape_scaled.set(1, (in.shape()[1] + round_value) * scale_y, /* apply_dim_correction = */ false); SimpleTensor<T> out(shape_scaled, in.data_type()); - const auto needs_align_corners = policy == InterpolationPolicy::BILINEAR - && sampling_policy == SamplingPolicy::TOP_LEFT - && align_corners; - // Compute the ratio between source width/height and destination width/height - const auto wr = arm_compute::calculate_resize_ratio(in.shape()[0], out.shape()[0], needs_align_corners); - const auto hr = arm_compute::calculate_resize_ratio(in.shape()[1], out.shape()[1], needs_align_corners); + const auto wr = arm_compute::scale_utils::calculate_resize_ratio(in.shape()[0], out.shape()[0], align_corners); + const auto hr = arm_compute::scale_utils::calculate_resize_ratio(in.shape()[1], out.shape()[1], align_corners); const auto width = static_cast<int>(in.shape().x()); const auto height = static_cast<int>(in.shape().y()); @@ -82,8 +79,8 @@ SimpleTensor<T> scale_core(const SimpleTensor<T> &in, float scale_x, float scale switch(sampling_policy) { case SamplingPolicy::TOP_LEFT: - x_src = std::floor(idx * wr); - y_src = std::floor(idy * hr); + x_src = align_corners ? arm_compute::utils::rounding::round_half_away_from_zero(idx * wr) : std::floor(idx * wr); + y_src = align_corners ? arm_compute::utils::rounding::round_half_away_from_zero(idy * hr) : std::floor(idy * hr); break; case SamplingPolicy::CENTER: //Calculate the source coords without -0.5f is equivalent to round the x_scr/y_src coords @@ -185,14 +182,15 @@ SimpleTensor<T> scale_core(const SimpleTensor<T> &in, float scale_x, float scale template <typename T> SimpleTensor<T> scale(const SimpleTensor<T> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners) + SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners, QuantizationInfo output_quantization_info) { + ARM_COMPUTE_UNUSED(output_quantization_info); return scale_core<T>(src, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy, ceil_policy_scale, align_corners); } template <> SimpleTensor<uint8_t> scale(const SimpleTensor<uint8_t> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners) + SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners, QuantizationInfo output_quantization_info) { SimpleTensor<uint8_t> dst; if(src.quantization_info().uniform().scale != 0.f) @@ -200,7 +198,7 @@ SimpleTensor<uint8_t> scale(const SimpleTensor<uint8_t> &src, float scale_x, flo SimpleTensor<float> src_tmp = convert_from_asymmetric(src); float constant_border_value_f = dequantize_qasymm8(constant_border_value, src.quantization_info()); SimpleTensor<float> dst_tmp = scale_core<float>(src_tmp, scale_x, scale_y, policy, border_mode, constant_border_value_f, sampling_policy, ceil_policy_scale, align_corners); - dst = convert_to_asymmetric<uint8_t>(dst_tmp, src.quantization_info()); + dst = convert_to_asymmetric<uint8_t>(dst_tmp, output_quantization_info); } else { @@ -211,7 +209,7 @@ SimpleTensor<uint8_t> scale(const SimpleTensor<uint8_t> &src, float scale_x, flo template <> SimpleTensor<int8_t> scale(const SimpleTensor<int8_t> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, int8_t constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners) + SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners, QuantizationInfo output_quantization_info) { SimpleTensor<int8_t> dst; if(src.quantization_info().uniform().scale != 0.f) @@ -219,7 +217,7 @@ SimpleTensor<int8_t> scale(const SimpleTensor<int8_t> &src, float scale_x, float SimpleTensor<float> src_tmp = convert_from_asymmetric(src); float constant_border_value_f = dequantize_qasymm8_signed(constant_border_value, src.quantization_info()); SimpleTensor<float> dst_tmp = scale_core<float>(src_tmp, scale_x, scale_y, policy, border_mode, constant_border_value_f, sampling_policy, ceil_policy_scale, align_corners); - dst = convert_to_asymmetric<int8_t>(dst_tmp, src.quantization_info()); + dst = convert_to_asymmetric<int8_t>(dst_tmp, output_quantization_info); } else { @@ -229,11 +227,11 @@ SimpleTensor<int8_t> scale(const SimpleTensor<int8_t> &src, float scale_x, float } template SimpleTensor<int16_t> scale(const SimpleTensor<int16_t> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, int16_t constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners); + SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners, QuantizationInfo output_quantization_info); template SimpleTensor<half> scale(const SimpleTensor<half> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, half constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners); + SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners, QuantizationInfo output_quantization_info); template SimpleTensor<float> scale(const SimpleTensor<float> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, float constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners); + SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners, QuantizationInfo output_quantization_info); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/Scale.h b/tests/validation/reference/Scale.h index 65cecbb6d5..c32c07d1c0 100644 --- a/tests/validation/reference/Scale.h +++ b/tests/validation/reference/Scale.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020, 2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -37,7 +37,7 @@ namespace reference { template <typename T> SimpleTensor<T> scale(const SimpleTensor<T> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value = 0, - SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool ceil_policy_scale = false, bool align_corners = false); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool ceil_policy_scale = false, bool align_corners = false, QuantizationInfo output_quantization_info = QuantizationInfo()); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/ScatterLayer.cpp b/tests/validation/reference/ScatterLayer.cpp new file mode 100644 index 0000000000..55c48a9002 --- /dev/null +++ b/tests/validation/reference/ScatterLayer.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2024 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "ScatterLayer.h" +#include "tests/validation/Helpers.h" +#include "arm_compute/core/TensorShape.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ + +template <typename T> +T reduce_op(const T ¤t,const T &update,const ScatterFunction func) +{ + switch(func) + { + case ScatterFunction::Update: + return update; + break; + case ScatterFunction::Add: + return current + update; + break; + case ScatterFunction::Sub: + return current - update; + break; + case ScatterFunction::Max: + return std::max(current, update); + break; + case ScatterFunction::Min: + return std::min(current, update); + break; + default: + ARM_COMPUTE_ERROR("Unsupported Scatter function"); + break; + } +} + +template float reduce_op(const float ¤t,const float &update,const ScatterFunction func); +template half reduce_op(const half ¤t,const half &update,const ScatterFunction func); +} + +// NOTE: This function expects collapsed tensors as input. +// Batch dims for update/indices tensors should be collapsed into a single dim. +// Data dims should be collapsed into a single dim for both update and src tensors prior to calling this function. +template <typename T> +SimpleTensor<T> scatter_layer_internal(const SimpleTensor<T> &src, const SimpleTensor<T> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info) +{ + // 1. If zero initialization variable is false, copy src data to dst. + SimpleTensor<T> dst{ out_shape, src.data_type(), 1 }; + if(!info.zero_initialization) + { + std::copy_n(src.data(), src.num_elements(), dst.data()); + } + + // Number of elements between each value of the dim being iterated through + const unsigned int data_stride = updates.shape().total_size_lower(updates.shape().num_dimensions() - 1); + const unsigned int no_output_dims = out_shape.num_dimensions(); + + // Calculate output stride at given index for all output dims. + std::vector<unsigned int> out_stride_at_idx(no_output_dims); + for (unsigned int i = 0 ; i < no_output_dims; i++) + { + out_stride_at_idx[i] = out_shape.total_size_lower(i); + } + + const unsigned int indices_x_dim = static_cast<unsigned int>(indices.shape()[0]); + const unsigned int indices_y_dim = static_cast<unsigned int>(indices.shape()[1]); + + // 2. Iterate over indices tensor y-dim and replace sections of dst tensor with relevant areas of update tensor. + for(unsigned int i = 0; i < indices_y_dim; i++) + { + // NOTE : Currently, indices.shape() == [X, Y, 1, 1], where X is the indices dim and Y is the batch dim + // Starting index for both the update and indices tensors. + const unsigned int update_dim_start = i * data_stride; + const unsigned int indices_dim_start = i * indices_x_dim; + bool out_of_bounds = false; + unsigned int out_offset_acc = 0; + + // Iterate over each indices value for the relevant batch and accumulate the offset. + for(unsigned int j = 0; j < indices_x_dim; j++) + { + // Get first index value with i * indices_x_dim (iterating through y-dim/batch idx), then iterate through x dim by adding k + const int index_value = indices[indices_dim_start + j]; + const unsigned int out_dim = no_output_dims - (j+1); // Calculate corresponding output dim to current index value. + if(index_value < static_cast<int>(out_shape[out_dim]) && index_value >= 0) + { + out_offset_acc += (index_value * out_stride_at_idx[out_dim]); // offset accumulation + } + else + { + out_of_bounds = true; + break; + } + } + + // If not out of bounds, copy update tensor elements to output + if(!out_of_bounds) + { + for (unsigned int j = 0 ; j < data_stride; j++) + { + dst[out_offset_acc + j] = reduce_op(dst[out_offset_acc + j], updates[update_dim_start + j], info.func); + } + } + } + return dst; +} + +template <typename T> +SimpleTensor<T> scatter_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info) +{ + return scatter_layer_internal<T>(src, updates, indices, out_shape, info); +} + +template SimpleTensor<float> scatter_layer(const SimpleTensor<float> &src, const SimpleTensor<float> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<half> scatter_layer(const SimpleTensor<half> &src, const SimpleTensor<half> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<int32_t> scatter_layer(const SimpleTensor<int32_t> &src, const SimpleTensor<int32_t> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<uint32_t> scatter_layer(const SimpleTensor<uint32_t> &src, const SimpleTensor<uint32_t> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<int16_t> scatter_layer(const SimpleTensor<int16_t> &src, const SimpleTensor<int16_t> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<uint16_t> scatter_layer(const SimpleTensor<uint16_t> &src, const SimpleTensor<uint16_t> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<int8_t> scatter_layer(const SimpleTensor<int8_t> &src, const SimpleTensor<int8_t> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor<uint8_t> scatter_layer(const SimpleTensor<uint8_t> &src, const SimpleTensor<uint8_t> &updates, const SimpleTensor<int32_t> &indices, const TensorShape &out_shape, const ScatterInfo &info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/HOGDescriptor.h b/tests/validation/reference/ScatterLayer.h index ef189ec1a3..97d5e70b0d 100644 --- a/tests/validation/reference/HOGDescriptor.h +++ b/tests/validation/reference/ScatterLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2024 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,9 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_TEST_HOG_DESCRIPTOR_H -#define ARM_COMPUTE_TEST_HOG_DESCRIPTOR_H +#ifndef ACL_TESTS_VALIDATION_REFERENCE_SCATTERLAYER_H +#define ACL_TESTS_VALIDATION_REFERENCE_SCATTERLAYER_H +#include "Utils.h" +#include "arm_compute/function_info/ScatterInfo.h" #include "tests/SimpleTensor.h" namespace arm_compute @@ -34,16 +36,13 @@ namespace validation { namespace reference { -template <typename T, typename U, typename V> -void hog_orientation_binning(const SimpleTensor<T> &mag, const SimpleTensor<U> &phase, SimpleTensor<V> &hog_space, const HOGInfo &hog_info); - template <typename T> -void hog_block_normalization(SimpleTensor<T> &desc, const SimpleTensor<T> &hog_space, const HOGInfo &hog_info); +SimpleTensor<T> scatter_layer_internal(const SimpleTensor<T> &src, const SimpleTensor<T> &update, const SimpleTensor<int32_t> &indices, const TensorShape &shape, const ScatterInfo &info); -template <typename T, typename U> -SimpleTensor<T> hog_descriptor(const SimpleTensor<U> &src, BorderMode border_mode, U constant_border_value, const HOGInfo &hog_info); +template <typename T> +SimpleTensor<T> scatter_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &update, const SimpleTensor<int32_t> &indices, const TensorShape &shape, const ScatterInfo &info); } // namespace reference } // namespace validation } // namespace test } // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_HOG_DESCRIPTOR_H */ +#endif // ACL_TESTS_VALIDATION_REFERENCE_SCATTERLAYER_H diff --git a/tests/validation/reference/Scharr.cpp b/tests/validation/reference/Scharr.cpp deleted file mode 100644 index 060192b74c..0000000000 --- a/tests/validation/reference/Scharr.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Scharr.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <array> -#include <map> -#include <utility> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array<int8_t, 9> scharr_3_x{ { -3, 0, 3, -10, 0, 10, -3, 0, 3 } }; -const std::array<int8_t, 9> scharr_3_y{ { -3, -10, -3, 0, 0, 0, 3, 10, 3 } }; - -const std::map<int, std::pair<const int8_t *, const int8_t *>> masks -{ - { 3, { scharr_3_x.data(), scharr_3_y.data() } } -}; - -template <typename T> -struct data_type; - -template <> -struct data_type<int16_t> -{ - const static DataType value = DataType::S16; -}; -} // namespace - -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> scharr(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - const auto shape_size = static_cast<unsigned int>(filter_size); - - SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); - SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> scharr(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Scharr.h b/tests/validation/reference/Scharr.h deleted file mode 100644 index 4a41333991..0000000000 --- a/tests/validation/reference/Scharr.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_SCHARR_H -#define ARM_COMPUTE_TEST_SCHARR_H - -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> scharr(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_SCHARR_H */ diff --git a/tests/validation/reference/Select.cpp b/tests/validation/reference/Select.cpp index 91b6b66c42..f3f9b415d7 100644 --- a/tests/validation/reference/Select.cpp +++ b/tests/validation/reference/Select.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Select.h b/tests/validation/reference/Select.h index e00d5cc5c9..d23ebdac4a 100644 --- a/tests/validation/reference/Select.h +++ b/tests/validation/reference/Select.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/SliceOperations.cpp b/tests/validation/reference/SliceOperations.cpp index b34afdc92e..222b1463dd 100644 --- a/tests/validation/reference/SliceOperations.cpp +++ b/tests/validation/reference/SliceOperations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/SliceOperations.h b/tests/validation/reference/SliceOperations.h index ac3b289aca..0a893255ed 100644 --- a/tests/validation/reference/SliceOperations.h +++ b/tests/validation/reference/SliceOperations.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Sobel.cpp b/tests/validation/reference/Sobel.cpp deleted file mode 100644 index 1f35717fb9..0000000000 --- a/tests/validation/reference/Sobel.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Sobel.h" - -#include "Utils.h" -#include "tests/validation/Helpers.h" - -#include <array> -#include <map> -#include <utility> - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -namespace -{ -const std::array<int8_t, 9> sobel_3_x{ { -1, 0, 1, -2, 0, 2, -1, 0, 1 } }; -const std::array<int8_t, 9> sobel_3_y{ { -1, -2, -1, 0, 0, 0, 1, 2, 1 } }; - -const std::array<int8_t, 25> sobel_5_x{ { - -1, -2, 0, 2, 1, - -4, -8, 0, 8, 4, - -6, -12, 0, 12, 6, - -4, -8, 0, 8, 4, - -1, -2, 0, 2, 1 - } }; - -const std::array<int8_t, 25> sobel_5_y{ { - -1, -4, -6, -4, -1, - -2, -8, -12, -8, -2, - 0, 0, 0, 0, 0, - 2, 8, 12, 8, 2, - 1, 4, 6, 4, 1 - } }; - -const std::array<int8_t, 49> sobel_7_x{ { - -1, -4, -5, 0, 5, 4, 1, - -6, -24, -30, 0, 30, 24, 6, - -15, -60, -75, 0, 75, 60, 15, - -20, -80, -100, 0, 100, 80, 20, - -15, -60, -75, 0, 75, 60, 15, - -6, -24, -30, 0, 30, 24, 6, - -1, -4, -5, 0, 5, 4, 1 - } }; - -const std::array<int8_t, 49> sobel_7_y{ { - -1, -6, -15, -20, -15, -6, -1, - -4, -24, -60, -80, -60, -24, -4, - -5, -30, -75, -100, -75, -30, -5, - 0, 0, 0, 0, 0, 0, 0, - 5, 30, 75, 100, 75, 30, 5, - 4, 24, 60, 80, 60, 24, 4, - 1, 6, 15, 20, 15, 6, 1 - } }; - -const std::map<int, std::pair<const int8_t *, const int8_t *>> masks -{ - { 3, { sobel_3_x.data(), sobel_3_y.data() } }, - { 5, { sobel_5_x.data(), sobel_5_y.data() } }, - { 7, { sobel_7_x.data(), sobel_7_y.data() } }, -}; - -template <typename T> -struct data_type; - -template <> -struct data_type<int16_t> -{ - const static DataType value = DataType::S16; -}; - -template <> -struct data_type<int> -{ - const static DataType value = DataType::S32; -}; -} // namespace - -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> sobel(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) -{ - SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); - SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); - - ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t i = 0; i < num_elements; ++i) - { - Coordinates coord = index2coord(src.shape(), i); - - if(!is_in_valid_region(valid_region, coord)) - { - continue; - } - switch(gradient_dimension) - { - case GradientDimension::GRAD_X: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_Y: - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, - constant_border_value); - break; - case GradientDimension::GRAD_XY: - apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).first, 1.f, border_mode, - constant_border_value); - apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ static_cast<unsigned int>(filter_size), static_cast<unsigned int>(filter_size) }, masks.at(filter_size).second, 1.f, border_mode, - constant_border_value); - break; - default: - ARM_COMPUTE_ERROR("Gradient dimension not supported"); - } - } - - return std::make_pair(dst_x, dst_y); -} - -template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> sobel(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -template std::pair<SimpleTensor<int>, SimpleTensor<int>> sobel(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, - GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Sobel.h b/tests/validation/reference/Sobel.h deleted file mode 100644 index 43f0131a9a..0000000000 --- a/tests/validation/reference/Sobel.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_SOBEL_H -#define ARM_COMPUTE_TEST_SOBEL_H - -#include "arm_compute/core/Types.h" -#include "tests/SimpleTensor.h" -#include "tests/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename U> -std::pair<SimpleTensor<T>, SimpleTensor<T>> sobel(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_SOBEL_H */ diff --git a/tests/validation/reference/SoftmaxLayer.cpp b/tests/validation/reference/SoftmaxLayer.cpp index 2fe1faef50..3fbac32a9b 100644 --- a/tests/validation/reference/SoftmaxLayer.cpp +++ b/tests/validation/reference/SoftmaxLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -23,7 +23,9 @@ */ #include "SoftmaxLayer.h" +#include "arm_compute/core/Helpers.h" #include "arm_compute/core/Types.h" +#include "utils/TypePrinter.h" namespace arm_compute { @@ -39,45 +41,38 @@ SimpleTensor<T> softmax_layer_generic(const SimpleTensor<T> &src, float beta, in // Create reference SimpleTensor<T> dst{ src.shape(), src.data_type(), 1 }; - // Negative index is used to specify axis from the end (e.g. -1 for the last axis). - if(axis < 0) - { - axis += src.shape().num_dimensions(); - } - - // Compute reference. Lower dims are the collapsing of the first axis - // dimensions (i.e., the flattened dimension of each batch). The upper dims are - // instead the batches we want to normalize - - int lower_dims = 1; - for(size_t i = 0; i < static_cast<size_t>(axis); ++i) - { - lower_dims *= src.shape()[i]; - } + const int32_t n_dims = static_cast<int32_t>(src.shape().num_dimensions()); + ARM_COMPUTE_ERROR_ON(axis < -n_dims || axis >= n_dims); - int upper_dims = 1; - for(size_t i = static_cast<size_t>(axis); i < TensorShape::num_max_dimensions; ++i) - { - upper_dims *= src.shape()[i]; - } + const unsigned int actual_axis = static_cast<unsigned int>(wrap_around(axis, n_dims)); + Window window; + window.use_tensor_dimensions(src.shape()); + const unsigned int axis_dimension = src.shape()[actual_axis]; + window.set(actual_axis, Window::Dimension(0, 1, 1)); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(int r = 0; r < upper_dims; ++r) + execute_window_loop(window, [&](const Coordinates & id) { - const T *src_row_ptr = src.data() + r * lower_dims; - T *dst_row_ptr = dst.data() + r * lower_dims; - - // Find max - const T max = *std::max_element(src_row_ptr, src_row_ptr + lower_dims); + // Find max along axis + Coordinates offset(id); + offset.set(actual_axis, 0); + T max = *reinterpret_cast<const T *>(src(offset)); + for(unsigned int axis_id = 1; axis_id < axis_dimension; ++axis_id) + { + offset.set(actual_axis, axis_id); + const T val = *reinterpret_cast<const T *>(src(offset)); + if(val > max) + { + max = val; + } + } // Regularize T sum(0.f); - std::transform(src_row_ptr, src_row_ptr + lower_dims, dst_row_ptr, [&sum, max, beta, is_log](T val) + for(unsigned int axis_id = 0; axis_id < axis_dimension; ++axis_id) { - T res{ (val - max) *beta }; - + offset.set(actual_axis, axis_id); + const T val = *reinterpret_cast<const T *>(src(offset)); + T res{ (val - max) *beta }; if(is_log) { sum += std::exp(res); @@ -87,23 +82,24 @@ SimpleTensor<T> softmax_layer_generic(const SimpleTensor<T> &src, float beta, in res = std::exp(res); sum += res; } - return res; - }); + *reinterpret_cast<T *>(dst(offset)) = res; + } // Normalize - std::transform(dst_row_ptr, dst_row_ptr + lower_dims, dst_row_ptr, [sum, is_log](T val) + for(unsigned int axis_id = 0; axis_id < axis_dimension; ++axis_id) { + offset.set(actual_axis, axis_id); + const T val = *reinterpret_cast<const T *>(dst(offset)); if(is_log) { - return val - sum; + *reinterpret_cast<T *>(dst(offset)) = val - static_cast<T>(std::log(sum)); } else { - return val / sum; + *reinterpret_cast<T *>(dst(offset)) = val / sum; } - }); - } - + } + }); return dst; } @@ -111,26 +107,27 @@ template SimpleTensor<float> softmax_layer_generic(const SimpleTensor<float> &sr template SimpleTensor<half> softmax_layer_generic(const SimpleTensor<half> &src, float beta, int32_t axis, bool is_log); template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis) +SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis, bool is_log) { - return softmax_layer_generic<T>(src, beta, axis, false); + return softmax_layer_generic<T>(src, beta, axis, is_log); } template < typename T, typename std::enable_if < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int >::type > -SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis) +SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis, bool is_log) { - const QuantizationInfo output_quantization_info = arm_compute::get_softmax_output_quantization_info(src.data_type(), false); + const QuantizationInfo output_quantization_info = arm_compute::get_softmax_output_quantization_info(src.data_type(), is_log); SimpleTensor<float> src_tmp = convert_from_asymmetric(src); - SimpleTensor<float> dst_tmp = softmax_layer<float>(src_tmp, beta, axis); + SimpleTensor<float> dst_tmp = softmax_layer<float>(src_tmp, beta, axis, is_log); SimpleTensor<T> dst = convert_to_asymmetric<T>(dst_tmp, output_quantization_info); return dst; } -template SimpleTensor<float> softmax_layer(const SimpleTensor<float> &src, float beta, int32_t axis); -template SimpleTensor<half> softmax_layer(const SimpleTensor<half> &src, float beta, int32_t axis); -template SimpleTensor<uint8_t> softmax_layer(const SimpleTensor<uint8_t> &src, float beta, int32_t axis); -template SimpleTensor<int8_t> softmax_layer(const SimpleTensor<int8_t> &src, float beta, int32_t axis); +template SimpleTensor<float> softmax_layer(const SimpleTensor<float> &src, float beta, int32_t axis, bool is_log); +template SimpleTensor<half> softmax_layer(const SimpleTensor<half> &src, float beta, int32_t axis, bool is_log); +template SimpleTensor<uint8_t> softmax_layer(const SimpleTensor<uint8_t> &src, float beta, int32_t axis, bool is_log); +template SimpleTensor<int8_t> softmax_layer(const SimpleTensor<int8_t> &src, float beta, int32_t axis, bool is_log); + } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/SoftmaxLayer.h b/tests/validation/reference/SoftmaxLayer.h index f819853d95..3362f195c9 100644 --- a/tests/validation/reference/SoftmaxLayer.h +++ b/tests/validation/reference/SoftmaxLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -39,10 +39,10 @@ template <typename T, typename std::enable_if<is_floating_point<T>::value, int>: SimpleTensor<T> softmax_layer_generic(const SimpleTensor<T> &src, float beta, int32_t axis, bool is_log = false); template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> -SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis = -1); +SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis = 0, bool is_log = false); template < typename T, typename std::enable_if < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int >::type = 0 > -SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis = -1); +SimpleTensor<T> softmax_layer(const SimpleTensor<T> &src, float beta, int32_t axis = 0, bool is_log = false); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/SpaceToBatch.cpp b/tests/validation/reference/SpaceToBatch.cpp index 8c25bb7d91..1d632a31c2 100644 --- a/tests/validation/reference/SpaceToBatch.cpp +++ b/tests/validation/reference/SpaceToBatch.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/SpaceToBatch.h b/tests/validation/reference/SpaceToBatch.h index c4e7797a89..809be80e8c 100644 --- a/tests/validation/reference/SpaceToBatch.h +++ b/tests/validation/reference/SpaceToBatch.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/SpaceToDepth.cpp b/tests/validation/reference/SpaceToDepth.cpp index bd8e37a8bf..da911ae5e2 100644 --- a/tests/validation/reference/SpaceToDepth.cpp +++ b/tests/validation/reference/SpaceToDepth.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/SpaceToDepth.h b/tests/validation/reference/SpaceToDepth.h index faead46dd1..e2ea1b75c7 100644 --- a/tests/validation/reference/SpaceToDepth.h +++ b/tests/validation/reference/SpaceToDepth.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ARM Limited. + * Copyright (c) 2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/StackLayer.cpp b/tests/validation/reference/StackLayer.cpp index 9e9e434230..5873101e99 100644 --- a/tests/validation/reference/StackLayer.cpp +++ b/tests/validation/reference/StackLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/StackLayer.h b/tests/validation/reference/StackLayer.h index 301d59a463..6a7181ec91 100644 --- a/tests/validation/reference/StackLayer.h +++ b/tests/validation/reference/StackLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/TableLookup.cpp b/tests/validation/reference/TableLookup.cpp index 7f105d99ca..1cd14b5a58 100644 --- a/tests/validation/reference/TableLookup.cpp +++ b/tests/validation/reference/TableLookup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/TableLookup.h b/tests/validation/reference/TableLookup.h index 3431343220..d765a14a7d 100644 --- a/tests/validation/reference/TableLookup.h +++ b/tests/validation/reference/TableLookup.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Threshold.cpp b/tests/validation/reference/Threshold.cpp deleted file mode 100644 index d0ef31df04..0000000000 --- a/tests/validation/reference/Threshold.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal src the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included src all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. src NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER src AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * dst OF OR src CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS src THE - * SOFTWARE. - */ -#include "Threshold.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> threshold(const SimpleTensor<T> &src, T threshold, T false_value, T true_value, ThresholdType type, T upper) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - switch(type) - { - case ThresholdType::BINARY: - for(int i = 0; i < src.num_elements(); ++i) - { - dst[i] = ((src[i] > threshold) ? true_value : false_value); - } - break; - case ThresholdType::RANGE: - for(int i = 0; i < src.num_elements(); ++i) - { - if(src[i] > upper) - { - dst[i] = false_value; - } - else if(src[i] < threshold) - { - dst[i] = false_value; - } - else - { - dst[i] = true_value; - } - } - break; - default: - ARM_COMPUTE_ERROR("Thresholding type not recognised"); - break; - } - - return dst; -} - -template SimpleTensor<uint8_t> threshold(const SimpleTensor<uint8_t> &src, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Threshold.h b/tests/validation/reference/Threshold.h deleted file mode 100644 index b8b58ff09c..0000000000 --- a/tests/validation/reference/Threshold.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_THRESHOLD_H -#define ARM_COMPUTE_TEST_THRESHOLD_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> threshold(const SimpleTensor<T> &src, T threshold, T false_value, T true_value, ThresholdType type, T upper); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_THRESHOLD_H */ diff --git a/tests/validation/reference/Tile.cpp b/tests/validation/reference/Tile.cpp index 694f645007..8b5a8d1e7c 100644 --- a/tests/validation/reference/Tile.cpp +++ b/tests/validation/reference/Tile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Tile.h b/tests/validation/reference/Tile.h index 36de9661d8..d37836931f 100644 --- a/tests/validation/reference/Tile.h +++ b/tests/validation/reference/Tile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Transpose.cpp b/tests/validation/reference/Transpose.cpp index a8c0e95322..02c6d86f53 100644 --- a/tests/validation/reference/Transpose.cpp +++ b/tests/validation/reference/Transpose.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Transpose.h b/tests/validation/reference/Transpose.h index aedd494d5d..bbe1c35dfb 100644 --- a/tests/validation/reference/Transpose.h +++ b/tests/validation/reference/Transpose.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Unstack.cpp b/tests/validation/reference/Unstack.cpp index 3474c15173..02a9c7ab75 100644 --- a/tests/validation/reference/Unstack.cpp +++ b/tests/validation/reference/Unstack.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Unstack.h b/tests/validation/reference/Unstack.h index a9e48d7bd2..88f8a662f4 100644 --- a/tests/validation/reference/Unstack.h +++ b/tests/validation/reference/Unstack.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/UpsampleLayer.cpp b/tests/validation/reference/UpsampleLayer.cpp deleted file mode 100644 index a81a601057..0000000000 --- a/tests/validation/reference/UpsampleLayer.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "UpsampleLayer.h" - -#include "arm_compute/core/utils/misc/Requires.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> upsample_layer(const SimpleTensor<T> &src, const Size2D &info, const InterpolationPolicy policy) -{ - ARM_COMPUTE_ERROR_ON(policy != InterpolationPolicy::NEAREST_NEIGHBOR); - ARM_COMPUTE_UNUSED(policy); - - TensorShape output_shape = src.shape(); - output_shape.set(0, src.shape().x() * info.x()); - output_shape.set(1, src.shape().y() * info.y()); - - // Create reference - const int stride_x = info.x(); - const int stride_y = info.y(); - int width_out = output_shape.x(); - int height_out = output_shape.y(); - SimpleTensor<T> out{ output_shape, src.data_type(), 1, src.quantization_info() }; - - const int width_in = src.shape().x(); - const int height_in = src.shape().y(); - const int num_2d_slices = src.shape().total_size() / (width_in * height_in); - - for(int slice = 0; slice < num_2d_slices; ++slice) - { - const int offset_slice_in = slice * width_in * height_in; - const int offset_slice_out = slice * height_out * width_out; - for(int y = 0; y < height_out; ++y) - { - for(int x = 0; x < width_out; ++x) - { - const int out_offset = y * width_out + x; - const int in_offset = (y / stride_y) * width_in + x / stride_x; - - T *_out = out.data() + offset_slice_out + out_offset; - const T *in = src.data() + offset_slice_in + in_offset; - *_out = *in; - } - } - } - return out; -} - -template SimpleTensor<float> upsample_layer(const SimpleTensor<float> &src, - const Size2D &info, const InterpolationPolicy policy); -template SimpleTensor<half> upsample_layer(const SimpleTensor<half> &src, - const Size2D &info, const InterpolationPolicy policy); -template SimpleTensor<uint8_t> upsample_layer(const SimpleTensor<uint8_t> &src, - const Size2D &info, const InterpolationPolicy policy); -template SimpleTensor<int8_t> upsample_layer(const SimpleTensor<int8_t> &src, - const Size2D &info, const InterpolationPolicy policy); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/Utils.cpp b/tests/validation/reference/Utils.cpp index 7a9bfeeaab..844103fe64 100644 --- a/tests/validation/reference/Utils.cpp +++ b/tests/validation/reference/Utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Utils.h b/tests/validation/reference/Utils.h index f7699b1fdf..c83c6ea4b3 100644 --- a/tests/validation/reference/Utils.h +++ b/tests/validation/reference/Utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -26,7 +26,6 @@ #include "arm_compute/core/Types.h" #include "tests/Globals.h" -#include "tests/ILutAccessor.h" #include "tests/Types.h" #include <array> @@ -56,6 +55,9 @@ inline bool is_valid_pixel_index(int x, int y, int width, int height, int border return ((x >= -border_size) && (y >= -border_size) && (x < (width + border_size)) && (y < height + border_size)); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-overflow" + // Return a tensor element at a specified coordinate with different border modes template <typename T> T tensor_elem_at(const SimpleTensor<T> &src, Coordinates coord, BorderMode border_mode, T constant_border_value) @@ -84,6 +86,8 @@ T tensor_elem_at(const SimpleTensor<T> &src, Coordinates coord, BorderMode borde return src[coord2index(src.shape(), coord)]; } +#pragma GCC diagnostic pop + template <typename T> T bilinear_policy(const SimpleTensor<T> &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value); @@ -118,26 +122,6 @@ void apply_2d_spatial_filter(Coordinates coord, const SimpleTensor<T> &src, Simp RawTensor transpose(const RawTensor &src, int chunk_width = 1); -/** Fill matrix random. - * - * @param[in,out] matrix Matrix - */ -template <std::size_t SIZE> -inline void fill_warp_matrix(std::array<float, SIZE> &matrix) -{ - std::mt19937 gen(library.get()->seed()); - std::uniform_real_distribution<float> dist(-1, 1); - for(auto &x : matrix) - { - x = dist(gen); - } - if(SIZE == 9) - { - // This is only used in Warp Perspective, we set M[3][3] = 1 so that Z0 is not 0 and we avoid division by 0. - matrix[8] = 1.f; - } -} - bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode); } // namespace validation } // namespace test diff --git a/tests/validation/reference/UtilsQuantizedAsymm.h b/tests/validation/reference/UtilsQuantizedAsymm.h index 444696c93a..e5ecc66545 100644 --- a/tests/validation/reference/UtilsQuantizedAsymm.h +++ b/tests/validation/reference/UtilsQuantizedAsymm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -32,6 +32,22 @@ namespace test { namespace validation { +namespace +{ +#if __clang__ +// This has been tested on clang 7.0.2 (__clang_major__ == 7 && __clang_minor__ == 0 && __clang_patchlevel__ == 2) +inline int64_t to_int64(int32_t val) +{ + return static_cast<int64_t>(val) | ((val < 0) ? (((1ll << 32) - 1) << 32) : 0); +} +#else // __clang__ +inline int64_t to_int64(int32_t val) +{ + return static_cast<int64_t>(val); +} +#endif // __clang__ +} // namespace + /** Rounded to nearest division by a power-of-two. */ inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent) { @@ -40,15 +56,15 @@ inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent) return (x >> exponent) + ((x & mask) > threshold ? 1 : 0); } -/** Multiplication of two integers. The same as ARMv7 NEON VQRDMULH instruction. */ +/** Multiplication of two integers. The same as ARMv7 Arm® Neon™ VQRDMULH instruction. */ inline int32_t asymm_int_mult(int32_t a, int32_t b) { - bool overflow = a == b && a == std::numeric_limits<int32_t>::min(); - int64_t a_64(a); - int64_t b_64(b); - int64_t ab_64 = a_64 * b_64; - int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); - int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31)); + const bool overflow = a == b && a == std::numeric_limits<int32_t>::min(); + const int64_t a_64 = to_int64(a); + const int64_t b_64 = to_int64(b); + const int64_t ab_64 = a_64 * b_64; + const int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); + const int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31)); return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32; } diff --git a/tests/validation/reference/WarpAffine.cpp b/tests/validation/reference/WarpAffine.cpp deleted file mode 100644 index 2a7aeb7cc2..0000000000 --- a/tests/validation/reference/WarpAffine.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "WarpAffine.h" - -#include "Utils.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -bool valid_bilinear_policy(float xn, float yn, int width, int height, BorderMode border_mode) -{ - if(border_mode != BorderMode::UNDEFINED) - { - return true; - } - if((0 <= yn + 1) && (yn + 1 < height) && (0 <= xn + 1) && (xn + 1 < width)) - { - return true; - } - return false; -} - -template <typename T> -SimpleTensor<T> warp_affine(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - // x0 = M00 * x + M01 * y + M02 - // y0 = M10 * x + M11 * y + M12 - const float M00 = matrix[0]; - const float M10 = matrix[1]; - const float M01 = matrix[0 + 1 * 2]; - const float M11 = matrix[1 + 1 * 2]; - const float M02 = matrix[0 + 2 * 2]; - const float M12 = matrix[1 + 2 * 2]; - - const int width = src.shape().x(); - const int height = src.shape().y(); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(src.shape(), element_idx); - int idx = id.x(); - int idy = id.y(); - - float x0 = M00 * idx + M01 * idy + M02; - float y0 = M10 * idx + M11 * idy + M12; - - id.set(0, static_cast<int>(std::floor(x0))); - id.set(1, static_cast<int>(std::floor(y0))); - if((0 <= y0) && (y0 < height) && (0 <= x0) && (x0 < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(x0, y0, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value) : - valid_mask[element_idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[element_idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - if(border_mode == BorderMode::CONSTANT) - { - dst[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast<int>(x0), width - 1))); - id.set(1, std::max(0, std::min(static_cast<int>(y0), height - 1))); - dst[element_idx] = src[coord2index(src.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - dst[element_idx] = bilinear_policy(src, id, x0, y0, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - } - } - } - } - - return dst; -} - -template SimpleTensor<uint8_t> warp_affine(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute
\ No newline at end of file diff --git a/tests/validation/reference/WarpAffine.h b/tests/validation/reference/WarpAffine.h deleted file mode 100644 index 3d980031f8..0000000000 --- a/tests/validation/reference/WarpAffine.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_WARP_AFFINE_H -#define ARM_COMPUTE_TEST_WARP_AFFINE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> warp_affine(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_WARP_AFFINE_H */ diff --git a/tests/validation/reference/WarpPerspective.cpp b/tests/validation/reference/WarpPerspective.cpp deleted file mode 100644 index dc7420b93b..0000000000 --- a/tests/validation/reference/WarpPerspective.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "arm_compute/core/Helpers.h" - -#include "Utils.h" -#include "WarpPerspective.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> warp_perspective(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) -{ - SimpleTensor<T> dst(src.shape(), src.data_type()); - - // x0 = M00 * x + M01 * y + M02 - // y0 = M10 * x + M11 * y + M12 - // z0 = M20 * x + M21 * y + M22 - // xn = x0 / z0 - // yn = y0 / z0 - const float M00 = matrix[0]; - const float M10 = matrix[1]; - const float M20 = matrix[2]; - const float M01 = matrix[0 + 1 * 3]; - const float M11 = matrix[1 + 1 * 3]; - const float M21 = matrix[2 + 1 * 3]; - const float M02 = matrix[0 + 2 * 3]; - const float M12 = matrix[1 + 2 * 3]; - const float M22 = matrix[2 + 2 * 3]; - - const int width = src.shape().x(); - const int height = src.shape().y(); - - const uint32_t num_elements = src.num_elements(); - for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx) - { - valid_mask[element_idx] = 1; - Coordinates id = index2coord(src.shape(), element_idx); - const int idx = id.x(); - const int idy = id.y(); - const float z0 = M20 * idx + M21 * idy + M22; - - const float x0 = (M00 * idx + M01 * idy + M02); - const float y0 = (M10 * idx + M11 * idy + M12); - - const float xn = x0 / z0; - const float yn = y0 / z0; - id.set(0, static_cast<int>(std::floor(xn))); - id.set(1, static_cast<int>(std::floor(yn))); - if((0 <= yn) && (yn < height) && (0 <= xn) && (xn < width)) - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - dst[element_idx] = tensor_elem_at(src, id, border_mode, constant_border_value); - break; - case InterpolationPolicy::BILINEAR: - (valid_bilinear_policy(xn, yn, width, height, border_mode)) ? dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value) : valid_mask[element_idx] = 0; - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - else - { - if(border_mode == BorderMode::UNDEFINED) - { - valid_mask[element_idx] = 0; - } - else - { - switch(policy) - { - case InterpolationPolicy::NEAREST_NEIGHBOR: - if(border_mode == BorderMode::CONSTANT) - { - dst[element_idx] = constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) - { - id.set(0, std::max(0, std::min(static_cast<int>(xn), width - 1))); - id.set(1, std::max(0, std::min(static_cast<int>(yn), height - 1))); - dst[element_idx] = src[coord2index(src.shape(), id)]; - } - break; - case InterpolationPolicy::BILINEAR: - dst[element_idx] = bilinear_policy(src, id, xn, yn, border_mode, constant_border_value); - break; - case InterpolationPolicy::AREA: - default: - ARM_COMPUTE_ERROR("Interpolation not supported"); - break; - } - } - } - } - return dst; -} - -template SimpleTensor<uint8_t> warp_perspective(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, - uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/reference/WarpPerspective.h b/tests/validation/reference/WarpPerspective.h deleted file mode 100644 index b919d625ea..0000000000 --- a/tests/validation/reference/WarpPerspective.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017-2019 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H -#define ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H - -#include "tests/SimpleTensor.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T> -SimpleTensor<T> warp_perspective(const SimpleTensor<T> &src, SimpleTensor<T> &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_WARP_PERSPECTIVE_H */ diff --git a/tests/validation/reference/WeightsReshape.cpp b/tests/validation/reference/WeightsReshape.cpp index fc023951fb..bb6caea60e 100644 --- a/tests/validation/reference/WeightsReshape.cpp +++ b/tests/validation/reference/WeightsReshape.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/WeightsReshape.h b/tests/validation/reference/WeightsReshape.h index d7999b541e..7a6ce4b154 100644 --- a/tests/validation/reference/WeightsReshape.h +++ b/tests/validation/reference/WeightsReshape.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Winograd.cpp b/tests/validation/reference/Winograd.cpp index 61ba510fc6..64cd9e69a3 100644 --- a/tests/validation/reference/Winograd.cpp +++ b/tests/validation/reference/Winograd.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 ARM Limited. + * Copyright (c) 2018-2020 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/Winograd.h b/tests/validation/reference/Winograd.h index 99e7a9a8ac..8e28aa3079 100644 --- a/tests/validation/reference/Winograd.h +++ b/tests/validation/reference/Winograd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/validation/reference/YOLOLayer.cpp b/tests/validation/reference/YOLOLayer.cpp deleted file mode 100644 index 92bbf5445f..0000000000 --- a/tests/validation/reference/YOLOLayer.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2018-2020 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "YOLOLayer.h" - -#include "ActivationLayer.h" - -#include "arm_compute/core/Types.h" -#include "tests/validation/Helpers.h" - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -namespace reference -{ -template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> yolo_layer(const SimpleTensor<T> &src, const ActivationLayerInfo &info, int32_t num_classes) -{ - // Create reference - SimpleTensor<T> dst{ src.shape(), src.data_type() }; - - // Compute reference - const T a(info.a()); - const T b(info.b()); - - const uint32_t num_elements = src.num_elements(); -#if defined(_OPENMP) - #pragma omp parallel for -#endif /* _OPENMP */ - for(uint32_t i = 0; i < num_elements; ++i) - { - const size_t z = index2coord(dst.shape(), i).z() % (num_classes + 5); - - if(z != 2 && z != 3) - { - dst[i] = activate_float<T>(src[i], a, b, info.activation()); - } - else - { - dst[i] = src[i]; - } - } - - return dst; -} - -template <> -SimpleTensor<uint8_t> yolo_layer<uint8_t>(const SimpleTensor<uint8_t> &src, const ActivationLayerInfo &info, int32_t num_classes) -{ - SimpleTensor<float> src_tmp = convert_from_asymmetric(src); - SimpleTensor<float> dst_tmp = yolo_layer<float>(src_tmp, info, num_classes); - SimpleTensor<uint8_t> dst = convert_to_asymmetric<uint8_t>(dst_tmp, src.quantization_info()); - return dst; -} - -template SimpleTensor<float> yolo_layer(const SimpleTensor<float> &src, const ActivationLayerInfo &info, int32_t num_classes); -template SimpleTensor<half> yolo_layer(const SimpleTensor<half> &src, const ActivationLayerInfo &info, int32_t num_classes); -} // namespace reference -} // namespace validation -} // namespace test -} // namespace arm_compute |