Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 1 | /* |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, 2023 Arm Limited. |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLGather.h" |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/datasets/GatherDataset.h" |
| 30 | #include "tests/framework/Asserts.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/framework/datasets/Datasets.h" |
| 33 | #include "tests/validation/Validation.h" |
| 34 | #include "tests/validation/fixtures/GatherFixture.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | TEST_SUITE(CL) |
| 43 | TEST_SUITE(Gather) |
| 44 | |
| 45 | // *INDENT-OFF* |
| 46 | // clang-format off |
| 47 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 48 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), |
| 49 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), |
| 50 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 51 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Output shape |
| 52 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Indices data type |
| 53 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Indices dimensionality |
| 54 | TensorInfo(TensorShape(5U, 5U, 5U, 5U, 5U), 1, DataType::F32), // Invalid Input dimensionality |
| 55 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), // Mismatching data type input/output |
| 56 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid positive axis value |
| 57 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), // Invalid negative axis value |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 58 | }), |
| 59 | framework::dataset::make("IndicesInfo", { |
| 60 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
| 61 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
| 62 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 63 | TensorInfo(TensorShape(10U, 10U), 1, DataType::U32), |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 64 | TensorInfo(TensorShape(10U), 1, DataType::U8), |
| 65 | TensorInfo(TensorShape(10U, 10U, 10U, 10U), 1, DataType::U32), |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 66 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
| 67 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
| 68 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
| 69 | TensorInfo(TensorShape(10U), 1, DataType::U32), |
| 70 | })), |
| 71 | framework::dataset::make("OutputInfo", { |
| 72 | TensorInfo(TensorShape(10U, 27U), 1, DataType::F16), |
| 73 | TensorInfo(TensorShape(27U, 10U), 1, DataType::F32), |
| 74 | TensorInfo(TensorShape(10U, 27U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(10U, 27U), 1, DataType::F32), |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 76 | TensorInfo(TensorShape(10U, 27U), 1, DataType::F32), |
| 77 | TensorInfo(TensorShape(27U, 10U, 10U, 10U, 10U), 1, DataType::F32), |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 78 | TensorInfo(TensorShape(10U, 5U, 5U, 5U, 5U), 1, DataType::F32), |
| 79 | TensorInfo(TensorShape(27U, 10U), 1, DataType::F32), |
| 80 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), |
| 81 | TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), |
| 82 | })), |
| 83 | framework::dataset::make("Axis", { |
| 84 | 0, |
| 85 | 1, |
| 86 | -2, |
| 87 | 0, |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 88 | 0, |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 89 | 1, |
| 90 | 0, |
| 91 | 1, |
| 92 | 2, |
| 93 | -3, |
| 94 | })), |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 95 | framework::dataset::make("Expected", { true, true, true, false, false, false, false, false, false, false })), |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 96 | input_info, indices_info, output_info, axis, expected) |
| 97 | { |
| 98 | const Status status = CLGather::validate(&input_info.clone()->set_is_resizable(true), &indices_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), axis); |
| 99 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 100 | } |
| 101 | // clang-format on |
| 102 | // *INDENT-ON* |
| 103 | |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 104 | template <typename T> |
| 105 | using CLGatherFixture = GatherFixture<CLTensor, CLAccessor, CLGather, T>; |
| 106 | |
| 107 | TEST_SUITE(Float) |
| 108 | TEST_SUITE(FP16) |
| 109 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 110 | CLGatherFixture<half>, |
| 111 | framework::DatasetMode::PRECOMMIT, |
| 112 | combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F16))) |
| 113 | { |
| 114 | // Validate output |
| 115 | validate(CLAccessor(_target), _reference); |
| 116 | } |
| 117 | |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 118 | FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices, |
| 119 | CLGatherFixture<half>, |
| 120 | framework::DatasetMode::PRECOMMIT, |
| 121 | combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::F16))) |
| 122 | { |
| 123 | // Validate output |
| 124 | validate(CLAccessor(_target), _reference); |
| 125 | } |
| 126 | |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 127 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 128 | CLGatherFixture<half>, |
| 129 | framework::DatasetMode::NIGHTLY, |
| 130 | combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F16))) |
| 131 | { |
| 132 | // Validate output |
| 133 | validate(CLAccessor(_target), _reference); |
| 134 | } |
| 135 | TEST_SUITE_END() // FP16 |
| 136 | |
| 137 | TEST_SUITE(FP32) |
| 138 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 139 | CLGatherFixture<float>, |
| 140 | framework::DatasetMode::PRECOMMIT, |
| 141 | combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 142 | { |
| 143 | // Validate output |
| 144 | validate(CLAccessor(_target), _reference); |
| 145 | } |
| 146 | |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 147 | FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices, |
| 148 | CLGatherFixture<float>, |
| 149 | framework::DatasetMode::PRECOMMIT, |
| 150 | combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 151 | { |
| 152 | // Validate output |
| 153 | validate(CLAccessor(_target), _reference); |
| 154 | } |
| 155 | |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 156 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 157 | CLGatherFixture<float>, |
| 158 | framework::DatasetMode::NIGHTLY, |
| 159 | combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 160 | { |
| 161 | // Validate output |
| 162 | validate(CLAccessor(_target), _reference); |
| 163 | } |
| 164 | TEST_SUITE_END() // FP32 |
| 165 | TEST_SUITE_END() // Float |
| 166 | |
| 167 | TEST_SUITE(U8) |
| 168 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 169 | CLGatherFixture<uint8_t>, |
| 170 | framework::DatasetMode::PRECOMMIT, |
| 171 | combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U8))) |
| 172 | { |
| 173 | // Validate output |
| 174 | validate(CLAccessor(_target), _reference); |
| 175 | } |
| 176 | |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 177 | FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices, |
| 178 | CLGatherFixture<uint8_t>, |
| 179 | framework::DatasetMode::PRECOMMIT, |
| 180 | combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::U8))) |
| 181 | { |
| 182 | // Validate output |
| 183 | validate(CLAccessor(_target), _reference); |
| 184 | } |
| 185 | |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 186 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 187 | CLGatherFixture<uint8_t>, |
| 188 | framework::DatasetMode::NIGHTLY, |
| 189 | combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U8))) |
| 190 | { |
| 191 | // Validate output |
| 192 | validate(CLAccessor(_target), _reference); |
| 193 | } |
| 194 | TEST_SUITE_END() // U8 |
| 195 | |
| 196 | TEST_SUITE(U16) |
| 197 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 198 | CLGatherFixture<uint16_t>, |
| 199 | framework::DatasetMode::PRECOMMIT, |
| 200 | combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U16))) |
| 201 | { |
| 202 | // Validate output |
| 203 | validate(CLAccessor(_target), _reference); |
| 204 | } |
| 205 | |
Omar Al Khatib | cdd1e03 | 2023-04-26 11:31:45 +0100 | [diff] [blame] | 206 | FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices, |
| 207 | CLGatherFixture<uint16_t>, |
| 208 | framework::DatasetMode::PRECOMMIT, |
| 209 | combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::U16))) |
| 210 | { |
| 211 | // Validate output |
| 212 | validate(CLAccessor(_target), _reference); |
| 213 | } |
| 214 | |
| 215 | |
Manuel Bottini | 8529bd6 | 2018-11-21 11:53:04 +0000 | [diff] [blame] | 216 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 217 | CLGatherFixture<uint16_t>, |
| 218 | framework::DatasetMode::NIGHTLY, |
| 219 | combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U16))) |
| 220 | { |
| 221 | // Validate output |
| 222 | validate(CLAccessor(_target), _reference); |
| 223 | } |
| 224 | TEST_SUITE_END() // U16 |
| 225 | |
| 226 | TEST_SUITE_END() // Gather |
| 227 | TEST_SUITE_END() // CL |
| 228 | } // namespace validation |
| 229 | } // namespace test |
| 230 | } // namespace arm_compute |