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" |
| 36 | #include "tests/validation/fixtures/ArithmeticAdditionFixture.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 | { |
| 46 | /** Input data sets **/ |
| 47 | const auto ArithmeticAdditionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType", |
| 48 | DataType::U8)); |
| 49 | const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 50 | framework::dataset::make("DataType", DataType::S16)); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 51 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 52 | const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 53 | framework::dataset::make("DataType", DataType::F16)); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 54 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 55 | const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 56 | framework::dataset::make("DataType", DataType::F32)); |
| 57 | } // namespace |
| 58 | |
| 59 | TEST_SUITE(NEON) |
| 60 | TEST_SUITE(ArithmeticAddition) |
| 61 | |
| 62 | template <typename T> |
| 63 | using NEArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<Tensor, Accessor, NEArithmeticAddition, T>; |
| 64 | |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 65 | // *INDENT-OFF* |
| 66 | // clang-format off |
| 67 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 68 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 69 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 70 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 71 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 72 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 73 | }), |
| 74 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 75 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 76 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 77 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 78 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 79 | })), |
| 80 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 82 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 83 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 84 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 85 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 86 | framework::dataset::make("Expected", { true, true, false, false, false})), |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 87 | input1_info, input2_info, output_info, expected) |
| 88 | { |
| 89 | 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); |
| 90 | } |
| 91 | // clang-format on |
| 92 | // *INDENT-ON* |
| 93 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 94 | TEST_SUITE(U8) |
| 95 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 96 | shape, policy) |
| 97 | { |
| 98 | // Create tensors |
| 99 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8); |
| 100 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8); |
| 101 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
| 102 | |
| 103 | // Create and Configure function |
| 104 | NEArithmeticAddition add; |
| 105 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 106 | |
| 107 | // Validate valid region |
| 108 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 109 | validate(dst.info()->valid_region(), valid_region); |
| 110 | |
| 111 | // Validate padding |
| 112 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 113 | validate(ref_src1.info()->padding(), padding); |
| 114 | validate(ref_src2.info()->padding(), padding); |
| 115 | validate(dst.info()->padding(), padding); |
| 116 | } |
| 117 | |
| 118 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset), |
| 119 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 120 | { |
| 121 | // Validate output |
| 122 | validate(Accessor(_target), _reference); |
| 123 | } |
| 124 | TEST_SUITE_END() |
| 125 | |
| 126 | TEST_SUITE(S16) |
| 127 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
| 128 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 129 | shape, data_type, policy) |
| 130 | { |
| 131 | // Create tensors |
| 132 | Tensor ref_src1 = create_tensor<Tensor>(shape, data_type); |
| 133 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16); |
| 134 | Tensor dst = create_tensor<Tensor>(shape, DataType::S16); |
| 135 | |
| 136 | // Create and Configure function |
| 137 | NEArithmeticAddition add; |
| 138 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 139 | |
| 140 | // Validate valid region |
| 141 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 142 | validate(dst.info()->valid_region(), valid_region); |
| 143 | |
| 144 | // Validate padding |
| 145 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 146 | validate(ref_src1.info()->padding(), padding); |
| 147 | validate(ref_src2.info()->padding(), padding); |
| 148 | validate(dst.info()->padding(), padding); |
| 149 | } |
| 150 | |
| 151 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset), |
| 152 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 153 | { |
| 154 | // Validate output |
| 155 | validate(Accessor(_target), _reference); |
| 156 | } |
| 157 | |
| 158 | FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset), |
| 159 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 160 | { |
| 161 | // Validate output |
| 162 | validate(Accessor(_target), _reference); |
| 163 | } |
| 164 | TEST_SUITE_END() |
| 165 | |
| 166 | template <typename T> |
| 167 | using NEArithmeticAdditionFixedPointFixture = ArithmeticAdditionValidationFixedPointFixture<Tensor, Accessor, NEArithmeticAddition, T>; |
| 168 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 169 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 170 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 171 | TEST_SUITE(F16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 172 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset), |
| 173 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 174 | { |
| 175 | // Validate output |
| 176 | validate(Accessor(_target), _reference); |
| 177 | } |
| 178 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 179 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 180 | |
| 181 | TEST_SUITE(F32) |
| 182 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 183 | shape, policy) |
| 184 | { |
| 185 | // Create tensors |
| 186 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 187 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 188 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
| 189 | |
| 190 | // Create and Configure function |
| 191 | NEArithmeticAddition add; |
| 192 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 193 | |
| 194 | // Validate valid region |
| 195 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 196 | validate(dst.info()->valid_region(), valid_region); |
| 197 | |
| 198 | // Validate padding |
| 199 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 200 | validate(ref_src1.info()->padding(), padding); |
| 201 | validate(ref_src2.info()->padding(), padding); |
| 202 | validate(dst.info()->padding(), padding); |
| 203 | } |
| 204 | |
| 205 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset), |
| 206 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 207 | { |
| 208 | // Validate output |
| 209 | validate(Accessor(_target), _reference); |
| 210 | } |
| 211 | |
| 212 | FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset), |
| 213 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 214 | { |
| 215 | // Validate output |
| 216 | validate(Accessor(_target), _reference); |
| 217 | } |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 218 | |
| 219 | template <typename T> |
| 220 | using NEArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticAddition, T>; |
| 221 | |
| 222 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(), |
| 223 | ArithmeticAdditionFP32Dataset), |
| 224 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 225 | { |
| 226 | // Validate output |
| 227 | validate(Accessor(_target), _reference); |
| 228 | } |
| 229 | |
| 230 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(), |
| 231 | ArithmeticAdditionFP32Dataset), |
| 232 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 233 | { |
| 234 | // Validate output |
| 235 | validate(Accessor(_target), _reference); |
| 236 | } |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 237 | TEST_SUITE_END() |
| 238 | TEST_SUITE_END() |
| 239 | |
| 240 | TEST_SUITE_END() |
| 241 | TEST_SUITE_END() |
| 242 | } // namespace validation |
| 243 | } // namespace test |
| 244 | } // namespace arm_compute |