Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 1 | /* |
Pablo Marquez Tello | 653b96c | 2023-07-11 15:15:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 2023 Arm Limited. |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +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/CLArgMinMaxLayer.h" |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/datasets/ShapeDatasets.h" |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 30 | #include "tests/framework/Macros.h" |
| 31 | #include "tests/validation/Validation.h" |
| 32 | #include "tests/validation/fixtures/ArgMinMaxFixture.h" |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | namespace validation |
| 39 | { |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 40 | namespace |
| 41 | { |
| 42 | const auto ArgMinMaxSmallDataset = framework::dataset::make("Shape", |
| 43 | { |
Giorgio Arena | 76cb751 | 2021-02-03 12:29:57 +0000 | [diff] [blame] | 44 | TensorShape{ 1U, 7U, 1U, 3U }, |
Pablo Marquez Tello | 653b96c | 2023-07-11 15:15:46 +0100 | [diff] [blame] | 45 | TensorShape{ 3U, 1U, 3U, 2U }, |
| 46 | TensorShape{ 2U, 1U, 3U, 2U }, |
Manuel Bottini | 5c829ca | 2020-01-28 17:25:48 +0000 | [diff] [blame] | 47 | TensorShape{ 149U, 5U, 1U, 2U }, |
| 48 | TensorShape{ 166U, 5U, 1U, 2U }, |
| 49 | TensorShape{ 322U, 5U, 1U, 2U }, |
| 50 | TensorShape{ 128U, 5U, 21U, 3U }, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 51 | TensorShape{ 2560, 2U, 2U, 2U }, |
| 52 | }); |
| 53 | |
Pablo Marquez Tello | 653b96c | 2023-07-11 15:15:46 +0100 | [diff] [blame] | 54 | const auto ArgMinMaxSmallDatasetAxis0 = framework::dataset::make("Shape", |
| 55 | { |
| 56 | TensorShape{ 1U, 5U }, |
| 57 | TensorShape{ 2U, 3U }, |
| 58 | TensorShape{ 1U }, |
| 59 | TensorShape{ 3U }, |
| 60 | TensorShape{ 2U }, |
| 61 | TensorShape{ 5U }, |
| 62 | TensorShape{ 17U }, |
| 63 | TensorShape{ 15U, 2U }, |
| 64 | }); |
| 65 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 66 | const auto ArgMinMaxLargeDataset = framework::dataset::make("Shape", |
| 67 | { TensorShape{ 517U, 123U, 13U, 2U } }); |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 68 | } // namespace |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 69 | TEST_SUITE(CL) |
| 70 | TEST_SUITE(ArgMinMax) |
| 71 | |
| 72 | // *INDENT-OFF* |
| 73 | // clang-format off |
| 74 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 75 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis |
| 76 | TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape |
| 77 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 78 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation |
| 79 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Not allowed keeping the dimension |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 80 | }), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 81 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), |
| 82 | TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), |
Sang-Hoon Park | eaa01ab | 2019-11-11 17:33:28 +0000 | [diff] [blame] | 83 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::S32), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 84 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), |
| 85 | TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 86 | })), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 87 | framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })), |
| 88 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })), |
| 89 | framework::dataset::make("Expected", { false, false, true, false, false })), |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 90 | input_info, output_info, axis, operation, expected) |
| 91 | { |
| 92 | const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation); |
| 93 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 94 | } |
| 95 | // clang-format on |
| 96 | // *INDENT-ON* |
| 97 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 98 | template <typename T> |
| 99 | using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>; |
| 100 | |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 101 | TEST_SUITE(S32) |
Pablo Marquez Tello | 653b96c | 2023-07-11 15:15:46 +0100 | [diff] [blame] | 102 | FIXTURE_DATA_TEST_CASE(RunSmallAxis0, |
| 103 | CLArgMinMaxValidationFixture<int32_t>, |
| 104 | framework::DatasetMode::PRECOMMIT, |
| 105 | combine(combine(combine(ArgMinMaxSmallDatasetAxis0, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0 })), |
| 106 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 107 | { |
| 108 | // Validate output |
| 109 | validate(CLAccessor(_target), _reference); |
| 110 | } |
| 111 | |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 112 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 113 | CLArgMinMaxValidationFixture<int32_t>, |
| 114 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 115 | combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 116 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 117 | { |
| 118 | // Validate output |
| 119 | validate(CLAccessor(_target), _reference); |
| 120 | } |
| 121 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 122 | CLArgMinMaxValidationFixture<int32_t>, |
| 123 | framework::DatasetMode::NIGHTLY, |
| 124 | combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 125 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 126 | { |
| 127 | // Validate output |
| 128 | validate(CLAccessor(_target), _reference); |
| 129 | } |
| 130 | TEST_SUITE_END() // S32 |
| 131 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 132 | TEST_SUITE(Float) |
| 133 | TEST_SUITE(FP16) |
| 134 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 135 | CLArgMinMaxValidationFixture<half>, |
| 136 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 137 | combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 138 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 139 | { |
| 140 | // Validate output |
| 141 | validate(CLAccessor(_target), _reference); |
| 142 | } |
| 143 | |
| 144 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 145 | CLArgMinMaxValidationFixture<half>, |
| 146 | framework::DatasetMode::NIGHTLY, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 147 | combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 148 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 149 | { |
| 150 | // Validate output |
| 151 | validate(CLAccessor(_target), _reference); |
| 152 | } |
| 153 | TEST_SUITE_END() // FP16 |
| 154 | |
| 155 | TEST_SUITE(FP32) |
| 156 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 157 | CLArgMinMaxValidationFixture<float>, |
| 158 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 159 | combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 160 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 161 | { |
| 162 | // Validate output |
| 163 | validate(CLAccessor(_target), _reference); |
| 164 | } |
| 165 | |
| 166 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 167 | CLArgMinMaxValidationFixture<float>, |
| 168 | framework::DatasetMode::NIGHTLY, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 169 | combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 170 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 171 | { |
| 172 | // Validate output |
| 173 | validate(CLAccessor(_target), _reference); |
| 174 | } |
| 175 | TEST_SUITE_END() // FP32 |
| 176 | TEST_SUITE_END() // Float |
Michalis Spyrou | 7317e39 | 2020-01-17 11:27:49 +0000 | [diff] [blame] | 177 | |
| 178 | template <typename T> |
| 179 | using CLArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>; |
| 180 | |
| 181 | TEST_SUITE(Quantized) |
| 182 | TEST_SUITE(QASYMM8) |
| 183 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 184 | CLArgMinMaxQuantizedValidationFixture<uint8_t>, |
| 185 | framework::DatasetMode::PRECOMMIT, |
| 186 | combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 187 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })), |
| 188 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) }))) |
| 189 | { |
| 190 | // Validate output |
| 191 | validate(CLAccessor(_target), _reference); |
| 192 | } |
| 193 | |
| 194 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 195 | CLArgMinMaxQuantizedValidationFixture<uint8_t>, |
| 196 | framework::DatasetMode::NIGHTLY, |
| 197 | combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 198 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })), |
| 199 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) }))) |
| 200 | { |
| 201 | // Validate output |
| 202 | validate(CLAccessor(_target), _reference); |
| 203 | } |
| 204 | TEST_SUITE_END() // QASYMM8 |
Sheri Zhang | c5b6d88 | 2020-06-26 14:46:59 +0100 | [diff] [blame] | 205 | |
| 206 | TEST_SUITE(QASYMM8_SIGNED) |
| 207 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 208 | CLArgMinMaxQuantizedValidationFixture<int8_t>, |
| 209 | framework::DatasetMode::PRECOMMIT, |
| 210 | combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 211 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })), |
| 212 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) }))) |
| 213 | { |
| 214 | // Validate output |
| 215 | validate(CLAccessor(_target), _reference); |
| 216 | } |
| 217 | |
| 218 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 219 | CLArgMinMaxQuantizedValidationFixture<int8_t>, |
| 220 | framework::DatasetMode::NIGHTLY, |
| 221 | combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 222 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })), |
| 223 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) }))) |
| 224 | { |
| 225 | // Validate output |
| 226 | validate(CLAccessor(_target), _reference); |
| 227 | } |
| 228 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 229 | |
Michalis Spyrou | 7317e39 | 2020-01-17 11:27:49 +0000 | [diff] [blame] | 230 | TEST_SUITE_END() // Quantized |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 231 | TEST_SUITE_END() // ArgMinMax |
| 232 | TEST_SUITE_END() // CL |
| 233 | } // namespace validation |
| 234 | } // namespace test |
| 235 | } // namespace arm_compute |