Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 1 | /* |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [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 CONCLCTION 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/NEON/functions/NEArithmeticAddition.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.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" |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 36 | #include "tests/validation/fixtures/ArithmeticOperationsFixture.h" |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 46 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 47 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 48 | /** Input data sets **/ |
| 49 | const auto ArithmeticAdditionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType", |
| 50 | DataType::U8)); |
| 51 | const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 52 | framework::dataset::make("DataType", DataType::S16)); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 53 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 54 | const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 55 | framework::dataset::make("DataType", DataType::F16)); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 56 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 57 | const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 58 | framework::dataset::make("DataType", DataType::F32)); |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 59 | const auto ArithmeticAdditionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 60 | framework::dataset::make("DataType", DataType::QASYMM8)); |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 61 | } // namespace |
| 62 | |
| 63 | TEST_SUITE(NEON) |
| 64 | TEST_SUITE(ArithmeticAddition) |
| 65 | |
| 66 | template <typename T> |
| 67 | using NEArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<Tensor, Accessor, NEArithmeticAddition, T>; |
| 68 | |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 69 | // *INDENT-OFF* |
| 70 | // clang-format off |
| 71 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 72 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 74 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 75 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 77 | }), |
| 78 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 80 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 82 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 83 | })), |
| 84 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 85 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 86 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 87 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 88 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 89 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 90 | framework::dataset::make("Expected", { true, true, false, false, false})), |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 91 | input1_info, input2_info, output_info, expected) |
| 92 | { |
| 93 | ARM_COMPUTE_EXPECT(bool(NEArithmeticAddition::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), ConvertPolicy::WRAP)) == expected, framework::LogLevel::ERRORS); |
| 94 | } |
| 95 | // clang-format on |
| 96 | // *INDENT-ON* |
| 97 | |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 98 | TEST_SUITE(Integer) |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 99 | TEST_SUITE(U8) |
| 100 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 101 | shape, policy) |
| 102 | { |
| 103 | // Create tensors |
| 104 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8); |
| 105 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8); |
| 106 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
| 107 | |
| 108 | // Create and Configure function |
| 109 | NEArithmeticAddition add; |
| 110 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 111 | |
| 112 | // Validate valid region |
| 113 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 114 | validate(dst.info()->valid_region(), valid_region); |
| 115 | |
| 116 | // Validate padding |
| 117 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 118 | validate(ref_src1.info()->padding(), padding); |
| 119 | validate(ref_src2.info()->padding(), padding); |
| 120 | validate(dst.info()->padding(), padding); |
| 121 | } |
| 122 | |
| 123 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset), |
| 124 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 125 | { |
| 126 | // Validate output |
| 127 | validate(Accessor(_target), _reference); |
| 128 | } |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 129 | TEST_SUITE_END() // U8 |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 130 | |
| 131 | TEST_SUITE(S16) |
| 132 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
| 133 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 134 | shape, data_type, policy) |
| 135 | { |
| 136 | // Create tensors |
| 137 | Tensor ref_src1 = create_tensor<Tensor>(shape, data_type); |
| 138 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16); |
| 139 | Tensor dst = create_tensor<Tensor>(shape, DataType::S16); |
| 140 | |
| 141 | // Create and Configure function |
| 142 | NEArithmeticAddition add; |
| 143 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 144 | |
| 145 | // Validate valid region |
| 146 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 147 | validate(dst.info()->valid_region(), valid_region); |
| 148 | |
| 149 | // Validate padding |
| 150 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 151 | validate(ref_src1.info()->padding(), padding); |
| 152 | validate(ref_src2.info()->padding(), padding); |
| 153 | validate(dst.info()->padding(), padding); |
| 154 | } |
| 155 | |
| 156 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset), |
| 157 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 158 | { |
| 159 | // Validate output |
| 160 | validate(Accessor(_target), _reference); |
| 161 | } |
| 162 | |
| 163 | FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset), |
| 164 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 165 | { |
| 166 | // Validate output |
| 167 | validate(Accessor(_target), _reference); |
| 168 | } |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 169 | TEST_SUITE_END() // S16 |
| 170 | TEST_SUITE_END() // Integer |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 171 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 172 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 173 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 174 | TEST_SUITE(F16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 175 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset), |
| 176 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 177 | { |
| 178 | // Validate output |
| 179 | validate(Accessor(_target), _reference); |
| 180 | } |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 181 | TEST_SUITE_END() // F16 |
| 182 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 183 | |
| 184 | TEST_SUITE(F32) |
| 185 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 186 | shape, policy) |
| 187 | { |
| 188 | // Create tensors |
| 189 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 190 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 191 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
| 192 | |
| 193 | // Create and Configure function |
| 194 | NEArithmeticAddition add; |
| 195 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 196 | |
| 197 | // Validate valid region |
| 198 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 199 | validate(dst.info()->valid_region(), valid_region); |
| 200 | |
| 201 | // Validate padding |
| 202 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 203 | validate(ref_src1.info()->padding(), padding); |
| 204 | validate(ref_src2.info()->padding(), padding); |
| 205 | validate(dst.info()->padding(), padding); |
| 206 | } |
| 207 | |
| 208 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset), |
| 209 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 210 | { |
| 211 | // Validate output |
| 212 | validate(Accessor(_target), _reference); |
| 213 | } |
| 214 | |
| 215 | FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset), |
| 216 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 217 | { |
| 218 | // Validate output |
| 219 | validate(Accessor(_target), _reference); |
| 220 | } |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 221 | |
| 222 | template <typename T> |
| 223 | using NEArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticAddition, T>; |
| 224 | |
| 225 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(), |
| 226 | ArithmeticAdditionFP32Dataset), |
| 227 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 228 | { |
| 229 | // Validate output |
| 230 | validate(Accessor(_target), _reference); |
| 231 | } |
| 232 | |
| 233 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(), |
| 234 | ArithmeticAdditionFP32Dataset), |
| 235 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 236 | { |
| 237 | // Validate output |
| 238 | validate(Accessor(_target), _reference); |
| 239 | } |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 240 | TEST_SUITE_END() // F32 |
| 241 | TEST_SUITE_END() // Float |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 242 | |
Georgios Pinitas | a84faff | 2018-12-05 18:17:24 +0000 | [diff] [blame] | 243 | template <typename T> |
| 244 | using NEArithmeticAdditionQuantizedFixture = ArithmeticAdditionValidationQuantizedFixture<Tensor, Accessor, NEArithmeticAddition, T>; |
| 245 | |
| 246 | TEST_SUITE(Quantized) |
| 247 | TEST_SUITE(QASYMM8) |
| 248 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 249 | shape, policy) |
| 250 | { |
| 251 | // Create tensors |
| 252 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 253 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 254 | Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 255 | |
| 256 | // Create and Configure function |
| 257 | NEArithmeticAddition add; |
| 258 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 259 | |
| 260 | // Validate valid region |
| 261 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 262 | validate(dst.info()->valid_region(), valid_region); |
| 263 | |
| 264 | // Validate padding |
| 265 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 266 | validate(ref_src1.info()->padding(), padding); |
| 267 | validate(ref_src2.info()->padding(), padding); |
| 268 | validate(dst.info()->padding(), padding); |
| 269 | } |
| 270 | |
| 271 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 272 | NEArithmeticAdditionQuantizedFixture<uint8_t>, |
| 273 | framework::DatasetMode::PRECOMMIT, |
| 274 | combine(combine(combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQASYMM8Dataset), |
| 275 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 276 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 277 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 278 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 279 | { |
| 280 | // Validate output |
| 281 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 282 | } |
| 283 | TEST_SUITE_END() // QASYMM8 |
| 284 | TEST_SUITE_END() // Quantized |
| 285 | |
| 286 | TEST_SUITE_END() // ArithmeticAddition |
| 287 | TEST_SUITE_END() // NEON |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 288 | } // namespace validation |
| 289 | } // namespace test |
| 290 | } // namespace arm_compute |