Gian Marco Iodice | 8aa985e | 2018-11-27 15:58:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 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) |
| 120 | TEST_SUITE(Shapes1D) |
| 121 | |
| 122 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_1d_small, |
| 123 | data_types), |
| 124 | n_values), |
| 125 | shape_in, axis, data_type, num_tensors) |
| 126 | { |
| 127 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 128 | } |
| 129 | |
| 130 | TEST_SUITE(S32) |
| 131 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 132 | combine(combine(shapes_1d_small, |
| 133 | framework::dataset::make("DataType", { DataType::S32 })), |
| 134 | n_values)) |
| 135 | { |
| 136 | // Validate output |
| 137 | validate(CLAccessor(_target), _reference); |
| 138 | } |
| 139 | |
| 140 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 141 | combine(combine(shapes_1d_large, |
| 142 | framework::dataset::make("DataType", { DataType::S32 })), |
| 143 | n_values)) |
| 144 | { |
| 145 | // Validate output |
| 146 | validate(CLAccessor(_target), _reference); |
| 147 | } |
| 148 | TEST_SUITE_END() // S32 |
| 149 | |
| 150 | TEST_SUITE(S16) |
| 151 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 152 | combine(combine(shapes_1d_small, |
| 153 | framework::dataset::make("DataType", { DataType::S16 })), |
| 154 | n_values)) |
| 155 | { |
| 156 | // Validate output |
| 157 | validate(CLAccessor(_target), _reference); |
| 158 | } |
| 159 | |
| 160 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 161 | combine(combine(shapes_1d_large, |
| 162 | framework::dataset::make("DataType", { DataType::S16 })), |
| 163 | n_values)) |
| 164 | { |
| 165 | // Validate output |
| 166 | validate(CLAccessor(_target), _reference); |
| 167 | } |
| 168 | TEST_SUITE_END() // S16 |
| 169 | |
| 170 | TEST_SUITE(S8) |
| 171 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 172 | combine(combine(shapes_1d_small, |
| 173 | framework::dataset::make("DataType", { DataType::S8 })), |
| 174 | n_values)) |
| 175 | { |
| 176 | // Validate output |
| 177 | validate(CLAccessor(_target), _reference); |
| 178 | } |
| 179 | |
| 180 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 181 | combine(combine(shapes_1d_large, |
| 182 | framework::dataset::make("DataType", { DataType::S8 })), |
| 183 | n_values)) |
| 184 | { |
| 185 | // Validate output |
| 186 | validate(CLAccessor(_target), _reference); |
| 187 | } |
| 188 | TEST_SUITE_END() // S8 |
| 189 | TEST_SUITE_END() // Shapes1D |
| 190 | |
| 191 | TEST_SUITE(Shapes2D) |
| 192 | |
| 193 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_2d_small, |
| 194 | data_types), |
| 195 | n_values), |
| 196 | shape_in, axis, data_type, num_tensors) |
| 197 | { |
| 198 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 199 | } |
| 200 | |
| 201 | TEST_SUITE(S32) |
| 202 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 203 | combine(combine(shapes_2d_small, |
| 204 | framework::dataset::make("DataType", { DataType::S32 })), |
| 205 | n_values)) |
| 206 | { |
| 207 | // Validate output |
| 208 | validate(CLAccessor(_target), _reference); |
| 209 | } |
| 210 | |
| 211 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 212 | combine(combine(shapes_2d_large, |
| 213 | framework::dataset::make("DataType", { DataType::S32 })), |
| 214 | n_values)) |
| 215 | { |
| 216 | // Validate output |
| 217 | validate(CLAccessor(_target), _reference); |
| 218 | } |
| 219 | TEST_SUITE_END() // S32 |
| 220 | |
| 221 | TEST_SUITE(S16) |
| 222 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 223 | combine(combine(shapes_2d_small, |
| 224 | framework::dataset::make("DataType", { DataType::S16 })), |
| 225 | n_values)) |
| 226 | { |
| 227 | // Validate output |
| 228 | validate(CLAccessor(_target), _reference); |
| 229 | } |
| 230 | |
| 231 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 232 | combine(combine(shapes_2d_large, |
| 233 | framework::dataset::make("DataType", { DataType::S16 })), |
| 234 | n_values)) |
| 235 | { |
| 236 | // Validate output |
| 237 | validate(CLAccessor(_target), _reference); |
| 238 | } |
| 239 | TEST_SUITE_END() // S16 |
| 240 | |
| 241 | TEST_SUITE(S8) |
| 242 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 243 | combine(combine(shapes_2d_small, |
| 244 | framework::dataset::make("DataType", { DataType::S8 })), |
| 245 | n_values)) |
| 246 | { |
| 247 | // Validate output |
| 248 | validate(CLAccessor(_target), _reference); |
| 249 | } |
| 250 | |
| 251 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 252 | combine(combine(shapes_2d_large, |
| 253 | framework::dataset::make("DataType", { DataType::S8 })), |
| 254 | n_values)) |
| 255 | { |
| 256 | // Validate output |
| 257 | validate(CLAccessor(_target), _reference); |
| 258 | } |
| 259 | TEST_SUITE_END() // S8 |
| 260 | TEST_SUITE_END() // Shapes2D |
| 261 | |
| 262 | TEST_SUITE(Shapes3D) |
| 263 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_3d_small, |
| 264 | data_types), |
| 265 | n_values), |
| 266 | shape_in, axis, data_type, num_tensors) |
| 267 | { |
| 268 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 269 | } |
| 270 | |
| 271 | TEST_SUITE(S32) |
| 272 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 273 | combine(combine(shapes_3d_small, |
| 274 | framework::dataset::make("DataType", { DataType::S32 })), |
| 275 | n_values)) |
| 276 | { |
| 277 | // Validate output |
| 278 | validate(CLAccessor(_target), _reference); |
| 279 | } |
| 280 | |
| 281 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 282 | combine(combine(shapes_3d_large, |
| 283 | framework::dataset::make("DataType", { DataType::S32 })), |
| 284 | n_values)) |
| 285 | { |
| 286 | // Validate output |
| 287 | validate(CLAccessor(_target), _reference); |
| 288 | } |
| 289 | TEST_SUITE_END() // S32 |
| 290 | |
| 291 | TEST_SUITE(S16) |
| 292 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 293 | combine(combine(shapes_3d_small, |
| 294 | framework::dataset::make("DataType", { DataType::S16 })), |
| 295 | n_values)) |
| 296 | { |
| 297 | // Validate output |
| 298 | validate(CLAccessor(_target), _reference); |
| 299 | } |
| 300 | |
| 301 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 302 | combine(combine(shapes_3d_large, |
| 303 | framework::dataset::make("DataType", { DataType::S16 })), |
| 304 | n_values)) |
| 305 | { |
| 306 | // Validate output |
| 307 | validate(CLAccessor(_target), _reference); |
| 308 | } |
| 309 | TEST_SUITE_END() // S16 |
| 310 | |
| 311 | TEST_SUITE(S8) |
| 312 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 313 | combine(combine(shapes_3d_small, |
| 314 | framework::dataset::make("DataType", { DataType::S8 })), |
| 315 | n_values)) |
| 316 | { |
| 317 | // Validate output |
| 318 | validate(CLAccessor(_target), _reference); |
| 319 | } |
| 320 | |
| 321 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 322 | combine(combine(shapes_3d_large, |
| 323 | framework::dataset::make("DataType", { DataType::S8 })), |
| 324 | n_values)) |
| 325 | { |
| 326 | // Validate output |
| 327 | validate(CLAccessor(_target), _reference); |
| 328 | } |
| 329 | TEST_SUITE_END() // S8 |
| 330 | TEST_SUITE_END() // Shapes3D |
| 331 | |
| 332 | TEST_SUITE(Shapes4D) |
| 333 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_4d_small, |
| 334 | data_types), |
| 335 | n_values), |
| 336 | shape_in, axis, data_type, num_tensors) |
| 337 | { |
| 338 | validate_configuration(shape_in, axis, data_type, num_tensors); |
| 339 | } |
| 340 | |
| 341 | TEST_SUITE(S32) |
| 342 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL, |
| 343 | combine(combine(shapes_4d_small, |
| 344 | framework::dataset::make("DataType", { DataType::S32 })), |
| 345 | n_values)) |
| 346 | { |
| 347 | // Validate output |
| 348 | validate(CLAccessor(_target), _reference); |
| 349 | } |
| 350 | |
| 351 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY, |
| 352 | combine(combine(shapes_4d_large, |
| 353 | framework::dataset::make("DataType", { DataType::S32 })), |
| 354 | n_values)) |
| 355 | { |
| 356 | // Validate output |
| 357 | validate(CLAccessor(_target), _reference); |
| 358 | } |
| 359 | TEST_SUITE_END() // S32 |
| 360 | |
| 361 | TEST_SUITE(S16) |
| 362 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL, |
| 363 | combine(combine(shapes_4d_small, |
| 364 | framework::dataset::make("DataType", { DataType::S16 })), |
| 365 | n_values)) |
| 366 | { |
| 367 | // Validate output |
| 368 | validate(CLAccessor(_target), _reference); |
| 369 | } |
| 370 | |
| 371 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY, |
| 372 | combine(combine(shapes_4d_large, |
| 373 | framework::dataset::make("DataType", { DataType::S16 })), |
| 374 | n_values)) |
| 375 | { |
| 376 | // Validate output |
| 377 | validate(CLAccessor(_target), _reference); |
| 378 | } |
| 379 | TEST_SUITE_END() // S16 |
| 380 | |
| 381 | TEST_SUITE(S8) |
| 382 | FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL, |
| 383 | combine(combine(shapes_4d_small, |
| 384 | framework::dataset::make("DataType", { DataType::S8 })), |
| 385 | n_values)) |
| 386 | { |
| 387 | // Validate output |
| 388 | validate(CLAccessor(_target), _reference); |
| 389 | } |
| 390 | |
| 391 | FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY, |
| 392 | combine(combine(shapes_4d_large, |
| 393 | framework::dataset::make("DataType", { DataType::S8 })), |
| 394 | n_values)) |
| 395 | { |
| 396 | // Validate output |
| 397 | validate(CLAccessor(_target), _reference); |
| 398 | } |
| 399 | TEST_SUITE_END() // S8 |
| 400 | TEST_SUITE_END() // Shapes4D |
| 401 | TEST_SUITE_END() // StackLayer |
| 402 | TEST_SUITE_END() // CL |
| 403 | } // namespace validation |
| 404 | } // namespace test |
| 405 | } // namespace arm_compute |