blob: aeee54c835c79889efc77ff73aa0e8ef66d6e79e [file] [log] [blame]
Michele Di Giorgio4e09b382017-07-05 18:20:02 +01001/*
Georgios Pinitasd30405a2021-01-13 14:42:54 +00002 * Copyright (c) 2017-2021 Arm Limited.
Michele Di Giorgio4e09b382017-07-05 18:20:02 +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/NEON/functions/NEQuantizationLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
Michele Di Giorgio4e09b382017-07-05 18:20:02 +010028#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/datasets/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/QuantizationLayerFixture.h"
Michele Di Giorgio4e09b382017-07-05 18:20:02 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45/** Tolerance for quantization */
Manuel Bottini4370cff2020-02-07 16:31:59 +000046constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); /**< Tolerance value for comparing reference's output against implementation's output for QASYMM8 data types */
47constexpr AbsoluteTolerance<int8_t> tolerance_s8(1); /**< Tolerance value for comparing reference's output against implementation's output for QASYMM8_SIGNED data types */
48constexpr AbsoluteTolerance<uint16_t> tolerance_u16(1); /**< Tolerance value for comparing reference's output against implementation's output for QASYMM16 data types */
49const auto QuantizationSmallShapes = concat(datasets::Small3DShapes(), datasets::Small4DShapes());
50const auto QuantizationLargeShapes = concat(datasets::Large3DShapes(), datasets::Large4DShapes());
Michele Di Giorgio4e09b382017-07-05 18:20:02 +010051} // namespace
52
53TEST_SUITE(NEON)
54TEST_SUITE(QuantizationLayer)
55
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000056// *INDENT-OFF*
57// clang-format off
58DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
Manuel Bottini4370cff2020-02-07 16:31:59 +000059 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::QASYMM8), // Wrong output data type
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000060 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), // Wrong output data type
John Kesapidesadfb2732019-03-04 16:29:22 +000061 TensorInfo(TensorShape(16U, 16U, 2U, 5U), 1, DataType::F32), // Missmatching shapes
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000062 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), // Valid
63 }),
64 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32),
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000065 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U16),
John Kesapidesadfb2732019-03-04 16:29:22 +000066 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::QASYMM8),
67 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::QASYMM8),
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000068 })),
John Kesapidesadfb2732019-03-04 16:29:22 +000069 framework::dataset::make("Expected", { false, false, false, true})),
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000070 input_info, output_info, expected)
71{
72 ARM_COMPUTE_EXPECT(bool(NEQuantizationLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
73}
74// clang-format on
75// *INDENT-ON*
76
Michele Di Giorgio4e09b382017-07-05 18:20:02 +010077template <typename T>
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +010078using NEQuantizationLayerQASYMM8Fixture = QuantizationValidationFixture<Tensor, Accessor, NEQuantizationLayer, T, uint8_t>;
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +010079template <typename T>
Sang-Hoon Parkfb6aaeb2019-11-27 15:26:44 +000080using NEQuantizationLayerQASYMM8SignedFixture = QuantizationValidationFixture<Tensor, Accessor, NEQuantizationLayer, T, int8_t>;
81template <typename T>
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +010082using NEQuantizationLayerQASYMM16Fixture = QuantizationValidationFixture<Tensor, Accessor, NEQuantizationLayer, T, uint16_t>;
Michele Di Giorgio4e09b382017-07-05 18:20:02 +010083
84TEST_SUITE(Float)
85TEST_SUITE(FP32)
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +010086FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8, NEQuantizationLayerQASYMM8Fixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(QuantizationSmallShapes,
87 framework::dataset::make("DataType", DataType::F32)),
88 framework::dataset::make("DataTypeOut", { DataType::QASYMM8 })),
89 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
Michele Di Giorgio4e09b382017-07-05 18:20:02 +010090{
91 // Validate output
92 validate(Accessor(_target), _reference, tolerance_u8);
93}
Sang-Hoon Parkfb6aaeb2019-11-27 15:26:44 +000094FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8Signed, NEQuantizationLayerQASYMM8SignedFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(QuantizationSmallShapes,
95 framework::dataset::make("DataType", DataType::F32)),
96 framework::dataset::make("DataTypeOut", { DataType::QASYMM8_SIGNED })),
97 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
98{
99 // Validate output
Georgios Pinitasd30405a2021-01-13 14:42:54 +0000100 validate(Accessor(_target), _reference, tolerance_s8);
Sang-Hoon Parkfb6aaeb2019-11-27 15:26:44 +0000101}
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +0100102FIXTURE_DATA_TEST_CASE(RunSmallQASYMM16, NEQuantizationLayerQASYMM16Fixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(QuantizationSmallShapes,
103 framework::dataset::make("DataType", DataType::F32)),
104 framework::dataset::make("DataTypeOut", { DataType::QASYMM16 })),
105 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
106{
107 // Validate output
108 validate(Accessor(_target), _reference, tolerance_u16);
109}
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100110FIXTURE_DATA_TEST_CASE(RunLargeQASYMM8, NEQuantizationLayerQASYMM8Fixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(QuantizationLargeShapes,
111 framework::dataset::make("DataType", DataType::F32)),
112 framework::dataset::make("DataTypeOut", { DataType::QASYMM8 })),
113 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
Michele Di Giorgio4e09b382017-07-05 18:20:02 +0100114{
115 // Validate output
116 validate(Accessor(_target), _reference, tolerance_u8);
117}
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +0100118FIXTURE_DATA_TEST_CASE(RunLargeQASYMM16, NEQuantizationLayerQASYMM16Fixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(QuantizationLargeShapes,
119 framework::dataset::make("DataType", DataType::F32)),
120 framework::dataset::make("DataTypeOut", { DataType::QASYMM16 })),
121 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
122{
123 // Validate output
124 validate(Accessor(_target), _reference, tolerance_u16);
125}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000126TEST_SUITE_END() // FP32
John Kesapidesadfb2732019-03-04 16:29:22 +0000127#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
John Kesapidesadfb2732019-03-04 16:29:22 +0000128TEST_SUITE(FP16)
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100129FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8, NEQuantizationLayerQASYMM8Fixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(QuantizationSmallShapes,
130 framework::dataset::make("DataType", DataType::F16)),
131 framework::dataset::make("DataTypeOut", { DataType::QASYMM8 })),
132 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
John Kesapidesadfb2732019-03-04 16:29:22 +0000133{
134 // Validate output
135 validate(Accessor(_target), _reference, tolerance_u8);
136}
Sang-Hoon Parkfb6aaeb2019-11-27 15:26:44 +0000137FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8Signed, NEQuantizationLayerQASYMM8SignedFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(QuantizationSmallShapes,
138 framework::dataset::make("DataType", DataType::F16)),
139 framework::dataset::make("DataTypeOut", { DataType::QASYMM8_SIGNED })),
140 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
141{
142 // Validate output
Georgios Pinitasd30405a2021-01-13 14:42:54 +0000143 validate(Accessor(_target), _reference, tolerance_s8);
Sang-Hoon Parkfb6aaeb2019-11-27 15:26:44 +0000144}
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +0100145FIXTURE_DATA_TEST_CASE(RunSmallQASYMM16, NEQuantizationLayerQASYMM16Fixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(QuantizationSmallShapes,
146 framework::dataset::make("DataType", DataType::F16)),
147 framework::dataset::make("DataTypeOut", { DataType::QASYMM16 })),
148 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
149{
150 // Validate output
151 validate(Accessor(_target), _reference, tolerance_u16);
152}
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100153FIXTURE_DATA_TEST_CASE(RunLargeQASYMM8, NEQuantizationLayerQASYMM8Fixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(QuantizationLargeShapes,
154 framework::dataset::make("DataType", DataType::F16)),
155 framework::dataset::make("DataTypeOut", { DataType::QASYMM8 })),
156 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
John Kesapidesadfb2732019-03-04 16:29:22 +0000157{
158 // Validate output
159 validate(Accessor(_target), _reference, tolerance_u8);
160}
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +0100161FIXTURE_DATA_TEST_CASE(RunLargeQASYMM16, NEQuantizationLayerQASYMM16Fixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(QuantizationLargeShapes,
162 framework::dataset::make("DataType", DataType::F16)),
163 framework::dataset::make("DataTypeOut", { DataType::QASYMM16 })),
164 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })))
165{
166 // Validate output
167 validate(Accessor(_target), _reference, tolerance_u16);
168}
John Kesapidesadfb2732019-03-04 16:29:22 +0000169TEST_SUITE_END() // FP16
John Kesapidesadfb2732019-03-04 16:29:22 +0000170#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michele Di Giorgiod64a46c2019-10-01 12:25:49 +0100171TEST_SUITE_END() // Float
Michele Di Giorgio4e09b382017-07-05 18:20:02 +0100172
Manuel Bottini4370cff2020-02-07 16:31:59 +0000173TEST_SUITE(Quantized)
174template <typename T>
175using NEQuantizationLayerQASYMM8GenFixture = QuantizationValidationGenericFixture<Tensor, Accessor, NEQuantizationLayer, T, uint8_t>;
176template <typename T>
177using NEQuantizationLayerQASYMM8_SIGNEDGenFixture = QuantizationValidationGenericFixture<Tensor, Accessor, NEQuantizationLayer, T, int8_t>;
178template <typename T>
179using NEQuantizationLayerQASYMM16GenFixture = QuantizationValidationGenericFixture<Tensor, Accessor, NEQuantizationLayer, T, uint16_t>;
180TEST_SUITE(QASYMM8)
181FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8, NEQuantizationLayerQASYMM8GenFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(QuantizationSmallShapes,
182 framework::dataset::make("DataType", DataType::QASYMM8)),
183 framework::dataset::make("DataTypeOut", { DataType::QASYMM8 })),
184 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(0.5f, 10) })),
185 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(2.0f, 15) })))
186{
187 // Validate output
188 validate(Accessor(_target), _reference, tolerance_u8);
189}
190FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8_SIGNED, NEQuantizationLayerQASYMM8_SIGNEDGenFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(QuantizationSmallShapes,
191 framework::dataset::make("DataTypeIn", DataType::QASYMM8)),
192 framework::dataset::make("DataTypeOut", { DataType::QASYMM8_SIGNED })),
193 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.0f, 10), QuantizationInfo(2.0f, -25) })),
194 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.0f, 15) })))
195{
196 // Validate output
197 validate(Accessor(_target), _reference, tolerance_s8);
198}
199FIXTURE_DATA_TEST_CASE(RunSmallQASYMM16, NEQuantizationLayerQASYMM16GenFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(QuantizationSmallShapes,
200 framework::dataset::make("DataTypeIn", DataType::QASYMM8)),
201 framework::dataset::make("DataTypeOut", { DataType::QASYMM16 })),
202 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.0f, 10) })),
203 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(4.0f, 23) })))
204{
205 // Validate output
206 validate(Accessor(_target), _reference, tolerance_u16);
207}
208TEST_SUITE_END() // QASYMM8
209TEST_SUITE(QASYMM8_SIGNED)
210FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8_SIGNED, NEQuantizationLayerQASYMM8_SIGNEDGenFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(QuantizationSmallShapes,
211 framework::dataset::make("DataTypeIn", DataType::QASYMM8_SIGNED)),
212 framework::dataset::make("DataTypeOut", { DataType::QASYMM8_SIGNED })),
213 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.0f, 10) })),
214 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(2.0f, -5) })))
215{
216 // Validate output
217 validate(Accessor(_target), _reference, tolerance_s8);
218}
219FIXTURE_DATA_TEST_CASE(RunSmallQASYMM8, NEQuantizationLayerQASYMM8GenFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(QuantizationSmallShapes,
220 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
221 framework::dataset::make("DataTypeOut", { DataType::QASYMM8 })),
222 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(2.0f, 10), QuantizationInfo(2.0f, -25) })),
223 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.0f, 30) })))
224{
225 // Validate output
226 validate(Accessor(_target), _reference, tolerance_u8);
227}
228TEST_SUITE_END() // QASYMM8_SIGNED
229TEST_SUITE_END() // Quantized
230
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000231TEST_SUITE_END() // QuantizationLayer
Sheri Zhangac6499a2021-02-10 15:32:38 +0000232TEST_SUITE_END() // Neon
Michele Di Giorgio4e09b382017-07-05 18:20:02 +0100233} // namespace validation
234} // namespace test
235} // namespace arm_compute