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, |
Sanghoon Lee | a7a5b7b | 2017-09-14 12:11:03 +0100 | [diff] [blame] | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 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/CLArithmeticAddition.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" |
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 | { |
| 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)); |
Michele Di Giorgio | 4622ac1 | 2018-06-27 16:41:17 +0100 | [diff] [blame] | 49 | const auto ArithmeticAdditionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 50 | framework::dataset::make("DataType", |
| 51 | DataType::QASYMM8)); |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 52 | const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 53 | framework::dataset::make("DataType", DataType::S16)); |
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)); |
| 56 | const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 57 | framework::dataset::make("DataType", DataType::F32)); |
| 58 | } // namespace |
| 59 | |
| 60 | TEST_SUITE(CL) |
| 61 | TEST_SUITE(ArithmeticAddition) |
| 62 | |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 63 | // *INDENT-OFF* |
| 64 | // clang-format off |
| 65 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 66 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 67 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 68 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 69 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 70 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 71 | }), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 72 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 74 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 75 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 76 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 77 | })), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 78 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 80 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 82 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 83 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 84 | framework::dataset::make("Expected", { true, true, false, false, false})), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 85 | input1_info, input2_info, output_info, expected) |
| 86 | { |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 87 | ARM_COMPUTE_EXPECT(bool(CLArithmeticAddition::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); |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 88 | } |
| 89 | // clang-format on |
| 90 | // *INDENT-ON* |
| 91 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 92 | template <typename T> |
| 93 | using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>; |
| 94 | |
| 95 | TEST_SUITE(U8) |
| 96 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 97 | shape, policy) |
| 98 | { |
| 99 | // Create tensors |
| 100 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8); |
| 101 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8); |
| 102 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8); |
| 103 | |
| 104 | // Create and Configure function |
| 105 | CLArithmeticAddition add; |
| 106 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 107 | |
| 108 | // Validate valid region |
| 109 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 110 | validate(dst.info()->valid_region(), valid_region); |
| 111 | |
| 112 | // Validate padding |
| 113 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 114 | validate(ref_src1.info()->padding(), padding); |
| 115 | validate(ref_src2.info()->padding(), padding); |
| 116 | validate(dst.info()->padding(), padding); |
| 117 | } |
| 118 | |
| 119 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset), |
| 120 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 121 | { |
| 122 | // Validate output |
| 123 | validate(CLAccessor(_target), _reference); |
| 124 | } |
| 125 | TEST_SUITE_END() |
| 126 | |
Michele Di Giorgio | 4622ac1 | 2018-06-27 16:41:17 +0100 | [diff] [blame] | 127 | template <typename T> |
| 128 | using CLArithmeticAdditionQuantizedFixture = ArithmeticAdditionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>; |
| 129 | |
| 130 | TEST_SUITE(Quantized) |
| 131 | TEST_SUITE(QASYMM8) |
| 132 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 133 | shape, policy) |
| 134 | { |
| 135 | // Create tensors |
| 136 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 137 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 138 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 139 | |
| 140 | // Create and Configure function |
| 141 | CLArithmeticAddition add; |
| 142 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 143 | |
| 144 | // Validate valid region |
| 145 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 146 | validate(dst.info()->valid_region(), valid_region); |
| 147 | |
| 148 | // Validate padding |
| 149 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 150 | validate(ref_src1.info()->padding(), padding); |
| 151 | validate(ref_src2.info()->padding(), padding); |
| 152 | validate(dst.info()->padding(), padding); |
| 153 | } |
| 154 | |
Pablo Tello | 76259ca | 2018-07-12 11:14:20 +0100 | [diff] [blame] | 155 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(), |
| 156 | ArithmeticAdditionQASYMM8Dataset), |
Michele Di Giorgio | 4622ac1 | 2018-06-27 16:41:17 +0100 | [diff] [blame] | 157 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
Pablo Tello | 76259ca | 2018-07-12 11:14:20 +0100 | [diff] [blame] | 158 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 159 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 160 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })) |
| 161 | |
| 162 | ) |
Michele Di Giorgio | 4622ac1 | 2018-06-27 16:41:17 +0100 | [diff] [blame] | 163 | { |
| 164 | // Validate output |
| 165 | validate(CLAccessor(_target), _reference); |
| 166 | } |
| 167 | TEST_SUITE_END() |
| 168 | TEST_SUITE_END() |
| 169 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 170 | TEST_SUITE(S16) |
| 171 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
| 172 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 173 | shape, data_type, policy) |
| 174 | { |
| 175 | // Create tensors |
| 176 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type); |
| 177 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16); |
| 178 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16); |
| 179 | |
| 180 | // Create and Configure function |
| 181 | CLArithmeticAddition add; |
| 182 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 183 | |
| 184 | // Validate valid region |
| 185 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 186 | validate(dst.info()->valid_region(), valid_region); |
| 187 | |
| 188 | // Validate padding |
| 189 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 190 | validate(ref_src1.info()->padding(), padding); |
| 191 | validate(ref_src2.info()->padding(), padding); |
| 192 | validate(dst.info()->padding(), padding); |
| 193 | } |
| 194 | |
| 195 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset), |
| 196 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 197 | { |
| 198 | // Validate output |
| 199 | validate(CLAccessor(_target), _reference); |
| 200 | } |
| 201 | |
| 202 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset), |
| 203 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 204 | { |
| 205 | // Validate output |
| 206 | validate(CLAccessor(_target), _reference); |
| 207 | } |
| 208 | TEST_SUITE_END() |
| 209 | |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 210 | TEST_SUITE(Float) |
| 211 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 212 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset), |
| 213 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 214 | { |
| 215 | // Validate output |
| 216 | validate(CLAccessor(_target), _reference); |
| 217 | } |
| 218 | TEST_SUITE_END() |
| 219 | |
| 220 | TEST_SUITE(FP32) |
| 221 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 222 | shape, policy) |
| 223 | { |
| 224 | // Create tensors |
| 225 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32); |
| 226 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32); |
| 227 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32); |
| 228 | |
| 229 | // Create and Configure function |
| 230 | CLArithmeticAddition add; |
| 231 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 232 | |
| 233 | // Validate valid region |
| 234 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 235 | validate(dst.info()->valid_region(), valid_region); |
| 236 | |
| 237 | // Validate padding |
| 238 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 239 | validate(ref_src1.info()->padding(), padding); |
| 240 | validate(ref_src2.info()->padding(), padding); |
| 241 | validate(dst.info()->padding(), padding); |
| 242 | } |
| 243 | |
| 244 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset), |
| 245 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 246 | { |
| 247 | // Validate output |
| 248 | validate(CLAccessor(_target), _reference); |
| 249 | } |
| 250 | |
| 251 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset), |
| 252 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 253 | { |
| 254 | // Validate output |
| 255 | validate(CLAccessor(_target), _reference); |
| 256 | } |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 257 | |
| 258 | template <typename T> |
| 259 | using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>; |
| 260 | |
| 261 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(), |
| 262 | ArithmeticAdditionFP32Dataset), |
| 263 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 264 | { |
| 265 | // Validate output |
| 266 | validate(CLAccessor(_target), _reference); |
| 267 | } |
| 268 | |
| 269 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(), |
| 270 | ArithmeticAdditionFP32Dataset), |
| 271 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 272 | { |
| 273 | // Validate output |
| 274 | validate(CLAccessor(_target), _reference); |
| 275 | } |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 276 | TEST_SUITE_END() |
| 277 | TEST_SUITE_END() |
| 278 | |
| 279 | TEST_SUITE_END() |
| 280 | TEST_SUITE_END() |
| 281 | } // namespace validation |
| 282 | } // namespace test |
| 283 | } // namespace arm_compute |