diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/validation/CL/Scale.cpp | 61 | ||||
-rw-r--r-- | tests/validation/fixtures/ScaleFixture.h | 70 | ||||
-rw-r--r-- | tests/validation/reference/Scale.cpp | 32 | ||||
-rw-r--r-- | tests/validation/reference/Scale.h | 5 |
4 files changed, 135 insertions, 33 deletions
diff --git a/tests/validation/CL/Scale.cpp b/tests/validation/CL/Scale.cpp index 92d4f96c6a..3bf7c90a1e 100644 --- a/tests/validation/CL/Scale.cpp +++ b/tests/validation/CL/Scale.cpp @@ -78,7 +78,6 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( TensorInfo(TensorShape(36U, 36U, 2U, 4U), 1, DataType::U8), TensorInfo(TensorShape(40U, 35U, 2U, 4U), 1, DataType::S16), TensorInfo(TensorShape(37U, 37U, 2U), 1, DataType::F32), // window shrink - TensorInfo(TensorShape(128U, 64U, 1U, 3U), 1, DataType::QASYMM8), // not supported TensorInfo(TensorShape(37U, 37U, 3U, 4U), 1, DataType::F32), // mismatching datatype TensorInfo(TensorShape(28U, 33U, 2U), 1, DataType::F32), // policy area, scale factor not correct }), @@ -87,7 +86,6 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( TensorInfo(TensorShape(40U, 76U, 2U, 4U), 1, DataType::U8), TensorInfo(TensorShape(28U, 32U, 2U, 4U), 1, DataType::S16), TensorInfo(TensorShape(39U, 55U, 2U), 1, DataType::F32), // window shrink - TensorInfo(TensorShape(137U, 134U, 1U, 3U), 1, DataType::QASYMM8), // not supported TensorInfo(TensorShape(39U, 77U, 3U, 4U), 1, DataType::F16), // mismatching datatype TensorInfo(TensorShape(26U, 21U, 2U), 1, DataType::F32), // policy area, scale factor not correct })), @@ -97,7 +95,6 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR, - InterpolationPolicy::BILINEAR, InterpolationPolicy::AREA, })), framework::dataset::make("BorderMode",{ BorderMode::UNDEFINED, @@ -107,9 +104,8 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( BorderMode::UNDEFINED, BorderMode::UNDEFINED, BorderMode::UNDEFINED, - BorderMode::UNDEFINED, })), - framework::dataset::make("Expected", { true, true, true, true, false, false, false, false })), + framework::dataset::make("Expected", { true, true, true, true, false, false, false })), input_info, output_info, policy, border_mode, expected) { Status status = CLScale::validate(&input_info.clone()->set_is_resizable(false), @@ -197,7 +193,7 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<float>, framework::DatasetMode:: // Validate output validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute); } -TEST_SUITE_END() +TEST_SUITE_END() // FP32 TEST_SUITE(FP16) FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), @@ -227,8 +223,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<half>, framework::DatasetMode::N // Validate output validate(CLAccessor(_target), _reference, valid_region, tolerance_f16); } -TEST_SUITE_END() -TEST_SUITE_END() +TEST_SUITE_END() // FP16 +TEST_SUITE_END() // Float TEST_SUITE(Integer) TEST_SUITE(U8) @@ -260,7 +256,7 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode // Validate output validate(CLAccessor(_target), _reference, valid_region, tolerance_u8); } -TEST_SUITE_END() +TEST_SUITE_END() // U8 TEST_SUITE(S16) FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::S16)), @@ -290,11 +286,50 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<int16_t>, framework::DatasetMode // Validate output validate(CLAccessor(_target), _reference, valid_region, tolerance_s16); } -TEST_SUITE_END() -TEST_SUITE_END() +TEST_SUITE_END() // S16 +TEST_SUITE_END() // Integer + +template <typename T> +using CLScaleQuantizedFixture = ScaleValidationQuantizedFixture<CLTensor, CLAccessor, CLScale, T>; +TEST_SUITE(Quantized) +TEST_SUITE(QASYMM8) +FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(datasets::SmallShapes(), + framework::dataset::make("DataType", + DataType::QASYMM8)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -1) })), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), + framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), + datasets::BorderModes()), + datasets::SamplingPolicies())) +{ + //Create valid region + TensorInfo src_info(_shape, 1, _data_type); + const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); + + // Validate output + validate(CLAccessor(_target), _reference, valid_region, tolerance_u8); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(datasets::LargeShapes(), + framework::dataset::make("DataType", + DataType::QASYMM8)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -1) })), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), + framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), + datasets::BorderModes()), + datasets::SamplingPolicies())) +{ + //Create valid region + TensorInfo src_info(_shape, 1, _data_type); + const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); + + // Validate output + validate(CLAccessor(_target), _reference, valid_region, tolerance_u8); +} +TEST_SUITE_END() // QASYMM8 +TEST_SUITE_END() // Quantized -TEST_SUITE_END() -TEST_SUITE_END() +TEST_SUITE_END() // Scale +TEST_SUITE_END() // CL } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/fixtures/ScaleFixture.h b/tests/validation/fixtures/ScaleFixture.h index 5413147699..2be02ec4d6 100644 --- a/tests/validation/fixtures/ScaleFixture.h +++ b/tests/validation/fixtures/ScaleFixture.h @@ -41,20 +41,21 @@ namespace test namespace validation { template <typename TensorType, typename AccessorType, typename FunctionType, typename T> -class ScaleValidationFixture : public framework::Fixture +class ScaleValidationGenericFixture : public framework::Fixture { public: template <typename...> - void setup(TensorShape shape, DataType data_type, DataLayout data_layout, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy) + void setup(TensorShape shape, DataType data_type, QuantizationInfo quantization_info, DataLayout data_layout, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy) { constexpr float max_width = 8192.0f; constexpr float max_height = 6384.0f; - _shape = shape; - _policy = policy; - _border_mode = border_mode; - _sampling_policy = sampling_policy; - _data_type = data_type; + _shape = shape; + _policy = policy; + _border_mode = border_mode; + _sampling_policy = sampling_policy; + _data_type = data_type; + _quantization_info = quantization_info; std::mt19937 generator(library->seed()); std::uniform_real_distribution<float> distribution_float(0.25, 3); @@ -70,8 +71,8 @@ public: std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); T constant_border_value = static_cast<T>(distribution_u8(generator)); - _target = compute_target(shape, data_layout, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy); - _reference = compute_reference(shape, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy); + _target = compute_target(shape, data_layout, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy, quantization_info); + _reference = compute_reference(shape, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy, quantization_info); } protected: @@ -82,6 +83,11 @@ protected: { library->fill_tensor_uniform(tensor, 0); } + else if(is_data_type_quantized(tensor.data_type())) + { + std::uniform_int_distribution<> distribution(0, 100); + library->fill(tensor, distribution, 0); + } else { // Restrict range for float to avoid any floating point issues @@ -91,7 +97,8 @@ protected: } TensorType compute_target(TensorShape shape, DataLayout data_layout, const float scale_x, const float scale_y, - InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy) + InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy, + QuantizationInfo quantization_info) { // Change shape in case of NHWC. if(data_layout == DataLayout::NHWC) @@ -100,7 +107,7 @@ protected: } // Create tensors - TensorType src = create_tensor<TensorType>(shape, _data_type, 1, QuantizationInfo(), data_layout); + TensorType src = create_tensor<TensorType>(shape, _data_type, 1, quantization_info, data_layout); const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); @@ -108,7 +115,7 @@ protected: TensorShape shape_scaled(shape); shape_scaled.set(idx_width, shape[idx_width] * scale_x); shape_scaled.set(idx_height, shape[idx_height] * scale_y); - TensorType dst = create_tensor<TensorType>(shape_scaled, _data_type, 1, QuantizationInfo(), data_layout); + TensorType dst = create_tensor<TensorType>(shape_scaled, _data_type, 1, quantization_info, data_layout); // Create and configure function FunctionType scale; @@ -134,10 +141,11 @@ protected: } SimpleTensor<T> compute_reference(const TensorShape &shape, const float scale_x, const float scale_y, - InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy) + InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy, + QuantizationInfo quantization_info) { // Create reference - SimpleTensor<T> src{ shape, _data_type, 1, QuantizationInfo() }; + SimpleTensor<T> src{ shape, _data_type, 1, quantization_info }; // Fill reference fill(src); @@ -152,6 +160,40 @@ protected: BorderMode _border_mode{}; SamplingPolicy _sampling_policy{}; DataType _data_type{}; + QuantizationInfo _quantization_info{}; +}; + +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class ScaleValidationQuantizedFixture : public ScaleValidationGenericFixture<TensorType, AccessorType, FunctionType, T> +{ +public: + template <typename...> + void setup(TensorShape shape, DataType data_type, QuantizationInfo quantization_info, DataLayout data_layout, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy) + { + ScaleValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, + data_type, + quantization_info, + data_layout, + policy, + border_mode, + sampling_policy); + } +}; +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class ScaleValidationFixture : public ScaleValidationGenericFixture<TensorType, AccessorType, FunctionType, T> +{ +public: + template <typename...> + void setup(TensorShape shape, DataType data_type, DataLayout data_layout, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy) + { + ScaleValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, + data_type, + QuantizationInfo(), + data_layout, + policy, + border_mode, + sampling_policy); + } }; } // namespace validation } // namespace test diff --git a/tests/validation/reference/Scale.cpp b/tests/validation/reference/Scale.cpp index f8a8b88cf9..2f7bf2deb3 100644 --- a/tests/validation/reference/Scale.cpp +++ b/tests/validation/reference/Scale.cpp @@ -37,8 +37,8 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> scale(const SimpleTensor<T> &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, - SamplingPolicy sampling_policy, bool ceil_policy_scale) +SimpleTensor<T> scale_core(const SimpleTensor<T> &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, + SamplingPolicy sampling_policy, bool ceil_policy_scale) { // Add 1 if ceil_policy_scale is true const size_t round_value = ceil_policy_scale ? 1U : 0U; @@ -168,8 +168,32 @@ SimpleTensor<T> scale(const SimpleTensor<T> &in, float scale_x, float scale_y, I return out; } -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); +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) +{ + return scale_core<T>(src, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy, ceil_policy_scale); +} + +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) +{ + SimpleTensor<uint8_t> dst; + if(src.quantization_info().scale != 0.f) + { + SimpleTensor<float> src_tmp = convert_from_asymmetric(src); + float constant_border_value_f = scvt_f32_qasymm8(constant_border_value, src.quantization_info().scale, src.quantization_info().offset); + 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); + dst = convert_to_asymmetric(dst_tmp, src.quantization_info()); + } + else + { + dst = scale_core<uint8_t>(src, scale_x, scale_y, policy, border_mode, constant_border_value, sampling_policy, ceil_policy_scale); + } + return dst; +} + 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); template SimpleTensor<half> scale(const SimpleTensor<half> &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, half constant_border_value, diff --git a/tests/validation/reference/Scale.h b/tests/validation/reference/Scale.h index 566e30af10..66267ebc9a 100644 --- a/tests/validation/reference/Scale.h +++ b/tests/validation/reference/Scale.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ #define __ARM_COMPUTE_TEST_SCALE_H__ #include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" namespace arm_compute { @@ -35,7 +36,7 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> scale(const SimpleTensor<T> &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value = 0, +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); } // namespace reference } // namespace validation |