Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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/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)); |
| 51 | const auto ArithmeticAdditionQS8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QS8), framework::dataset::make("DataType", DataType::QS8)), |
| 52 | framework::dataset::make("DataType", DataType::QS8)); |
| 53 | const auto ArithmeticAdditionQS16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QS16), framework::dataset::make("DataType", DataType::QS16)), |
| 54 | framework::dataset::make("DataType", DataType::QS16)); |
| 55 | const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 56 | framework::dataset::make("DataType", DataType::F16)); |
| 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)); |
| 59 | } // namespace |
| 60 | |
| 61 | TEST_SUITE(CL) |
| 62 | TEST_SUITE(ArithmeticAddition) |
| 63 | |
| 64 | template <typename T> |
| 65 | using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>; |
| 66 | |
| 67 | TEST_SUITE(U8) |
| 68 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 69 | shape, policy) |
| 70 | { |
| 71 | // Create tensors |
| 72 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8); |
| 73 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8); |
| 74 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8); |
| 75 | |
| 76 | // Create and Configure function |
| 77 | CLArithmeticAddition add; |
| 78 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 79 | |
| 80 | // Validate valid region |
| 81 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 82 | validate(dst.info()->valid_region(), valid_region); |
| 83 | |
| 84 | // Validate padding |
| 85 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 86 | validate(ref_src1.info()->padding(), padding); |
| 87 | validate(ref_src2.info()->padding(), padding); |
| 88 | validate(dst.info()->padding(), padding); |
| 89 | } |
| 90 | |
| 91 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset), |
| 92 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 93 | { |
| 94 | // Validate output |
| 95 | validate(CLAccessor(_target), _reference); |
| 96 | } |
| 97 | TEST_SUITE_END() |
| 98 | |
| 99 | TEST_SUITE(S16) |
| 100 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
| 101 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 102 | shape, data_type, policy) |
| 103 | { |
| 104 | // Create tensors |
| 105 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type); |
| 106 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16); |
| 107 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16); |
| 108 | |
| 109 | // Create and Configure function |
| 110 | CLArithmeticAddition add; |
| 111 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 112 | |
| 113 | // Validate valid region |
| 114 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 115 | validate(dst.info()->valid_region(), valid_region); |
| 116 | |
| 117 | // Validate padding |
| 118 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 119 | validate(ref_src1.info()->padding(), padding); |
| 120 | validate(ref_src2.info()->padding(), padding); |
| 121 | validate(dst.info()->padding(), padding); |
| 122 | } |
| 123 | |
| 124 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset), |
| 125 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 126 | { |
| 127 | // Validate output |
| 128 | validate(CLAccessor(_target), _reference); |
| 129 | } |
| 130 | |
| 131 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset), |
| 132 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 133 | { |
| 134 | // Validate output |
| 135 | validate(CLAccessor(_target), _reference); |
| 136 | } |
| 137 | TEST_SUITE_END() |
| 138 | |
| 139 | template <typename T> |
| 140 | using CLArithmeticAdditionFixedPointFixture = ArithmeticAdditionValidationFixedPointFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>; |
| 141 | |
| 142 | TEST_SUITE(Quantized) |
| 143 | TEST_SUITE(QS8) |
| 144 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQS8Dataset), |
| 145 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 146 | framework::dataset::make("FractionalBits", 1, 7))) |
| 147 | { |
| 148 | // Validate output |
| 149 | validate(CLAccessor(_target), _reference); |
| 150 | } |
| 151 | |
| 152 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticAdditionQS8Dataset), |
| 153 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 154 | framework::dataset::make("FractionalBits", 1, 7))) |
| 155 | { |
| 156 | // Validate output |
| 157 | validate(CLAccessor(_target), _reference); |
| 158 | } |
| 159 | TEST_SUITE_END() |
| 160 | |
| 161 | TEST_SUITE(QS16) |
| 162 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQS16Dataset), |
| 163 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 164 | framework::dataset::make("FractionalBits", 1, 15))) |
| 165 | { |
| 166 | // Validate output |
| 167 | validate(CLAccessor(_target), _reference); |
| 168 | } |
| 169 | |
| 170 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticAdditionQS16Dataset), |
| 171 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 172 | framework::dataset::make("FractionalBits", 1, 15))) |
| 173 | { |
| 174 | // Validate output |
| 175 | validate(CLAccessor(_target), _reference); |
| 176 | } |
| 177 | TEST_SUITE_END() |
| 178 | TEST_SUITE_END() |
| 179 | |
| 180 | TEST_SUITE(Float) |
| 181 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame^] | 182 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset), |
| 183 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 70f8291 | 2017-08-24 14:21:24 +0100 | [diff] [blame] | 184 | { |
| 185 | // Validate output |
| 186 | validate(CLAccessor(_target), _reference); |
| 187 | } |
| 188 | TEST_SUITE_END() |
| 189 | |
| 190 | TEST_SUITE(FP32) |
| 191 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 192 | shape, policy) |
| 193 | { |
| 194 | // Create tensors |
| 195 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32); |
| 196 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32); |
| 197 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32); |
| 198 | |
| 199 | // Create and Configure function |
| 200 | CLArithmeticAddition add; |
| 201 | add.configure(&ref_src1, &ref_src2, &dst, policy); |
| 202 | |
| 203 | // Validate valid region |
| 204 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 205 | validate(dst.info()->valid_region(), valid_region); |
| 206 | |
| 207 | // Validate padding |
| 208 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 209 | validate(ref_src1.info()->padding(), padding); |
| 210 | validate(ref_src2.info()->padding(), padding); |
| 211 | validate(dst.info()->padding(), padding); |
| 212 | } |
| 213 | |
| 214 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset), |
| 215 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 216 | { |
| 217 | // Validate output |
| 218 | validate(CLAccessor(_target), _reference); |
| 219 | } |
| 220 | |
| 221 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset), |
| 222 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 223 | { |
| 224 | // Validate output |
| 225 | validate(CLAccessor(_target), _reference); |
| 226 | } |
| 227 | TEST_SUITE_END() |
| 228 | TEST_SUITE_END() |
| 229 | |
| 230 | TEST_SUITE_END() |
| 231 | TEST_SUITE_END() |
| 232 | } // namespace validation |
| 233 | } // namespace test |
| 234 | } // namespace arm_compute |