blob: 62265c6ac9b75aef28068af137a0aad5b00667fb [file] [log] [blame]
Manuel Bottini11091762019-06-17 12:04:40 +01001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2019-2021 Arm Limited.
Manuel Bottini11091762019-06-17 12:04:40 +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/runtime/NEON/functions/NEFuseBatchNormalization.h"
25#include "tests/Globals.h"
26#include "tests/NEON/Accessor.h"
27#include "tests/datasets/ShapeDatasets.h"
28#include "tests/framework/Macros.h"
29#include "tests/framework/datasets/Datasets.h"
30#include "tests/validation/Validation.h"
31#include "tests/validation/fixtures/FuseBatchNormalizationFixture.h"
32
33namespace arm_compute
34{
35namespace test
36{
37namespace validation
38{
39namespace
40{
41AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
42#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
43AbsoluteTolerance<float> absolute_tolerance_f16(0.2f);
44#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
45} // namespace
46
47template <typename T>
48using NEFuseBatchNormalizationConvFixture = FuseBatchNormalizationFixture<Tensor, Accessor, NEFuseBatchNormalization, 4, T>;
49template <typename T>
50using NEFuseBatchNormalizationDWCFixture = FuseBatchNormalizationFixture<Tensor, Accessor, NEFuseBatchNormalization, 3, T>;
51
52// *INDENT-OFF*
53// clang-format off
54
55/** Shapes to test - Precommit */
56const auto shape_conv_values_precommit = concat(datasets::Small4DShapes(), datasets::Small3DShapes());
57
58/** Shapes to test - Nightly */
59const auto shape_conv_values_nightly = concat(datasets::Large4DShapes(), datasets::Large3DShapes());
60
61/** Data layout to test */
62const auto data_layout_values = framework::dataset::make("DataLayout", { DataLayout::NHWC, DataLayout::NCHW });
63
64/** In-place flags to test */
65const auto in_place_values = framework::dataset::make("InPlace", { true, false });
66
67/** With bias flags to test */
68const auto with_bias_values = framework::dataset::make("WithBias", { true, false });
69
70/** With gamma flags to test */
71const auto with_gamma_values = framework::dataset::make("WithGamma", { true, false });
72
73/** With beta flags to test */
74const auto with_beta_values = framework::dataset::make("WithBeta", { true, false });
75
76TEST_SUITE(NEON)
77TEST_SUITE(FuseBatchNormalization)
78TEST_SUITE(Convolution)
79TEST_SUITE(Float)
80TEST_SUITE(FP32)
81FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::PRECOMMIT,
82 combine(combine(combine(combine(combine(combine(
83 shape_conv_values_precommit,
84 framework::dataset::make("DataType", { DataType::F32 })),
85 data_layout_values),
86 in_place_values),
87 with_bias_values),
88 with_gamma_values),
89 with_beta_values))
90{
91 // Validate outputs
92 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
93 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
94}
95
96FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::NIGHTLY,
97 combine(combine(combine(combine(combine(combine(
98 shape_conv_values_nightly,
99 framework::dataset::make("DataType", { DataType::F32 })),
100 data_layout_values),
101 in_place_values),
102 with_bias_values),
103 with_gamma_values),
104 with_beta_values))
105{
106 // Validate outputs
107 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
108 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
109}
110TEST_SUITE_END() // FP32
111#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
112TEST_SUITE(FP16)
113FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::PRECOMMIT,
114 combine(combine(combine(combine(combine(combine(
115 shape_conv_values_precommit,
116 framework::dataset::make("DataType", { DataType::F16 })),
117 data_layout_values),
118 in_place_values),
119 with_bias_values),
120 with_gamma_values),
121 with_beta_values))
122{
123 // Validate outputs
124 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
125 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
126}
127
128FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::NIGHTLY,
129 combine(combine(combine(combine(combine(combine(
130 shape_conv_values_nightly,
131 framework::dataset::make("DataType", { DataType::F16 })),
132 data_layout_values),
133 in_place_values),
134 with_bias_values),
135 with_gamma_values),
136 with_beta_values))
137{
138 // Validate outputs
139 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
140 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
141}
142TEST_SUITE_END() // FP16
143#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
144TEST_SUITE_END() // Float
145TEST_SUITE_END() // Convolution
146TEST_SUITE(DepthwiseConvolution)
147TEST_SUITE(Float)
148TEST_SUITE(FP32)
149FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationDWCFixture<float>, framework::DatasetMode::PRECOMMIT,
150 combine(combine(combine(combine(combine(combine(
151 datasets::Small3DShapes(),
152 framework::dataset::make("DataType", { DataType::F32 })),
153 data_layout_values),
154 in_place_values),
155 with_bias_values),
156 with_gamma_values),
157 with_beta_values))
158{
159 // Validate outputs
160 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
161 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
162}
163
164FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationDWCFixture<float>, framework::DatasetMode::NIGHTLY,
165 combine(combine(combine(combine(combine(combine(
166 datasets::Large3DShapes(),
167 framework::dataset::make("DataType", { DataType::F32 })),
168 data_layout_values),
169 in_place_values),
170 with_bias_values),
171 with_gamma_values),
172 with_beta_values))
173{
174 // Validate outputs
175 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
176 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
177}
178
179TEST_SUITE_END() // FP32
180#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
181TEST_SUITE(FP16)
182FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationDWCFixture<half>, framework::DatasetMode::PRECOMMIT,
183 combine(combine(combine(combine(combine(combine(
184 datasets::Small3DShapes(),
185 framework::dataset::make("DataType", { DataType::F16 })),
186 data_layout_values),
187 in_place_values),
188 with_bias_values),
189 with_gamma_values),
190 with_beta_values))
191{
192 // Validate outputs
193 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
194 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
195}
196
197FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationDWCFixture<half>, framework::DatasetMode::NIGHTLY,
198 combine(combine(combine(combine(combine(combine(
199 datasets::Large3DShapes(),
200 framework::dataset::make("DataType", { DataType::F16 })),
201 data_layout_values),
202 in_place_values),
203 with_bias_values),
204 with_gamma_values),
205 with_beta_values))
206{
207 // Validate outputs
208 validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
209 validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
210}
211
212TEST_SUITE_END() // FP16
213#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
214TEST_SUITE_END() // Float
215TEST_SUITE_END() // DepthwiseConvolution
216TEST_SUITE_END() // FuseBatchNormalization
Sheri Zhangac6499a2021-02-10 15:32:38 +0000217TEST_SUITE_END() // Neon
Manuel Bottini11091762019-06-17 12:04:40 +0100218} // namespace validation
219} // namespace test
Sheri Zhangac6499a2021-02-10 15:32:38 +0000220} // namespace arm_compute