Compute Library
 22.11
FuseBatchNormalization.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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  */
25 #include "tests/Globals.h"
26 #include "tests/NEON/Accessor.h"
27 #include "tests/datasets/ShapeDatasets.h"
28 #include "tests/framework/Macros.h"
31 #include "tests/validation/fixtures/FuseBatchNormalizationFixture.h"
32 
33 namespace arm_compute
34 {
35 namespace test
36 {
37 namespace validation
38 {
39 namespace
40 {
41 AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
42 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
43 AbsoluteTolerance<float> absolute_tolerance_f16(0.2f);
44 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
45 } // namespace
46 
47 template <typename T>
48 using NEFuseBatchNormalizationConvFixture = FuseBatchNormalizationFixture<Tensor, Accessor, NEFuseBatchNormalization, 4, T>;
49 template <typename T>
50 using NEFuseBatchNormalizationDWCFixture = FuseBatchNormalizationFixture<Tensor, Accessor, NEFuseBatchNormalization, 3, T>;
51 
52 // *INDENT-OFF*
53 // clang-format off
54 
55 /** Shapes to test - Precommit */
56 const auto shape_conv_values_precommit = concat(datasets::Small4DShapes(), datasets::Small3DShapes());
57 
58 /** Shapes to test - Nightly */
59 const auto shape_conv_values_nightly = concat(datasets::Large4DShapes(), datasets::Large3DShapes());
60 
61 /** Data layout to test */
63 
64 /** In-place flags to test */
65 const auto in_place_values = framework::dataset::make("InPlace", { true, false });
66 
67 /** With bias flags to test */
68 const auto with_bias_values = framework::dataset::make("WithBias", { true, false });
69 
70 /** With gamma flags to test */
71 const auto with_gamma_values = framework::dataset::make("WithGamma", { true, false });
72 
73 /** With beta flags to test */
74 const auto with_beta_values = framework::dataset::make("WithBeta", { true, false });
75 
76 TEST_SUITE(NEON)
77 TEST_SUITE(FuseBatchNormalization)
78 TEST_SUITE(Convolution)
79 TEST_SUITE(Float)
80 TEST_SUITE(FP32)
84  framework::dataset::make("DataType", { DataType::F32 })),
86  in_place_values),
88  with_gamma_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 
99  framework::dataset::make("DataType", { DataType::F32 })),
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 }
110 TEST_SUITE_END() // FP32
111 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
112 TEST_SUITE(FP16)
116  framework::dataset::make("DataType", { DataType::F16 })),
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 
131  framework::dataset::make("DataType", { DataType::F16 })),
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 }
142 TEST_SUITE_END() // FP16
143 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
144 TEST_SUITE_END() // Float
145 TEST_SUITE_END() // Convolution
146 TEST_SUITE(DepthwiseConvolution)
147 TEST_SUITE(Float)
148 TEST_SUITE(FP32)
151  datasets::Small3DShapes(),
152  framework::dataset::make("DataType", { DataType::F32 })),
154  in_place_values),
156  with_gamma_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 
166  datasets::Large3DShapes(),
167  framework::dataset::make("DataType", { DataType::F32 })),
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 
179 TEST_SUITE_END() // FP32
180 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
181 TEST_SUITE(FP16)
184  datasets::Small3DShapes(),
185  framework::dataset::make("DataType", { DataType::F16 })),
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 
199  datasets::Large3DShapes(),
200  framework::dataset::make("DataType", { DataType::F16 })),
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 
212 TEST_SUITE_END() // FP16
213 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
214 TEST_SUITE_END() // Float
215 TEST_SUITE_END() // DepthwiseConvolution
216 TEST_SUITE_END() // FuseBatchNormalization
217 TEST_SUITE_END() // Neon
218 } // namespace validation
219 } // namespace test
220 } // namespace arm_compute
const auto shape_conv_values_nightly
Shapes to test - Nightly.
FuseBatchNormalizationFixture< Tensor, Accessor, NEFuseBatchNormalization, 4, T > NEFuseBatchNormalizationConvFixture
const auto in_place_values
In-place flags to test.
FuseBatchNormalizationFixture< Tensor, Accessor, NEFuseBatchNormalization, 3, T > NEFuseBatchNormalizationDWCFixture
1 channel, 1 F32 per channel
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Copyright (c) 2017-2022 Arm Limited.
const auto shape_conv_values_precommit
Shapes to test - Precommit.
1 channel, 1 F16 per channel
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
const auto with_bias_values
With bias flags to test.
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
validate(CLAccessor(output_state), expected_output)
const auto with_gamma_values
With gamma flags to test.
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
const auto with_beta_values
With beta flags to test.
Num samples, height, width, channels.
JoinDataset< T, U > concat(T &&dataset1, U &&dataset2)
Helper function to create a JoinDataset.
Definition: JoinDataset.h:160
const auto data_layout_values
Data layout to test.
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