blob: 22ca96423a51f429f71d9ae1c4d1f6229b8badf4 [file] [log] [blame]
Michele Di Giorgio6c928342017-06-22 16:55:57 +01001/*
2 * Copyright (c) 2017 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/core/Types.h"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLNormalizationLayer.h"
28#include "framework/Asserts.h"
29#include "framework/Macros.h"
30#include "framework/datasets/Datasets.h"
31#include "tests/CL/CLAccessor.h"
32#include "tests/PaddingCalculator.h"
33#include "tests/datasets_new/NormalizationTypesDataset.h"
34#include "tests/datasets_new/ShapeDatasets.h"
35#include "tests/validation_new/Validation.h"
36#include "tests/validation_new/fixtures/NormalizationLayerFixture.h"
37#include "tests/validation_new/half.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47/** Tolerance for float operations */
48#ifdef ARM_COMPUTE_ENABLE_FP16
49constexpr float tolerance_f16 = 0.001f;
50#endif /* ARM_COMPUTE_ENABLE_FP16 */
51constexpr float tolerance_f32 = 0.00001f;
52/** Tolerance for fixed point operations */
53constexpr int8_t tolerance_qs8 = 2;
54constexpr int16_t tolerance_qs16 = 2;
55
56/** Input data set. */
57const auto NormalizationDataset = combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("NormType", { NormType::IN_MAP_1D, NormType::CROSS_MAP })),
58 framework::dataset::make("NormalizationSize", 3, 9, 2)),
59 framework::dataset::make("Beta", { 0.5f, 1.f, 2.f }));
60} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(NormalizationLayer)
64
65//TODO(COMPMID-415): Missing configuration?
66
67template <typename T>
68using CLNormalizationLayerFixture = NormalizationValidationFixture<CLTensor, CLAccessor, CLNormalizationLayer, T>;
69
70TEST_SUITE(Float)
71#ifdef ARM_COMPUTE_ENABLE_FP16
72TEST_SUITE(FP16)
73FIXTURE_DATA_TEST_CASE(RunSmall, CLNormalizationLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(NormalizationDataset, framework::dataset::make("DataType", DataType::F16)))
74{
75 // Validate output
76 validate(CLAccessor(_target), _reference, tolerance_f16);
77}
78FIXTURE_DATA_TEST_CASE(RunLarge, CLNormalizationLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(NormalizationDataset, framework::dataset::make("DataType", DataType::F16)))
79{
80 // Validate output
81 validate(CLAccessor(_target), _reference, tolerance_f16);
82}
83TEST_SUITE_END()
84#endif /* ARM_COMPUTE_ENABLE_FP16 */
85
86TEST_SUITE(FP32)
87FIXTURE_DATA_TEST_CASE(RunSmall, CLNormalizationLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(NormalizationDataset, framework::dataset::make("DataType", DataType::F32)))
88{
89 // Validate output
90 validate(CLAccessor(_target), _reference, tolerance_f32);
91}
92FIXTURE_DATA_TEST_CASE(RunLarge, CLNormalizationLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(NormalizationDataset, framework::dataset::make("DataType", DataType::F32)))
93{
94 // Validate output
95 validate(CLAccessor(_target), _reference, tolerance_f32);
96}
97TEST_SUITE_END()
98TEST_SUITE_END()
99
100template <typename T>
101using CLNormalizationLayerFixedPointFixture = NormalizationValidationFixedPointFixture<CLTensor, CLAccessor, CLNormalizationLayer, T>;
102
103TEST_SUITE(Quantized)
104TEST_SUITE(QS8)
105// Testing for fixed point position [1,6) as reciprocal limits the maximum fixed point position to 5
106FIXTURE_DATA_TEST_CASE(RunSmall, CLNormalizationLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(NormalizationDataset, framework::dataset::make("DataType",
107 DataType::QS8)),
108 framework::dataset::make("FractionalBits", 1, 6)))
109{
110 // Validate output
111 validate(CLAccessor(_target), _reference, tolerance_qs8);
112}
113FIXTURE_DATA_TEST_CASE(RunLarge, CLNormalizationLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(NormalizationDataset, framework::dataset::make("DataType",
114 DataType::QS8)),
115 framework::dataset::make("FractionalBits", 1, 6)))
116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance_qs8);
119}
120TEST_SUITE_END()
121
122TEST_SUITE(QS16)
123// Testing for fixed point position [1,14) as reciprocal limits the maximum fixed point position to 5
124FIXTURE_DATA_TEST_CASE(RunSmall, CLNormalizationLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(NormalizationDataset, framework::dataset::make("DataType",
125 DataType::QS16)),
126 framework::dataset::make("FractionalBits", 1, 14)))
127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance_qs16);
130}
131FIXTURE_DATA_TEST_CASE(RunLarge, CLNormalizationLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(NormalizationDataset, framework::dataset::make("DataType",
132 DataType::QS16)),
133 framework::dataset::make("FractionalBits", 1, 14)))
134{
135 // Validate output
136 validate(CLAccessor(_target), _reference, tolerance_qs16);
137}
138TEST_SUITE_END()
139TEST_SUITE_END()
140
141TEST_SUITE_END()
142TEST_SUITE_END()
143} // namespace validation
144} // namespace test
145} // namespace arm_compute