From 920f2b6c2070f6328891e26538e8bcad63e2a79c Mon Sep 17 00:00:00 2001 From: Pablo Marquez Tello Date: Wed, 27 Apr 2022 11:46:31 +0100 Subject: Add support for 2d and 3d indices for axis 0 * Partially resolves COMPMID-5055 Change-Id: Id05374b8c69e6b9ab4c2790a4de93d7172063b71 Signed-off-by: Pablo Marquez Tello Change-Id: Ic6e2c2d1d34abbf6222c8d56859514e267447266 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7488 Tested-by: Arm Jenkins Reviewed-by: Giorgio Arena Comments-Addressed: Arm Jenkins --- tests/validation/NEON/Gather.cpp | 10 +++++---- tests/validation/reference/Gather.cpp | 41 +++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 16 deletions(-) (limited to 'tests/validation') diff --git a/tests/validation/NEON/Gather.cpp b/tests/validation/NEON/Gather.cpp index ca1e166bd1..1ab2668aad 100644 --- a/tests/validation/NEON/Gather.cpp +++ b/tests/validation/NEON/Gather.cpp @@ -100,12 +100,14 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( template using NEGatherFixture = GatherFixture; +const auto gather_small_shapes = arm_compute::test::framework::dataset::concat(datasets::SmallGatherDataset(),datasets::SmallGatherMultiDimIndicesDataset()); + TEST_SUITE(Float) TEST_SUITE(FP16) FIXTURE_DATA_TEST_CASE(RunSmall, NEGatherFixture, framework::DatasetMode::PRECOMMIT, - combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F16))) + combine( gather_small_shapes, framework::dataset::make("DataType", DataType::F16))) { // Validate output validate(Accessor(_target), _reference); @@ -125,7 +127,7 @@ TEST_SUITE(FP32) FIXTURE_DATA_TEST_CASE(RunSmall, NEGatherFixture, framework::DatasetMode::PRECOMMIT, - combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F32))) + combine(gather_small_shapes, framework::dataset::make("DataType", DataType::F32))) { // Validate output validate(Accessor(_target), _reference); @@ -146,7 +148,7 @@ TEST_SUITE(U8) FIXTURE_DATA_TEST_CASE(RunSmall, NEGatherFixture, framework::DatasetMode::PRECOMMIT, - combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U8))) + combine(gather_small_shapes, framework::dataset::make("DataType", DataType::U8))) { // Validate output validate(Accessor(_target), _reference); @@ -166,7 +168,7 @@ TEST_SUITE(U16) FIXTURE_DATA_TEST_CASE(RunSmall, NEGatherFixture, framework::DatasetMode::PRECOMMIT, - combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U16))) + combine(gather_small_shapes, framework::dataset::make("DataType", DataType::U16))) { // Validate output validate(Accessor(_target), _reference); diff --git a/tests/validation/reference/Gather.cpp b/tests/validation/reference/Gather.cpp index 93ac09cf95..02292fb74e 100644 --- a/tests/validation/reference/Gather.cpp +++ b/tests/validation/reference/Gather.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Arm Limited. + * Copyright (c) 2018-2019, 2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -45,22 +45,39 @@ SimpleTensor gather(const SimpleTensor &src, const SimpleTensor Window win; win.use_tensor_dimensions(dst_shape); - execute_window_loop(win, [&](const Coordinates & id) + if(indices.shape().num_dimensions() == 1u) { - Coordinates offset; - for(unsigned int dim = 0; dim < id.num_dimensions(); ++dim) + execute_window_loop(win, [&](const Coordinates & id) { - if(dim == actual_axis) + Coordinates offset; + for(unsigned int dim = 0; dim < id.num_dimensions(); ++dim) { - offset.set(dim, indices_ptr[id[dim]]); + if(dim == actual_axis) + { + offset.set(dim, indices_ptr[id[dim]]); + } + else + { + offset.set(dim, id[dim]); + } } - else + *reinterpret_cast(dst(id)) = *reinterpret_cast(src(offset)); + }); + } + else + { + if(actual_axis == 0) + { + win.set(Window::DimX, Window::Dimension(0, 1, 1)); + uint32_t index = 0; + execute_window_loop(win, [&](const Coordinates & id) { - offset.set(dim, id[dim]); - } + auto *dst_ptr = reinterpret_cast(dst(id)); + const int row_to_copy = indices[index++]; + std::copy_n(src.data() + row_to_copy * src.shape()[0], src.shape()[0], dst_ptr); + }); } - *reinterpret_cast(dst(id)) = *reinterpret_cast(src(offset)); - }); + } return dst; } @@ -72,4 +89,4 @@ template SimpleTensor gather(const SimpleTensor &src, const Si } // namespace reference } // namespace validation } // namespace test -} // namespace arm_compute \ No newline at end of file +} // namespace arm_compute -- cgit v1.2.1