From e03802edd37229a1868bacedd7571cc443810caf Mon Sep 17 00:00:00 2001 From: Usama Arif Date: Mon, 11 Mar 2019 12:20:20 +0000 Subject: COMPMID-1936: Add support for QASYMM8 in CLQuantizeLayer. Change-Id: I9aa1f1f1753bcdee6a74ec15b4fb366f823788b4 Signed-off-by: Usama Arif Reviewed-on: https://review.mlplatform.org/c/850 Reviewed-by: Georgios Pinitas Tested-by: Arm Jenkins --- tests/benchmark/CL/QuantizationLayer.cpp | 4 +- .../benchmark/fixtures/QuantizationLayerFixture.h | 6 ++- tests/validation/CL/QuantizationLayer.cpp | 48 +++++++++++------ tests/validation/NEON/QuantizationLayer.cpp | 2 +- .../validation/fixtures/QuantizationLayerFixture.h | 62 ---------------------- tests/validation/reference/QuantizationLayer.cpp | 50 +---------------- tests/validation/reference/QuantizationLayer.h | 3 -- 7 files changed, 39 insertions(+), 136 deletions(-) (limited to 'tests') diff --git a/tests/benchmark/CL/QuantizationLayer.cpp b/tests/benchmark/CL/QuantizationLayer.cpp index 2dc775af0a..f52e6f078d 100644 --- a/tests/benchmark/CL/QuantizationLayer.cpp +++ b/tests/benchmark/CL/QuantizationLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -40,7 +40,7 @@ namespace benchmark { namespace { -const auto data_types = framework::dataset::make("DataType", { DataType::F32 }); +const auto data_types = framework::dataset::make("DataType", { DataType::F32, DataType::F16 }); } // namespace using CLQuantizationLayerFixture = QuantizationLayerFixture; diff --git a/tests/benchmark/fixtures/QuantizationLayerFixture.h b/tests/benchmark/fixtures/QuantizationLayerFixture.h index 4b2fc88602..f2e8889423 100644 --- a/tests/benchmark/fixtures/QuantizationLayerFixture.h +++ b/tests/benchmark/fixtures/QuantizationLayerFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -43,9 +43,11 @@ public: template void setup(TensorShape shape, DataType data_type) { + const QuantizationInfo q_info(0.5f, -10); + // Create tensors src = create_tensor(shape, data_type); - dst = create_tensor(shape, DataType::U8); + dst = create_tensor(shape, DataType::QASYMM8, 1, q_info); // Create and configure function quantization_func.configure(&src, &dst); diff --git a/tests/validation/CL/QuantizationLayer.cpp b/tests/validation/CL/QuantizationLayer.cpp index f0cc4ccafa..26e030489c 100644 --- a/tests/validation/CL/QuantizationLayer.cpp +++ b/tests/validation/CL/QuantizationLayer.cpp @@ -53,21 +53,17 @@ TEST_SUITE(QuantizationLayer) // *INDENT-OFF* // clang-format off DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip( - framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U8), // Wrong input data type - TensorInfo(TensorShape(16U, 5U, 16U), 1, DataType::U8), // Invalid shape + framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::QASYMM8), // Wrong input data type TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), // Wrong output data type - TensorInfo(TensorShape(16U, 16U, 2U, 5U), 1, DataType::U8), // Mismatching shapes - TensorInfo(TensorShape(17U, 16U, 16U, 5U), 1, DataType::U8), // Shrink window + TensorInfo(TensorShape(16U, 16U, 2U, 5U), 1, DataType::F32), // Mismatching shapes TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), // Valid }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), - TensorInfo(TensorShape(16U, 5U, 16U), 1, DataType::U8), TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U16), - TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), - TensorInfo(TensorShape(17U, 16U, 16U, 5U), 1, DataType::F32), - TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U8), + TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::QASYMM8), + TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::QASYMM8), })), - framework::dataset::make("Expected", { false, false, false, false, false, true})), + framework::dataset::make("Expected", { false, false, false, true})), input_info, output_info, expected) { ARM_COMPUTE_EXPECT(bool(CLQuantizationLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); @@ -79,7 +75,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(QuantizationS { // Create tensors CLTensor src = create_tensor(shape, data_type); - CLTensor dst = create_tensor(shape, DataType::U8); + CLTensor dst = create_tensor(shape, DataType::QASYMM8); ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); @@ -94,9 +90,8 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(QuantizationS validate(dst.info()->valid_region(), valid_region); // Validate padding - const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding(); - validate(src.info()->padding(), padding); - validate(dst.info()->padding(), padding); + validate(src.info()->padding(), PaddingSize()); + validate(dst.info()->padding(), PaddingSize()); } template @@ -104,19 +99,38 @@ using CLQuantizationLayerFixture = QuantizationValidationFixture, framework::DatasetMode::PRECOMMIT, combine(concat(datasets::Small3DShapes(), datasets::Small4DShapes()), - framework::dataset::make("DataType", DataType::F32))) +FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizationLayerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(concat(datasets::Small3DShapes(), datasets::Small4DShapes()), + framework::dataset::make("DataType", DataType::F32)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) }))) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); } -FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizationLayerFixture, framework::DatasetMode::NIGHTLY, combine(concat(datasets::Large3DShapes(), datasets::Large4DShapes()), - framework::dataset::make("DataType", DataType::F32))) +FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizationLayerFixture, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::Large3DShapes(), datasets::Large4DShapes()), + framework::dataset::make("DataType", DataType::F32)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) }))) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); } TEST_SUITE_END() // FP32 + +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizationLayerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(concat(datasets::Small3DShapes(), datasets::Small4DShapes()), + framework::dataset::make("DataType", DataType::F16)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_f32); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizationLayerFixture, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::Large3DShapes(), datasets::Large4DShapes()), + framework::dataset::make("DataType", DataType::F16)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_f32); +} +TEST_SUITE_END() // FP16 TEST_SUITE_END() // Float TEST_SUITE_END() // QuantizationLayer diff --git a/tests/validation/NEON/QuantizationLayer.cpp b/tests/validation/NEON/QuantizationLayer.cpp index 487eb70120..0b503c09b3 100644 --- a/tests/validation/NEON/QuantizationLayer.cpp +++ b/tests/validation/NEON/QuantizationLayer.cpp @@ -97,7 +97,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(QuantizationS } template -using NEQuantizationLayerFixture = QAsymm8QuantizationValidationFixture; +using NEQuantizationLayerFixture = QuantizationValidationFixture; TEST_SUITE(Float) TEST_SUITE(FP32) diff --git a/tests/validation/fixtures/QuantizationLayerFixture.h b/tests/validation/fixtures/QuantizationLayerFixture.h index 65de405788..84d4d7a7b3 100644 --- a/tests/validation/fixtures/QuantizationLayerFixture.h +++ b/tests/validation/fixtures/QuantizationLayerFixture.h @@ -45,68 +45,6 @@ namespace validation template class QuantizationValidationFixture : public framework::Fixture { -public: - template - void setup(TensorShape shape, DataType data_type) - { - _target = compute_target(shape, data_type); - _reference = compute_reference(shape, data_type); - } - -protected: - template - void fill(U &&tensor) - { - library->fill_tensor_uniform(tensor, 0); - } - - TensorType compute_target(const TensorShape &shape, DataType data_type) - { - // Create tensors - TensorType src = create_tensor(shape, data_type); - TensorType dst = create_tensor(shape, DataType::U8); - - // Create and configure function - FunctionType quantization_layer; - quantization_layer.configure(&src, &dst); - - ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); - - // Fill tensors - fill(AccessorType(src)); - - // Compute function - quantization_layer.run(); - - return dst; - } - - SimpleTensor compute_reference(const TensorShape &shape, DataType data_type) - { - // Create reference - SimpleTensor src{ shape, data_type }; - - // Fill reference - fill(src); - - return reference::quantization_layer(src); - } - - TensorType _target{}; - SimpleTensor _reference{}; -}; - -template -class QAsymm8QuantizationValidationFixture : public framework::Fixture -{ public: template void setup(TensorShape shape, DataType data_type, QuantizationInfo quant_info) diff --git a/tests/validation/reference/QuantizationLayer.cpp b/tests/validation/reference/QuantizationLayer.cpp index 3d6c5bc13d..2f3348178c 100644 --- a/tests/validation/reference/QuantizationLayer.cpp +++ b/tests/validation/reference/QuantizationLayer.cpp @@ -33,55 +33,6 @@ namespace validation { namespace reference { -template ::value, int>::type> -SimpleTensor quantization_layer(const SimpleTensor &src) -{ - // Create reference - SimpleTensor dst{ src.shape(), DataType::U8 }; - - const int width = src.shape().x(); - const int height = src.shape().y(); - const int depth = src.shape().z(); - const int stride_w = width * height * depth; - const int num_batches = src.shape().total_size_upper(3); - - for(int k = 0; k < num_batches; ++k) - { - // Compute min and max of the 3D tensor - float min = src[k * stride_w]; - float max = src[k * stride_w]; - - // Look for min and max values - for(int i = 1; i < stride_w; ++i) - { - float val = src[i + k * stride_w]; - min = std::min(min, val); - max = std::max(max, val); - } - - // Saturate the result in case min = max - if(min == max) - { - min = 0.0f; - max = 1.0f; - } - - const float range = max - min; - - for(int i = 0; i < stride_w; ++i) - { - // map values to range [0.0, 1.0] - float val = src[i + k * stride_w]; - const float normalized = (val - min) / range; - dst[i + k * stride_w] = static_cast(std::min(255.0f, normalized * 256.0f)); - } - } - - return dst; -} - -template SimpleTensor quantization_layer(const SimpleTensor &src); - template SimpleTensor quantization_layer(const SimpleTensor &src, const QuantizationInfo quantization_info) { @@ -98,6 +49,7 @@ SimpleTensor quantization_layer(const SimpleTensor &src, const Quant } return dst; } + template SimpleTensor quantization_layer(const SimpleTensor &src, const QuantizationInfo quantization_info); template SimpleTensor quantization_layer(const SimpleTensor &src, const QuantizationInfo quantization_info); } // namespace reference diff --git a/tests/validation/reference/QuantizationLayer.h b/tests/validation/reference/QuantizationLayer.h index 60d8ea4023..2d136908af 100644 --- a/tests/validation/reference/QuantizationLayer.h +++ b/tests/validation/reference/QuantizationLayer.h @@ -35,9 +35,6 @@ namespace validation { namespace reference { -template ::value, int>::type = 0> -SimpleTensor quantization_layer(const SimpleTensor &src); - template SimpleTensor quantization_layer(const SimpleTensor &src, const QuantizationInfo quantization_info); } // namespace reference -- cgit v1.2.1