From 0b18d9740f04cc4e9cb6000a76b9c1dcd8327e24 Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Thu, 30 Jan 2020 18:11:13 +0000 Subject: COMPMID-2762: Add support for QASYMM8_SIGNED in CLReductionOperation and CLReduceMean Change-Id: Ib6babd9ad80c57cf21c2f0ee2aab404221088595 Signed-off-by: Michalis Spyrou Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2670 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio --- tests/validation/CL/ReduceMean.cpp | 42 ++++++------- tests/validation/CL/ReductionOperation.cpp | 72 ++++++++++++---------- .../fixtures/ReductionOperationFixture.h | 17 +++-- tests/validation/reference/ReductionOperation.cpp | 15 +++++ 4 files changed, 87 insertions(+), 59 deletions(-) (limited to 'tests') diff --git a/tests/validation/CL/ReduceMean.cpp b/tests/validation/CL/ReduceMean.cpp index 036ea181ac..5069711296 100644 --- a/tests/validation/CL/ReduceMean.cpp +++ b/tests/validation/CL/ReduceMean.cpp @@ -80,28 +80,6 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( // clang-format on // *INDENT-ON* -DATA_TEST_CASE(Configuration, - framework::DatasetMode::ALL, - combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })), - shape, data_type) -{ - // Create tensors - CLTensor ref_src = create_tensor(shape, data_type); - CLTensor dst; - - Coordinates axis(1); - - // Create and Configure function - CLReduceMean reduce_mean; - reduce_mean.configure(&ref_src, axis, true, &dst); - - // Validate valid region - TensorShape output_shape = shape; - output_shape.set(1, 1); - const ValidRegion valid_region = shape_to_valid_region(output_shape); - validate(dst.info()->valid_region(), valid_region); -} - template using CLReduceMeanFixture = ReduceMeanFixture; @@ -170,6 +148,26 @@ FIXTURE_DATA_TEST_CASE(RunLarge, validate(CLAccessor(_target), _reference, tolerance_qasymm8); } TEST_SUITE_END() // QASYMM8 + +TEST_SUITE(QASYMM8_SIGNED) +FIXTURE_DATA_TEST_CASE(RunSmall, + CLReduceMeanQuantizedFixture, + framework::DatasetMode::PRECOMMIT, + combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 102, 2) }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_qasymm8); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + CLReduceMeanQuantizedFixture, + framework::DatasetMode::NIGHTLY, + combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 102, 2) }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_qasymm8); +} +TEST_SUITE_END() // QASYMM8_SIGNED TEST_SUITE_END() // Quantized TEST_SUITE_END() // ReduceMean TEST_SUITE_END() // CL diff --git a/tests/validation/CL/ReductionOperation.cpp b/tests/validation/CL/ReductionOperation.cpp index 1dec020d18..8ec3eb208f 100644 --- a/tests/validation/CL/ReductionOperation.cpp +++ b/tests/validation/CL/ReductionOperation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -47,14 +47,19 @@ AbsoluteTolerance tolerance_f32(0.001f); RelativeTolerance rel_tolerance_f32(0.00001f); AbsoluteTolerance tolerance_f16(0.5f); RelativeTolerance rel_tolerance_f16(0.2f); +/** Tolerance for quantized operations */ +RelativeTolerance tolerance_qasymm8(1); -const auto ReductionOperations = framework::dataset::make("ReductionOperation", +const auto ReductionOperationsSumProd = framework::dataset::make("ReductionOperationsSumProd", { ReductionOperation::SUM, ReductionOperation::PROD, + +}); +const auto ReductionOperationsMinMax = framework::dataset::make("ReductionMinMax", +{ ReductionOperation::MIN, ReductionOperation::MAX, - }); const auto KeepDimensions = framework::dataset::make("KeepDims", { true, false }); @@ -103,54 +108,34 @@ using CLReductionOperationFixture = ReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(combine(datasets::Small2DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1 })), ReductionOperations), KeepDimensions)) -{ - // Validate output - validate(CLAccessor(_target), _reference, tolerance_f16); -} -FIXTURE_DATA_TEST_CASE(RunSmall3D, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2 })), ReductionOperations), KeepDimensions)) -{ - // Validate output - validate(CLAccessor(_target), _reference, tolerance_f16); -} FIXTURE_DATA_TEST_CASE(RunSmall4D, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations), + combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), concat(ReductionOperationsSumProd, + ReductionOperationsMinMax)), KeepDimensions)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f16); } FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework::DatasetMode::NIGHTLY, - combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations), KeepDimensions)) + combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), concat(ReductionOperationsSumProd, + ReductionOperationsMinMax)), KeepDimensions)) { // Validate output validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0, tolerance_f16); } TEST_SUITE_END() // F16 TEST_SUITE(FP32) -FIXTURE_DATA_TEST_CASE(RunSmall2D, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(combine(datasets::Small2DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1 })), ReductionOperations), KeepDimensions)) -{ - // Validate output - validate(CLAccessor(_target), _reference, tolerance_f32); -} -FIXTURE_DATA_TEST_CASE(RunSmall3D, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2 })), ReductionOperations), KeepDimensions)) -{ - // Validate output - validate(CLAccessor(_target), _reference, tolerance_f32); -} FIXTURE_DATA_TEST_CASE(RunSmall4D, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations), + combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), concat(ReductionOperationsSumProd, + ReductionOperationsMinMax)), KeepDimensions)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); } FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework::DatasetMode::NIGHTLY, - combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations), KeepDimensions)) + combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), concat(ReductionOperationsSumProd, + ReductionOperationsMinMax)), KeepDimensions)) { // Validate output validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0, tolerance_f32); @@ -158,6 +143,31 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework:: TEST_SUITE_END() // F32 TEST_SUITE_END() // Float +template +using CLReductionOperationQuantizedFixture = ReductionOperationQuantizedFixture; + +TEST_SUITE(Quantized) +TEST_SUITE(QASYMM8_SIGNED) +FIXTURE_DATA_TEST_CASE(RunSmall, CLReductionOperationQuantizedFixture, framework::DatasetMode::ALL, + combine(combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), + ReductionOperationsSumProd), + framework::dataset::make("QuantizationInfo", QuantizationInfo(1.f / 64, 2))), + KeepDimensions)) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_qasymm8); +} +FIXTURE_DATA_TEST_CASE(RunSmallMinMax, CLReductionOperationQuantizedFixture, framework::DatasetMode::ALL, + combine(combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), + ReductionOperationsMinMax), + framework::dataset::make("QuantizationInfo", QuantizationInfo(1.f / 64, 2))), + KeepDimensions)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // QASYMM8_SIGNED +TEST_SUITE_END() // Quantized TEST_SUITE_END() // Reduction TEST_SUITE_END() // CL } // namespace validation diff --git a/tests/validation/fixtures/ReductionOperationFixture.h b/tests/validation/fixtures/ReductionOperationFixture.h index 867c08ec3a..2802cd4c0a 100644 --- a/tests/validation/fixtures/ReductionOperationFixture.h +++ b/tests/validation/fixtures/ReductionOperationFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -61,16 +61,21 @@ protected: template void fill(U &&tensor) { - if(!is_data_type_quantized(tensor.data_type())) + if(tensor.data_type() == DataType::QASYMM8) { - std::uniform_real_distribution<> distribution(-1.0f, 1.0f); + std::pair bounds = get_quantized_bounds(tensor.quantization_info(), -1.0f, 1.0f); + std::uniform_int_distribution distribution(bounds.first, bounds.second); + library->fill(tensor, distribution, 0); + } + else if(tensor.data_type() == DataType::QASYMM8_SIGNED) + { + std::pair bounds = get_quantized_qasymm8_signed_bounds(tensor.quantization_info(), -1.0f, 1.0f); + std::uniform_int_distribution distribution(bounds.first, bounds.second); library->fill(tensor, distribution, 0); } else { - std::pair bounds = get_quantized_bounds(tensor.quantization_info(), -1.0f, 1.0f); - std::uniform_int_distribution distribution(bounds.first, bounds.second); - + std::uniform_real_distribution<> distribution(-1.0f, 1.0f); library->fill(tensor, distribution, 0); } } diff --git a/tests/validation/reference/ReductionOperation.cpp b/tests/validation/reference/ReductionOperation.cpp index 9c2c8eeb94..9b35cdf6f5 100644 --- a/tests/validation/reference/ReductionOperation.cpp +++ b/tests/validation/reference/ReductionOperation.cpp @@ -289,6 +289,21 @@ SimpleTensor reduction_operation(const SimpleTensor &src, cons } } +template <> +SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op) +{ + if(src.data_type() == DataType::QASYMM8_SIGNED) + { + SimpleTensor src_f = convert_from_asymmetric(src); + SimpleTensor dst_f = reference::reduction_operation(src_f, dst_shape, axis, op); + return convert_to_asymmetric(dst_f, src.quantization_info()); + } + else + { + return compute_reduction_operation(src, dst_shape, axis, op); + } +} + template SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); template SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShape &dst_shape, unsigned int axis, ReductionOperation op); -- cgit v1.2.1