giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [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 CONNECTION 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/CLElementwiseOperations.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/ElementwiseOperationsFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 47 | RelativeTolerance<float> tolerance_fp16(0.001f); |
| 48 | |
| 49 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 50 | /** Input data sets **/ |
| 51 | const auto ElementwiseMinU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType", |
| 52 | DataType::U8)); |
| 53 | const auto ElementwiseMinQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 54 | framework::dataset::make("DataType", |
| 55 | DataType::QASYMM8)); |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 56 | const auto ElementwiseMinQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)), |
| 57 | framework::dataset::make("DataType", |
| 58 | DataType::QSYMM16)); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 59 | const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 60 | framework::dataset::make("DataType", DataType::S16)); |
| 61 | const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 62 | framework::dataset::make("DataType", DataType::F16)); |
| 63 | const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 64 | framework::dataset::make("DataType", DataType::F32)); |
| 65 | } // namespace |
| 66 | |
| 67 | TEST_SUITE(CL) |
| 68 | TEST_SUITE(ElementwiseMin) |
| 69 | |
| 70 | // *INDENT-OFF* |
| 71 | // clang-format off |
| 72 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 73 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 74 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 75 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 77 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 78 | }), |
| 79 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 80 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 81 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 83 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 84 | })), |
| 85 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 86 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 87 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 88 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 89 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 90 | })), |
| 91 | framework::dataset::make("Expected", { true, true, false, false, false})), |
| 92 | input1_info, input2_info, output_info, expected) |
| 93 | { |
| 94 | ARM_COMPUTE_EXPECT(bool(CLElementwiseMin::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); |
| 95 | } |
| 96 | // clang-format on |
| 97 | // *INDENT-ON* |
| 98 | |
| 99 | template <typename T> |
| 100 | using CLElementwiseMinFixture = ElementwiseMinValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>; |
| 101 | |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 102 | TEST_SUITE(Integer) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 103 | TEST_SUITE(U8) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 104 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 105 | shape) |
| 106 | { |
| 107 | // Create tensors |
| 108 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8); |
| 109 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8); |
| 110 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8); |
| 111 | |
| 112 | // Create and Configure function |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 113 | CLElementwiseMin min; |
| 114 | min.configure(&ref_src1, &ref_src2, &dst); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 115 | |
| 116 | // Validate valid region |
| 117 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 118 | validate(dst.info()->valid_region(), valid_region); |
| 119 | |
| 120 | // Validate padding |
| 121 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 122 | validate(ref_src1.info()->padding(), padding); |
| 123 | validate(ref_src2.info()->padding(), padding); |
| 124 | validate(dst.info()->padding(), padding); |
| 125 | } |
| 126 | |
| 127 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinU8Dataset)) |
| 128 | { |
| 129 | // Validate output |
| 130 | validate(CLAccessor(_target), _reference); |
| 131 | } |
| 132 | TEST_SUITE_END() |
| 133 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 134 | TEST_SUITE(S16) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 135 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 136 | shape, data_type) |
| 137 | { |
| 138 | // Create tensors |
| 139 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type); |
| 140 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16); |
| 141 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16); |
| 142 | |
| 143 | // Create and Configure function |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 144 | CLElementwiseMin min; |
| 145 | min.configure(&ref_src1, &ref_src2, &dst); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 146 | |
| 147 | // Validate valid region |
| 148 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 149 | validate(dst.info()->valid_region(), valid_region); |
| 150 | |
| 151 | // Validate padding |
| 152 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 153 | validate(ref_src1.info()->padding(), padding); |
| 154 | validate(ref_src2.info()->padding(), padding); |
| 155 | validate(dst.info()->padding(), padding); |
| 156 | } |
| 157 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 158 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 159 | { |
| 160 | // Validate output |
| 161 | validate(CLAccessor(_target), _reference); |
| 162 | } |
| 163 | TEST_SUITE_END() |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 164 | TEST_SUITE_END() |
| 165 | |
| 166 | template <typename T> |
| 167 | using CLElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseMin, T>; |
| 168 | |
| 169 | TEST_SUITE(Quantized) |
| 170 | TEST_SUITE(QASYMM8) |
| 171 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
| 172 | shape) |
| 173 | { |
| 174 | // Create tensors |
| 175 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 176 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 177 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 178 | |
| 179 | // Create and Configure function |
| 180 | CLElementwiseMin min; |
| 181 | min.configure(&ref_src1, &ref_src2, &dst); |
| 182 | |
| 183 | // Validate valid region |
| 184 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 185 | validate(dst.info()->valid_region(), valid_region); |
| 186 | |
| 187 | // Validate padding |
| 188 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 189 | validate(ref_src1.info()->padding(), padding); |
| 190 | validate(ref_src2.info()->padding(), padding); |
| 191 | validate(dst.info()->padding(), padding); |
| 192 | } |
| 193 | |
| 194 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 195 | ElementwiseMinQASYMM8Dataset), |
| 196 | framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 197 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 198 | framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 199 | { |
| 200 | // Validate output |
| 201 | validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01); |
| 202 | } |
| 203 | TEST_SUITE_END() |
| 204 | TEST_SUITE(QSYMM16) |
| 205 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
| 206 | shape) |
| 207 | { |
| 208 | // Create tensors |
| 209 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16); |
| 210 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16); |
| 211 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16); |
| 212 | |
| 213 | // Create and Configure function |
| 214 | CLElementwiseMin min; |
| 215 | min.configure(&ref_src1, &ref_src2, &dst); |
| 216 | |
| 217 | // Validate valid region |
| 218 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 219 | validate(dst.info()->valid_region(), valid_region); |
| 220 | |
| 221 | // Validate padding |
| 222 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 223 | validate(ref_src1.info()->padding(), padding); |
| 224 | validate(ref_src2.info()->padding(), padding); |
| 225 | validate(dst.info()->padding(), padding); |
| 226 | } |
| 227 | |
| 228 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 229 | ElementwiseMinQSYMM16Dataset), |
| 230 | framework::dataset::make("SrcQInfo0", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })), |
| 231 | framework::dataset::make("SrcQInfo1", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })), |
| 232 | framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) }))) |
| 233 | { |
| 234 | // Validate output |
| 235 | validate(CLAccessor(_target), _reference); |
| 236 | } |
| 237 | TEST_SUITE_END() |
| 238 | TEST_SUITE_END() |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 239 | |
| 240 | TEST_SUITE(Float) |
| 241 | TEST_SUITE(FP16) |
| 242 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset)) |
| 243 | { |
| 244 | // Validate output |
| 245 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 246 | } |
| 247 | TEST_SUITE_END() |
| 248 | |
| 249 | TEST_SUITE(FP32) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 250 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 251 | shape) |
| 252 | { |
| 253 | // Create tensors |
| 254 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32); |
| 255 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32); |
| 256 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32); |
| 257 | |
| 258 | // Create and Configure function |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 259 | CLElementwiseMin min; |
| 260 | min.configure(&ref_src1, &ref_src2, &dst); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 261 | |
| 262 | // Validate valid region |
| 263 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 264 | validate(dst.info()->valid_region(), valid_region); |
| 265 | |
| 266 | // Validate padding |
| 267 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
| 268 | validate(ref_src1.info()->padding(), padding); |
| 269 | validate(ref_src2.info()->padding(), padding); |
| 270 | validate(dst.info()->padding(), padding); |
| 271 | } |
| 272 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 273 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 274 | { |
| 275 | // Validate output |
| 276 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 277 | } |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 278 | template <typename T> |
| 279 | using CLElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>; |
| 280 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 281 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseMinBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(), |
| 282 | ElementwiseMinFP32Dataset)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 283 | { |
| 284 | // Validate output |
| 285 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 286 | } |
| 287 | TEST_SUITE_END() |
| 288 | TEST_SUITE_END() |
| 289 | |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 290 | TEST_SUITE_END() // ElementwiseMin |
| 291 | TEST_SUITE_END() // CL |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 292 | } // namespace validation |
| 293 | } // namespace test |
| 294 | } // namespace arm_compute |