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 | { |
| 45 | TEST_SUITE(CL) |
| 46 | TEST_SUITE(ArgMinMax) |
| 47 | |
| 48 | // *INDENT-OFF* |
| 49 | // clang-format off |
| 50 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 51 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis |
| 52 | TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape |
| 53 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 54 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation |
| 55 | 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] | 56 | }), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 57 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), |
| 58 | TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32), |
| 59 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::U32), |
| 60 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), |
| 61 | TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32) |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 62 | })), |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 63 | framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })), |
| 64 | framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })), |
| 65 | framework::dataset::make("Expected", { false, false, true, false, false })), |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 66 | input_info, output_info, axis, operation, expected) |
| 67 | { |
| 68 | const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation); |
| 69 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 70 | } |
| 71 | // clang-format on |
| 72 | // *INDENT-ON* |
| 73 | |
| 74 | DATA_TEST_CASE(Configuration, |
| 75 | framework::DatasetMode::ALL, |
| 76 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })), |
| 77 | shape, data_type) |
| 78 | { |
| 79 | // Create tensors |
| 80 | CLTensor ref_src = create_tensor<CLTensor>(shape, data_type); |
| 81 | CLTensor dst; |
| 82 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 83 | constexpr int axis = 1; |
| 84 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 85 | // Create and Configure function |
| 86 | CLArgMinMaxLayer arg_min_max_layer; |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 87 | 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] | 88 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 89 | 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] | 90 | const ValidRegion valid_region = shape_to_valid_region(output_shape); |
| 91 | validate(dst.info()->valid_region(), valid_region); |
| 92 | } |
| 93 | |
| 94 | template <typename T> |
| 95 | using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>; |
| 96 | |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 97 | TEST_SUITE(S32) |
| 98 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 99 | CLArgMinMaxValidationFixture<int32_t>, |
| 100 | framework::DatasetMode::PRECOMMIT, |
| 101 | combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 102 | { |
| 103 | // Validate output |
| 104 | validate(CLAccessor(_target), _reference); |
| 105 | } |
| 106 | TEST_SUITE_END() // S32 |
| 107 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 108 | TEST_SUITE(Float) |
| 109 | TEST_SUITE(FP16) |
| 110 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 111 | CLArgMinMaxValidationFixture<half>, |
| 112 | framework::DatasetMode::PRECOMMIT, |
| 113 | combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 114 | { |
| 115 | // Validate output |
| 116 | validate(CLAccessor(_target), _reference); |
| 117 | } |
| 118 | |
| 119 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 120 | CLArgMinMaxValidationFixture<half>, |
| 121 | framework::DatasetMode::NIGHTLY, |
| 122 | combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 123 | { |
| 124 | // Validate output |
| 125 | validate(CLAccessor(_target), _reference); |
| 126 | } |
| 127 | TEST_SUITE_END() // FP16 |
| 128 | |
| 129 | TEST_SUITE(FP32) |
| 130 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 131 | CLArgMinMaxValidationFixture<float>, |
| 132 | framework::DatasetMode::PRECOMMIT, |
| 133 | combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 134 | { |
| 135 | // Validate output |
| 136 | validate(CLAccessor(_target), _reference); |
| 137 | } |
| 138 | |
| 139 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 140 | CLArgMinMaxValidationFixture<float>, |
| 141 | framework::DatasetMode::NIGHTLY, |
| 142 | combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX }))) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(CLAccessor(_target), _reference); |
| 146 | } |
| 147 | TEST_SUITE_END() // FP32 |
| 148 | TEST_SUITE_END() // Float |
| 149 | TEST_SUITE_END() // ArgMinMax |
| 150 | TEST_SUITE_END() // CL |
| 151 | } // namespace validation |
| 152 | } // namespace test |
| 153 | } // namespace arm_compute |