Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 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" |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/CL/functions/CLReductionOperation.h" |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 29 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 31 | #include "tests/CL/CLAccessor.h" |
| 32 | #include "tests/datasets/ShapeDatasets.h" |
| 33 | #include "tests/datasets/SplitDataset.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/ArgMinMaxFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 45 | namespace |
| 46 | { |
| 47 | const auto ArgMinMaxSmallDataset = framework::dataset::make("Shape", |
| 48 | { |
| 49 | TensorShape{ 2U, 7U, 1U, 3U }, |
| 50 | TensorShape{ 128U, 64U, 21U, 3U }, |
| 51 | TensorShape{ 2560, 2U, 2U, 2U }, |
| 52 | }); |
| 53 | |
| 54 | const auto ArgMinMaxLargeDataset = framework::dataset::make("Shape", |
| 55 | { TensorShape{ 517U, 123U, 13U, 2U } }); |
| 56 | } // namespace |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 57 | TEST_SUITE(CL) |
| 58 | TEST_SUITE(ArgMinMax) |
| 59 | |
| 60 | // *INDENT-OFF* |
| 61 | // clang-format off |
| 62 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 63 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis |
| 64 | TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape |
| 65 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 66 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation |
| 67 | 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] | 68 | }), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 69 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), |
| 70 | TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), |
Sang-Hoon Park | eaa01ab | 2019-11-11 17:33:28 +0000 | [diff] [blame] | 71 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::S32), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 72 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 74 | })), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 75 | framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })), |
| 76 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })), |
| 77 | framework::dataset::make("Expected", { false, false, true, false, false })), |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 78 | input_info, output_info, axis, operation, expected) |
| 79 | { |
| 80 | const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation); |
| 81 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 82 | } |
| 83 | // clang-format on |
| 84 | // *INDENT-ON* |
| 85 | |
| 86 | DATA_TEST_CASE(Configuration, |
| 87 | framework::DatasetMode::ALL, |
| 88 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })), |
| 89 | shape, data_type) |
| 90 | { |
| 91 | // Create tensors |
| 92 | CLTensor ref_src = create_tensor<CLTensor>(shape, data_type); |
| 93 | CLTensor dst; |
| 94 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 95 | constexpr int axis = 1; |
| 96 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 97 | // Create and Configure function |
| 98 | CLArgMinMaxLayer arg_min_max_layer; |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 99 | arg_min_max_layer.configure(&ref_src, axis, &dst, ReductionOperation::ARG_IDX_MAX); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 100 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 101 | const auto output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(shape, axis, false); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 102 | const ValidRegion valid_region = shape_to_valid_region(output_shape); |
| 103 | validate(dst.info()->valid_region(), valid_region); |
| 104 | } |
| 105 | |
| 106 | template <typename T> |
| 107 | using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>; |
| 108 | |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 109 | TEST_SUITE(S32) |
| 110 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 111 | CLArgMinMaxValidationFixture<int32_t>, |
| 112 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 113 | combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 114 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 115 | { |
| 116 | // Validate output |
| 117 | validate(CLAccessor(_target), _reference); |
| 118 | } |
| 119 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 120 | CLArgMinMaxValidationFixture<int32_t>, |
| 121 | framework::DatasetMode::NIGHTLY, |
| 122 | combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 123 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 124 | { |
| 125 | // Validate output |
| 126 | validate(CLAccessor(_target), _reference); |
| 127 | } |
| 128 | TEST_SUITE_END() // S32 |
| 129 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 130 | TEST_SUITE(Float) |
| 131 | TEST_SUITE(FP16) |
| 132 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 133 | CLArgMinMaxValidationFixture<half>, |
| 134 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 135 | combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 136 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 137 | { |
| 138 | // Validate output |
| 139 | validate(CLAccessor(_target), _reference); |
| 140 | } |
| 141 | |
| 142 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 143 | CLArgMinMaxValidationFixture<half>, |
| 144 | framework::DatasetMode::NIGHTLY, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 145 | combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 146 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 147 | { |
| 148 | // Validate output |
| 149 | validate(CLAccessor(_target), _reference); |
| 150 | } |
| 151 | TEST_SUITE_END() // FP16 |
| 152 | |
| 153 | TEST_SUITE(FP32) |
| 154 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 155 | CLArgMinMaxValidationFixture<float>, |
| 156 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 157 | combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 158 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 159 | { |
| 160 | // Validate output |
| 161 | validate(CLAccessor(_target), _reference); |
| 162 | } |
| 163 | |
| 164 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 165 | CLArgMinMaxValidationFixture<float>, |
| 166 | framework::DatasetMode::NIGHTLY, |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 167 | combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), |
| 168 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 169 | { |
| 170 | // Validate output |
| 171 | validate(CLAccessor(_target), _reference); |
| 172 | } |
| 173 | TEST_SUITE_END() // FP32 |
| 174 | TEST_SUITE_END() // Float |
| 175 | TEST_SUITE_END() // ArgMinMax |
| 176 | TEST_SUITE_END() // CL |
| 177 | } // namespace validation |
| 178 | } // namespace test |
| 179 | } // namespace arm_compute |