Georgios Pinitas | aaa2718 | 2018-11-21 16:32:15 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Georgios Pinitas | aaa2718 | 2018-11-21 16:32:15 +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 | |
| 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLSelect.h" |
| 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/PaddingCalculator.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/SelectFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
Georgios Pinitas | aaa2718 | 2018-11-21 16:32:15 +0000 | [diff] [blame] | 46 | auto run_small_dataset = combine(datasets::SmallShapes(), framework::dataset::make("has_same_rank", { false, true })); |
| 47 | auto run_large_dataset = combine(datasets::LargeShapes(), framework::dataset::make("has_same_rank", { false, true })); |
| 48 | |
| 49 | } // namespace |
| 50 | TEST_SUITE(CL) |
| 51 | TEST_SUITE(Select) |
| 52 | |
| 53 | // *INDENT-OFF* |
| 54 | // clang-format off |
| 55 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 56 | framework::dataset::make("CInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S8), // Invalid condition datatype |
| 57 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid output datatype |
| 58 | TensorInfo(TensorShape(13U), 1, DataType::U8), // Invalid c shape |
| 59 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Mismatching shapes |
| 60 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 61 | TensorInfo(TensorShape(2U), 1, DataType::U8), |
| 62 | }), |
| 63 | framework::dataset::make("XInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 64 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 65 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 66 | TensorInfo(TensorShape(32U, 10U, 2U), 1, DataType::F32), |
| 67 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 68 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 69 | })), |
| 70 | framework::dataset::make("YInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 71 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 72 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 74 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 76 | })), |
| 77 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 78 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S8), |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 80 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 83 | })), |
| 84 | framework::dataset::make("Expected", { false, false, false, false, true, true})), |
| 85 | c_info, x_info, y_info, output_info, expected) |
| 86 | { |
| 87 | Status s = CLSelect::validate(&c_info.clone()->set_is_resizable(false), |
| 88 | &x_info.clone()->set_is_resizable(false), |
| 89 | &y_info.clone()->set_is_resizable(false), |
| 90 | &output_info.clone()->set_is_resizable(false)); |
| 91 | ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); |
| 92 | } |
| 93 | // clang-format on |
| 94 | // *INDENT-ON* |
| 95 | |
| 96 | template <typename T> |
| 97 | using CLSelectFixture = SelectValidationFixture<CLTensor, CLAccessor, CLSelect, T>; |
| 98 | |
| 99 | TEST_SUITE(Float) |
| 100 | TEST_SUITE(F16) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 101 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, run_small_dataset, |
Georgios Pinitas | aaa2718 | 2018-11-21 16:32:15 +0000 | [diff] [blame] | 102 | shape, same_rank) |
| 103 | { |
| 104 | const DataType dt = DataType::F16; |
| 105 | |
| 106 | // Create tensors |
| 107 | CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8); |
| 108 | CLTensor ref_x = create_tensor<CLTensor>(shape, dt); |
| 109 | CLTensor ref_y = create_tensor<CLTensor>(shape, dt); |
| 110 | CLTensor dst = create_tensor<CLTensor>(shape, dt); |
| 111 | |
| 112 | // Create and Configure function |
| 113 | CLSelect select; |
| 114 | select.configure(&ref_c, &ref_x, &ref_y, &dst); |
| 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 int step = 16 / arm_compute::data_size_from_type(dt); |
| 122 | const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); |
| 123 | if(same_rank) |
| 124 | { |
| 125 | validate(ref_c.info()->padding(), padding); |
| 126 | } |
| 127 | validate(ref_x.info()->padding(), padding); |
| 128 | validate(ref_y.info()->padding(), padding); |
| 129 | validate(dst.info()->padding(), padding); |
| 130 | } |
| 131 | |
| 132 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 133 | CLSelectFixture<half>, |
| 134 | framework::DatasetMode::PRECOMMIT, |
| 135 | combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16))) |
| 136 | { |
| 137 | // Validate output |
| 138 | validate(CLAccessor(_target), _reference); |
| 139 | } |
| 140 | |
| 141 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 142 | CLSelectFixture<half>, |
| 143 | framework::DatasetMode::NIGHTLY, |
| 144 | combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16))) |
| 145 | { |
| 146 | // Validate output |
| 147 | validate(CLAccessor(_target), _reference); |
| 148 | } |
| 149 | TEST_SUITE_END() // F16 |
| 150 | |
| 151 | TEST_SUITE(FP32) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 152 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, run_small_dataset, |
Georgios Pinitas | aaa2718 | 2018-11-21 16:32:15 +0000 | [diff] [blame] | 153 | shape, same_rank) |
| 154 | { |
| 155 | const DataType dt = DataType::F32; |
| 156 | |
| 157 | // Create tensors |
| 158 | CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8); |
| 159 | CLTensor ref_x = create_tensor<CLTensor>(shape, dt); |
| 160 | CLTensor ref_y = create_tensor<CLTensor>(shape, dt); |
| 161 | CLTensor dst = create_tensor<CLTensor>(shape, dt); |
| 162 | |
| 163 | // Create and Configure function |
| 164 | CLSelect select; |
| 165 | select.configure(&ref_c, &ref_x, &ref_y, &dst); |
| 166 | |
| 167 | // Validate valid region |
| 168 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 169 | validate(dst.info()->valid_region(), valid_region); |
| 170 | |
| 171 | // Validate padding |
| 172 | const int step = 16 / arm_compute::data_size_from_type(dt); |
| 173 | const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); |
| 174 | if(same_rank) |
| 175 | { |
| 176 | validate(ref_c.info()->padding(), padding); |
| 177 | } |
| 178 | validate(ref_x.info()->padding(), padding); |
| 179 | validate(ref_y.info()->padding(), padding); |
| 180 | validate(dst.info()->padding(), padding); |
| 181 | } |
| 182 | |
| 183 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 184 | CLSelectFixture<float>, |
| 185 | framework::DatasetMode::PRECOMMIT, |
| 186 | combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32))) |
| 187 | { |
| 188 | // Validate output |
| 189 | validate(CLAccessor(_target), _reference); |
| 190 | } |
| 191 | |
| 192 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 193 | CLSelectFixture<float>, |
| 194 | framework::DatasetMode::NIGHTLY, |
| 195 | combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32))) |
| 196 | { |
| 197 | // Validate output |
| 198 | validate(CLAccessor(_target), _reference); |
| 199 | } |
| 200 | TEST_SUITE_END() // F32 |
| 201 | TEST_SUITE_END() // Float |
| 202 | |
| 203 | TEST_SUITE(Quantized) |
| 204 | TEST_SUITE(QASYMM8) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 205 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, run_small_dataset, |
Georgios Pinitas | aaa2718 | 2018-11-21 16:32:15 +0000 | [diff] [blame] | 206 | shape, same_rank) |
| 207 | { |
| 208 | const DataType dt = DataType::QASYMM8; |
| 209 | |
| 210 | // Create tensors |
| 211 | CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8); |
| 212 | CLTensor ref_x = create_tensor<CLTensor>(shape, dt); |
| 213 | CLTensor ref_y = create_tensor<CLTensor>(shape, dt); |
| 214 | CLTensor dst = create_tensor<CLTensor>(shape, dt); |
| 215 | |
| 216 | // Create and Configure function |
| 217 | CLSelect select; |
| 218 | select.configure(&ref_c, &ref_x, &ref_y, &dst); |
| 219 | |
| 220 | // Validate valid region |
| 221 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 222 | validate(dst.info()->valid_region(), valid_region); |
| 223 | |
| 224 | // Validate padding |
| 225 | const int step = 16 / arm_compute::data_size_from_type(dt); |
| 226 | const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); |
| 227 | if(same_rank) |
| 228 | { |
| 229 | validate(ref_c.info()->padding(), padding); |
| 230 | } |
| 231 | validate(ref_x.info()->padding(), padding); |
| 232 | validate(ref_y.info()->padding(), padding); |
| 233 | validate(dst.info()->padding(), padding); |
| 234 | } |
| 235 | |
| 236 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 237 | CLSelectFixture<uint8_t>, |
| 238 | framework::DatasetMode::PRECOMMIT, |
| 239 | combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8))) |
| 240 | { |
| 241 | // Validate output |
| 242 | validate(CLAccessor(_target), _reference); |
| 243 | } |
| 244 | |
| 245 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 246 | CLSelectFixture<uint8_t>, |
| 247 | framework::DatasetMode::NIGHTLY, |
| 248 | combine(run_large_dataset, framework::dataset::make("DataType", DataType::QASYMM8))) |
| 249 | { |
| 250 | // Validate output |
| 251 | validate(CLAccessor(_target), _reference); |
| 252 | } |
| 253 | TEST_SUITE_END() // QASYMM8 |
| 254 | TEST_SUITE_END() // Quantized |
| 255 | |
| 256 | TEST_SUITE_END() // Select |
| 257 | TEST_SUITE_END() // CL |
| 258 | } // namespace validation |
| 259 | } // namespace test |
| 260 | } // namespace arm_compute |