giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 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 | |
| 50 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 51 | /** Input data sets **/ |
| 52 | const auto ElementwiseSquaredDiffU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), |
| 53 | framework::dataset::make("DataType", |
| 54 | DataType::U8)); |
| 55 | const auto ElementwiseSquaredDiffQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 56 | framework::dataset::make("DataType", |
| 57 | DataType::QASYMM8)); |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 58 | const auto ElementwiseSquaredDiffQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)), |
| 59 | framework::dataset::make("DataType", |
| 60 | DataType::QSYMM16)); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 61 | const auto ElementwiseSquaredDiffS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 62 | framework::dataset::make("DataType", DataType::S16)); |
| 63 | const auto ElementwiseSquaredDiffFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 64 | framework::dataset::make("DataType", DataType::F16)); |
| 65 | const auto ElementwiseSquaredDiffFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 66 | framework::dataset::make("DataType", DataType::F32)); |
| 67 | } // namespace |
| 68 | |
| 69 | TEST_SUITE(CL) |
| 70 | TEST_SUITE(ElementwiseSquaredDiff) |
| 71 | |
| 72 | // *INDENT-OFF* |
| 73 | // clang-format off |
| 74 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 75 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 77 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 78 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 80 | }), |
| 81 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 83 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 84 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 85 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 86 | })), |
| 87 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 88 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 89 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 90 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 91 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 92 | })), |
| 93 | framework::dataset::make("Expected", { true, true, false, false, false})), |
| 94 | input1_info, input2_info, output_info, expected) |
| 95 | { |
| 96 | 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); |
| 97 | } |
| 98 | // clang-format on |
| 99 | // *INDENT-ON* |
| 100 | |
| 101 | template <typename T> |
| 102 | using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
| 103 | |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 104 | TEST_SUITE(Integer) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 105 | TEST_SUITE(U8) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 106 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 107 | shape) |
| 108 | { |
| 109 | // Create tensors |
| 110 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8); |
| 111 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8); |
| 112 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8); |
| 113 | |
| 114 | // Create and Configure function |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 115 | CLElementwiseSquaredDiff sqdiff; |
| 116 | sqdiff.configure(&ref_src1, &ref_src2, &dst); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 117 | |
| 118 | // Validate valid region |
| 119 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 120 | validate(dst.info()->valid_region(), valid_region); |
| 121 | |
| 122 | // Validate padding |
| 123 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 124 | validate(ref_src1.info()->padding(), padding); |
| 125 | validate(ref_src2.info()->padding(), padding); |
| 126 | validate(dst.info()->padding(), padding); |
| 127 | } |
| 128 | |
| 129 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset)) |
| 130 | { |
| 131 | // Validate output |
| 132 | validate(CLAccessor(_target), _reference); |
| 133 | } |
| 134 | TEST_SUITE_END() |
| 135 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 136 | TEST_SUITE(S16) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 137 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 138 | shape, data_type) |
| 139 | { |
| 140 | // Create tensors |
| 141 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type); |
| 142 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16); |
| 143 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16); |
| 144 | |
| 145 | // Create and Configure function |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 146 | CLElementwiseSquaredDiff sqdiff; |
| 147 | sqdiff.configure(&ref_src1, &ref_src2, &dst); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 148 | |
| 149 | // Validate valid region |
| 150 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 151 | validate(dst.info()->valid_region(), valid_region); |
| 152 | |
| 153 | // Validate padding |
| 154 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 155 | validate(ref_src1.info()->padding(), padding); |
| 156 | validate(ref_src2.info()->padding(), padding); |
| 157 | validate(dst.info()->padding(), padding); |
| 158 | } |
| 159 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 160 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 161 | { |
| 162 | // Validate output |
| 163 | validate(CLAccessor(_target), _reference); |
| 164 | } |
| 165 | TEST_SUITE_END() |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 166 | TEST_SUITE_END() |
| 167 | |
| 168 | template <typename T> |
| 169 | using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
| 170 | |
| 171 | TEST_SUITE(Quantized) |
| 172 | TEST_SUITE(QASYMM8) |
| 173 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
| 174 | shape) |
| 175 | { |
| 176 | // Create tensors |
| 177 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 178 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 179 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 180 | |
| 181 | // Create and Configure function |
| 182 | CLElementwiseSquaredDiff sqdiff; |
| 183 | sqdiff.configure(&ref_src1, &ref_src2, &dst); |
| 184 | |
| 185 | // Validate valid region |
| 186 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 187 | validate(dst.info()->valid_region(), valid_region); |
| 188 | |
| 189 | // Validate padding |
| 190 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 191 | validate(ref_src1.info()->padding(), padding); |
| 192 | validate(ref_src2.info()->padding(), padding); |
| 193 | validate(dst.info()->padding(), padding); |
| 194 | } |
| 195 | |
| 196 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 197 | ElementwiseSquaredDiffQASYMM8Dataset), |
| 198 | framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 199 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 200 | framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 201 | { |
| 202 | // Validate output |
| 203 | validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01); |
| 204 | } |
| 205 | TEST_SUITE_END() |
| 206 | TEST_SUITE(QSYMM16) |
| 207 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
| 208 | shape) |
| 209 | { |
| 210 | // Create tensors |
| 211 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16); |
| 212 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16); |
| 213 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16); |
| 214 | |
| 215 | // Create and Configure function |
| 216 | CLElementwiseSquaredDiff sqdiff; |
| 217 | sqdiff.configure(&ref_src1, &ref_src2, &dst); |
| 218 | |
| 219 | // Validate valid region |
| 220 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 221 | validate(dst.info()->valid_region(), valid_region); |
| 222 | |
| 223 | // Validate padding |
| 224 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 225 | validate(ref_src1.info()->padding(), padding); |
| 226 | validate(ref_src2.info()->padding(), padding); |
| 227 | validate(dst.info()->padding(), padding); |
| 228 | } |
| 229 | |
| 230 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 231 | ElementwiseSquaredDiffQSYMM16Dataset), |
| 232 | framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })), |
| 233 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })), |
| 234 | framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) }))) |
| 235 | { |
| 236 | // Validate output |
| 237 | validate(CLAccessor(_target), _reference, tolerance_qsymm16); |
| 238 | } |
| 239 | TEST_SUITE_END() |
| 240 | TEST_SUITE_END() |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 241 | |
| 242 | TEST_SUITE(Float) |
| 243 | TEST_SUITE(FP16) |
| 244 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset)) |
| 245 | { |
| 246 | // Validate output |
| 247 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 248 | } |
| 249 | TEST_SUITE_END() |
| 250 | |
| 251 | TEST_SUITE(FP32) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 252 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 253 | shape) |
| 254 | { |
| 255 | // Create tensors |
| 256 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32); |
| 257 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32); |
| 258 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32); |
| 259 | |
| 260 | // Create and Configure function |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 261 | CLElementwiseSquaredDiff sqdiff; |
| 262 | sqdiff.configure(&ref_src1, &ref_src2, &dst); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 263 | |
| 264 | // Validate valid region |
| 265 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 266 | validate(dst.info()->valid_region(), valid_region); |
| 267 | |
| 268 | // Validate padding |
| 269 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 270 | validate(ref_src1.info()->padding(), padding); |
| 271 | validate(ref_src2.info()->padding(), padding); |
| 272 | validate(dst.info()->padding(), padding); |
| 273 | } |
| 274 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 275 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 276 | { |
| 277 | // Validate output |
| 278 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 279 | } |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 280 | template <typename T> |
| 281 | using CLElementwiseSquaredDiffBroadcastFixture = ElementwiseSquaredDiffBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>; |
| 282 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 283 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 284 | ElementwiseSquaredDiffFP32Dataset)) |
| 285 | { |
| 286 | // Validate output |
| 287 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 288 | } |
| 289 | TEST_SUITE_END() |
| 290 | TEST_SUITE_END() |
| 291 | |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 292 | TEST_SUITE_END() // ElementwiseSquaredDiff |
| 293 | TEST_SUITE_END() // CL |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 294 | } // namespace validation |
| 295 | } // namespace test |
| 296 | } // namespace arm_compute |