From d1794ebfa10d05af7d2458c5d506152fd38068d3 Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Fri, 15 Jun 2018 16:15:26 +0100 Subject: COMPMID-1226 Extend CLMeanStdDev to support FP32 / FP16 - Extend support for FP16 in CLReduction. - For F16/F32 MeanStdDev we perform one reduction operation for mean and one for stddev and we calculate the final result in the host CPU. Change-Id: Iad2099f26c0ba7969737d22f00c6c275634d875c Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/135870 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- tests/validation/CL/MeanStdDev.cpp | 48 ++++++++++++++++++++-- tests/validation/CL/ReductionOperation.cpp | 27 +++++++++--- tests/validation/fixtures/MeanStdDevFixture.h | 12 +++++- .../fixtures/ReductionOperationFixture.h | 5 ++- tests/validation/reference/MeanStdDev.cpp | 4 +- tests/validation/reference/ReductionOperation.cpp | 5 ++- 6 files changed, 84 insertions(+), 17 deletions(-) (limited to 'tests/validation') diff --git a/tests/validation/CL/MeanStdDev.cpp b/tests/validation/CL/MeanStdDev.cpp index 92d87e09f2..8ccb757364 100644 --- a/tests/validation/CL/MeanStdDev.cpp +++ b/tests/validation/CL/MeanStdDev.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -39,12 +39,17 @@ namespace { RelativeTolerance tolerance_rel_high_error(0.05f); RelativeTolerance tolerance_rel_low_error(0.0005f); +RelativeTolerance tolerance_rel_high_error_f32(0.001f); +RelativeTolerance tolerance_rel_low_error_f32(0.00001f); +RelativeTolerance tolerance_rel_high_error_f16(0.1f); +RelativeTolerance tolerance_rel_low_error_f16(0.01f); } // namespace TEST_SUITE(CL) TEST_SUITE(MeanStdDev) -DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), framework::dataset::make("DataType", DataType::U8)), shape, data_type) +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), framework::dataset::make("DataType", { DataType::U8 })), shape, + data_type) { // Create tensors CLTensor src = create_tensor(shape, data_type); @@ -71,6 +76,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datase template using CLMeanStdDevFixture = MeanStdDevValidationFixture; +TEST_SUITE(U8) FIXTURE_DATA_TEST_CASE(RunSmall, CLMeanStdDevFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", DataType::U8))) { @@ -89,9 +95,43 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLMeanStdDevFixture, framework::Datase // Validate std_dev output validate(_target.second, _reference.second, tolerance_rel_high_error); } +TEST_SUITE_END() // U8 -TEST_SUITE_END() -TEST_SUITE_END() +TEST_SUITE(F16) +FIXTURE_DATA_TEST_CASE(RunSmall, CLMeanStdDevFixture, framework::DatasetMode::ALL, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", + DataType::F16))) +{ + // Validate mean output + validate(_target.first, _reference.first, tolerance_rel_low_error_f16); + + // Validate std_dev output + validate(_target.second, _reference.second, tolerance_rel_high_error_f16); +} +TEST_SUITE_END() // F16 + +TEST_SUITE(F32) +FIXTURE_DATA_TEST_CASE(RunSmall, CLMeanStdDevFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", + DataType::F32))) +{ + // Validate mean output + validate(_target.first, _reference.first, tolerance_rel_low_error_f32); + + // Validate std_dev output + validate(_target.second, _reference.second, tolerance_rel_high_error_f32); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLMeanStdDevFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), framework::dataset::make("DataType", + DataType::F32))) +{ + // Validate mean output + validate(_target.first, _reference.first, tolerance_rel_low_error_f32); + + // Validate std_dev output + validate(_target.second, _reference.second, tolerance_rel_high_error_f32); +} +TEST_SUITE_END() // F32 + +TEST_SUITE_END() // MeanStdDev +TEST_SUITE_END() // CL } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/CL/ReductionOperation.cpp b/tests/validation/CL/ReductionOperation.cpp index a48e2f9d5f..ca0988f955 100644 --- a/tests/validation/CL/ReductionOperation.cpp +++ b/tests/validation/CL/ReductionOperation.cpp @@ -45,6 +45,7 @@ namespace { /** Tolerance for float operations */ RelativeTolerance tolerance_f32(0.00001f); +RelativeTolerance tolerance_f16(0.1f); } // namespace TEST_SUITE(CL) @@ -55,7 +56,7 @@ TEST_SUITE(ReductionOperation) DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( framework::dataset::make("InputInfo", { TensorInfo(TensorShape(128U, 64U), 1, DataType::F32), // Mismatching data type input/output TensorInfo(TensorShape(128U, 64U), 2, DataType::F32), // Number of Input channels != 1 - TensorInfo(TensorShape(128U, 64U), 1, DataType::S16), // DataType != F32 + TensorInfo(TensorShape(128U, 64U), 1, DataType::S16), // DataType != F16/F32 TensorInfo(TensorShape(128U, 64U), 1, DataType::F32), // Axis >= num_max_dimensions TensorInfo(TensorShape(128U, 64U), 1, DataType::F32), // Axis > 0 TensorInfo(TensorShape(128U, 64U), 1, DataType::F32) @@ -84,9 +85,23 @@ template using CLReductionOperationFixture = ReductionOperationValidationFixture; TEST_SUITE(Float) +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, + combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0 })), datasets::ReductionOperations())) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_f16); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework::DatasetMode::NIGHTLY, + combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0 })), datasets::ReductionOperations())) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_f16); +} +TEST_SUITE_END() // F16 TEST_SUITE(FP32) FIXTURE_DATA_TEST_CASE(RunSmall, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0 })), datasets::ReductionOperations())) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); @@ -97,11 +112,11 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework:: // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); } -TEST_SUITE_END() -TEST_SUITE_END() +TEST_SUITE_END() // F32 +TEST_SUITE_END() // Float -TEST_SUITE_END() -TEST_SUITE_END() +TEST_SUITE_END() // Reduction +TEST_SUITE_END() // CL } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/fixtures/MeanStdDevFixture.h b/tests/validation/fixtures/MeanStdDevFixture.h index 17dfe78dbd..58d4644069 100644 --- a/tests/validation/fixtures/MeanStdDevFixture.h +++ b/tests/validation/fixtures/MeanStdDevFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -50,7 +50,15 @@ protected: template void fill(U &&tensor) { - library->fill_tensor_uniform(tensor, 0); + if(is_data_type_float(tensor.data_type())) + { + std::uniform_real_distribution<> distribution(-1.0f, 1.0f); + library->fill(tensor, distribution, 0); + } + else + { + library->fill_tensor_uniform(tensor, 0); + } } std::pair compute_target(const TensorShape &shape, DataType data_type) diff --git a/tests/validation/fixtures/ReductionOperationFixture.h b/tests/validation/fixtures/ReductionOperationFixture.h index 6fa5f0c44f..0dee7eb707 100644 --- a/tests/validation/fixtures/ReductionOperationFixture.h +++ b/tests/validation/fixtures/ReductionOperationFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -56,7 +56,8 @@ protected: template void fill(U &&tensor) { - library->fill_tensor_uniform(tensor, 0); + std::uniform_real_distribution<> distribution(-1.0f, 1.0f); + library->fill(tensor, distribution, 0); } TensorType compute_target(const TensorShape &src_shape, const TensorShape &dst_shape, DataType data_type, unsigned int axis, ReductionOperation op) diff --git a/tests/validation/reference/MeanStdDev.cpp b/tests/validation/reference/MeanStdDev.cpp index 4a39b13d56..f48fcb11d2 100644 --- a/tests/validation/reference/MeanStdDev.cpp +++ b/tests/validation/reference/MeanStdDev.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -51,6 +51,8 @@ std::pair mean_and_standard_deviation(const SimpleTensor &in) } template std::pair mean_and_standard_deviation(const SimpleTensor &in); +template std::pair mean_and_standard_deviation(const SimpleTensor &in); +template std::pair mean_and_standard_deviation(const SimpleTensor &in); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/ReductionOperation.cpp b/tests/validation/reference/ReductionOperation.cpp index acfcc09cea..871a761b1a 100644 --- a/tests/validation/reference/ReductionOperation.cpp +++ b/tests/validation/reference/ReductionOperation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -53,7 +53,7 @@ T reduce_operation(T *ptr, int reduce_elements, ReductionOperation op) switch(op) { case ReductionOperation::SUM_SQUARE: - return std::accumulate(ptr, ptr + reduce_elements, 0.f, square()); + return std::accumulate(ptr, ptr + reduce_elements, static_cast(0), square()); default: ARM_COMPUTE_ERROR("Unsupported reduction operation"); } @@ -87,6 +87,7 @@ SimpleTensor reduction_operation(const SimpleTensor &src, const TensorShap } 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); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1