• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019-2020 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/runtime/CL/functions/CLFuseBatchNormalization.h"
25 #include "tests/CL/CLAccessor.h"
26 #include "tests/Globals.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 
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 AbsoluteTolerance<float> absolute_tolerance_f16(0.2f);
43 } // namespace
44 
45 template <typename T>
46 using CLFuseBatchNormalizationConvFixture = FuseBatchNormalizationFixture<CLTensor, CLAccessor, CLFuseBatchNormalization, 4, T>;
47 template <typename T>
48 using CLFuseBatchNormalizationDWCFixture = FuseBatchNormalizationFixture<CLTensor, CLAccessor, CLFuseBatchNormalization, 3, T>;
49 
50 // *INDENT-OFF*
51 // clang-format off
52 
53 /** Shapes to test - Precommit */
54 const auto shape_conv_values_precommit = concat(datasets::Small4DShapes(), datasets::Small3DShapes());
55 
56 /** Shapes to test - Nightly */
57 const auto shape_conv_values_nightly = concat(datasets::Large4DShapes(), datasets::Large3DShapes());
58 
59 /** Data layout to test */
60 const auto data_layout_values = framework::dataset::make("DataLayout", { DataLayout::NHWC, DataLayout::NCHW });
61 
62 /** In-place flags to test */
63 const auto in_place_values = framework::dataset::make("InPlace", { true, false });
64 
65 /** With bias flags to test */
66 const auto with_bias_values = framework::dataset::make("WithBias", { true, false });
67 
68 /** With gamma flags to test */
69 const auto with_gamma_values = framework::dataset::make("WithGamma", { true, false });
70 
71 /** With beta flags to test */
72 const auto with_beta_values = framework::dataset::make("WithBeta", { true, false });
73 
74 TEST_SUITE(CL)
TEST_SUITE(FuseBatchNormalization)75 TEST_SUITE(FuseBatchNormalization)
76 TEST_SUITE(Convolution)
77 TEST_SUITE(Float)
78 TEST_SUITE(FP32)
79 FIXTURE_DATA_TEST_CASE(RunSmall, CLFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::PRECOMMIT,
80                                         combine(combine(combine(combine(combine(combine(
81                                                         shape_conv_values_precommit,
82                                                         framework::dataset::make("DataType", { DataType::F32 })),
83                                                         data_layout_values),
84                                                         in_place_values),
85                                                         with_bias_values),
86                                                         with_gamma_values),
87                                                         with_beta_values))
88 {
89     // Validate outputs
90     validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f32);
91     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f32);
92 }
93 
94 FIXTURE_DATA_TEST_CASE(RunLarge, CLFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::NIGHTLY,
95                                         combine(combine(combine(combine(combine(combine(
96                                                         shape_conv_values_nightly,
97                                                         framework::dataset::make("DataType", { DataType::F32 })),
98                                                         data_layout_values),
99                                                         in_place_values),
100                                                         with_bias_values),
101                                                         with_gamma_values),
102                                                         with_beta_values))
103 {
104     // Validate outputs
105     validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f32);
106     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f32);
107 }
108 
109 TEST_SUITE_END() // FP32
110 
TEST_SUITE(FP16)111 TEST_SUITE(FP16)
112 FIXTURE_DATA_TEST_CASE(RunSmall, CLFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::PRECOMMIT,
113                                         combine(combine(combine(combine(combine(combine(
114                                                         shape_conv_values_precommit,
115                                                         framework::dataset::make("DataType", { DataType::F16 })),
116                                                         data_layout_values),
117                                                         in_place_values),
118                                                         with_bias_values),
119                                                         with_gamma_values),
120                                                         with_beta_values))
121 {
122     // Validate outputs
123     validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f16);
124     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f16);
125 }
126 
127 FIXTURE_DATA_TEST_CASE(RunLarge, CLFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::NIGHTLY,
128                                         combine(combine(combine(combine(combine(combine(
129                                                         shape_conv_values_nightly,
130                                                         framework::dataset::make("DataType", { DataType::F16 })),
131                                                         data_layout_values),
132                                                         in_place_values),
133                                                         with_bias_values),
134                                                         with_gamma_values),
135                                                         with_beta_values))
136 {
137     // Validate outputs
138     validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f16);
139     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f16);
140 }
141 
142 TEST_SUITE_END() // FP16
TEST_SUITE_END()143 TEST_SUITE_END() // Float
144 TEST_SUITE_END() // Convolution
145 
146 TEST_SUITE(DepthwiseConvolution)
147 TEST_SUITE(Float)
148 TEST_SUITE(FP32)
149 FIXTURE_DATA_TEST_CASE(RunSmall, CLFuseBatchNormalizationDWCFixture<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(CLAccessor(_target_w), _reference_w, absolute_tolerance_f32);
161     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f32);
162 }
163 
164 FIXTURE_DATA_TEST_CASE(RunLarge, CLFuseBatchNormalizationDWCFixture<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(CLAccessor(_target_w), _reference_w, absolute_tolerance_f32);
176     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f32);
177 }
178 
179 TEST_SUITE_END() // FP32
180 
TEST_SUITE(FP16)181 TEST_SUITE(FP16)
182 FIXTURE_DATA_TEST_CASE(RunSmall, CLFuseBatchNormalizationDWCFixture<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(CLAccessor(_target_w), _reference_w, absolute_tolerance_f16);
194     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f16);
195 }
196 
197 FIXTURE_DATA_TEST_CASE(RunLarge, CLFuseBatchNormalizationDWCFixture<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(CLAccessor(_target_w), _reference_w, absolute_tolerance_f16);
209     validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f16);
210 }
211 
212 TEST_SUITE_END() // FP16
213 TEST_SUITE_END() // Float
214 TEST_SUITE_END() // DepthwiseConvolution
215 
216 TEST_SUITE_END() // FuseBatchNormalization
217 TEST_SUITE_END() // CL
218 } // namespace validation
219 } // namespace test
220 } // namespace arm_compute