blob: cdeb62213099daaba62bd6e6e111b43b5ce302fa [file] [log] [blame]
Michele Di Giorgio5b48ad72019-06-04 18:43:35 +01001/*
Giorgio Arenaed4b8a02021-05-12 12:28:58 +01002 * Copyright (c) 2019-2021 Arm Limited.
Michele Di Giorgio5b48ad72019-06-04 18:43:35 +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/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/CLMeanStdDevNormalizationLayer.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/NormalizationTypesDataset.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/MeanStdDevNormalizationLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Tolerance for float operations */
47RelativeTolerance<half> tolerance_f16(half(0.2f));
48RelativeTolerance<float> tolerance_f32(1e-8f);
49} // namespace
50
51TEST_SUITE(CL)
52TEST_SUITE(MeanStdDevNormalizationLayer)
53
54// *INDENT-OFF*
55// clang-format off
56DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
57 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data type input/output
58 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
59 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
60 }),
61 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
62 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
63 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
64 })),
65 framework::dataset::make("Expected", { false, false, true })),
66 input_info, output_info, expected)
67{
68 ARM_COMPUTE_EXPECT(bool(CLMeanStdDevNormalizationLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
69}
70// clang-format on
71// *INDENT-ON*
72
73template <typename T>
74using CLMeanStdDevNormalizationLayerFixture = MeanStdDevNormalizationLayerValidationFixture<CLTensor, CLAccessor, CLMeanStdDevNormalizationLayer, T>;
75
76TEST_SUITE(Float)
77TEST_SUITE(FP16)
78FIXTURE_DATA_TEST_CASE(RunSmall, CLMeanStdDevNormalizationLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(),
79 framework::dataset::make("DataType", DataType::F16)),
80 framework::dataset::make("InPlace", { false, true })),
Giorgio Arenaed4b8a02021-05-12 12:28:58 +010081 framework::dataset::make("Epsilon", { 1e-3 })))
Michele Di Giorgio5b48ad72019-06-04 18:43:35 +010082{
83 // Validate output
84 validate(CLAccessor(_target), _reference, tolerance_f16);
85}
86FIXTURE_DATA_TEST_CASE(RunLarge, CLMeanStdDevNormalizationLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(),
87 framework::dataset::make("DataType", DataType::F16)),
88 framework::dataset::make("InPlace", { false, true })),
89 framework::dataset::make("Epsilon", { 1e-8 })))
90{
91 // Validate output
92 validate(CLAccessor(_target), _reference, tolerance_f16);
93}
94TEST_SUITE_END() // FP16
95
96TEST_SUITE(FP32)
97FIXTURE_DATA_TEST_CASE(RunSmall, CLMeanStdDevNormalizationLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(),
98 framework::dataset::make("DataType", DataType::F32)),
99 framework::dataset::make("InPlace", { false, true })),
100 framework::dataset::make("Epsilon", { 1e-8 })))
101{
102 // Validate output
103 validate(CLAccessor(_target), _reference, tolerance_f32);
104}
105FIXTURE_DATA_TEST_CASE(RunLarge, CLMeanStdDevNormalizationLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(),
106 framework::dataset::make("DataType", DataType::F32)),
107 framework::dataset::make("InPlace", { false, true })),
108 framework::dataset::make("Epsilon", { 1e-8 })))
109{
110 // Validate output
111 validate(CLAccessor(_target), _reference, tolerance_f32);
112}
113TEST_SUITE_END() // FP32
114TEST_SUITE_END() // Float
115
116TEST_SUITE_END() // MeanStdNormalizationLayer
117TEST_SUITE_END() // CL
118} // namespace validation
119} // namespace test
120} // namespace arm_compute