blob: 00ed1fa820ff28277c628e0d451b49b6ff581323 [file] [log] [blame]
Michalis Spyrou16934a52018-08-21 18:03:58 +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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLSpaceToBatchLayer.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ShapeDatasets.h"
31#include "tests/datasets/SpaceToBatchDataset.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/SpaceToBatchFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45TEST_SUITE(CL)
46TEST_SUITE(SpaceToBatchLayer)
47
48template <typename T>
49using CLSpaceToBatchLayerFixture = SpaceToBatchLayerValidationFixture<CLTensor, CLAccessor, CLSpaceToBatchLayer, T>;
50
51DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallSpaceToBatchLayerDataset(),
52 framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
53 input_shape, block_shape_shape, paddings_shape, output_shape, dt)
54{
55 // Create tensors
56 CLTensor src = create_tensor<CLTensor>(input_shape, dt, 1);
57 CLTensor dst = create_tensor<CLTensor>(output_shape, dt, 1);
58 CLTensor block_shape = create_tensor<CLTensor>(block_shape_shape, DataType::S32, 1);
59 CLTensor paddings = create_tensor<CLTensor>(paddings_shape, DataType::S32, 1);
60
61 // Create and Configure function
62 CLSpaceToBatchLayer batch_to_space;
63 batch_to_space.configure(&src, &block_shape, &paddings, &dst);
64
65 // Validate valid region
66 const ValidRegion valid_region = shape_to_valid_region(output_shape);
67 validate(dst.info()->valid_region(), valid_region);
68}
69
70// *INDENT-OFF*
71// clang-format off
72DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
73 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), // Mismatching data types
75 TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), // Wrong data type block shape
76 TensorInfo(TensorShape(32U, 13U, 2U, 2U, 4U), 1, DataType::F32), // Wrong tensor shape
77 }),
Isabella Gottardicc6129c2018-12-14 11:40:40 +000078 framework::dataset::make("BlockShapeInfo",{ TensorInfo(TensorShape(2U), 1, DataType::S32),
79 TensorInfo(TensorShape(2U), 1, DataType::S32),
80 TensorInfo(TensorShape(2U), 1, DataType::F16),
81 TensorInfo(TensorShape(2U), 1, DataType::S32),
Michalis Spyrou16934a52018-08-21 18:03:58 +010082 })),
83 framework::dataset::make("PaddingsShapeInfo",{ TensorInfo(TensorShape(2U, 2U), 1, DataType::S32),
84 TensorInfo(TensorShape(2U, 2U), 1, DataType::S32),
85 TensorInfo(TensorShape(2U, 2U), 1, DataType::F16),
86 TensorInfo(TensorShape(2U, 2U), 1, DataType::S32),
87 })),
88 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32),
89 TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F16),
90 TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32),
91 TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32),
92 })),
93 framework::dataset::make("Expected", { true, false, false, false})),
94 input_info, block_shape_info, paddings_info, output_info, expected)
95{
96 bool has_error = bool(CLSpaceToBatchLayer::validate(&input_info.clone()->set_is_resizable(false), &block_shape_info.clone()->set_is_resizable(false), &paddings_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false)));
97 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
98}
99DATA_TEST_CASE(ValidateStatic, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
100 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32),
101 TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32), // Mismatching data types
102 TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32), // Negative block shapes
103 TensorInfo(TensorShape(32U, 16U, 2U, 1U, 4U), 1, DataType::F32), // Wrong tensor shape
104 TensorInfo(TensorShape(32U, 16U, 2U, 1U, 4U), 1, DataType::F32), // Wrong paddings
105 }),
106 framework::dataset::make("BlockShapeX", { 2, 2, 2, 2, 2 })),
107 framework::dataset::make("BlockShapeY", { 2, 2, -2, 2, 2 })),
108 framework::dataset::make("PadLeft", { Size2D(0, 0), Size2D(0, 0), Size2D(0, 0), Size2D(0, 0), Size2D(3, 11) })),
109 framework::dataset::make("PadRight", { Size2D(0, 0), Size2D(0, 0), Size2D(0, 0), Size2D(0, 0), Size2D(3, 11) })),
110 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(16U, 8U, 2U, 4U), 1, DataType::F32),
111 TensorInfo(TensorShape(32U, 8U, 2U, 4U), 1, DataType::F16),
112 TensorInfo(TensorShape(32U, 8U, 2U, 4U), 1, DataType::F32),
113 TensorInfo(TensorShape(32U, 8U, 2U, 4U), 1, DataType::F32),
114 TensorInfo(TensorShape(32U, 8U, 2U, 4U), 1, DataType::F32),
115 })),
116 framework::dataset::make("Expected", { true, false, false, false, false})),
117 input_info, block_shape_x, block_shape_y, padding_left, padding_right, output_info, expected)
118{
119 bool has_error = bool(CLSpaceToBatchLayer::validate(&input_info.clone()->set_is_resizable(false), block_shape_x, block_shape_y, padding_left, padding_right, &output_info.clone()->set_is_resizable(false)));
120 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
121}
122// clang-format on
123// *INDENT-ON*
124
125TEST_SUITE(Float)
126TEST_SUITE(FP32)
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100127FIXTURE_DATA_TEST_CASE(Small, CLSpaceToBatchLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallSpaceToBatchLayerDataset(), framework::dataset::make("DataType",
128 DataType::F32)),
129 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Michalis Spyrou16934a52018-08-21 18:03:58 +0100130{
131 // Validate output
132 validate(CLAccessor(_target), _reference);
133}
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100134FIXTURE_DATA_TEST_CASE(Large, CLSpaceToBatchLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeSpaceToBatchLayerDataset(), framework::dataset::make("DataType",
135 DataType::F32)),
136 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Michalis Spyrou16934a52018-08-21 18:03:58 +0100137{
138 // Validate output
139 validate(CLAccessor(_target), _reference);
140}
141TEST_SUITE_END() // FP32
142
143TEST_SUITE(FP16)
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100144FIXTURE_DATA_TEST_CASE(Small, CLSpaceToBatchLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallSpaceToBatchLayerDataset(), framework::dataset::make("DataType",
145 DataType::F16)),
146 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Michalis Spyrou16934a52018-08-21 18:03:58 +0100147{
148 // Validate output
149 validate(CLAccessor(_target), _reference);
150}
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100151FIXTURE_DATA_TEST_CASE(Large, CLSpaceToBatchLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeSpaceToBatchLayerDataset(), framework::dataset::make("DataType",
152 DataType::F16)),
153 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Michalis Spyrou16934a52018-08-21 18:03:58 +0100154{
155 // Validate output
156 validate(CLAccessor(_target), _reference);
157}
158TEST_SUITE_END() // FP16
159TEST_SUITE_END() // Float
160
161TEST_SUITE_END() // SpaceToBatch
162TEST_SUITE_END() // CL
163} // namespace validation
164} // namespace test
165} // namespace arm_compute