From 64856912aa5a5b31ef3cf35b3e0a94615ea0968f Mon Sep 17 00:00:00 2001 From: Alex Gilday Date: Fri, 5 Jan 2018 10:10:28 +0000 Subject: COMPMID-773: Add CL/NEON Harris Corners benchmark tests Change-Id: Idf452cfa0428a36f2d718a6d438d6e59897e1e99 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115061 Reviewed-by: Georgios Pinitas Reviewed-by: Pablo Tello Tested-by: Jenkins --- arm_compute/runtime/CL/functions/CLHarrisCorners.h | 5 +- src/runtime/CL/functions/CLHarrisCorners.cpp | 5 +- tests/benchmark/CL/HarrisCorners.cpp | 81 ++++++++++++++++ tests/benchmark/NEON/HarrisCorners.cpp | 104 +++++++++++++++++++++ tests/benchmark/fixtures/HarrisCornersFixture.h | 85 +++++++++++++++++ 5 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 tests/benchmark/CL/HarrisCorners.cpp create mode 100644 tests/benchmark/NEON/HarrisCorners.cpp create mode 100644 tests/benchmark/fixtures/HarrisCornersFixture.h diff --git a/arm_compute/runtime/CL/functions/CLHarrisCorners.h b/arm_compute/runtime/CL/functions/CLHarrisCorners.h index e09e67060f..4cb7fbd307 100644 --- a/arm_compute/runtime/CL/functions/CLHarrisCorners.h +++ b/arm_compute/runtime/CL/functions/CLHarrisCorners.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 ARM Limited. + * Copyright (c) 2016-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -77,10 +77,11 @@ public: * @param[out] corners Array of keypoints to store the results. * @param[in] border_mode Border mode to use * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. + * @param[in] use_fp16 (Optional) If true the FP16 kernels will be used. If false F32 kernels are used. */ void configure(ICLImage *input, float threshold, float min_dist, float sensitivity, int32_t gradient_size, int32_t block_size, ICLKeyPointArray *corners, - BorderMode border_mode, uint8_t constant_border_value = 0); + BorderMode border_mode, uint8_t constant_border_value = 0, bool use_fp16 = false); // Inherited methods overridden: void run() override; diff --git a/src/runtime/CL/functions/CLHarrisCorners.cpp b/src/runtime/CL/functions/CLHarrisCorners.cpp index 059528fe30..65ce7de490 100644 --- a/src/runtime/CL/functions/CLHarrisCorners.cpp +++ b/src/runtime/CL/functions/CLHarrisCorners.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 ARM Limited. + * Copyright (c) 2016-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -63,8 +63,9 @@ CLHarrisCorners::CLHarrisCorners(std::shared_ptr memory_manager) void CLHarrisCorners::configure(ICLImage *input, float threshold, float min_dist, float sensitivity, int32_t gradient_size, int32_t block_size, ICLKeyPointArray *corners, - BorderMode border_mode, uint8_t constant_border_value) + BorderMode border_mode, uint8_t constant_border_value, bool use_fp16) { + ARM_COMPUTE_UNUSED(use_fp16); //TODO(COMPMID-772): Add half float support ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(input); ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); ARM_COMPUTE_ERROR_ON(!(block_size == 3 || block_size == 5 || block_size == 7)); diff --git a/tests/benchmark/CL/HarrisCorners.cpp b/tests/benchmark/CL/HarrisCorners.cpp new file mode 100644 index 0000000000..90c657f8e4 --- /dev/null +++ b/tests/benchmark/CL/HarrisCorners.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 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. + */ +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/CL/CLArray.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLHarrisCorners.h" +#include "tests/CL/CLAccessor.h" +#include "tests/benchmark/fixtures/HarrisCornersFixture.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "utils/TypePrinter.h" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +namespace +{ +const auto threshold = framework::dataset::make("Threshold", { 0.00115f }); +const auto min_dist = framework::dataset::make("MinDist", { 2.f }); +const auto sensitivity = framework::dataset::make("Sensitivity", { 0.04f }); +const auto gradient_size = framework::dataset::make("GradientSize", { 3, 5, 7 }); +const auto block_size = framework::dataset::make("BlockSize", { 3, 5, 7 }); +const auto border_mode = framework::dataset::make("BorderMode", { BorderMode::UNDEFINED, BorderMode::CONSTANT, BorderMode::REPLICATE }); +} // namespace + +using CLHarrisCornersFixture = HarrisCornersFixture; + +TEST_SUITE(CL) +TEST_SUITE(HarrisCorners) + +REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageShapes(), + framework::dataset::make("Format", { Format::S16 })), + threshold), + min_dist), + sensitivity), + gradient_size), + block_size), + border_mode), + framework::dataset::make("UseFP16", { false }))); + +REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageShapes(), + framework::dataset::make("Format", { Format::S16 })), + threshold), + min_dist), + sensitivity), + gradient_size), + block_size), + border_mode), + framework::dataset::make("UseFP16", { false }))); + +TEST_SUITE_END() // HarrisCorners +TEST_SUITE_END() // CL +} // namespace benchmark +} // namespace test +} // namespace arm_compute \ No newline at end of file diff --git a/tests/benchmark/NEON/HarrisCorners.cpp b/tests/benchmark/NEON/HarrisCorners.cpp new file mode 100644 index 0000000000..359e5f786e --- /dev/null +++ b/tests/benchmark/NEON/HarrisCorners.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 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. + */ +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/NEON/functions/NEHarrisCorners.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" +#include "tests/NEON/Accessor.h" +#include "tests/benchmark/fixtures/HarrisCornersFixture.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "utils/TypePrinter.h" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +namespace +{ +const auto threshold = framework::dataset::make("Threshold", { 0.00115f }); +const auto min_dist = framework::dataset::make("MinDist", { 2.f }); +const auto sensitivity = framework::dataset::make("Sensitivity", { 0.04f }); +const auto gradient_size = framework::dataset::make("GradientSize", { 3, 5, 7 }); +const auto block_size = framework::dataset::make("BlockSize", { 3, 5, 7 }); +const auto border_mode = framework::dataset::make("BorderMode", { BorderMode::UNDEFINED, BorderMode::CONSTANT, BorderMode::REPLICATE }); +} // namespace + +using NEHarrisCornersFixture = HarrisCornersFixture; + +TEST_SUITE(NEON) +TEST_SUITE(HarrisCorners) + +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +TEST_SUITE(FP16) + +REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageShapes(), + framework::dataset::make("Format", { Format::S16 })), + threshold), + min_dist), + sensitivity), + gradient_size), + block_size), + border_mode), + framework::dataset::make("UseFP16", { true }))); +REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageShapes(), + framework::dataset::make("Format", { Format::S16 })), + threshold), + min_dist), + sensitivity), + gradient_size), + block_size), + border_mode), + framework::dataset::make("UseFP16", { true }))); +TEST_SUITE_END() // FP16 +#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC + +TEST_SUITE(S16) +REGISTER_FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallImageShapes(), + framework::dataset::make("Format", { Format::S16 })), + threshold), + min_dist), + sensitivity), + gradient_size), + block_size), + border_mode), + framework::dataset::make("UseFP16", { false }))); +REGISTER_FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeImageShapes(), + framework::dataset::make("Format", { Format::S16 })), + threshold), + min_dist), + sensitivity), + gradient_size), + block_size), + border_mode), + framework::dataset::make("UseFP16", { false }))); +TEST_SUITE_END() // S16 +TEST_SUITE_END() // HarrisCorners +TEST_SUITE_END() // NEON +} // namespace benchmark +} // namespace test +} // namespace arm_compute \ No newline at end of file diff --git a/tests/benchmark/fixtures/HarrisCornersFixture.h b/tests/benchmark/fixtures/HarrisCornersFixture.h new file mode 100644 index 0000000000..1596ede962 --- /dev/null +++ b/tests/benchmark/fixtures/HarrisCornersFixture.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 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_HARRIS_CORNERS_FIXTURE +#define ARM_COMPUTE_TEST_HARRIS_CORNERS_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/Globals.h" +#include "tests/Utils.h" +#include "tests/framework/Fixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +template +class HarrisCornersFixture : public framework::Fixture +{ +public: + template + void setup(const TensorShape &shape, Format format, float threshold, float min_dist, float sensitivity, + int32_t gradient_size, int32_t block_size, + BorderMode border_mode, bool use_fp16) + { + // Create tensor + src = create_tensor(shape, format); + + // Create and configure function + harris_corners_func.configure(&src, threshold, min_dist, sensitivity, gradient_size, block_size, &out, border_mode, 0, use_fp16); + + // Allocate tensor + src.allocator()->allocate(); + + // Fill tensor + std::uniform_int_distribution distribution(100, 100); + library->fill(Accessor(src), distribution, 0); + } + + void run() + { + harris_corners_func.run(); + } + + void sync() + { + sync_if_necessary(); + } + + void teardown() + { + src.allocator()->free(); + } + +private: + TensorType src{}; + ArrayType out{ 20000 }; + Function harris_corners_func{}; +}; +} // namespace benchmark +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_HARRIS_CORNERS_FIXTURE */ \ No newline at end of file -- cgit v1.2.1