diff options
Diffstat (limited to 'tests/benchmark')
-rw-r--r-- | tests/benchmark/CL/ROIPoolingLayer.cpp | 20 | ||||
-rw-r--r-- | tests/benchmark/NEON/ROIPoolingLayer.cpp | 13 | ||||
-rw-r--r-- | tests/benchmark/fixtures/ROIPoolingLayerFixture.h | 78 |
3 files changed, 80 insertions, 31 deletions
diff --git a/tests/benchmark/CL/ROIPoolingLayer.cpp b/tests/benchmark/CL/ROIPoolingLayer.cpp index 2ef91d45fd..eadb027b75 100644 --- a/tests/benchmark/CL/ROIPoolingLayer.cpp +++ b/tests/benchmark/CL/ROIPoolingLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,7 +30,7 @@ #include "tests/CL/CLAccessor.h" #include "tests/CL/CLArrayAccessor.h" #include "tests/benchmark/fixtures/ROIPoolingLayerFixture.h" -#include "tests/datasets/ROIPoolingLayerDataset.h" +#include "tests/datasets/ROIDataset.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" #include "utils/TypePrinter.h" @@ -41,16 +41,20 @@ namespace test { namespace benchmark { -using CLROIPoolingLayerFixture = ROIPoolingLayerFixture<CLTensor, CLROIPoolingLayer, CLAccessor, CLArray<ROI>, CLArrayAccessor<ROI>>; +template <typename T> +using CLROIPoolingLayerFixture = ROIPoolingLayerFixture<CLTensor, CLROIPoolingLayer, CLAccessor, T>; TEST_SUITE(CL) - -REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayer, CLROIPoolingLayerFixture, framework::DatasetMode::ALL, - framework::dataset::combine(framework::dataset::combine(datasets::SmallROIPoolingLayerDataset(), - framework::dataset::make("DataType", { DataType::F16, DataType::F32 })), +REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayerHalf, CLROIPoolingLayerFixture<half>, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::SmallROIDataset(), + framework::dataset::make("DataType", { DataType::F16 })), framework::dataset::make("Batches", { 1, 4, 8 }))); -TEST_SUITE_END() +REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayerFloat, CLROIPoolingLayerFixture<float>, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::SmallROIDataset(), + framework::dataset::make("DataType", { DataType::F32 })), + framework::dataset::make("Batches", { 1, 4, 8 }))); +TEST_SUITE_END() // CL } // namespace benchmark } // namespace test } // namespace arm_compute diff --git a/tests/benchmark/NEON/ROIPoolingLayer.cpp b/tests/benchmark/NEON/ROIPoolingLayer.cpp index 02cf47b189..10652a5606 100644 --- a/tests/benchmark/NEON/ROIPoolingLayer.cpp +++ b/tests/benchmark/NEON/ROIPoolingLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,7 +30,7 @@ #include "tests/NEON/Accessor.h" #include "tests/NEON/ArrayAccessor.h" #include "tests/benchmark/fixtures/ROIPoolingLayerFixture.h" -#include "tests/datasets/ROIPoolingLayerDataset.h" +#include "tests/datasets/ROIDataset.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" #include "utils/TypePrinter.h" @@ -41,16 +41,17 @@ namespace test { namespace benchmark { -using NEROIPoolingLayerFixture = ROIPoolingLayerFixture<Tensor, NEROIPoolingLayer, Accessor, Array<ROI>, ArrayAccessor<ROI>>; +template <typename T> +using NEROIPoolingLayerFixture = ROIPoolingLayerFixture<Tensor, NEROIPoolingLayer, Accessor, T>; TEST_SUITE(NEON) -REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayer, NEROIPoolingLayerFixture, framework::DatasetMode::ALL, - framework::dataset::combine(framework::dataset::combine(datasets::SmallROIPoolingLayerDataset(), +REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayerFloat, NEROIPoolingLayerFixture<float>, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::SmallROIDataset(), framework::dataset::make("DataType", { DataType::F32 })), framework::dataset::make("Batches", { 1, 4, 8 }))); -TEST_SUITE_END() +TEST_SUITE_END() // NEON } // namespace benchmark } // namespace test } // namespace arm_compute diff --git a/tests/benchmark/fixtures/ROIPoolingLayerFixture.h b/tests/benchmark/fixtures/ROIPoolingLayerFixture.h index fa4a5b7044..2c828272de 100644 --- a/tests/benchmark/fixtures/ROIPoolingLayerFixture.h +++ b/tests/benchmark/fixtures/ROIPoolingLayerFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -39,37 +39,38 @@ namespace test namespace benchmark { /** Fixture that can be used for NEON and CL */ -template <typename TensorType, typename Function, typename Accessor, typename Array_T, typename ArrayAccessor> +template <typename TensorType, typename Function, typename AccessorType, typename T> class ROIPoolingLayerFixture : public framework::Fixture { public: template <typename...> - void setup(TensorShape shape, const ROIPoolingLayerInfo pool_info, unsigned int num_rois, DataType data_type, int batches) + void setup(TensorShape input_shape, const ROIPoolingLayerInfo pool_info, TensorShape rois_shape, DataType data_type, int batches) { // Set batched in source and destination shapes TensorShape shape_dst; - shape.set(shape.num_dimensions(), batches); + rois_tensor = create_tensor<TensorType>(rois_shape, DataType::U16); + + input_shape.set(input_shape.num_dimensions(), batches); shape_dst.set(0, pool_info.pooled_width()); shape_dst.set(1, pool_info.pooled_height()); - shape_dst.set(2, shape.z()); - shape_dst.set(3, num_rois); + shape_dst.set(2, input_shape.z()); + shape_dst.set(3, rois_shape[1]); // Create tensors - src = create_tensor<TensorType>(shape, data_type, 1); + src = create_tensor<TensorType>(input_shape, data_type, 1); dst = create_tensor<TensorType>(shape_dst, data_type, 1); - // Create random ROIs - std::vector<ROI> rois = generate_random_rois(shape, pool_info, num_rois, 0U); - rois_array = arm_compute::support::cpp14::make_unique<Array_T>(num_rois); - fill_array(ArrayAccessor(*rois_array), rois); - // Create and configure function - roi_pool.configure(&src, rois_array.get(), &dst, pool_info); + roi_pool.configure(&src, &rois_tensor, &dst, pool_info); // Allocate tensors + rois_tensor.allocator()->allocate(); src.allocator()->allocate(); dst.allocator()->allocate(); + + // Create random ROIs + generate_rois(AccessorType(rois_tensor), input_shape, pool_info, rois_shape); } void run() @@ -89,11 +90,54 @@ public: dst.allocator()->free(); } +protected: + template <typename U> + void generate_rois(U &&rois, const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, TensorShape rois_shape) + { + const size_t values_per_roi = rois_shape.x(); + const size_t num_rois = rois_shape.y(); + + std::mt19937 gen(library->seed()); + uint16_t *rois_ptr = static_cast<uint16_t *>(rois.data()); + + const float pool_width = pool_info.pooled_width(); + const float pool_height = pool_info.pooled_height(); + const float roi_scale = pool_info.spatial_scale(); + + // Calculate distribution bounds + const auto scaled_width = static_cast<uint16_t>((shape.x() / roi_scale) / pool_width); + const auto scaled_height = static_cast<uint16_t>((shape.y() / roi_scale) / pool_height); + const auto min_width = static_cast<uint16_t>(pool_width / roi_scale); + const auto min_height = static_cast<uint16_t>(pool_height / roi_scale); + + // Create distributions + std::uniform_int_distribution<int> dist_batch(0, shape[3] - 1); + std::uniform_int_distribution<uint16_t> dist_x1(0, scaled_width); + std::uniform_int_distribution<uint16_t> dist_y1(0, scaled_height); + std::uniform_int_distribution<uint16_t> dist_w(min_width, std::max(float(min_width), (pool_width - 2) * scaled_width)); + std::uniform_int_distribution<uint16_t> dist_h(min_height, std::max(float(min_height), (pool_height - 2) * scaled_height)); + + for(unsigned int pw = 0; pw < num_rois; ++pw) + { + const auto batch_idx = dist_batch(gen); + const auto x1 = dist_x1(gen); + const auto y1 = dist_y1(gen); + const auto x2 = x1 + dist_w(gen); + const auto y2 = y1 + dist_h(gen); + + rois_ptr[values_per_roi * pw] = batch_idx; + rois_ptr[values_per_roi * pw + 1] = x1; + rois_ptr[values_per_roi * pw + 2] = y1; + rois_ptr[values_per_roi * pw + 3] = x2; + rois_ptr[values_per_roi * pw + 4] = y2; + } + } + private: - TensorType src{}; - TensorType dst{}; - std::unique_ptr<Array_T> rois_array{}; - Function roi_pool{}; + TensorType src{}; + TensorType dst{}; + TensorType rois_tensor{}; + Function roi_pool{}; }; } // namespace benchmark } // namespace test |