Gian Marco Iodice | 8aa985e | 2018-11-27 15:58:08 +0000 | [diff] [blame] | 1 | /* |
Isabella Gottardi | ee7c15d | 2018-12-17 16:15:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Gian Marco Iodice | 8aa985e | 2018-11-27 15:58:08 +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/Helpers.h" |
| 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 28 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 29 | #include "arm_compute/runtime/CL/functions/CLStackLayer.h" |
| 30 | #include "tests/CL/CLAccessor.h" |
| 31 | #include "tests/CL/Helper.h" |
| 32 | #include "tests/PaddingCalculator.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/StackLayerFixture.h" |
| 39 | |
| 40 | #include <vector> |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | namespace test |
| 45 | { |
| 46 | namespace validation |
| 47 | { |
| 48 | namespace |
| 49 | { |
| 50 | // *INDENT-OFF* |
| 51 | // clang-format off |
| 52 | /** Data types */ |
| 53 | const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 }); |
| 54 | |
| 55 | /** Num tensors values to test */ |
| 56 | const auto n_values = framework::dataset::make("NumTensors", { 3, 4 }); |
| 57 | |
| 58 | /** Shapes 1D to test */ |
| 59 | const auto shapes_1d_small = combine(datasets::Small1DShapes(), framework::dataset::make("Axis", -1, 2)); |
| 60 | |
| 61 | /** Shapes 2D to test */ |
| 62 | const auto shapes_2d_small = combine(datasets::Small2DShapes(), framework::dataset::make("Axis", -2, 3)); |
| 63 | |
| 64 | /** Shapes 3D to test */ |
| 65 | const auto shapes_3d_small = combine(datasets::Small3DShapes(), framework::dataset::make("Axis", -3, 4)); |
| 66 | |
| 67 | /** Shapes 4D to test */ |
| 68 | const auto shapes_4d_small = combine(datasets::Small4DShapes(), framework::dataset::make("Axis", -4, 5)); |
| 69 | |
| 70 | /** Shapes 1D to test */ |
| 71 | const auto shapes_1d_large = combine(datasets::Large1DShapes(), framework::dataset::make("Axis", -1, 2)); |
| 72 | |
| 73 | /** Shapes 2D to test */ |
| 74 | const auto shapes_2d_large = combine(datasets::Large2DShapes(), framework::dataset::make("Axis", -2, 3)); |
| 75 | |
| 76 | /** Shapes 3D to test */ |
| 77 | const auto shapes_3d_large = combine(datasets::Large3DShapes(), framework::dataset::make("Axis", -3, 4)); |
| 78 | |
| 79 | /** Shapes 4D to test */ |
| 80 | const auto shapes_4d_large = combine(datasets::Large4DShapes(), framework::dataset::make("Axis", -4, 5)); |
| 81 | |
| 82 | /** Configuration test */ |
| 83 | void validate_configuration(TensorShape shape_in, int axis, DataType data_type, int num_tensors) |
| 84 | { |
| 85 | // Wrap around negative values |
| 86 | const unsigned int axis_u = wrap_around(axis, static_cast<int>(shape_in.num_dimensions() + 1)); |
| 87 | |
| 88 | const TensorShape shape_dst = compute_stack_shape(TensorInfo(shape_in, 1, data_type), axis_u, num_tensors); |
| 89 | |
| 90 | std::vector<CLTensor> tensors(num_tensors); |
| 91 | std::vector<ICLTensor*> src(num_tensors); |
| 92 | |
| 93 | // Create vector of input tensors |
| 94 | for(int i = 0; i < num_tensors; ++i) |
| 95 | { |
| 96 | tensors[i] = create_tensor<CLTensor>(shape_in, data_type); |
| 97 | src[i] = &(tensors[i]); |
| 98 | ARM_COMPUTE_EXPECT(src[i]->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 99 | } |
| 100 | |
| 101 | // Create tensors |
| 102 | CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type); |
| 103 | |
| 104 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 105 | |
| 106 | // Create and configure function |
| 107 | CLStackLayer stack; |
| 108 | stack.configure(src, axis, &dst); |
| 109 | } |
| 110 | } // namespace |
| 111 | |
| 112 | /** Fixture to use */ |
| 113 | template<typename T> |
| 114 | using CLStackLayerFixture = StackLayerValidationFixture<CLTensor, ICLTensor, CLAccessor, CLStackLayer, T>; |
| 115 | |
| 116 | using namespace arm_compute::misc::shape_calculator; |
| 117 | |
| 118 | TEST_SUITE(CL) |
| 119 | TEST_SUITE(StackLayer) |
Isabella Gottardi | ee7c15d | 2018-12-17 16:15:34 +0000 | [diff] [blame] | 120 | |
| 121 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 122 | framework::dataset::make("InputInfo", |
| 123 | { |
| 124 | std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::U8) }, |
| 125 | std::vector<TensorInfo>{ TensorInfo(TensorShape(1U, 2U), 1, DataType::U8) , TensorInfo(TensorShape(1U, 2U), 1, DataType::U8), TensorInfo(TensorShape(1U, 2U), 1, DataType::U8)}, |
| 126 | std::vector<TensorInfo>{ TensorInfo(TensorShape(2U, 3U), 1, DataType::S32) }, |
| 127 | std::vector<TensorInfo>{ TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32)}, |
| 128 | std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::S32) }, |
| 129 | }), |
| 130 | framework::dataset::make("OutputInfo", |
| 131 | { |
| 132 | TensorInfo(TensorShape(1U, 9U, 8U), 1, DataType::U8), // Passes, stack 1 tensor on x axis |
| 133 | TensorInfo(TensorShape(1U, 3U, 2U), 1, DataType::U8), // Passes, stack 3 tensors on y axis |
| 134 | TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::S32), // fails axis < (- input's rank) |
| 135 | TensorInfo(TensorShape(3U, 7U, 5U), 1, DataType::S32), // fails, input dimensions > 4 |
| 136 | TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails mismatching data types |
| 137 | })), |
| 138 | framework::dataset::make("Axis", { -3, 1, -4, -3, 1 })), |
| 139 | framework::dataset::make("Expected", { true, true, false, false, false })), |
| 140 | input_info, output_info, axis, expected) |
| 141 | { |
| 142 | std::vector<TensorInfo> ti(input_info); |
| 143 | std::vector<ITensorInfo *> vec(input_info.size()); |
| 144 | for(size_t j = 0; j < vec.size(); ++j) |
| 145 | { |
| 146 | vec[j] = &ti[j]; |
| 147 | } |
| 148 | ARM_COMPUTE_EXPECT(bool(CLStackLayer::validate(vec, axis, &output_info)) == expected, framework::LogLevel::ERRORS); |
| 149 | } |
| 150 | |
Gian Marco Iodice | 8aa985e | 2018-11-27 15:58:08 +0000 | [diff] [blame] | 151 | TEST_SUITE(Shapes1D) |
| 152 | |
| 153 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_1d_small, |
| 154 | data_types), |
| 155 | n_values), |
| 156 | shape_in, axis, data_type, num_tensors) |
| 157 | { |
| 158 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 159 | } |
| 160 | |
| 161 | TEST_SUITE(S32) |
| 162 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 163 | combine(combine(shapes_1d_small, |
| 164 | framework::dataset::make("DataType", { DataType::S32 })), |
| 165 | n_values)) |
| 166 | { |
| 167 | // Validate output |
| 168 | validate(CLAccessor(_target), _reference); |
| 169 | } |
| 170 | |
| 171 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 172 | combine(combine(shapes_1d_large, |
| 173 | framework::dataset::make("DataType", { DataType::S32 })), |
| 174 | n_values)) |
| 175 | { |
| 176 | // Validate output |
| 177 | validate(CLAccessor(_target), _reference); |
| 178 | } |
| 179 | TEST_SUITE_END() // S32 |
| 180 | |
| 181 | TEST_SUITE(S16) |
| 182 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 183 | combine(combine(shapes_1d_small, |
| 184 | framework::dataset::make("DataType", { DataType::S16 })), |
| 185 | n_values)) |
| 186 | { |
| 187 | // Validate output |
| 188 | validate(CLAccessor(_target), _reference); |
| 189 | } |
| 190 | |
| 191 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 192 | combine(combine(shapes_1d_large, |
| 193 | framework::dataset::make("DataType", { DataType::S16 })), |
| 194 | n_values)) |
| 195 | { |
| 196 | // Validate output |
| 197 | validate(CLAccessor(_target), _reference); |
| 198 | } |
| 199 | TEST_SUITE_END() // S16 |
| 200 | |
| 201 | TEST_SUITE(S8) |
| 202 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 203 | combine(combine(shapes_1d_small, |
| 204 | framework::dataset::make("DataType", { DataType::S8 })), |
| 205 | n_values)) |
| 206 | { |
| 207 | // Validate output |
| 208 | validate(CLAccessor(_target), _reference); |
| 209 | } |
| 210 | |
| 211 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 212 | combine(combine(shapes_1d_large, |
| 213 | framework::dataset::make("DataType", { DataType::S8 })), |
| 214 | n_values)) |
| 215 | { |
| 216 | // Validate output |
| 217 | validate(CLAccessor(_target), _reference); |
| 218 | } |
| 219 | TEST_SUITE_END() // S8 |
| 220 | TEST_SUITE_END() // Shapes1D |
| 221 | |
| 222 | TEST_SUITE(Shapes2D) |
| 223 | |
| 224 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_2d_small, |
| 225 | data_types), |
| 226 | n_values), |
| 227 | shape_in, axis, data_type, num_tensors) |
| 228 | { |
| 229 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 230 | } |
| 231 | |
| 232 | TEST_SUITE(S32) |
| 233 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 234 | combine(combine(shapes_2d_small, |
| 235 | framework::dataset::make("DataType", { DataType::S32 })), |
| 236 | n_values)) |
| 237 | { |
| 238 | // Validate output |
| 239 | validate(CLAccessor(_target), _reference); |
| 240 | } |
| 241 | |
| 242 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 243 | combine(combine(shapes_2d_large, |
| 244 | framework::dataset::make("DataType", { DataType::S32 })), |
| 245 | n_values)) |
| 246 | { |
| 247 | // Validate output |
| 248 | validate(CLAccessor(_target), _reference); |
| 249 | } |
| 250 | TEST_SUITE_END() // S32 |
| 251 | |
| 252 | TEST_SUITE(S16) |
| 253 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 254 | combine(combine(shapes_2d_small, |
| 255 | framework::dataset::make("DataType", { DataType::S16 })), |
| 256 | n_values)) |
| 257 | { |
| 258 | // Validate output |
| 259 | validate(CLAccessor(_target), _reference); |
| 260 | } |
| 261 | |
| 262 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 263 | combine(combine(shapes_2d_large, |
| 264 | framework::dataset::make("DataType", { DataType::S16 })), |
| 265 | n_values)) |
| 266 | { |
| 267 | // Validate output |
| 268 | validate(CLAccessor(_target), _reference); |
| 269 | } |
| 270 | TEST_SUITE_END() // S16 |
| 271 | |
| 272 | TEST_SUITE(S8) |
| 273 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 274 | combine(combine(shapes_2d_small, |
| 275 | framework::dataset::make("DataType", { DataType::S8 })), |
| 276 | n_values)) |
| 277 | { |
| 278 | // Validate output |
| 279 | validate(CLAccessor(_target), _reference); |
| 280 | } |
| 281 | |
| 282 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 283 | combine(combine(shapes_2d_large, |
| 284 | framework::dataset::make("DataType", { DataType::S8 })), |
| 285 | n_values)) |
| 286 | { |
| 287 | // Validate output |
| 288 | validate(CLAccessor(_target), _reference); |
| 289 | } |
| 290 | TEST_SUITE_END() // S8 |
| 291 | TEST_SUITE_END() // Shapes2D |
| 292 | |
| 293 | TEST_SUITE(Shapes3D) |
| 294 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_3d_small, |
| 295 | data_types), |
| 296 | n_values), |
| 297 | shape_in, axis, data_type, num_tensors) |
| 298 | { |
| 299 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 300 | } |
| 301 | |
| 302 | TEST_SUITE(S32) |
| 303 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 304 | combine(combine(shapes_3d_small, |
| 305 | framework::dataset::make("DataType", { DataType::S32 })), |
| 306 | n_values)) |
| 307 | { |
| 308 | // Validate output |
| 309 | validate(CLAccessor(_target), _reference); |
| 310 | } |
| 311 | |
| 312 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 313 | combine(combine(shapes_3d_large, |
| 314 | framework::dataset::make("DataType", { DataType::S32 })), |
| 315 | n_values)) |
| 316 | { |
| 317 | // Validate output |
| 318 | validate(CLAccessor(_target), _reference); |
| 319 | } |
| 320 | TEST_SUITE_END() // S32 |
| 321 | |
| 322 | TEST_SUITE(S16) |
| 323 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 324 | combine(combine(shapes_3d_small, |
| 325 | framework::dataset::make("DataType", { DataType::S16 })), |
| 326 | n_values)) |
| 327 | { |
| 328 | // Validate output |
| 329 | validate(CLAccessor(_target), _reference); |
| 330 | } |
| 331 | |
| 332 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 333 | combine(combine(shapes_3d_large, |
| 334 | framework::dataset::make("DataType", { DataType::S16 })), |
| 335 | n_values)) |
| 336 | { |
| 337 | // Validate output |
| 338 | validate(CLAccessor(_target), _reference); |
| 339 | } |
| 340 | TEST_SUITE_END() // S16 |
| 341 | |
| 342 | TEST_SUITE(S8) |
| 343 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 344 | combine(combine(shapes_3d_small, |
| 345 | framework::dataset::make("DataType", { DataType::S8 })), |
| 346 | n_values)) |
| 347 | { |
| 348 | // Validate output |
| 349 | validate(CLAccessor(_target), _reference); |
| 350 | } |
| 351 | |
| 352 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 353 | combine(combine(shapes_3d_large, |
| 354 | framework::dataset::make("DataType", { DataType::S8 })), |
| 355 | n_values)) |
| 356 | { |
| 357 | // Validate output |
| 358 | validate(CLAccessor(_target), _reference); |
| 359 | } |
| 360 | TEST_SUITE_END() // S8 |
| 361 | TEST_SUITE_END() // Shapes3D |
| 362 | |
| 363 | TEST_SUITE(Shapes4D) |
| 364 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_4d_small, |
| 365 | data_types), |
| 366 | n_values), |
| 367 | shape_in, axis, data_type, num_tensors) |
| 368 | { |
| 369 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 370 | } |
| 371 | |
| 372 | TEST_SUITE(S32) |
| 373 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 374 | combine(combine(shapes_4d_small, |
| 375 | framework::dataset::make("DataType", { DataType::S32 })), |
| 376 | n_values)) |
| 377 | { |
| 378 | // Validate output |
| 379 | validate(CLAccessor(_target), _reference); |
| 380 | } |
| 381 | |
| 382 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 383 | combine(combine(shapes_4d_large, |
| 384 | framework::dataset::make("DataType", { DataType::S32 })), |
| 385 | n_values)) |
| 386 | { |
| 387 | // Validate output |
| 388 | validate(CLAccessor(_target), _reference); |
| 389 | } |
| 390 | TEST_SUITE_END() // S32 |
| 391 | |
| 392 | TEST_SUITE(S16) |
| 393 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 394 | combine(combine(shapes_4d_small, |
| 395 | framework::dataset::make("DataType", { DataType::S16 })), |
| 396 | n_values)) |
| 397 | { |
| 398 | // Validate output |
| 399 | validate(CLAccessor(_target), _reference); |
| 400 | } |
| 401 | |
| 402 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 403 | combine(combine(shapes_4d_large, |
| 404 | framework::dataset::make("DataType", { DataType::S16 })), |
| 405 | n_values)) |
| 406 | { |
| 407 | // Validate output |
| 408 | validate(CLAccessor(_target), _reference); |
| 409 | } |
| 410 | TEST_SUITE_END() // S16 |
| 411 | |
| 412 | TEST_SUITE(S8) |
| 413 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 414 | combine(combine(shapes_4d_small, |
| 415 | framework::dataset::make("DataType", { DataType::S8 })), |
| 416 | n_values)) |
| 417 | { |
| 418 | // Validate output |
| 419 | validate(CLAccessor(_target), _reference); |
| 420 | } |
| 421 | |
| 422 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 423 | combine(combine(shapes_4d_large, |
| 424 | framework::dataset::make("DataType", { DataType::S8 })), |
| 425 | n_values)) |
| 426 | { |
| 427 | // Validate output |
| 428 | validate(CLAccessor(_target), _reference); |
| 429 | } |
| 430 | TEST_SUITE_END() // S8 |
| 431 | TEST_SUITE_END() // Shapes4D |
| 432 | TEST_SUITE_END() // StackLayer |
| 433 | TEST_SUITE_END() // CL |
| 434 | } // namespace validation |
| 435 | } // namespace test |
| 436 | } // namespace arm_compute |