From dd715f2a88827241a3fb9e4a2d8be82455f649f7 Mon Sep 17 00:00:00 2001 From: John Richardson Date: Mon, 18 Sep 2017 16:10:48 +0100 Subject: COMPMID-505: Move PixelWiseMultiplication to new validation Change-Id: I4daff53f5ee7f0393451425ba20aee1013466954 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/89200 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- tests/validation/CL/PixelWiseMultiplication.cpp | 133 ++++++++++++ .../CPP/FixedPointPixelWiseMultiplication.cpp | 85 ++++++++ .../CPP/FixedPointPixelWiseMultiplication.h | 43 ++++ tests/validation/CPP/PixelWiseMultiplication.cpp | 100 +++++++++ tests/validation/CPP/PixelWiseMultiplication.h | 43 ++++ .../NEON/FixedPointPixelWiseMultiplication.cpp | 147 ++++++++++++++ tests/validation/NEON/PixelWiseMultiplication.cpp | 225 +++++++++++++++++++++ tests/validation/Validation.h | 86 +++++++- .../FixedPointPixelWiseMultiplicationFixture.h | 119 +++++++++++ .../fixtures/PixelWiseMultiplicationFixture.h | 118 +++++++++++ 10 files changed, 1097 insertions(+), 2 deletions(-) create mode 100644 tests/validation/CL/PixelWiseMultiplication.cpp create mode 100644 tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp create mode 100644 tests/validation/CPP/FixedPointPixelWiseMultiplication.h create mode 100644 tests/validation/CPP/PixelWiseMultiplication.cpp create mode 100644 tests/validation/CPP/PixelWiseMultiplication.h create mode 100644 tests/validation/NEON/FixedPointPixelWiseMultiplication.cpp create mode 100644 tests/validation/NEON/PixelWiseMultiplication.cpp create mode 100644 tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h create mode 100644 tests/validation/fixtures/PixelWiseMultiplicationFixture.h (limited to 'tests/validation') diff --git a/tests/validation/CL/PixelWiseMultiplication.cpp b/tests/validation/CL/PixelWiseMultiplication.cpp new file mode 100644 index 0000000000..66f3ff6375 --- /dev/null +++ b/tests/validation/CL/PixelWiseMultiplication.cpp @@ -0,0 +1,133 @@ +/* + * 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. + */ +#include "arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h" +#include "tests/CL/CLAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/ConvertPolicyDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h" +#include "tests/validation/fixtures/PixelWiseMultiplicationFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const float scale_unity = 1.f; +const float scale_255 = 1.f / 255.f; + +// *INDENT-OFF* +// clang-format off +#define WRAP_VALIDATE(TYPE, TOLERANCE) validate_wrap(CLAccessor(_target), _reference, AbsoluteTolerance(TOLERANCE), 0.f); + +#define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, VALIDATE) \ + FIXTURE_DATA_TEST_CASE(TEST_NAME, CLPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ + combine(combine(combine(combine(combine( \ + datasets::SHAPES, \ + framework::dataset::make("DataType1", DataType::DT1)), \ + framework::dataset::make("DataType2", DataType::DT2)), \ + framework::dataset::make("Scale", std::move(SCALE))), \ + datasets::ConvertPolicies()), \ + framework::dataset::make("RoundingPolicy", RoundingPolicy::RP))) \ + { \ + VALIDATE \ + } + +#define FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, FPP_START, FPP_END) \ + FIXTURE_DATA_TEST_CASE(TEST_NAME, CLFixedPointPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ + combine(combine(combine(combine(combine(combine( \ + datasets::SHAPES, \ + framework::dataset::make("DataType1", DataType::DT1)), \ + framework::dataset::make("DataType2", DataType::DT2)), \ + framework::dataset::make("Scale", std::move(SCALE))), \ + datasets::ConvertPolicies()), \ + framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), \ + framework::dataset::make("FixedPointPosition", FPP_START, FPP_END))) \ + { \ + validate(CLAccessor(_target), _reference); \ + } +// clang-format on +// *INDENT-ON* +} // namespace + +template +using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture; +template +using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture; +template +using CLPixelWiseMultiplicationToQS8Fixture = PixelWiseMultiplicationValidationFixture; +template +using CLPixelWiseMultiplicationToQS16Fixture = PixelWiseMultiplicationValidationFixture; +template +using CLFixedPointPixelWiseMultiplicationFixture = FixedPointPixelWiseMultiplicationValidationFixture; + +TEST_SUITE(CL) +TEST_SUITE(PixelWiseMultiplication) + +TEST_SUITE(F16toF16) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF16Fixture, PRECOMMIT, SmallShapes(), F16, F16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE_END() // F16toF16 + +TEST_SUITE(F32toF32) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE_END() // F32toF32 + +TEST_SUITE_END() // PixelWiseMultiplication + +TEST_SUITE(FixedPointPixelWiseMultiplication) + +TEST_SUITE(QS8) + +TEST_SUITE(ScaleUnity) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, scale_unity, TO_ZERO, 1, 7) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE_END() // QS8 + +TEST_SUITE(QS16) + +TEST_SUITE(ScaleUnity) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, scale_unity, TO_ZERO, 1, 15) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE_END() // QS16 + +TEST_SUITE_END() // FixedPointPixelWiseMultiplication +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp b/tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp new file mode 100644 index 0000000000..636919b1ff --- /dev/null +++ b/tests/validation/CPP/FixedPointPixelWiseMultiplication.cpp @@ -0,0 +1,85 @@ +/* + * 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, + * dst OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "FixedPointPixelWiseMultiplication.h" + +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy) +{ + using namespace fixed_point_arithmetic; + + SimpleTensor dst(src2.shape(), src2.data_type(), 1, src2.fixed_point_position()); + + const int fixed_point_position = src1.fixed_point_position(); + + ARM_COMPUTE_ERROR_ON_MSG(src1.data_type() != src2.data_type() || src1.data_type() != dst.data_type(), + "Tensors must all have the same DataType"); + ARM_COMPUTE_ERROR_ON_MSG(fixed_point_position != src2.fixed_point_position() || fixed_point_position != dst.fixed_point_position(), + "Fixed-point position must be the same for both inputs and outputs"); + + // Validate fixed_point_position + ARM_COMPUTE_ERROR_ON((src1.data_type() == DataType::QS8) && (fixed_point_position == 0 || fixed_point_position > 7)); + ARM_COMPUTE_ERROR_ON((src1.data_type() == DataType::QS16) && (fixed_point_position == 0 || fixed_point_position > 15)); + + const fixed_point fp_scale(scale, fixed_point_position); + const bool is_sat = convert_policy == ConvertPolicy::SATURATE; + + for(int i = 0; i < src1.num_elements(); ++i) + { + const fixed_point val1(src1[i], fixed_point_position, true); + fixed_point res(src2[i], fixed_point_position, true); + if(is_sat) + { + res = mul(mul(res, val1), fp_scale); + } + else + { + res = mul(mul(res, val1), fp_scale); + } + dst[i] = res.raw(); + } + + return dst; +} + +// *INDENT-OFF* +// clang-format off +template SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); +template SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); +// *INDENT-ON* +// clang-format on + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/FixedPointPixelWiseMultiplication.h b/tests/validation/CPP/FixedPointPixelWiseMultiplication.h new file mode 100644 index 0000000000..124a33c9da --- /dev/null +++ b/tests/validation/CPP/FixedPointPixelWiseMultiplication.h @@ -0,0 +1,43 @@ +/* + * 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_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ +#define __ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor fixed_point_pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_H__ */ diff --git a/tests/validation/CPP/PixelWiseMultiplication.cpp b/tests/validation/CPP/PixelWiseMultiplication.cpp new file mode 100644 index 0000000000..b3647fc9ce --- /dev/null +++ b/tests/validation/CPP/PixelWiseMultiplication.cpp @@ -0,0 +1,100 @@ +/* + * 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, + * dst OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "PixelWiseMultiplication.h" + +#include "tests/validation/FixedPoint.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +struct is_floating_point + : std::integral_constant < bool, + std::is_same::type>::value || std::is_same::type>::value + || std::is_same::type>::value || std::is_same::type>::value > +{ +}; + +template +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) +{ + SimpleTensor dst(src2.shape(), src2.data_type()); + + if(scale < 0) + { + ARM_COMPUTE_ERROR("Scale of pixel-wise multiplication must be non-negative"); + } + + using intermediate_type = typename common_promoted_signed_type::intermediate_type; + + for(int i = 0; i < src1.num_elements(); ++i) + { + double val = static_cast(src1[i]) * static_cast(src2[i]) * static_cast(scale); + if(is_floating_point::value) + { + dst[i] = val; + } + else + { + double rounded_val = 0; + switch(rounding_policy) + { + case(RoundingPolicy::TO_ZERO): + rounded_val = support::cpp11::trunc(val); + break; + case(RoundingPolicy::TO_NEAREST_UP): + rounded_val = round_half_up(val); + break; + case(RoundingPolicy::TO_NEAREST_EVEN): + rounded_val = round_half_even(val); + break; + default: + ARM_COMPUTE_ERROR("Unsupported rounding policy"); + } + + dst[i] = (convert_policy == ConvertPolicy::SATURATE) ? saturate_cast(rounded_val) : static_cast(rounded_val); + } + } + + return dst; +} + +// *INDENT-OFF* +// clang-format off +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +// clang-format on +// *INDENT-ON* +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/PixelWiseMultiplication.h b/tests/validation/CPP/PixelWiseMultiplication.h new file mode 100644 index 0000000000..1dce154719 --- /dev/null +++ b/tests/validation/CPP/PixelWiseMultiplication.h @@ -0,0 +1,43 @@ +/* + * 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_PIXEL_WISE_MULTIPLICATION_H__ +#define __ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_H__ */ diff --git a/tests/validation/NEON/FixedPointPixelWiseMultiplication.cpp b/tests/validation/NEON/FixedPointPixelWiseMultiplication.cpp new file mode 100644 index 0000000000..f0a499d8d1 --- /dev/null +++ b/tests/validation/NEON/FixedPointPixelWiseMultiplication.cpp @@ -0,0 +1,147 @@ +/* + * 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. + */ +#include "arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h" +#include "tests/NEON/Accessor.h" +#include "tests/datasets/ConvertPolicyDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const float tolerance = 1.f; +const float scale_255 = 1.f / 255.f; +const float scale_unity = 1.f; + +// *INDENT-OFF* +// clang-format off +#define FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, FPP_START, FPP_END) \ + FIXTURE_DATA_TEST_CASE(TEST_NAME, NEFixedPointPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ + combine(combine(combine(combine(combine(combine( \ + datasets::SHAPES, \ + framework::dataset::make("DataType1", DataType::DT1)), \ + framework::dataset::make("DataType2", DataType::DT2)), \ + framework::dataset::make("Scale", std::move(SCALE))), \ + datasets::ConvertPolicies()), \ + framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), \ + framework::dataset::make("FixedPointPosition", FPP_START, FPP_END))) \ + { \ + validate(Accessor(_target), _reference); \ + } + +#define FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, RP, FPP, TOLERANCE) \ + FIXTURE_DATA_TEST_CASE(TEST_NAME, NEFixedPointPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ + combine(combine(combine(combine(combine(combine( \ + datasets::SHAPES, \ + framework::dataset::make("DataType1", DataType::DT1)), \ + framework::dataset::make("DataType2", DataType::DT2)), \ + framework::dataset::make("Scale", 1.f / static_cast(1 << (FPP)))), \ + datasets::ConvertPolicies()), \ + framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), \ + framework::dataset::make("FixedPointPosition", FPP))) \ + { \ + validate(Accessor(_target), _reference, AbsoluteTolerance(TOLERANCE), 0.f); \ + } +// clang-format on +// *INDENT-ON* +} // namespace + +template +using NEFixedPointPixelWiseMultiplicationFixture = FixedPointPixelWiseMultiplicationValidationFixture; + +TEST_SUITE(NEON) +TEST_SUITE(FixedPointPixelWiseMultiplication) + +TEST_SUITE(QS8) + +TEST_SUITE(Scale255) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, scale_255, TO_NEAREST_UP, 1, 7) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, scale_255, TO_NEAREST_UP, 1, 7) +TEST_SUITE_END() // Scale255 + +TEST_SUITE(ScaleUnity) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, scale_unity, TO_ZERO, 1, 7) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, scale_unity, TO_ZERO, 1, 7) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE(ScaleOther) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther1, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, TO_ZERO, 1, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther2, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, TO_ZERO, 2, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther3, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, TO_ZERO, 3, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther4, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, TO_ZERO, 4, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther5, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, TO_ZERO, 5, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther6, Fixture, PRECOMMIT, SmallShapes(), QS8, QS8, TO_ZERO, 6, tolerance) + +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunLargeOther1, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, TO_ZERO, 1, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunLargeOther2, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, TO_ZERO, 2, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunLargeOther3, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, TO_ZERO, 3, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunLargeOther4, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, TO_ZERO, 4, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunLargeOther5, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, TO_ZERO, 5, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunLargeOther6, Fixture, NIGHTLY, LargeShapes(), QS8, QS8, TO_ZERO, 6, tolerance) +TEST_SUITE_END() // ScaleOther + +TEST_SUITE_END() // QS8 + +TEST_SUITE(QS16) + +TEST_SUITE(Scale255) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, scale_255, TO_NEAREST_UP, 1, 15) +TEST_SUITE_END() // Scale255 + +TEST_SUITE(ScaleUnity) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, scale_unity, TO_ZERO, 1, 15) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, Fixture, NIGHTLY, LargeShapes(), QS16, QS16, scale_unity, TO_ZERO, 1, 15) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE(ScaleOther) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther1, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 1, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther2, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 2, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther3, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 3, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther4, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 4, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther5, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 5, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther6, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 6, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther7, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 7, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther8, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 8, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther9, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 9, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther10, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 10, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther11, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 11, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther12, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 12, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther13, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 13, tolerance) +FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE_OTHER(RunSmallOther14, Fixture, PRECOMMIT, SmallShapes(), QS16, QS16, TO_ZERO, 14, tolerance) +TEST_SUITE_END() // ScaleOther + +TEST_SUITE_END() // QS16 + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/NEON/PixelWiseMultiplication.cpp b/tests/validation/NEON/PixelWiseMultiplication.cpp new file mode 100644 index 0000000000..e1e62e46ef --- /dev/null +++ b/tests/validation/NEON/PixelWiseMultiplication.cpp @@ -0,0 +1,225 @@ +/* + * 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. + */ +#include "arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h" +#include "tests/NEON/Accessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/ConvertPolicyDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/PixelWiseMultiplicationFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const float scale_unity = 1.f; +const float scale_255 = 1.f / 255.f; +const float scale_other = 1.f / 32768.f; + +#define DEFAULT_VALIDATE validate(Accessor(_target), _reference); +#define WRAP_VALIDATE(TYPE, TOLERANCE) validate_wrap(Accessor(_target), _reference, AbsoluteTolerance(TOLERANCE), 0.f); + +// *INDENT-OFF* +// clang-format off +#define PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(DT1, DT2, SCALE, RP) \ + DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, \ + combine(combine(combine(combine(combine( \ + concat(datasets::SmallShapes(), datasets::LargeShapes()), \ + framework::dataset::make("DataType1", DataType::DT1)), \ + framework::dataset::make("DataType2", DataType::DT2)), \ + framework::dataset::make("Scale", std::move(SCALE))), \ + datasets::ConvertPolicies()), \ + framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), \ + shape, dt1, dt2, scale, convert_policy, rounding_policy) \ + { \ + validate_configuration(shape, dt1, dt2, scale, convert_policy, rounding_policy); \ + } + +#define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, VALIDATE) \ + FIXTURE_DATA_TEST_CASE(TEST_NAME, NEPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ + combine(combine(combine(combine(combine( \ + datasets::SHAPES, \ + framework::dataset::make("DataType1", DataType::DT1)), \ + framework::dataset::make("DataType2", DataType::DT2)), \ + framework::dataset::make("Scale", std::move(SCALE))), \ + datasets::ConvertPolicies()), \ + framework::dataset::make("RoundingPolicy", RoundingPolicy::RP))) \ + { \ + VALIDATE \ + } +// *INDENT-ON* +// clang-format on + +void validate_configuration(TensorShape shape, DataType dt1, DataType dt2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) +{ + Tensor src1 = create_tensor(shape, dt1); + Tensor src2 = create_tensor(shape, dt2); + Tensor dst = create_tensor(shape, dt2); + + ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Create and configure function + NEPixelWiseMultiplication multiply; + multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape); + validate(src1.info()->valid_region(), valid_region); + validate(src2.info()->valid_region(), valid_region); + validate(dst.info()->valid_region(), valid_region); + + // Validate padding + const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); + validate(src1.info()->padding(), padding); + validate(src2.info()->padding(), padding); + validate(dst.info()->padding(), padding); +} +} // namespace + +template +using NEPixelWiseMultiplicationToU8Fixture = PixelWiseMultiplicationValidationFixture; +template +using NEPixelWiseMultiplicationToS16Fixture = PixelWiseMultiplicationValidationFixture; +template +using NEPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture; +template +using NEPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture; +template +using NEPixelWiseMultiplicationToQS8Fixture = PixelWiseMultiplicationValidationFixture; +template +using NEPixelWiseMultiplicationToQS16Fixture = PixelWiseMultiplicationValidationFixture; + +TEST_SUITE(NEON) +TEST_SUITE(PixelWiseMultiplication) + +TEST_SUITE(U8toU8) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(U8, U8, scale_255, TO_NEAREST_UP) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToU8Fixture, PRECOMMIT, SmallShapes(), U8, U8, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(uint8_t, 1)) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToU8Fixture, NIGHTLY, LargeShapes(), U8, U8, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(uint8_t, 1)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE(ScaleUnity) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(U8, U8, scale_unity, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToU8Fixture, PRECOMMIT, SmallShapes(), U8, U8, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToU8Fixture, NIGHTLY, LargeShapes(), U8, U8, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE(ScaleOther) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(U8, U8, scale_other, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToU8Fixture, PRECOMMIT, SmallShapes(), U8, U8, scale_other, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToU8Fixture, NIGHTLY, LargeShapes(), U8, U8, scale_other, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleOther + +TEST_SUITE_END() // U8toU8 + +TEST_SUITE(U8toS16) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(U8, S16, scale_255, TO_NEAREST_UP) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToS16Fixture, PRECOMMIT, SmallShapes(), U8, S16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(int16_t, 2)) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToS16Fixture, NIGHTLY, LargeShapes(), U8, S16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(int16_t, 2)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE(ScaleUnity) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(U8, S16, scale_unity, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToS16Fixture, PRECOMMIT, SmallShapes(), U8, S16, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToS16Fixture, NIGHTLY, LargeShapes(), U8, S16, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE(ScaleOther) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(U8, S16, scale_other, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToS16Fixture, PRECOMMIT, SmallShapes(), U8, S16, scale_other, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToS16Fixture, NIGHTLY, LargeShapes(), U8, S16, scale_other, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleOther + +TEST_SUITE_END() // U8toS16 + +TEST_SUITE(S16toS16) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(S16, S16, scale_255, TO_NEAREST_UP) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToS16Fixture, PRECOMMIT, SmallShapes(), S16, S16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(int16_t, 2)) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToS16Fixture, NIGHTLY, LargeShapes(), S16, S16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(int16_t, 2)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE(ScaleUnity) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(S16, S16, scale_unity, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToS16Fixture, PRECOMMIT, SmallShapes(), S16, S16, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToS16Fixture, NIGHTLY, LargeShapes(), S16, S16, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE(ScaleOther) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(S16, S16, scale_other, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToS16Fixture, PRECOMMIT, SmallShapes(), S16, S16, scale_other, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToS16Fixture, NIGHTLY, LargeShapes(), S16, S16, scale_other, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleOther + +TEST_SUITE_END() // S16toS16 + +#ifdef ARM_COMPUTE_ENABLE_FP16 +TEST_SUITE(F16toF16) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF16Fixture, PRECOMMIT, SmallShapes(), F16, F16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE_END() // F16toF16 +#endif // ARM_COMPUTE_ENABLE_FP16 + +TEST_SUITE(F32toF32) + +TEST_SUITE(Scale255) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(F32, F32, scale_255, TO_NEAREST_UP) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f)) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToF32Fixture, NIGHTLY, LargeShapes(), F32, F32, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f)) +TEST_SUITE_END() // Scale255 + +TEST_SUITE(ScaleUnity) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(F32, F32, scale_unity, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture, PRECOMMIT, SmallShapes(), F32, F32, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToF32Fixture, NIGHTLY, LargeShapes(), F32, F32, scale_unity, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleUnity + +TEST_SUITE(ScaleOther) +PIXEL_WISE_MULTIPLICATION_DATA_TEST_CASE(F32, F32, scale_other, TO_ZERO) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture, PRECOMMIT, SmallShapes(), F32, F32, scale_other, TO_ZERO, DEFAULT_VALIDATE) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunLarge, ToF32Fixture, NIGHTLY, LargeShapes(), F32, F32, scale_other, TO_ZERO, DEFAULT_VALIDATE) +TEST_SUITE_END() // ScaleOther + +TEST_SUITE_END() // F32toF32 + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/Validation.h b/tests/validation/Validation.h index f220224991..8ed98fbc82 100644 --- a/tests/validation/Validation.h +++ b/tests/validation/Validation.h @@ -235,14 +235,15 @@ void validate_keypoints(T target_first, T target_last, U reference_first, U refe template struct compare_base { - compare_base(typename T::value_type target, typename T::value_type reference, T tolerance = T(0)) - : _target{ target }, _reference{ reference }, _tolerance{ tolerance } + compare_base(typename T::value_type target, typename T::value_type reference, T tolerance = T(0), bool wrap_range = false) + : _target{ target }, _reference{ reference }, _tolerance{ tolerance }, _wrap_range{ wrap_range } { } typename T::value_type _target{}; typename T::value_type _reference{}; T _tolerance{}; + bool _wrap_range{}; }; template @@ -266,6 +267,12 @@ struct compare> : public compare_base> using comparison_type = typename std::conditional::value, int64_t, U>::type; + if(this->_wrap_range) + { + const comparison_type abs_difference(std::abs(static_cast(this->_target)) - std::abs(static_cast(this->_reference))); + return abs_difference <= static_cast(this->_tolerance); + } + const comparison_type abs_difference(std::abs(static_cast(this->_target) - static_cast(this->_reference))); return abs_difference <= static_cast(this->_tolerance); @@ -315,6 +322,13 @@ void validate(const IAccessor &tensor, const SimpleTensor &reference, U toler validate(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number); } +template +void validate_wrap(const IAccessor &tensor, const SimpleTensor &reference, U tolerance_value, float tolerance_number) +{ + // Validate with valid region covering the entire shape + validate_wrap(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number); +} + template void validate(const IAccessor &tensor, const SimpleTensor &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number) { @@ -376,6 +390,74 @@ void validate(const IAccessor &tensor, const SimpleTensor &reference, const V } } +template +void validate_wrap(const IAccessor &tensor, const SimpleTensor &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number) +{ + int64_t num_mismatches = 0; + int64_t num_elements = 0; + + ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type(), framework::LogLevel::ERRORS); + + if(reference.format() != Format::UNKNOWN) + { + ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format(), framework::LogLevel::ERRORS); + } + + ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); + + const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); + const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); + + // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ... + for(int element_idx = 0; element_idx < min_elements; ++element_idx) + { + const Coordinates id = index2coord(reference.shape(), element_idx); + + if(is_in_valid_region(valid_region, id)) + { + // Iterate over all channels within one element + for(int c = 0; c < min_channels; ++c) + { + const T &target_value = reinterpret_cast(tensor(id))[c]; + const T &reference_value = reinterpret_cast(reference(id))[c]; + + bool equal = compare(target_value, reference_value, tolerance_value); + + if(!equal) + { + equal = compare(target_value, reference_value, tolerance_value, true); + } + + if(!equal) + { + ARM_COMPUTE_TEST_INFO("id = " << id); + ARM_COMPUTE_TEST_INFO("channel = " << c); + ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << framework::make_printable(target_value)); + ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << framework::make_printable(reference_value)); + ARM_COMPUTE_TEST_INFO("tolerance = " << std::setprecision(5) << framework::make_printable(static_cast(tolerance_value))); + framework::ARM_COMPUTE_PRINT_INFO(); + + ++num_mismatches; + } + + ++num_elements; + } + } + } + + if(num_elements > 0) + { + const int64_t absolute_tolerance_number = tolerance_number * num_elements; + const float percent_mismatches = static_cast(num_mismatches) / num_elements * 100.f; + + ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::fixed << std::setprecision(2) << percent_mismatches + << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)"); + ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number, framework::LogLevel::ERRORS); + } +} + /** Check which keypoints from [first1, last1) are missing in [first2, last2) */ template std::pair compare_keypoints(T first1, T last1, U first2, U last2, V tolerance) diff --git a/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h b/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h new file mode 100644 index 0000000000..d090d8583d --- /dev/null +++ b/tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h @@ -0,0 +1,119 @@ +/* + * 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_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_FIXTURE +#define ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/CPP/FixedPointPixelWiseMultiplication.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class FixedPointPixelWiseMultiplicationValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape, + DataType dt_in1, + DataType dt_in2, + float scale, + ConvertPolicy convert_policy, + RoundingPolicy rounding_policy, + int fixed_point_position) + { + _target = compute_target(shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy, fixed_point_position); + _reference = compute_reference(shape, dt_in1, dt_in2, scale, convert_policy, fixed_point_position); + } + +protected: + template + void fill(U &&tensor, unsigned int seed_offset) + { + library->fill_tensor_uniform(tensor, seed_offset); + } + + TensorType compute_target(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, int fixed_point_position) + { + // Create tensors + TensorType src1 = create_tensor(shape, dt_in1, 1, fixed_point_position); + TensorType src2 = create_tensor(shape, dt_in2, 1, fixed_point_position); + TensorType dst = create_tensor(shape, dt_in2, 1, fixed_point_position); + + // Create and configure function + FunctionType multiply; + multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy); + + ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src1.allocator()->allocate(); + src2.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src1), 0); + fill(AccessorType(src2), 1); + + // Compute function + multiply.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, int fixed_point_position) + { + // Create reference + SimpleTensor src1{ shape, dt_in1, 1, fixed_point_position }; + SimpleTensor src2{ shape, dt_in2, 1, fixed_point_position }; + + // Fill reference + fill(src1, 0); + fill(src2, 1); + + return reference::fixed_point_pixel_wise_multiplication(src1, src2, scale, convert_policy); + } + + TensorType _target{}; + SimpleTensor _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_FIXTURE */ diff --git a/tests/validation/fixtures/PixelWiseMultiplicationFixture.h b/tests/validation/fixtures/PixelWiseMultiplicationFixture.h new file mode 100644 index 0000000000..351349e64e --- /dev/null +++ b/tests/validation/fixtures/PixelWiseMultiplicationFixture.h @@ -0,0 +1,118 @@ +/* + * 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_PIXEL_WISE_MULTIPLICATION_FIXTURE +#define ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/CPP/PixelWiseMultiplication.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class PixelWiseMultiplicationValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape, + DataType dt_in1, + DataType dt_in2, + float scale, + ConvertPolicy convert_policy, + RoundingPolicy rounding_policy) + { + _target = compute_target(shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy); + _reference = compute_reference(shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy); + } + +protected: + template + void fill(U &&tensor, unsigned int seed_offset) + { + library->fill_tensor_uniform(tensor, seed_offset); + } + + TensorType compute_target(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) + { + // Create tensors + TensorType src1 = create_tensor(shape, dt_in1); + TensorType src2 = create_tensor(shape, dt_in2); + TensorType dst = create_tensor(shape, dt_in2); + + // Create and configure function + FunctionType multiply; + multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy); + + ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src1.allocator()->allocate(); + src2.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src1), 0); + fill(AccessorType(src2), 1); + + // Compute function + multiply.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) + { + // Create reference + SimpleTensor src1{ shape, dt_in1 }; + SimpleTensor src2{ shape, dt_in2 }; + + // Fill reference + fill(src1, 0); + fill(src2, 1); + + return reference::pixel_wise_multiplication(src1, src2, scale, convert_policy, rounding_policy); + } + + TensorType _target{}; + SimpleTensor _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_FIXTURE */ -- cgit v1.2.1