blob: 3d037405993fd3c04e6979a8e05c88ea7861c80c [file] [log] [blame]
Gian Marco Iodice477531c2018-08-21 17:53:38 +01001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2018-2019 ARM Limited.
Gian Marco Iodice477531c2018-08-21 17:53:38 +01003 *
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
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42TEST_SUITE(CL)
43TEST_SUITE(ReorgLayer)
44
45// *INDENT-OFF*
46// clang-format off
47DATA_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 Spyrou80943252019-01-10 17:19:50 +000070DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallReorgLayerDataset(),
Gian Marco Iodice477531c2018-08-21 17:53:38 +010071 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
108template <typename T>
109using CLReorgLayerFixture = ReorgLayerValidationFixture<CLTensor, CLAccessor, CLReorgLayer, T>;
110
111TEST_SUITE(S32)
112FIXTURE_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
120FIXTURE_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}
127TEST_SUITE_END() // S32
128
129TEST_SUITE(S16)
130FIXTURE_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
138FIXTURE_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}
145TEST_SUITE_END() // S16
146
147TEST_SUITE(S8)
148FIXTURE_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
156FIXTURE_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}
162TEST_SUITE_END() // S8
163
164TEST_SUITE_END() // ReorgLayer
165TEST_SUITE_END() // CL
166} // namespace validation
167} // namespace test
168} // namespace arm_compute