From 02dfb2cd0bfab1bcff141db4598c23055e67311b Mon Sep 17 00:00:00 2001 From: SiCong Li Date: Thu, 27 Jul 2017 17:59:20 +0100 Subject: COMPMID-457 Fix F16 NormalizationLayer CL kernel Change-Id: I307c7ef6a49c852615c4425dc8dc0b1066a6974f Reviewed-on: http://mpd-gerrit.cambridge.arm.com/81895 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/AssetsLibrary.h | 6 ++ tests/benchmark_new/CL/NormalizationLayer.cpp | 12 +++- tests/benchmark_new/CL/SYSTEM/AlexNet.cpp | 1 - tests/benchmark_new/NEON/NormalizationLayer.cpp | 15 ++++- tests/benchmark_new/NEON/SYSTEM/AlexNet.cpp | 12 +++- .../AlexNetNormalizationLayerDataset.h | 58 ++++++++++++++++ .../GoogLeNetNormalizationLayerDataset.h | 61 +++++++++++++++++ tests/datasets_new/NormalizationLayerDataset.h | 77 ---------------------- tests/validation/CL/PixelWiseMultiplication.cpp | 19 ++++++ 9 files changed, 175 insertions(+), 86 deletions(-) create mode 100644 tests/datasets_new/AlexNetNormalizationLayerDataset.h create mode 100644 tests/datasets_new/GoogLeNetNormalizationLayerDataset.h delete mode 100644 tests/datasets_new/NormalizationLayerDataset.h (limited to 'tests') diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 58738f871d..3dd30e7629 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -473,6 +473,12 @@ void AssetsLibrary::fill_tensor_uniform(T &&tensor, std::random_device::result_t break; } case DataType::F16: + { + // It doesn't make sense to check [-inf, inf], so hard code it to a big number + std::uniform_real_distribution distribution_f16(-100.f, 100.f); + fill(tensor, distribution_f16, seed_offset); + break; + } case DataType::F32: { // It doesn't make sense to check [-inf, inf], so hard code it to a big number diff --git a/tests/benchmark_new/CL/NormalizationLayer.cpp b/tests/benchmark_new/CL/NormalizationLayer.cpp index 6d5142c7d7..7ba78a5e99 100644 --- a/tests/benchmark_new/CL/NormalizationLayer.cpp +++ b/tests/benchmark_new/CL/NormalizationLayer.cpp @@ -30,25 +30,31 @@ #include "framework/datasets/Datasets.h" #include "tests/CL/CLAccessor.h" #include "tests/TypePrinter.h" -#include "tests/datasets_new/NormalizationLayerDataset.h" +#include "tests/datasets_new/AlexNetNormalizationLayerDataset.h" +#include "tests/datasets_new/GoogLeNetNormalizationLayerDataset.h" #include "tests/fixtures_new/NormalizationLayerFixture.h" namespace arm_compute { namespace test { +namespace +{ +const auto normalization_layer_data_types = framework::dataset::make("DataType", { DataType::F16, DataType::F32 }); +} // namespace + using CLNormalizationLayerFixture = NormalizationLayerFixture; TEST_SUITE(CL) REGISTER_FIXTURE_DATA_TEST_CASE(AlexNetNormalizationLayer, CLNormalizationLayerFixture, framework::DatasetMode::ALL, framework::dataset::combine(framework::dataset::combine(datasets::AlexNetNormalizationLayerDataset(), - framework::dataset::make("DataType", { DataType::F32 })), + normalization_layer_data_types), framework::dataset::make("Batches", { 1, 4, 8 }))); REGISTER_FIXTURE_DATA_TEST_CASE(GoogLeNetNormalizationLayer, CLNormalizationLayerFixture, framework::DatasetMode::ALL, framework::dataset::combine(framework::dataset::combine(datasets::GoogLeNetNormalizationLayerDataset(), - framework::dataset::make("DataType", DataType::F32)), + normalization_layer_data_types), framework::dataset::make("Batches", { 1, 4, 8 }))); TEST_SUITE_END() diff --git a/tests/benchmark_new/CL/SYSTEM/AlexNet.cpp b/tests/benchmark_new/CL/SYSTEM/AlexNet.cpp index 85cd701648..e6d91d9706 100644 --- a/tests/benchmark_new/CL/SYSTEM/AlexNet.cpp +++ b/tests/benchmark_new/CL/SYSTEM/AlexNet.cpp @@ -36,7 +36,6 @@ #include "framework/datasets/Datasets.h" #include "tests/CL/CLAccessor.h" #include "tests/TypePrinter.h" -#include "tests/datasets_new/ActivationLayerDataset.h" #include "tests/fixtures_new/AlexNetFixture.h" namespace arm_compute diff --git a/tests/benchmark_new/NEON/NormalizationLayer.cpp b/tests/benchmark_new/NEON/NormalizationLayer.cpp index c3d4969a10..71dd9c354c 100644 --- a/tests/benchmark_new/NEON/NormalizationLayer.cpp +++ b/tests/benchmark_new/NEON/NormalizationLayer.cpp @@ -30,25 +30,34 @@ #include "framework/datasets/Datasets.h" #include "tests/NEON/Accessor.h" #include "tests/TypePrinter.h" -#include "tests/datasets_new/NormalizationLayerDataset.h" +#include "tests/datasets_new/AlexNetNormalizationLayerDataset.h" +#include "tests/datasets_new/GoogLeNetNormalizationLayerDataset.h" #include "tests/fixtures_new/NormalizationLayerFixture.h" namespace arm_compute { namespace test { +namespace +{ +#ifdef ARM_COMPUTE_ENABLE_FP16 +const auto normalization_layer_data_types = framework::dataset::make("DataType", { DataType::F16, DataType::F32, DataType::QS8 }); +#else /* ARM_COMPUTE_ENABLE_FP16 */ +const auto normalization_layer_data_types = framework::dataset::make("DataType", { DataType::F32, DataType::QS8 }); +#endif /* ARM_COMPUTE_ENABLE_FP16 */ +} // namespace using NENormalizationLayerFixture = NormalizationLayerFixture; TEST_SUITE(NEON) REGISTER_FIXTURE_DATA_TEST_CASE(AlexNetNormalizationLayer, NENormalizationLayerFixture, framework::DatasetMode::ALL, framework::dataset::combine(framework::dataset::combine(datasets::AlexNetNormalizationLayerDataset(), - framework::dataset::make("DataType", { DataType::F32, DataType::QS8 })), + normalization_layer_data_types), framework::dataset::make("Batches", { 1, 4, 8 }))); REGISTER_FIXTURE_DATA_TEST_CASE(GoogLeNetNormalizationLayer, NENormalizationLayerFixture, framework::DatasetMode::ALL, framework::dataset::combine(framework::dataset::combine(datasets::GoogLeNetNormalizationLayerDataset(), - framework::dataset::make("DataType", DataType::F32)), + normalization_layer_data_types), framework::dataset::make("Batches", { 1, 4, 8 }))); TEST_SUITE_END() diff --git a/tests/benchmark_new/NEON/SYSTEM/AlexNet.cpp b/tests/benchmark_new/NEON/SYSTEM/AlexNet.cpp index e97919a21f..282d3e67bd 100644 --- a/tests/benchmark_new/NEON/SYSTEM/AlexNet.cpp +++ b/tests/benchmark_new/NEON/SYSTEM/AlexNet.cpp @@ -36,13 +36,21 @@ #include "framework/datasets/Datasets.h" #include "tests/NEON/Accessor.h" #include "tests/TypePrinter.h" -#include "tests/datasets_new/ActivationLayerDataset.h" #include "tests/fixtures_new/AlexNetFixture.h" namespace arm_compute { namespace test { +namespace +{ +#ifdef ARM_COMPUTE_ENABLE_FP16 +const auto alex_net_data_types = framework::dataset::make("DataType", { DataType::F16, DataType::F32, DataType::QS8 }); +#else /* ARM_COMPUTE_ENABLE_FP16 */ +const auto alex_net_data_types = framework::dataset::make("DataType", { DataType::F32, DataType::QS8 }); +#endif /* ARM_COMPUTE_ENABLE_FP16 */ +} // namespace + using NEAlexNetFixture = AlexNetFixture, framework::dataset::SingletonDataset> +{ +public: + AlexNetNormalizationLayerDataset() + : CartesianProductDataset + { + framework::dataset::make("Shape", { TensorShape(55U, 55U, 96U), TensorShape(27U, 27U, 256U) }), + framework::dataset::make("Info", NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f)) + } + { + } + AlexNetNormalizationLayerDataset(AlexNetNormalizationLayerDataset &&) = default; + ~AlexNetNormalizationLayerDataset() = default; +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_ALEXNET_NORMALIZATION_LAYER_DATASET */ diff --git a/tests/datasets_new/GoogLeNetNormalizationLayerDataset.h b/tests/datasets_new/GoogLeNetNormalizationLayerDataset.h new file mode 100644 index 0000000000..2c20a6b9af --- /dev/null +++ b/tests/datasets_new/GoogLeNetNormalizationLayerDataset.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_GOOGLENET_NORMALIZATION_LAYER_DATASET +#define ARM_COMPUTE_TEST_GOOGLENET_NORMALIZATION_LAYER_DATASET + +#include "framework/datasets/Datasets.h" + +#include "tests/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class GoogLeNetNormalizationLayerDataset final : public + framework::dataset::CartesianProductDataset, framework::dataset::SingletonDataset> +{ +public: + GoogLeNetNormalizationLayerDataset() + : CartesianProductDataset + { + framework::dataset::make("Shape", { // conv2/norm2 + TensorShape(56U, 56U, 192U), + // pool1/norm1 + TensorShape(56U, 56U, 64U) }), + framework::dataset::make("Info", NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f)) + } + { + } + GoogLeNetNormalizationLayerDataset(GoogLeNetNormalizationLayerDataset &&) = default; + ~GoogLeNetNormalizationLayerDataset() = default; +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_GOOGLENET_NORMALIZATION_LAYER_DATASET */ diff --git a/tests/datasets_new/NormalizationLayerDataset.h b/tests/datasets_new/NormalizationLayerDataset.h deleted file mode 100644 index 73e215be48..0000000000 --- a/tests/datasets_new/NormalizationLayerDataset.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef ARM_COMPUTE_TEST_NORMALIZATION_LAYER_DATASET -#define ARM_COMPUTE_TEST_NORMALIZATION_LAYER_DATASET - -#include "framework/datasets/Datasets.h" - -#include "tests/TypePrinter.h" - -#include "arm_compute/core/TensorShape.h" -#include "arm_compute/core/Types.h" - -namespace arm_compute -{ -namespace test -{ -namespace datasets -{ -class AlexNetNormalizationLayerDataset final : public - framework::dataset::CartesianProductDataset, framework::dataset::SingletonDataset> -{ -public: - AlexNetNormalizationLayerDataset() - : CartesianProductDataset - { - framework::dataset::make("Shape", { TensorShape(55U, 55U, 96U), TensorShape(27U, 27U, 256U) }), - framework::dataset::make("Info", NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f)) - } - { - } - AlexNetNormalizationLayerDataset(AlexNetNormalizationLayerDataset &&) = default; - ~AlexNetNormalizationLayerDataset() = default; -}; - -class GoogLeNetNormalizationLayerDataset final : public - framework::dataset::CartesianProductDataset, framework::dataset::SingletonDataset> -{ -public: - GoogLeNetNormalizationLayerDataset() - : CartesianProductDataset - { - framework::dataset::make("Shape", { // conv2/norm2 - TensorShape(56U, 56U, 192U), - // pool1/norm1 - TensorShape(56U, 56U, 64U) }), - framework::dataset::make("Info", NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f)) - } - { - } - GoogLeNetNormalizationLayerDataset(GoogLeNetNormalizationLayerDataset &&) = default; - ~GoogLeNetNormalizationLayerDataset() = default; -}; -} // namespace datasets -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_NORMALIZATION_LAYER_DATASET */ diff --git a/tests/validation/CL/PixelWiseMultiplication.cpp b/tests/validation/CL/PixelWiseMultiplication.cpp index a95c823aa5..375c77dedf 100644 --- a/tests/validation/CL/PixelWiseMultiplication.cpp +++ b/tests/validation/CL/PixelWiseMultiplication.cpp @@ -38,6 +38,7 @@ using namespace arm_compute::test::validation; namespace { const float tolerance_f32 = 1.f; /**< Tolerance value for comparing reference's output against implementation's output for float input */ +const float tolerance_f16 = 1.f; /**< Tolerance value for comparing reference's output against implementation's output for float input */ /** Compute CL pixel-wise multiplication function. * @@ -88,6 +89,24 @@ CLTensor compute_pixel_wise_multiplication(const TensorShape &shape, DataType dt BOOST_AUTO_TEST_SUITE(CL) BOOST_AUTO_TEST_SUITE(PixelWiseMultiplication) +BOOST_AUTO_TEST_SUITE(Float16) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * DataType::F16 *ConvertPolicies() * RoundingPolicy::TO_NEAREST_UP, + shape, dt, convert_policy, rounding_policy) +{ + constexpr float scale = 1.f / 255.f; + + // Compute function + CLTensor dst = compute_pixel_wise_multiplication(shape, dt, dt, dt, scale, convert_policy, rounding_policy); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, dt, dt, dt, scale, convert_policy, rounding_policy); + + // Validate output + validate(CLAccessor(dst), ref_dst, tolerance_f16); +} +BOOST_AUTO_TEST_SUITE_END() + BOOST_AUTO_TEST_SUITE(Float) BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * DataType::F32 *ConvertPolicies() * RoundingPolicy::TO_NEAREST_UP, -- cgit v1.2.1