Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 1 | /* |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 2023 Arm Limited. |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +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 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/CLBatchToSpaceLayer.h" |
| 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/BatchToSpaceDataset.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/Helpers.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/BatchToSpaceLayerFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | TEST_SUITE(CL) |
| 46 | TEST_SUITE(BatchToSpaceLayer) |
| 47 | |
| 48 | template <typename T> |
| 49 | using CLBatchToSpaceLayerFixture = BatchToSpaceLayerValidationFixture<CLTensor, CLAccessor, CLBatchToSpaceLayer, T>; |
| 50 | |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 51 | // *INDENT-OFF* |
| 52 | // clang-format off |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 53 | DATA_TEST_CASE(ValidateStatic, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
Michalis Spyrou | 8f2cbfa | 2018-11-20 12:39:47 +0000 | [diff] [blame] | 54 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 8U, 2U, 4U), 1, DataType::F32), |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 55 | TensorInfo(TensorShape(16U, 8U, 2U, 16U), 1, DataType::F32), // Supported: blockx != blocky && blockx > blocky |
| 56 | TensorInfo(TensorShape(16U, 8U, 2U, 16U), 1, DataType::F32), // Supported: blockx != blocky && blocky > blockx |
| 57 | TensorInfo(TensorShape(16U, 8U, 2U, 4U), 1, DataType::F32), // Invalid: Mismatching data types |
| 58 | TensorInfo(TensorShape(16U, 8U, 2U, 4U), 1, DataType::F32), // Invalid: Negative block shapes |
| 59 | TensorInfo(TensorShape(32U, 16U, 2U, 4U, 4U), 1, DataType::F32),// Unsupported tensor rank |
| 60 | TensorInfo(TensorShape(16U, 8U, 2U, 16U), 1, DataType::F32), // Invalid output tensor shape (invalid batch dimension) |
| 61 | TensorInfo(TensorShape(16U, 8U, 2U, 16U), 1, DataType::F32), // Invalid output tensor shape (invalid spatial dimension) |
| 62 | TensorInfo(TensorShape(16U, 8U, 2U, 16U), 1, DataType::F32), // Supported: correct tensor shape with cropping |
| 63 | TensorInfo(TensorShape(16U, 8U, 2U, 16U), 1, DataType::F32), // Invalid tensor shape with cropping |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 64 | }), |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 65 | framework::dataset::make("BlockShapeX", { 2, 4, 2, 2, 2, 2, 2, 2, 2, 2 })), |
| 66 | framework::dataset::make("BlockShapeY", { 2, 2, 4, 2, -2, 2, 2, 2, 2, 2 })), |
| 67 | framework::dataset::make("CropInfo", { |
| 68 | CropInfo{}, CropInfo{}, CropInfo{}, CropInfo{}, CropInfo{}, CropInfo{}, CropInfo{}, CropInfo{}, CropInfo{3, 2, 1, 3}, CropInfo{3, 2, 1, 3} |
| 69 | })), |
Michalis Spyrou | 8f2cbfa | 2018-11-20 12:39:47 +0000 | [diff] [blame] | 70 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32), |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 71 | TensorInfo(TensorShape(64U, 16U, 2U, 2U), 1, DataType::F32), |
| 72 | TensorInfo(TensorShape(32U, 32U, 2U, 2U), 1, DataType::F32), |
Michalis Spyrou | 8f2cbfa | 2018-11-20 12:39:47 +0000 | [diff] [blame] | 73 | TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F16), |
| 74 | TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(32U, 8U, 2U, 1U), 1, DataType::F32), |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 76 | TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32), |
| 77 | TensorInfo(TensorShape(33U, 32U, 2U, 4U), 1, DataType::F32), |
| 78 | TensorInfo(TensorShape(27, 12U, 2U, 4U), 1, DataType::F32), |
| 79 | TensorInfo(TensorShape(32U, 16U, 2U, 4U), 1, DataType::F32), |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 80 | })), |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 81 | framework::dataset::make("Expected", { true, true, true, false, false, false, false, false, true, false})), |
| 82 | input_info, block_shape_x, block_shape_y, crop_info, output_info, expected) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 83 | { |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 84 | bool has_error = bool(CLBatchToSpaceLayer::validate(&input_info.clone()->set_is_resizable(false), block_shape_x, block_shape_y, &output_info.clone()->set_is_resizable(false), crop_info)); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 85 | ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); |
| 86 | } |
| 87 | // clang-format on |
| 88 | // *INDENT-ON* |
| 89 | |
| 90 | TEST_SUITE(Float) |
| 91 | TEST_SUITE(FP32) |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 92 | FIXTURE_DATA_TEST_CASE(RunSmall, CLBatchToSpaceLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchToSpaceLayerDataset(), framework::dataset::make("DataType", |
| 93 | DataType::F32)), |
| 94 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 95 | { |
| 96 | // Validate output |
| 97 | validate(CLAccessor(_target), _reference); |
| 98 | } |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 99 | |
| 100 | FIXTURE_DATA_TEST_CASE(RunSmallWithCropping, CLBatchToSpaceLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 101 | combine(combine(datasets::SmallBatchToSpaceLayerWithCroppingDataset(), framework::dataset::make("DataType", |
| 102 | DataType::F32)), |
| 103 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 104 | { |
| 105 | // Validate output |
| 106 | validate(CLAccessor(_target), _reference); |
| 107 | } |
| 108 | |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 109 | FIXTURE_DATA_TEST_CASE(RunLarge, CLBatchToSpaceLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeBatchToSpaceLayerDataset(), framework::dataset::make("DataType", |
| 110 | DataType::F32)), |
| 111 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 112 | { |
| 113 | // Validate output |
| 114 | validate(CLAccessor(_target), _reference); |
| 115 | } |
| 116 | TEST_SUITE_END() |
| 117 | |
| 118 | TEST_SUITE(FP16) |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 119 | FIXTURE_DATA_TEST_CASE(RunSmall, CLBatchToSpaceLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchToSpaceLayerDataset(), framework::dataset::make("DataType", |
| 120 | DataType::F16)), |
| 121 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 122 | { |
| 123 | // Validate output |
| 124 | validate(CLAccessor(_target), _reference); |
| 125 | } |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 126 | |
| 127 | FIXTURE_DATA_TEST_CASE(RunSmallWithCropping, CLBatchToSpaceLayerFixture<half>, framework::DatasetMode::PRECOMMIT, |
| 128 | combine(combine(datasets::SmallBatchToSpaceLayerWithCroppingDataset(), framework::dataset::make("DataType", |
| 129 | DataType::F16)), |
| 130 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 131 | { |
| 132 | // Validate output |
| 133 | validate(CLAccessor(_target), _reference); |
| 134 | } |
| 135 | |
Michalis Spyrou | f1addb6 | 2018-09-11 11:16:47 +0100 | [diff] [blame] | 136 | FIXTURE_DATA_TEST_CASE(RunLarge, CLBatchToSpaceLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeBatchToSpaceLayerDataset(), framework::dataset::make("DataType", |
| 137 | DataType::F16)), |
| 138 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 139 | { |
| 140 | // Validate output |
| 141 | validate(CLAccessor(_target), _reference); |
| 142 | } |
| 143 | TEST_SUITE_END() |
| 144 | TEST_SUITE_END() |
| 145 | |
| 146 | TEST_SUITE_END() // BatchToSpace |
| 147 | TEST_SUITE_END() // CL |
| 148 | } // namespace validation |
| 149 | } // namespace test |
| 150 | } // namespace arm_compute |