Compute Library
 22.11
PadLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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  */
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/Globals.h"
30 #include "tests/datasets/ShapeDatasets.h"
31 #include "tests/framework/Macros.h"
34 #include "tests/validation/fixtures/PadLayerFixture.h"
35 #include "utils/TypePrinter.h"
36 
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 namespace
44 {
45 const auto PaddingSizesDataset3D = framework::dataset::make("PaddingSize",
46 {
47  PaddingList{ { 0, 0 } },
48  PaddingList{ { 1, 1 } },
49  PaddingList{ { 33, 33 } },
50  PaddingList{ { 1, 1 }, { 5, 5 } },
51  PaddingList{ { 1, 1 }, { 1, 1 }, { 5, 5 } },
52  PaddingList{ { 0, 0 }, { 1, 0 }, { 0, 1 } },
53  PaddingList{ { 0, 0 }, { 0, 0 }, { 0, 0 } }
54 });
55 const auto PaddingSizesDataset4D = framework::dataset::make("PaddingSize",
56 {
57  PaddingList{ { 1, 1 }, { 1, 0 }, { 1, 1 }, { 0, 0 } },
58  PaddingList{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 1, 1 } },
59  PaddingList{ { 0, 1 }, { 1, 0 }, { 2, 2 }, { 1, 0 } },
60  PaddingList{ { 1, 1 }, { 1, 1 }, { 1, 1 }, { 3, 3 } }
61 });
62 } // namespace
63 
64 TEST_SUITE(CL)
65 TEST_SUITE(PadLayer)
66 
67 // *INDENT-OFF*
68 // clang-format off
69 
70 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
71  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/output
72  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes with padding
73  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
74  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid number of pad dimensions
75  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes dimension
76  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
77  TensorInfo(TensorShape(32U, 13U), 1, DataType::F32) // Invalid padding list
78  }),
79  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
80  TensorInfo(TensorShape(28U, 11U, 2U), 1, DataType::F32),
81  TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32),
82  TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32),
83  TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32),
84  TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32),
86  })),
87  framework::dataset::make("PaddingSize", { PaddingList{{0, 0}},
88  PaddingList{{1, 1}},
89  PaddingList{{1, 1}, {2, 2}},
90  PaddingList{{1,1}, {1,1}, {1,1}, {1,1}},
91  PaddingList{{1,1}, {1,1}, {1,1}},
92  PaddingList{{1, 1}, {2, 2}},
93  PaddingList{{0,0}, {0,0}, {1,1}}
94  })),
101  PaddingMode::REFLECT
102  })),
103  framework::dataset::make("Expected", { false,
104  false,
105  true,
106  false,
107  false,
108  true,
109  false })),
110  input_info, output_info, padding, mode, expected)
111 {
112  ARM_COMPUTE_EXPECT(bool(CLPadLayer::validate(&input_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), padding, PixelValue(), mode)) == expected, framework::LogLevel::ERRORS);
113 }
114 
115 DATA_TEST_CASE(CheckFusingWithConvolution, framework::DatasetMode::ALL, zip(zip(
132  }),
133  framework::dataset::make("PaddingList", { PaddingList({{0, 0}, {1, 1}, {1, 1}}), // nchw
134  PaddingList({{1, 1}, {1, 1}, {0, 0}, {0, 0}}),
135  PaddingList({{1, 1}, {1, 1}}),
136  PaddingList({}),
137  PaddingList({{0, 0}}),
138  PaddingList({{0, 0}, {0, 0}, {0, 0}, {0, 0}}),
139  PaddingList({{0, 0}, {0, 0}, {0, 0}, {1, 0}}),
140  PaddingList({{0, 1}}),
141  PaddingList({{0, 0}, {1, 1}, {1, 1}}), // nhwc
142  PaddingList({{0, 0}, {0, 0}, {1, 1}, {1, 1}}),
143  PaddingList({{0, 0}, {1, 0}, {1, 1}, {0, 0}}),
144  PaddingList({}),
145  PaddingList({{0, 0}}),
146  PaddingList({{0, 1}}),
147  PaddingList({{0, 0}, {1, 1}}),
148  PaddingList({{0, 0}})
149  })), // unknown
150  framework::dataset::make("Expected", { false, // nchw
151  true,
152  true,
153  true,
154  true,
155  true,
156  false,
157  true,
158  true, // nhwc
159  false,
160  true,
161  true,
162  true,
163  false,
164  true,
165  false // unknown
166  })),
167  data_layout, padding_list, expected)
168 {
170 }
171 
172 // clang-format on
173 // *INDENT-ON*
174 
175 template <typename T>
176 using CLPaddingFixture = PaddingFixture<CLTensor, CLAccessor, CLPadLayer, T>;
177 
178 TEST_SUITE(Float)
179 
180 TEST_SUITE(FP32)
181 FIXTURE_DATA_TEST_CASE(RunSmall, CLPaddingFixture<float>, framework::DatasetMode::ALL,
182  combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::F32 })), PaddingSizesDataset3D),
184 {
185  // Validate output
186  validate(CLAccessor(_target), _reference);
187 }
189  combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", { DataType::F32 })), PaddingSizesDataset4D),
190  framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT })))
191 {
192  // Validate output
193  validate(CLAccessor(_target), _reference);
194 }
196  combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::F32 })), PaddingSizesDataset3D),
198 {
199  // Validate output
200  validate(CLAccessor(_target), _reference);
201 }
202 TEST_SUITE_END() // FP32
203 
204 TEST_SUITE(FP16)
205 FIXTURE_DATA_TEST_CASE(RunLarge, CLPaddingFixture<half>, framework::DatasetMode::NIGHTLY,
206  combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::F16 })), PaddingSizesDataset3D),
208 {
209  // Validate output
210  validate(CLAccessor(_target), _reference);
211 }
212 TEST_SUITE_END() // FP16
213 TEST_SUITE_END() // Float
214 
215 TEST_SUITE(Quantized)
217 FIXTURE_DATA_TEST_CASE(RunSmall, CLPaddingFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
218  combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })), PaddingSizesDataset3D),
220 {
221  // Validate output
222  validate(CLAccessor(_target), _reference);
223 }
225  combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })), PaddingSizesDataset4D),
226  framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT })))
227 {
228  // Validate output
229  validate(CLAccessor(_target), _reference);
230 }
232  combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })), PaddingSizesDataset3D),
234 {
235  // Validate output
236  validate(CLAccessor(_target), _reference);
237 }
238 TEST_SUITE_END() // QASYMM8
239 
241 FIXTURE_DATA_TEST_CASE(RunSmall, CLPaddingFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
242  combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })), PaddingSizesDataset3D),
244 {
245  // Validate output
246  validate(CLAccessor(_target), _reference);
247 }
248 TEST_SUITE_END() // QASYMM8_SIGNED
249 
250 TEST_SUITE_END() // Quantized
251 
252 TEST_SUITE_END() // PadLayer
253 TEST_SUITE_END() // CL
254 } // namespace validation
255 } // namespace test
256 } // namespace arm_compute
bool is_padding_in_height_or_width(const DataLayout &layout, const PaddingList &padding_list)
Check if padding is in height and/or width dimensions.
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
Shape of a tensor.
Definition: TensorShape.h:39
std::vector< PaddingInfo > PaddingList
List of padding information.
Definition: Types.h:453
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
Static function to check if given info will lead to a valid configuration of CLPadLayer.
Definition: CLPadLayer.cpp:65
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
Accessor implementation for CLTensor objects.
Definition: CLAccessor.h:36
validate(CLAccessor(output_state), expected_output)
Num samples, channels, height, width.
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Num samples, height, width, channels.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
quantized, asymmetric fixed-point 8-bit number signed
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
PaddingFixture< CLTensor, CLAccessor, CLPadLayer, T > CLPaddingFixture
Definition: PadLayer.cpp:176