Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +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/NEArithmeticSubtraction.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 | 72898fe | 2017-09-01 11:42:16 +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 ArithmeticSubtractionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), |
| 48 | framework::dataset::make("DataType", |
| 49 | DataType::U8)); |
| 50 | const auto ArithmeticSubtractionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 51 | framework::dataset::make("DataType", DataType::S16)); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 52 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 53 | const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 54 | framework::dataset::make("DataType", DataType::F16)); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 55 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 56 | const auto ArithmeticSubtractionFP32Dataset = 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(NEON) |
| 61 | TEST_SUITE(ArithmeticSubtraction) |
| 62 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 63 | template <typename T> |
| 64 | using NEArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>; |
| 65 | |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 66 | // *INDENT-OFF* |
| 67 | // clang-format off |
| 68 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 69 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 70 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 71 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 72 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 74 | }), |
| 75 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 77 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 78 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 79 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 80 | })), |
| 81 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 83 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 84 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 85 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 86 | })), |
| 87 | framework::dataset::make("Expected", { true, true, false, false, false})), |
| 88 | input1_info, input2_info, output_info, expected) |
Ioan-Cristian Szabo | 397d58a | 2017-11-30 15:19:11 +0000 | [diff] [blame] | 89 | { |
| 90 | ARM_COMPUTE_EXPECT(bool(NEArithmeticSubtraction::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); |
| 91 | } |
| 92 | // clang-format on |
| 93 | // *INDENT-ON* |
| 94 | |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 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 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8); |
| 101 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8); |
| 102 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
| 103 | |
| 104 | // Create and Configure function |
| 105 | NEArithmeticSubtraction sub; |
| 106 | sub.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, NEArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset), |
| 120 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 121 | { |
| 122 | // Validate output |
| 123 | validate(Accessor(_target), _reference); |
| 124 | } |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 125 | TEST_SUITE_END() // U8 |
Isabella Gottardi | b5908c2 | 2017-10-30 15:28:13 +0000 | [diff] [blame] | 126 | |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 127 | TEST_SUITE(S16) |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 128 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 129 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 130 | shape, data_type, policy) |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 131 | { |
| 132 | // Create tensors |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 133 | Tensor ref_src1 = create_tensor<Tensor>(shape, data_type); |
| 134 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16); |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 135 | Tensor dst = create_tensor<Tensor>(shape, DataType::S16); |
| 136 | |
| 137 | // Create and Configure function |
| 138 | NEArithmeticSubtraction sub; |
| 139 | sub.configure(&ref_src1, &ref_src2, &dst, policy); |
| 140 | |
| 141 | // Validate valid region |
| 142 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 143 | validate(dst.info()->valid_region(), valid_region); |
| 144 | |
| 145 | // Validate padding |
| 146 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 147 | validate(ref_src1.info()->padding(), padding); |
| 148 | validate(ref_src2.info()->padding(), padding); |
| 149 | validate(dst.info()->padding(), padding); |
| 150 | } |
| 151 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 152 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset), |
| 153 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 154 | { |
| 155 | // Validate output |
| 156 | validate(Accessor(_target), _reference); |
| 157 | } |
| 158 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 159 | FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset), |
| 160 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 161 | { |
| 162 | // Validate output |
| 163 | validate(Accessor(_target), _reference); |
| 164 | } |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 165 | TEST_SUITE_END() // S16 |
Isabella Gottardi | b5908c2 | 2017-10-30 15:28:13 +0000 | [diff] [blame] | 166 | |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 167 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 168 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 169 | TEST_SUITE(F16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 170 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset), |
| 171 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 172 | { |
| 173 | // Validate output |
| 174 | validate(Accessor(_target), _reference); |
| 175 | } |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 176 | TEST_SUITE_END() // F16 |
| 177 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 178 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 179 | TEST_SUITE(F32) |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 180 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 181 | shape, policy) |
| 182 | { |
| 183 | // Create tensors |
| 184 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 185 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 186 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
| 187 | |
| 188 | // Create and Configure function |
| 189 | NEArithmeticSubtraction sub; |
| 190 | sub.configure(&ref_src1, &ref_src2, &dst, policy); |
| 191 | |
| 192 | // Validate valid region |
| 193 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 194 | validate(dst.info()->valid_region(), valid_region); |
| 195 | |
| 196 | // Validate padding |
| 197 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 198 | validate(ref_src1.info()->padding(), padding); |
| 199 | validate(ref_src2.info()->padding(), padding); |
| 200 | validate(dst.info()->padding(), padding); |
| 201 | } |
| 202 | |
| 203 | FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset), |
| 204 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 205 | { |
| 206 | // Validate output |
| 207 | validate(Accessor(_target), _reference); |
| 208 | } |
| 209 | |
| 210 | FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset), |
| 211 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 212 | { |
| 213 | // Validate output |
| 214 | validate(Accessor(_target), _reference); |
| 215 | } |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 216 | |
Georgios Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame^] | 217 | template <typename T> |
| 218 | using NEArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>; |
| 219 | |
| 220 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(), |
| 221 | ArithmeticSubtractionFP32Dataset), |
| 222 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 223 | { |
| 224 | // Validate output |
| 225 | validate(Accessor(_target), _reference); |
| 226 | } |
| 227 | |
| 228 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(), |
| 229 | ArithmeticSubtractionFP32Dataset), |
| 230 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP }))) |
| 231 | { |
| 232 | // Validate output |
| 233 | validate(Accessor(_target), _reference); |
| 234 | } |
| 235 | TEST_SUITE_END() // F32 |
| 236 | TEST_SUITE_END() // Float |
| 237 | |
| 238 | TEST_SUITE_END() // ArithmeticSubtraction |
| 239 | TEST_SUITE_END() // NEON |
Sanghoon Lee | 72898fe | 2017-09-01 11:42:16 +0100 | [diff] [blame] | 240 | } // namespace validation |
| 241 | } // namespace test |
| 242 | } // namespace arm_compute |