From a52e4cf36ec86b63660f5a687073fa0985384dc1 Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Mon, 1 Apr 2019 14:55:18 +0100 Subject: COMPMID-2060: Support different qinfo in PoolingLayer CL and Neon back ends now support different qinfos Change-Id: I638d5f258ab2f99b40659601b4c5398d2c34c43b Signed-off-by: Pablo Tello Reviewed-on: https://review.mlplatform.org/c/927 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Michalis Spyrou Reviewed-by: Gian Marco Iodice --- tests/validation/CL/PoolingLayer.cpp | 22 ++++++------- tests/validation/NEON/PoolingLayer.cpp | 22 ++++++------- tests/validation/fixtures/PoolingLayerFixture.h | 44 +++++++++++++------------ tests/validation/reference/PoolingLayer.cpp | 15 +++++---- tests/validation/reference/PoolingLayer.h | 4 +-- 5 files changed, 53 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/tests/validation/CL/PoolingLayer.cpp b/tests/validation/CL/PoolingLayer.cpp index 6afafe6c70..7d79f3f86c 100644 --- a/tests/validation/CL/PoolingLayer.cpp +++ b/tests/validation/CL/PoolingLayer.cpp @@ -74,6 +74,8 @@ framework::dataset::make("ExcludePadding", { true })); constexpr AbsoluteTolerance tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */ constexpr AbsoluteTolerance tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */ constexpr AbsoluteTolerance tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */ +const auto pool_data_layout_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }); + } // namespace TEST_SUITE(CL) @@ -133,7 +135,7 @@ FIXTURE_DATA_TEST_CASE(RunSpecial, CLSpecialPoolingLayerFixture, framewor FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall, framework::dataset::make("DataType", DataType::F32))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); @@ -141,7 +143,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture, framework::Datase FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", DataType::F32))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); @@ -151,14 +153,14 @@ TEST_SUITE_END() // FP32 TEST_SUITE(FP16) FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall, framework::dataset::make("DataType", DataType::F16))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f16); } FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", DataType::F16))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f16); @@ -172,20 +174,16 @@ template using CLPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture; TEST_SUITE(QASYMM8) -FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small, +FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small, framework::dataset::make("DataType", DataType::QASYMM8))), - framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127), - QuantizationInfo(7.f / 255, 123) - })), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_qasymm8); } -FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerQuantizedFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, +FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerQuantizedFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, framework::dataset::make("DataType", DataType::QASYMM8))), - framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_qasymm8); diff --git a/tests/validation/NEON/PoolingLayer.cpp b/tests/validation/NEON/PoolingLayer.cpp index 9a15775f8c..129f53bef2 100644 --- a/tests/validation/NEON/PoolingLayer.cpp +++ b/tests/validation/NEON/PoolingLayer.cpp @@ -67,6 +67,8 @@ constexpr AbsoluteTolerance tolerance_f32(0.001f); /**< Tolerance value f constexpr AbsoluteTolerance tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ constexpr AbsoluteTolerance tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */ +const auto pool_data_layout_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }); + } // namespace TEST_SUITE(NEON) @@ -124,7 +126,7 @@ FIXTURE_DATA_TEST_CASE(RunSpecial, NESpecialPoolingLayerFixture, framewor FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall, framework::dataset::make("DataType", DataType::F32))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(Accessor(_target), _reference, tolerance_f32); @@ -132,7 +134,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture, framework::Datase FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", DataType::F32))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(Accessor(_target), _reference, tolerance_f32); @@ -143,14 +145,14 @@ TEST_SUITE_END() // FP32 TEST_SUITE(FP16) FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall, framework::dataset::make("DataType", DataType::F16))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(Accessor(_target), _reference, tolerance_f16); } FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", DataType::F16))), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(Accessor(_target), _reference, tolerance_f16); @@ -165,20 +167,16 @@ template using NEPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture; TEST_SUITE(QASYMM8) -FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small, +FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small, framework::dataset::make("DataType", DataType::QASYMM8))), - framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127), - QuantizationInfo(7.f / 255, 123) - })), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(Accessor(_target), _reference, tolerance_qasymm8); } -FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerQuantizedFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, +FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerQuantizedFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, framework::dataset::make("DataType", DataType::QASYMM8))), - framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })), - framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) + pool_data_layout_dataset)) { // Validate output validate(Accessor(_target), _reference, tolerance_qasymm8); diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index 3e34f98271..1813ef4c84 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -26,6 +26,7 @@ #include "arm_compute/core/TensorShape.h" #include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" #include "arm_compute/runtime/Tensor.h" #include "tests/AssetsLibrary.h" #include "tests/Globals.h" @@ -47,13 +48,16 @@ class PoolingLayerValidationGenericFixture : public framework::Fixture { public: template - void setup(TensorShape shape, PoolingLayerInfo pool_info, DataType data_type, DataLayout data_layout, QuantizationInfo quantization_info) + void setup(TensorShape shape, PoolingLayerInfo pool_info, DataType data_type, DataLayout data_layout) { - _quantization_info = quantization_info; - _pool_info = pool_info; - - _target = compute_target(shape, pool_info, data_type, data_layout, quantization_info); - _reference = compute_reference(shape, pool_info, data_type, quantization_info); + std::mt19937 gen(library->seed()); + std::uniform_int_distribution<> offset_dis(0, 20); + const QuantizationInfo input_qinfo(1.f / 255.f, offset_dis(gen)); + const QuantizationInfo output_qinfo(1.f / 255.f, offset_dis(gen)); + + _pool_info = pool_info; + _target = compute_target(shape, pool_info, data_type, data_layout, input_qinfo, output_qinfo); + _reference = compute_reference(shape, pool_info, data_type, input_qinfo, output_qinfo); } protected: @@ -72,7 +76,7 @@ protected: } TensorType compute_target(TensorShape shape, PoolingLayerInfo info, - DataType data_type, DataLayout data_layout, QuantizationInfo quantization_info) + DataType data_type, DataLayout data_layout, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo) { // Change shape in case of NHWC. if(data_layout == DataLayout::NHWC) @@ -81,8 +85,9 @@ protected: } // Create tensors - TensorType src = create_tensor(shape, data_type, 1, quantization_info, data_layout); - TensorType dst; + TensorType src = create_tensor(shape, data_type, 1, input_qinfo, data_layout); + const TensorShape dst_shape = misc::shape_calculator::compute_pool_shape(*(src.info()), info); + TensorType dst = create_tensor(dst_shape, data_type, 1, output_qinfo, data_layout); // Create and configure function FunctionType pool_layer; @@ -107,21 +112,19 @@ protected: return dst; } - SimpleTensor compute_reference(const TensorShape &shape, PoolingLayerInfo info, - DataType data_type, QuantizationInfo quantization_info) + SimpleTensor compute_reference(const TensorShape &shape, PoolingLayerInfo info, DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo) { // Create reference - SimpleTensor src{ shape, data_type, 1, quantization_info }; + SimpleTensor src{ shape, data_type, 1, input_qinfo }; // Fill reference fill(src); - return reference::pooling_layer(src, info); + return reference::pooling_layer(src, info, output_qinfo); } TensorType _target{}; SimpleTensor _reference{}; - QuantizationInfo _quantization_info{}; PoolingLayerInfo _pool_info{}; }; @@ -133,7 +136,7 @@ public: void setup(TensorShape shape, PoolingType pool_type, Size2D pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, DataType data_type, DataLayout data_layout) { PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type, pool_size, pad_stride_info, exclude_padding), - data_type, data_layout, QuantizationInfo()); + data_type, data_layout); } }; @@ -142,11 +145,10 @@ class PoolingLayerValidationQuantizedFixture : public PoolingLayerValidationGene { public: template - void setup(TensorShape shape, PoolingType pool_type, Size2D pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, DataType data_type, - QuantizationInfo quantization_info, DataLayout data_layout = DataLayout::NCHW) + void setup(TensorShape shape, PoolingType pool_type, Size2D pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, DataType data_type, DataLayout data_layout = DataLayout::NCHW) { PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type, pool_size, pad_stride_info, exclude_padding), - data_type, data_layout, quantization_info); + data_type, data_layout); } }; @@ -157,7 +159,7 @@ public: template void setup(TensorShape src_shape, PoolingLayerInfo pool_info, DataType data_type) { - PoolingLayerValidationGenericFixture::setup(src_shape, pool_info, data_type, DataLayout::NCHW, QuantizationInfo()); + PoolingLayerValidationGenericFixture::setup(src_shape, pool_info, data_type, DataLayout::NCHW); } }; @@ -168,7 +170,7 @@ public: template void setup(TensorShape shape, PoolingType pool_type, DataType data_type, DataLayout data_layout = DataLayout::NCHW) { - PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type), data_type, DataLayout::NCHW, QuantizationInfo()); + PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type), data_type, DataLayout::NCHW); } }; diff --git a/tests/validation/reference/PoolingLayer.cpp b/tests/validation/reference/PoolingLayer.cpp index e617c939b0..f4112a486d 100644 --- a/tests/validation/reference/PoolingLayer.cpp +++ b/tests/validation/reference/PoolingLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -38,8 +38,9 @@ namespace reference using namespace arm_compute::misc::shape_calculator; template -SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info) +SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo) { + ARM_COMPUTE_UNUSED(output_qinfo); // requantization occurs in pooling_layer ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); // Create reference @@ -152,16 +153,16 @@ SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo } template <> -SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info) +SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo) { SimpleTensor src_tmp = convert_from_asymmetric(src); - SimpleTensor dst_tmp = pooling_layer(src_tmp, info); - SimpleTensor dst = convert_to_asymmetric(dst_tmp, src.quantization_info()); + SimpleTensor dst_tmp = pooling_layer(src_tmp, info, output_qinfo); + SimpleTensor dst = convert_to_asymmetric(dst_tmp, output_qinfo); return dst; } -template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info); -template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info); +template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo); +template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/PoolingLayer.h b/tests/validation/reference/PoolingLayer.h index 00977896a8..1c0b7ff40d 100644 --- a/tests/validation/reference/PoolingLayer.h +++ b/tests/validation/reference/PoolingLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -36,7 +36,7 @@ namespace validation namespace reference { template -SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info); +SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1