Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +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/functions/CLReorgLayer.h" |
| 26 | #include "tests/CL/CLAccessor.h" |
| 27 | #include "tests/CL/Helper.h" |
| 28 | #include "tests/PaddingCalculator.h" |
| 29 | #include "tests/datasets/ReorgLayerDataset.h" |
| 30 | #include "tests/framework/Asserts.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/framework/datasets/Datasets.h" |
| 33 | #include "tests/validation/Validation.h" |
| 34 | #include "tests/validation/fixtures/ReorgLayerFixture.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | TEST_SUITE(CL) |
| 43 | TEST_SUITE(ReorgLayer) |
| 44 | |
| 45 | // *INDENT-OFF* |
| 46 | // clang-format off |
| 47 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 48 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::S64), // Wrong output tensor |
| 49 | TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32), |
| 50 | TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32), // Wrong output tensor |
| 51 | TensorInfo(TensorShape(3U, 12U, 4U, 2U), 1, DataType::F32), |
| 52 | TensorInfo(TensorShape(3U, 12U, 4U, 2U), 1, DataType::F32), // Wrong data type |
| 53 | }), |
| 54 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::S64), |
| 55 | TensorInfo(TensorShape(5U, 6U, 4U, 2U), 1, DataType::F32), |
| 56 | TensorInfo(TensorShape(5U, 6U, 2, 2U), 1, DataType::F32), |
| 57 | TensorInfo(TensorShape(1U, 4U, 36U, 2U), 1, DataType::F32), |
| 58 | TensorInfo(TensorShape(1U, 4U, 36U, 2U), 1, DataType::F16), |
| 59 | })), |
| 60 | framework::dataset::make("Stride", { 2, 2, 4, 3 })), |
| 61 | framework::dataset::make("Expected", { false, true, false, true, false })), |
| 62 | input_info, output_info, stride, expected) |
| 63 | { |
| 64 | bool status = bool(CLReorgLayer::validate(&input_info, &output_info, stride)); |
| 65 | ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS); |
| 66 | } |
| 67 | // clang-format on |
| 68 | // *INDENT-ON* |
| 69 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 70 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallReorgLayerDataset(), |
Gian Marco Iodice | 477531c | 2018-08-21 17:53:38 +0100 | [diff] [blame] | 71 | framework::dataset::make("DataType", { DataType::F32, DataType::F16, DataType::QASYMM8 })), |
| 72 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 73 | shape, stride, data_type, data_layout) |
| 74 | { |
| 75 | // Permute the tensor shape in case of NHWC data layout |
| 76 | TensorShape shape_to_use = shape; |
| 77 | if(data_layout == DataLayout::NHWC) |
| 78 | { |
| 79 | permute(shape_to_use, PermutationVector(2U, 0U, 1U)); |
| 80 | } |
| 81 | |
| 82 | // Create tensors |
| 83 | CLTensor src = create_tensor<CLTensor>(shape_to_use, data_type, 1, QuantizationInfo(), data_layout); |
| 84 | CLTensor dst; |
| 85 | |
| 86 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 87 | |
| 88 | // Create and configure function |
| 89 | CLReorgLayer reorg_layer; |
| 90 | |
| 91 | // Auto-initialize the output within the function |
| 92 | reorg_layer.configure(&src, &dst, stride); |
| 93 | |
| 94 | // Validate valid region |
| 95 | const ValidRegion src_valid_region = shape_to_valid_region(shape_to_use); |
| 96 | const ValidRegion dst_valid_region = shape_to_valid_region(dst.info()->tensor_shape()); |
| 97 | validate(src.info()->valid_region(), src_valid_region); |
| 98 | validate(dst.info()->valid_region(), dst_valid_region); |
| 99 | |
| 100 | // Validate padding |
| 101 | const int step = 1; |
| 102 | const PaddingSize src_padding = PaddingCalculator(shape_to_use.x(), step).required_padding(); |
| 103 | const PaddingSize dst_padding = PaddingCalculator(dst.info()->tensor_shape().x(), step).required_padding(); |
| 104 | validate(src.info()->padding(), src_padding); |
| 105 | validate(dst.info()->padding(), dst_padding); |
| 106 | } |
| 107 | |
| 108 | template <typename T> |
| 109 | using CLReorgLayerFixture = ReorgLayerValidationFixture<CLTensor, CLAccessor, CLReorgLayer, T>; |
| 110 | |
| 111 | TEST_SUITE(S32) |
| 112 | FIXTURE_DATA_TEST_CASE(RunSmall, CLReorgLayerFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType", |
| 113 | DataType::S32)), |
| 114 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 115 | { |
| 116 | // Validate output |
| 117 | validate(CLAccessor(_target), _reference); |
| 118 | } |
| 119 | |
| 120 | FIXTURE_DATA_TEST_CASE(RunLarge, CLReorgLayerFixture<int32_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType", |
| 121 | DataType::S32)), |
| 122 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 123 | { |
| 124 | // Validate output |
| 125 | validate(CLAccessor(_target), _reference); |
| 126 | } |
| 127 | TEST_SUITE_END() // S32 |
| 128 | |
| 129 | TEST_SUITE(S16) |
| 130 | FIXTURE_DATA_TEST_CASE(RunSmall, CLReorgLayerFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType", |
| 131 | DataType::S16)), |
| 132 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 133 | { |
| 134 | // Validate output |
| 135 | validate(CLAccessor(_target), _reference); |
| 136 | } |
| 137 | |
| 138 | FIXTURE_DATA_TEST_CASE(RunLarge, CLReorgLayerFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType", |
| 139 | DataType::S16)), |
| 140 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 141 | { |
| 142 | // Validate output |
| 143 | validate(CLAccessor(_target), _reference); |
| 144 | } |
| 145 | TEST_SUITE_END() // S16 |
| 146 | |
| 147 | TEST_SUITE(S8) |
| 148 | FIXTURE_DATA_TEST_CASE(RunSmall, CLReorgLayerFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType", |
| 149 | DataType::S8)), |
| 150 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 151 | { |
| 152 | // Validate output |
| 153 | validate(CLAccessor(_target), _reference); |
| 154 | } |
| 155 | |
| 156 | FIXTURE_DATA_TEST_CASE(RunLarge, CLReorgLayerFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType", DataType::S8)), |
| 157 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
| 158 | { |
| 159 | // Validate output |
| 160 | validate(CLAccessor(_target), _reference); |
| 161 | } |
| 162 | TEST_SUITE_END() // S8 |
| 163 | |
| 164 | TEST_SUITE_END() // ReorgLayer |
| 165 | TEST_SUITE_END() // CL |
| 166 | } // namespace validation |
| 167 | } // namespace test |
| 168 | } // namespace arm_compute |