From b412fab0e3c8ec10e104f4d85760898a5b26179c Mon Sep 17 00:00:00 2001 From: Manuel Bottini Date: Mon, 10 Dec 2018 17:40:23 +0000 Subject: COMPMID-1724: CL Implement Prod Change-Id: I17e51f25064b53a8f7e13d6fcbecc14a192de103 Reviewed-on: https://review.mlplatform.org/387 Reviewed-by: Georgios Pinitas Tested-by: Arm Jenkins --- tests/datasets/ReductionOperationDataset.h | 53 ----------------------- tests/validation/CL/ReductionOperation.cpp | 20 ++++++--- tests/validation/NEON/ReductionOperation.cpp | 12 ++--- tests/validation/reference/ReductionOperation.cpp | 11 +++-- 4 files changed, 28 insertions(+), 68 deletions(-) delete mode 100644 tests/datasets/ReductionOperationDataset.h (limited to 'tests') diff --git a/tests/datasets/ReductionOperationDataset.h b/tests/datasets/ReductionOperationDataset.h deleted file mode 100644 index dadc4e9249..0000000000 --- a/tests/datasets/ReductionOperationDataset.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2017-2018 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_REDUCTION_OPERATION_DATASET_H__ -#define __ARM_COMPUTE_TEST_REDUCTION_OPERATION_DATASET_H__ - -#include "arm_compute/core/Types.h" -#include "tests/framework/datasets/ContainerDataset.h" -#include "utils/TypePrinter.h" - -#include - -namespace arm_compute -{ -namespace test -{ -namespace datasets -{ -class ReductionOperations final : public framework::dataset::ContainerDataset> -{ -public: - ReductionOperations() - : ContainerDataset("ReductionOperation", - { - ReductionOperation::SUM - }) - { - } -}; -} // namespace datasets -} // namespace test -} // namespace arm_compute -#endif /* __ARM_COMPUTE_TEST_REDUCTION_OPERATION_DATASET_H__ */ diff --git a/tests/validation/CL/ReductionOperation.cpp b/tests/validation/CL/ReductionOperation.cpp index 2adb4e90d6..c8474e97e6 100644 --- a/tests/validation/CL/ReductionOperation.cpp +++ b/tests/validation/CL/ReductionOperation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -27,7 +27,6 @@ #include "arm_compute/runtime/CL/functions/CLReductionOperation.h" #include "tests/CL/CLAccessor.h" #include "tests/PaddingCalculator.h" -#include "tests/datasets/ReductionOperationDataset.h" #include "tests/datasets/ShapeDatasets.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" @@ -44,10 +43,17 @@ namespace validation namespace { /** Tolerance for float operations */ -AbsoluteTolerance tolerance_f32(0.01f); +AbsoluteTolerance tolerance_f32(0.001f); RelativeTolerance rel_tolerance_f32(0.00001f); AbsoluteTolerance tolerance_f16(0.5f); RelativeTolerance rel_tolerance_f16(0.2f); + +const auto ReductionOperations = framework::dataset::make("ReductionOperation", +{ + ReductionOperation::SUM, + ReductionOperation::PROD +}); + } // namespace TEST_SUITE(CL) @@ -89,13 +95,13 @@ using CLReductionOperationFixture = ReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), 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, 1, 2, 3 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations)) { // Validate output validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0, tolerance_f16); @@ -103,13 +109,13 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework::D TEST_SUITE_END() // F16 TEST_SUITE(FP32) FIXTURE_DATA_TEST_CASE(RunSmall, CLReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations)) { // Validate output validate(CLAccessor(_target), _reference, tolerance_f32); } FIXTURE_DATA_TEST_CASE(RunLarge, CLReductionOperationFixture, framework::DatasetMode::NIGHTLY, - combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations)) { // Validate output validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0, tolerance_f32); diff --git a/tests/validation/NEON/ReductionOperation.cpp b/tests/validation/NEON/ReductionOperation.cpp index d064940366..e322947993 100644 --- a/tests/validation/NEON/ReductionOperation.cpp +++ b/tests/validation/NEON/ReductionOperation.cpp @@ -27,7 +27,6 @@ #include "arm_compute/runtime/TensorAllocator.h" #include "tests/NEON/Accessor.h" #include "tests/PaddingCalculator.h" -#include "tests/datasets/ReductionOperationDataset.h" #include "tests/datasets/ShapeDatasets.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" @@ -48,6 +47,9 @@ AbsoluteTolerance tolerance_f32(0.0001f); RelativeTolerance rel_tolerance_f32(0.00001f); /** Tolerance for quantized operations */ RelativeTolerance tolerance_qasymm8(1); + +const auto ReductionOperations = framework::dataset::make("ReductionOperation", +{ ReductionOperation::SUM }); } // namespace TEST_SUITE(NEON) @@ -86,13 +88,13 @@ using NEReductionOperationFixture = ReductionOperationFixture, framework::DatasetMode::PRECOMMIT, - combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations)) { // Validate output validate(Accessor(_target), _reference, tolerance_f32); } FIXTURE_DATA_TEST_CASE(RunLarge, NEReductionOperationFixture, framework::DatasetMode::NIGHTLY, - combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), datasets::ReductionOperations())) + combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), ReductionOperations)) { // Validate output validate(Accessor(_target), _reference, rel_tolerance_f32, 0, tolerance_f32); @@ -105,7 +107,7 @@ using NEReductionOperationQuantizedFixture = ReductionOperationQuantizedFixture< TEST_SUITE(QASYMM8) FIXTURE_DATA_TEST_CASE(RunSmall, NEReductionOperationQuantizedFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), - datasets::ReductionOperations()), + ReductionOperations), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) }))) { // Validate output @@ -113,7 +115,7 @@ FIXTURE_DATA_TEST_CASE(RunSmall, NEReductionOperationQuantizedFixture, } FIXTURE_DATA_TEST_CASE(RunLarge, NEReductionOperationQuantizedFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), - datasets::ReductionOperations()), + ReductionOperations), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) }))) { // Validate output diff --git a/tests/validation/reference/ReductionOperation.cpp b/tests/validation/reference/ReductionOperation.cpp index fc12e31d75..8e79c3bfb0 100644 --- a/tests/validation/reference/ReductionOperation.cpp +++ b/tests/validation/reference/ReductionOperation.cpp @@ -42,11 +42,11 @@ template OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, int stride) { using type = typename std::remove_cv::type; - auto res = type(0); + auto res = (op == ReductionOperation::PROD) ? type(1) : type(0); if(std::is_integral::value) { - uint32_t int_res = 0; + auto int_res = static_cast(res); for(int i = 0; i < reduce_elements; ++i) { auto elem = *(ptr + stride * i); @@ -72,6 +72,9 @@ OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, in case ReductionOperation::SUM: int_res += elem; break; + case ReductionOperation::PROD: + int_res *= elem; + break; default: ARM_COMPUTE_ERROR("Operation not supported"); } @@ -108,6 +111,9 @@ OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, in case ReductionOperation::SUM: res += elem; break; + case ReductionOperation::PROD: + res *= elem; + break; default: ARM_COMPUTE_ERROR("Operation not supported"); } @@ -117,7 +123,6 @@ OT reduce_operation(const T *ptr, int reduce_elements, ReductionOperation op, in res /= reduce_elements; } } - return res; } } // namespace -- cgit v1.2.1