Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | d175ece | 2020-07-30 23:39:32 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +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/CLComparison.h" |
| 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/ComparisonOperationsDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/ComparisonFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 46 | const auto configure_dataset = combine(datasets::SmallShapes(), |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 47 | framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 })); |
| 48 | |
| 49 | const auto run_small_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapes()); |
| 50 | const auto run_large_dataset = combine(datasets::ComparisonOperations(), datasets::LargeShapes()); |
| 51 | |
| 52 | } // namespace |
| 53 | |
| 54 | TEST_SUITE(CL) |
| 55 | TEST_SUITE(Comparison) |
| 56 | |
| 57 | // *INDENT-OFF* |
| 58 | // clang-format off |
| 59 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 60 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid output type |
| 61 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching input types |
| 62 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink |
| 63 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 64 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 65 | }), |
| 66 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 67 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 68 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 69 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 70 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 71 | })), |
| 72 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 74 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 75 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::U8), |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 77 | })), |
| 78 | framework::dataset::make("Expected", { false, false, false, false, true})), |
| 79 | input1_info, input2_info, output_info, expected) |
| 80 | { |
| 81 | Status s = CLComparison::validate(&input1_info.clone()->set_is_resizable(false), |
| 82 | &input2_info.clone()->set_is_resizable(false), |
| 83 | &output_info.clone()->set_is_resizable(false), |
| 84 | ComparisonOperation::Equal); |
| 85 | ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); |
| 86 | } |
| 87 | // clang-format on |
| 88 | // *INDENT-ON* |
| 89 | |
Georgios Pinitas | 7900a9e | 2018-11-23 11:44:58 +0000 | [diff] [blame] | 90 | template <typename T> |
| 91 | using CLComparisonFixture = ComparisonValidationFixture<CLTensor, CLAccessor, CLComparison, T>; |
| 92 | |
| 93 | TEST_SUITE(Float) |
| 94 | TEST_SUITE(FP16) |
| 95 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 96 | CLComparisonFixture<half>, |
| 97 | framework::DatasetMode::PRECOMMIT, |
| 98 | combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16))) |
| 99 | { |
| 100 | // Validate output |
| 101 | validate(CLAccessor(_target), _reference); |
| 102 | } |
| 103 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 104 | CLComparisonFixture<half>, |
| 105 | framework::DatasetMode::NIGHTLY, |
| 106 | combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16))) |
| 107 | { |
| 108 | // Validate output |
| 109 | validate(CLAccessor(_target), _reference); |
| 110 | } |
| 111 | TEST_SUITE_END() // FP16 |
| 112 | |
| 113 | TEST_SUITE(FP32) |
| 114 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 115 | CLComparisonFixture<float>, |
| 116 | framework::DatasetMode::PRECOMMIT, |
| 117 | combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32))) |
| 118 | { |
| 119 | // Validate output |
| 120 | validate(CLAccessor(_target), _reference); |
| 121 | } |
| 122 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 123 | CLComparisonFixture<float>, |
| 124 | framework::DatasetMode::NIGHTLY, |
| 125 | combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32))) |
| 126 | { |
| 127 | // Validate output |
| 128 | validate(CLAccessor(_target), _reference); |
| 129 | } |
| 130 | TEST_SUITE_END() // FP32 |
| 131 | TEST_SUITE_END() // Float |
| 132 | |
| 133 | template <typename T> |
| 134 | using CLComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<CLTensor, CLAccessor, CLComparison, T>; |
| 135 | |
| 136 | TEST_SUITE(Quantized) |
| 137 | TEST_SUITE(QASYMM8) |
| 138 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 139 | CLComparisonQuantizedFixture<uint8_t>, |
| 140 | framework::DatasetMode::PRECOMMIT, |
| 141 | combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8)), |
| 142 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 143 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) }))) |
| 144 | { |
| 145 | // Validate output |
| 146 | validate(CLAccessor(_target), _reference); |
| 147 | } |
| 148 | TEST_SUITE_END() |
| 149 | TEST_SUITE_END() |
| 150 | |
| 151 | TEST_SUITE_END() // Comparison |
| 152 | TEST_SUITE_END() // CL |
| 153 | } // namespace validation |
| 154 | } // namespace test |
| 155 | } // namespace arm_compute |