aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/NEON/FuseBatchNormalization.cpp
blob: 9fc3353aaf72f9084b192d37271261c0504e6d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 * Copyright (c) 2019 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include "arm_compute/runtime/NEON/functions/NEFuseBatchNormalization.h"
#include "tests/Globals.h"
#include "tests/NEON/Accessor.h"
#include "tests/datasets/ShapeDatasets.h"
#include "tests/framework/Macros.h"
#include "tests/framework/datasets/Datasets.h"
#include "tests/validation/Validation.h"
#include "tests/validation/fixtures/FuseBatchNormalizationFixture.h"

namespace arm_compute
{
namespace test
{
namespace validation
{
namespace
{
AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
AbsoluteTolerance<float> absolute_tolerance_f16(0.2f);
#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
} // namespace

template <typename T>
using NEFuseBatchNormalizationConvFixture = FuseBatchNormalizationFixture<Tensor, Accessor, NEFuseBatchNormalization, 4, T>;
template <typename T>
using NEFuseBatchNormalizationDWCFixture = FuseBatchNormalizationFixture<Tensor, Accessor, NEFuseBatchNormalization, 3, T>;

// *INDENT-OFF*
// clang-format off

/** Shapes to test - Precommit */
const auto shape_conv_values_precommit = concat(datasets::Small4DShapes(), datasets::Small3DShapes());

/** Shapes to test - Nightly */
const auto shape_conv_values_nightly = concat(datasets::Large4DShapes(), datasets::Large3DShapes());

/** Data layout to test */
const auto data_layout_values = framework::dataset::make("DataLayout", { DataLayout::NHWC, DataLayout::NCHW });

/** In-place flags to test */
const auto in_place_values = framework::dataset::make("InPlace", { true, false });

/** With bias flags to test */
const auto with_bias_values = framework::dataset::make("WithBias", { true, false });

/** With gamma flags to test */
const auto with_gamma_values = framework::dataset::make("WithGamma", { true, false });

/** With beta flags to test */
const auto with_beta_values = framework::dataset::make("WithBeta", { true, false });

TEST_SUITE(NEON)
TEST_SUITE(FuseBatchNormalization)
TEST_SUITE(Convolution)
TEST_SUITE(Float)
TEST_SUITE(FP32)
FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::PRECOMMIT,
                                        combine(combine(combine(combine(combine(combine(
                                                        shape_conv_values_precommit,
                                                        framework::dataset::make("DataType", { DataType::F32 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
}

FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::NIGHTLY,
                                        combine(combine(combine(combine(combine(combine(
                                                        shape_conv_values_nightly,
                                                        framework::dataset::make("DataType", { DataType::F32 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
}
TEST_SUITE_END() // FP32
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
TEST_SUITE(FP16)
FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::PRECOMMIT,
                                        combine(combine(combine(combine(combine(combine(
                                                        shape_conv_values_precommit,
                                                        framework::dataset::make("DataType", { DataType::F16 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
}

FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::NIGHTLY,
                                        combine(combine(combine(combine(combine(combine(
                                                        shape_conv_values_nightly,
                                                        framework::dataset::make("DataType", { DataType::F16 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
}
TEST_SUITE_END() // FP16
#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
TEST_SUITE_END() // Float
TEST_SUITE_END() // Convolution
TEST_SUITE(DepthwiseConvolution)
TEST_SUITE(Float)
TEST_SUITE(FP32)
FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationDWCFixture<float>, framework::DatasetMode::PRECOMMIT,
                                        combine(combine(combine(combine(combine(combine(
                                                        datasets::Small3DShapes(),
                                                        framework::dataset::make("DataType", { DataType::F32 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
}

FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationDWCFixture<float>, framework::DatasetMode::NIGHTLY,
                                        combine(combine(combine(combine(combine(combine(
                                                        datasets::Large3DShapes(),
                                                        framework::dataset::make("DataType", { DataType::F32 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f32);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f32);
}

TEST_SUITE_END() // FP32
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
TEST_SUITE(FP16)
FIXTURE_DATA_TEST_CASE(RunSmall, NEFuseBatchNormalizationDWCFixture<half>, framework::DatasetMode::PRECOMMIT,
                                        combine(combine(combine(combine(combine(combine(
                                                        datasets::Small3DShapes(),
                                                        framework::dataset::make("DataType", { DataType::F16 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
}

FIXTURE_DATA_TEST_CASE(RunLarge, NEFuseBatchNormalizationDWCFixture<half>, framework::DatasetMode::NIGHTLY,
                                        combine(combine(combine(combine(combine(combine(
                                                        datasets::Large3DShapes(),
                                                        framework::dataset::make("DataType", { DataType::F16 })),
                                                        data_layout_values),
                                                        in_place_values),
                                                        with_bias_values),
                                                        with_gamma_values),
                                                        with_beta_values))
{
    // Validate outputs
    validate(Accessor(_target_w), _reference_w, absolute_tolerance_f16);
    validate(Accessor(_target_b), _reference_b, absolute_tolerance_f16);
}

TEST_SUITE_END() // FP16
#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
TEST_SUITE_END() // Float
TEST_SUITE_END() // DepthwiseConvolution
TEST_SUITE_END() // FuseBatchNormalization
TEST_SUITE_END() // NEON
} // namespace validation
} // namespace test
} // namespace arm_compute