From 3e36369a5511c3028c30fc820752dc1248bddf5c Mon Sep 17 00:00:00 2001 From: SiCong Li Date: Tue, 4 Jul 2017 15:02:10 +0100 Subject: COMPMID-358 Implement OpenCL ROI Pooling * Implement OpenCL ROI Pooling * Add CLROIPoolingLayer benchmarks Change-Id: I8786d01d551850a1b4d599a48fabe3925e0a27d0 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/79833 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/validation/CL/CMakeLists.txt | 9 +++ tests/validation/CL/ROIPoolingLayer.cpp | 112 ++++++++++++++++++++++++++++++ tests/validation/Helpers.cpp | 72 ------------------- tests/validation/Helpers.h | 13 +--- tests/validation/NEON/Gaussian5x5.cpp | 2 - tests/validation/NEON/ROIPoolingLayer.cpp | 12 ++-- 6 files changed, 129 insertions(+), 91 deletions(-) create mode 100644 tests/validation/CL/ROIPoolingLayer.cpp delete mode 100644 tests/validation/Helpers.cpp (limited to 'tests/validation') diff --git a/tests/validation/CL/CMakeLists.txt b/tests/validation/CL/CMakeLists.txt index 67900b3edc..f4477f621f 100644 --- a/tests/validation/CL/CMakeLists.txt +++ b/tests/validation/CL/CMakeLists.txt @@ -27,15 +27,24 @@ set(arm_compute_test_validation_OPENCL_SOURCE_FILES ${CMAKE_SOURCE_DIR}/CL/CLAccessor.h ${CMAKE_CURRENT_SOURCE_DIR}/CLFixture.h ${CMAKE_CURRENT_SOURCE_DIR}/CLFixture.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ActivationLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/BitwiseAnd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Box3x3.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ConvolutionLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DepthConvert.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FillBorder.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FixedPoint/FixedPoint_QS8.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FullyConnectedLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gaussian3x3.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gaussian5x5.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/GEMM.cpp ` ${CMAKE_CURRENT_SOURCE_DIR}/IntegralImage.cpp +` ${CMAKE_CURRENT_SOURCE_DIR}/NonLinearFilter.cpp +` ${CMAKE_CURRENT_SOURCE_DIR}/PoolingLayer.cpp +` ${CMAKE_CURRENT_SOURCE_DIR}/ROIPoolingLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Sobel3x3.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Sobel5x5.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SoftmaxLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Threshold.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DirectConvolutionLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/MeanStdDev.cpp diff --git a/tests/validation/CL/ROIPoolingLayer.cpp b/tests/validation/CL/ROIPoolingLayer.cpp new file mode 100644 index 0000000000..19d7903128 --- /dev/null +++ b/tests/validation/CL/ROIPoolingLayer.cpp @@ -0,0 +1,112 @@ +/* + * 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 "CL/CLAccessor.h" +#include "CL/CLArrayAccessor.h" +#include "TypePrinter.h" +#include "arm_compute/runtime/CL/CLArray.h" +#include "arm_compute/runtime/CL/functions/CLROIPoolingLayer.h" +#include "tests/Globals.h" +#include "tests/Utils.h" +#include "validation/Datasets.h" +#include "validation/Reference.h" +#include "validation/Validation.h" +#include "validation/ValidationUserConfiguration.h" + +#include +#include + +using namespace arm_compute; +using namespace arm_compute::test; +using namespace arm_compute::test::validation; + +namespace +{ +CLTensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector &rois, ROIPoolingLayerInfo pool_info) +{ + TensorShape shape_dst; + 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, rois.size()); + + // Create tensors + CLTensor src = create_tensor(shape, dt); + CLTensor dst = create_tensor(shape_dst, dt); + + // Create ROI array + CLArray rois_array(rois.size()); + fill_array(CLArrayAccessor(rois_array), rois); + + // Create and configure function + CLROIPoolingLayer roi_pool; + roi_pool.configure(&src, &rois_array, &dst, pool_info); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + BOOST_TEST(!src.info()->is_resizable()); + BOOST_TEST(!dst.info()->is_resizable()); + + // Fill tensors + std::uniform_real_distribution<> distribution(-1, 1); + library->fill(CLAccessor(src), distribution, 0); + + // Compute function + roi_pool.run(); + + return dst; +} +} // namespace + +#ifndef DOXYGEN_SKIP_THIS +BOOST_AUTO_TEST_SUITE(CL) +BOOST_AUTO_TEST_SUITE(ROIPoolingLayer) + +BOOST_AUTO_TEST_SUITE(Float) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RunSmall, boost::unit_test::data::make({ DataType::F16, DataType::F32 }) * boost::unit_test::data::make({ 10, 20, 40 }) * boost::unit_test::data::make({ 7, 9 }) * + boost::unit_test::data::make({ 1.f / 8.f, 1.f / 16.f }), + dt, num_rois, roi_pool_size, roi_scale) +{ + TensorShape shape(50U, 47U, 2U, 3U); + ROIPoolingLayerInfo pool_info(roi_pool_size, roi_pool_size, roi_scale); + + // Construct ROI vector + std::vector rois = generate_random_rois(shape, pool_info, num_rois, user_config.seed); + + // Compute function + CLTensor dst = compute_roi_pooling_layer(shape, dt, rois, pool_info); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_roi_pooling_layer(shape, dt, rois, pool_info); + + // Validate output + validate(CLAccessor(dst), ref_dst); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() +#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation/Helpers.cpp b/tests/validation/Helpers.cpp deleted file mode 100644 index 747260ea99..0000000000 --- a/tests/validation/Helpers.cpp +++ /dev/null @@ -1,72 +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. - */ -#include "validation/Helpers.h" - -using namespace arm_compute::test; - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -std::vector generate_random_rois(const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, unsigned int num_rois, std::random_device::result_type seed) -{ - ARM_COMPUTE_ERROR_ON((pool_info.pooled_width() < 4) || (pool_info.pooled_height() < 4)); - - std::vector rois; - std::mt19937 gen(seed); - const int pool_width = pool_info.pooled_width(); - const int pool_height = pool_info.pooled_height(); - const float roi_scale = pool_info.spatial_scale(); - - // Calculate distribution bounds - const auto scaled_width = static_cast((shape.x() / roi_scale) / pool_width); - const auto scaled_height = static_cast((shape.y() / roi_scale) / pool_height); - const auto min_width = static_cast(pool_width / roi_scale); - const auto min_height = static_cast(pool_height / roi_scale); - - // Create distributions - std::uniform_int_distribution dist_batch(0, shape[3] - 1); - std::uniform_int_distribution dist_x(0, scaled_width); - std::uniform_int_distribution dist_y(0, scaled_height); - std::uniform_int_distribution dist_w(min_width, std::max(min_width, (pool_width - 2) * scaled_width)); - std::uniform_int_distribution dist_h(min_height, std::max(min_height, (pool_height - 2) * scaled_height)); - - for(unsigned int r = 0; r < num_rois; ++r) - { - ROI roi{}; - roi.batch_idx = dist_batch(gen); - roi.rect.x = dist_x(gen); - roi.rect.y = dist_y(gen); - roi.rect.width = dist_w(gen); - roi.rect.height = dist_h(gen); - rois.push_back(roi); - } - - return rois; -} -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h index 09ffda8957..19a0c4105c 100644 --- a/tests/validation/Helpers.h +++ b/tests/validation/Helpers.h @@ -32,6 +32,7 @@ #include "tests/validation/half.h" #include +#include #include #include #include @@ -250,17 +251,6 @@ inline void fill_warp_matrix(std::array &matrix, int cols, int rows } } -/** Create a vector of random ROIs. - * - * @param[in] shape The shape of the input tensor. - * @param[in] pool_info The ROI pooling information. - * @param[in] num_rois The number of ROIs to be created. - * @param[in] seed The random seed to be used. - * - * @return A vector that contains the requested number of random ROIs - */ -std::vector generate_random_rois(const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, unsigned int num_rois, std::random_device::result_type seed); - /** Helper function to fill the Lut random by a ILutAccessor. * * @param[in,out] table Accessor at the Lut. @@ -277,7 +267,6 @@ void fill_lookuptable(T &&table) table[i] = distribution(generator); } } - } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/NEON/Gaussian5x5.cpp b/tests/validation/NEON/Gaussian5x5.cpp index 522ececee9..7727340f66 100644 --- a/tests/validation/NEON/Gaussian5x5.cpp +++ b/tests/validation/NEON/Gaussian5x5.cpp @@ -41,8 +41,6 @@ #include "boost_wrapper.h" -#include - #include #include diff --git a/tests/validation/NEON/ROIPoolingLayer.cpp b/tests/validation/NEON/ROIPoolingLayer.cpp index 5775db7e03..523885d908 100644 --- a/tests/validation/NEON/ROIPoolingLayer.cpp +++ b/tests/validation/NEON/ROIPoolingLayer.cpp @@ -22,13 +22,12 @@ * SOFTWARE. */ #include "NEON/Accessor.h" -#include "NEON/Helper.h" +#include "NEON/ArrayAccessor.h" #include "TypePrinter.h" #include "arm_compute/runtime/NEON/functions/NEROIPoolingLayer.h" #include "tests/Globals.h" #include "tests/Utils.h" #include "validation/Datasets.h" -#include "validation/Helpers.h" #include "validation/Reference.h" #include "validation/Validation.h" #include "validation/ValidationUserConfiguration.h" @@ -51,9 +50,12 @@ Tensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const st shape_dst.set(3, rois.size()); // Create tensors - Tensor src = create_tensor(shape, dt); - Tensor dst = create_tensor(shape_dst, dt); - Array rois_array = create_array(rois); + Tensor src = create_tensor(shape, dt); + Tensor dst = create_tensor(shape_dst, dt); + + // Create ROI array + Array rois_array(rois.size()); + fill_array(ArrayAccessor(rois_array), rois); // Create and configure function NEROIPoolingLayer roi_pool; -- cgit v1.2.1