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