blob: 5a76315d77b12b853e118e08ef65b5279f79f5b1 [file] [log] [blame]
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +01001/*
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/Types.h"
25#include "arm_compute/runtime/NEON/functions/NEReorgLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
Gian Marco Iodice477531c2018-08-21 17:53:38 +010031#include "tests/datasets/ReorgLayerDataset.h"
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010032#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/ReorgLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44TEST_SUITE(NEON)
45TEST_SUITE(ReorgLayer)
46
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010047// *INDENT-OFF*
48// clang-format off
49DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Gian Marco Iodice477531c2018-08-21 17:53:38 +010050 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::S64), // Wrong output tensor
51 TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32),
52 TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32), // Wrong output tensor
53 TensorInfo(TensorShape(3U, 12U, 4U, 2U), 1, DataType::F32),
54 TensorInfo(TensorShape(3U, 12U, 4U, 2U), 1, DataType::F32), // Wrong data type
55 }),
56 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::S64),
57 TensorInfo(TensorShape(5U, 6U, 4U, 2U), 1, DataType::F32),
58 TensorInfo(TensorShape(5U, 6U, 2, 2U), 1, DataType::F32),
59 TensorInfo(TensorShape(1U, 4U, 36U, 2U), 1, DataType::F32),
60 TensorInfo(TensorShape(1U, 4U, 36U, 2U), 1, DataType::F16),
61 })),
62 framework::dataset::make("Stride", { 2, 2, 4, 3 })),
63 framework::dataset::make("Expected", { false, true, false, true, false })),
64 input_info, output_info, stride, expected)
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010065{
Gian Marco Iodice477531c2018-08-21 17:53:38 +010066 bool status = bool(NEReorgLayer::validate(&input_info, &output_info, stride));
67 ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010068}
69// clang-format on
70// *INDENT-ON*
71
Gian Marco Iodice477531c2018-08-21 17:53:38 +010072DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallReorgLayerDataset(), datasets::LargeReorgLayerDataset()),
73 framework::dataset::make("DataType", { DataType::F32, DataType::F16, DataType::QASYMM8 })),
74 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
75 shape, stride, data_type, data_layout)
76{
77 // Permute the tensor shape in case of NHWC data layout
78 TensorShape shape_to_use = shape;
79 if(data_layout == DataLayout::NHWC)
80 {
81 permute(shape_to_use, PermutationVector(2U, 0U, 1U));
82 }
83
84 // Create tensors
85 Tensor src = create_tensor<Tensor>(shape_to_use, data_type, 1, QuantizationInfo(), data_layout);
86 Tensor dst;
87
88 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
89
90 // Create and configure function
91 NEReorgLayer reorg_layer;
92
93 // Auto-initialize the output within the function
94 reorg_layer.configure(&src, &dst, stride);
95
96 // Validate valid region
97 const ValidRegion src_valid_region = shape_to_valid_region(shape_to_use);
98 const ValidRegion dst_valid_region = shape_to_valid_region(dst.info()->tensor_shape());
99 validate(src.info()->valid_region(), src_valid_region);
100 validate(dst.info()->valid_region(), dst_valid_region);
101
102 // Validate padding
103 const int step = 1;
104 const PaddingSize src_padding = PaddingCalculator(shape_to_use.x(), step).required_padding();
105 const PaddingSize dst_padding = PaddingCalculator(dst.info()->tensor_shape().x(), step).required_padding();
106 validate(src.info()->padding(), src_padding);
107 validate(dst.info()->padding(), dst_padding);
108}
109
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100110template <typename T>
111using NEReorgLayerFixture = ReorgLayerValidationFixture<Tensor, Accessor, NEReorgLayer, T>;
112
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100113TEST_SUITE(S32)
114FIXTURE_DATA_TEST_CASE(RunSmall, NEReorgLayerFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType",
115 DataType::S32)),
116 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100117{
118 // Validate output
119 validate(Accessor(_target), _reference);
120}
121
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100122FIXTURE_DATA_TEST_CASE(RunLarge, NEReorgLayerFixture<int32_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType",
123 DataType::S32)),
124 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100125{
126 // Validate output
127 validate(Accessor(_target), _reference);
128}
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100129TEST_SUITE_END() // S32
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100130
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100131TEST_SUITE(S16)
132FIXTURE_DATA_TEST_CASE(RunSmall, NEReorgLayerFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType",
133 DataType::S16)),
134 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100135{
136 // Validate output
137 validate(Accessor(_target), _reference);
138}
139
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100140FIXTURE_DATA_TEST_CASE(RunLarge, NEReorgLayerFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType",
141 DataType::S16)),
142 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100143{
144 // Validate output
145 validate(Accessor(_target), _reference);
146}
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100147TEST_SUITE_END() // S16
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100148
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100149TEST_SUITE(S8)
150FIXTURE_DATA_TEST_CASE(RunSmall, NEReorgLayerFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType",
151 DataType::S8)),
152 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100153{
154 // Validate output
155 validate(Accessor(_target), _reference);
156}
157
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100158FIXTURE_DATA_TEST_CASE(RunLarge, NEReorgLayerFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType", DataType::S8)),
159 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100160{
161 // Validate output
162 validate(Accessor(_target), _reference);
163}
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100164TEST_SUITE_END() // S8
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +0100165
166TEST_SUITE_END() // ReorgLayer
167TEST_SUITE_END() // NEON
168} // namespace validation
169} // namespace test
170} // namespace arm_compute