giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
giuros01 | 164a272 | 2018-11-20 18:34:46 +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/CLElementwiseOperations.h" |
| 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/ConvertPolicyDataset.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/ElementwiseOperationsFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 47 | RelativeTolerance<float> tolerance_fp16(0.001f); |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 48 | AbsoluteTolerance<float> tolerance_qsymm16(1); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 49 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 50 | /** Input data sets **/ |
| 51 | const auto ElementwiseSquaredDiffU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), |
| 52 | framework::dataset::make("DataType", |
| 53 | DataType::U8)); |
| 54 | const auto ElementwiseSquaredDiffQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 55 | framework::dataset::make("DataType", |
| 56 | DataType::QASYMM8)); |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 57 | const auto ElementwiseSquaredDiffQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)), |
| 58 | framework::dataset::make("DataType", |
| 59 | DataType::QSYMM16)); |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 60 | const auto ElementwiseSquaredDiffS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 61 | framework::dataset::make("DataType", DataType::S16)); |
| 62 | const auto ElementwiseSquaredDiffFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 63 | framework::dataset::make("DataType", DataType::F16)); |
| 64 | const auto ElementwiseSquaredDiffFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 65 | framework::dataset::make("DataType", DataType::F32)); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 66 | const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 67 | { ActivationLayerInfo() }); |
| 68 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 69 | { |
| 70 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f), |
| 71 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f) |
| 72 | }); |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 73 | const auto InPlaceDataSet = framework::dataset::make("InPlace", { false, true }); |
| 74 | const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false }); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 75 | } // namespace |
| 76 | |
| 77 | TEST_SUITE(CL) |
| 78 | TEST_SUITE(ElementwiseSquaredDiff) |
| 79 | |
| 80 | // *INDENT-OFF* |
| 81 | // clang-format off |
| 82 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 83 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 84 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 85 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 86 | }), |
| 87 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 88 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 89 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 90 | })), |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 91 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 92 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 93 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 94 | })), |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 95 | framework::dataset::make("Expected", { true, false, false})), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 96 | input1_info, input2_info, output_info, expected) |
| 97 | { |
| 98 | ARM_COMPUTE_EXPECT(bool(CLElementwiseSquaredDiff::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); |
| 99 | } |
| 100 | // clang-format on |
| 101 | // *INDENT-ON* |
| 102 | |
| 103 | template <typename T> |
| 104 | using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
| 105 | |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 106 | TEST_SUITE(Integer) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 107 | TEST_SUITE(U8) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 108 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset), |
| 109 | OutOfPlaceDataSet)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 110 | { |
| 111 | // Validate output |
| 112 | validate(CLAccessor(_target), _reference); |
| 113 | } |
| 114 | TEST_SUITE_END() |
| 115 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 116 | TEST_SUITE(S16) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 117 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset), |
| 118 | OutOfPlaceDataSet)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 119 | { |
| 120 | // Validate output |
| 121 | validate(CLAccessor(_target), _reference); |
| 122 | } |
| 123 | TEST_SUITE_END() |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 124 | TEST_SUITE_END() |
| 125 | |
| 126 | template <typename T> |
| 127 | using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
| 128 | |
| 129 | TEST_SUITE(Quantized) |
| 130 | TEST_SUITE(QASYMM8) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 131 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(), |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 132 | ElementwiseSquaredDiffQASYMM8Dataset), |
| 133 | framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 134 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 135 | framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })), |
| 136 | OutOfPlaceDataSet)) |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 137 | { |
| 138 | // Validate output |
| 139 | validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01); |
| 140 | } |
| 141 | TEST_SUITE_END() |
| 142 | TEST_SUITE(QSYMM16) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 143 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(), |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 144 | ElementwiseSquaredDiffQSYMM16Dataset), |
| 145 | framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })), |
| 146 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 147 | framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })), |
| 148 | OutOfPlaceDataSet)) |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 149 | { |
| 150 | // Validate output |
| 151 | validate(CLAccessor(_target), _reference, tolerance_qsymm16); |
| 152 | } |
| 153 | TEST_SUITE_END() |
| 154 | TEST_SUITE_END() |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 155 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 156 | template <typename T> |
| 157 | using CLElementwiseSquaredDiffFloatFixture = ElementwiseSquaredDiffValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
| 158 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 159 | TEST_SUITE(Float) |
| 160 | TEST_SUITE(FP16) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 161 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset), |
| 162 | EmptyActivationFunctionsDataset), |
| 163 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 164 | { |
| 165 | // Validate output |
| 166 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 167 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 168 | FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP16Dataset), |
| 169 | ActivationFunctionsDataset), |
| 170 | OutOfPlaceDataSet)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 171 | { |
| 172 | // Validate output |
| 173 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 174 | } |
| 175 | TEST_SUITE_END() |
| 176 | |
| 177 | TEST_SUITE(FP32) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 178 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset), |
| 179 | EmptyActivationFunctionsDataset), |
| 180 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 181 | { |
| 182 | // Validate output |
| 183 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 184 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 185 | FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP32Dataset), |
| 186 | ActivationFunctionsDataset), |
| 187 | OutOfPlaceDataSet)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 188 | { |
| 189 | // Validate output |
| 190 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 191 | } |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 192 | template <typename T> |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 193 | using CLElementwiseSquaredDiffBroadcastFloatFixture = ElementwiseSquaredDiffBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 194 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 195 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapesBroadcast(), |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 196 | ElementwiseSquaredDiffFP32Dataset), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 197 | EmptyActivationFunctionsDataset), |
| 198 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 199 | { |
| 200 | // Validate output |
| 201 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 202 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 203 | FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapesBroadcast(), |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 204 | ElementwiseSquaredDiffFP32Dataset), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame^] | 205 | ActivationFunctionsDataset), |
| 206 | OutOfPlaceDataSet)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 207 | { |
| 208 | // Validate output |
| 209 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 210 | } |
| 211 | TEST_SUITE_END() |
| 212 | TEST_SUITE_END() |
| 213 | |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 214 | TEST_SUITE_END() // ElementwiseSquaredDiff |
| 215 | TEST_SUITE_END() // CL |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 216 | } // namespace validation |
| 217 | } // namespace test |
| 218 | } // namespace arm_compute |