blob: 70203d9ce90b7add04eac08dc7594c7d79151b91 [file] [log] [blame]
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +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/NESoftmaxLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +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/SoftmaxLayerFixture.h"
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45/** Tolerance for float operations */
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010046constexpr AbsoluteTolerance<float> tolerance_f32(0.000001f);
Manuel Bottini678d83a2019-01-07 16:05:36 +000047RelativeTolerance<half> tolerance_f16(half(0.2));
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010048
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +000049/** Tolerance for quantized operations */
50constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
Sang-Hoon Parkc3a74202019-11-22 16:05:46 +000051constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1);
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +000052
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010053/** CNN data types */
54const auto CNNDataTypes = framework::dataset::make("DataType",
55{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000056#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010057 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000058#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010059 DataType::F32,
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010060});
61} // namespace
62
63TEST_SUITE(NEON)
64TEST_SUITE(SoftmaxLayer)
65
Michalis Spyrouafa5d812017-11-30 14:25:57 +000066// *INDENT-OFF*
67// clang-format off
Manuel Bottini678d83a2019-01-07 16:05:36 +000068DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
69 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types
70 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
71 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, // Invalid output quantization info
72 QuantizationInfo(1.f/256, 12)),
Manuel Bottini678d83a2019-01-07 16:05:36 +000073 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
75 QuantizationInfo(1.f/256, 12)),
SiCong Lid004a7a2020-05-28 15:26:41 +010076 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, //Invalid axis high
77 QuantizationInfo(1.f/256, 12)),
78 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, //Invalid axis low
Manuel Bottini678d83a2019-01-07 16:05:36 +000079 QuantizationInfo(1.f/256, 12)),
80 }),
81 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
82 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
83 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8,
84 QuantizationInfo(1.f/256, 12)),
Manuel Bottini678d83a2019-01-07 16:05:36 +000085 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
86 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
87 QuantizationInfo(1.f/256, 0)),
88 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
89 QuantizationInfo(1.f/256, 0)),
SiCong Lid004a7a2020-05-28 15:26:41 +010090 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
91 QuantizationInfo(1.f/256, 0)),
Manuel Bottini678d83a2019-01-07 16:05:36 +000092 })),
93 framework::dataset::make("beta", { 1.0,
94 2.0,
95 1.0,
96 2.0,
97 1.0,
98 2.0,
99 1.0,
Manuel Bottini678d83a2019-01-07 16:05:36 +0000100 })),
morgolock9c7fed82020-08-05 12:30:56 +0100101 framework::dataset::make("axis", { 0,
SiCong Lid004a7a2020-05-28 15:26:41 +0100102 0,
103 0,
morgolock9c7fed82020-08-05 12:30:56 +0100104 0,
SiCong Lid004a7a2020-05-28 15:26:41 +0100105 0,
106 2,
Sheri Zhang1f567af2020-05-05 11:47:36 +0100107 -3,
Manuel Bottini678d83a2019-01-07 16:05:36 +0000108 })),
SiCong Lid004a7a2020-05-28 15:26:41 +0100109 framework::dataset::make("Expected", { false, false, false, true, true, false, false })),
morgolock9c7fed82020-08-05 12:30:56 +0100110 input_info, output_info, beta, axis, expected)
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000111{
morgolock9c7fed82020-08-05 12:30:56 +0100112 ARM_COMPUTE_EXPECT(bool(NESoftmaxLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), beta, axis)) == expected, framework::LogLevel::ERRORS);
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000113}
114// clang-format on
115// *INDENT-ON*
116
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100117template <typename T>
118using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>;
119
120TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000121#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100122TEST_SUITE(FP16)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000123FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100124 framework::dataset::make("DataType", DataType::F16)),
giuros01efbf6c82018-09-03 09:53:53 +0100125 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100126 framework::dataset::make("Axis", { 0 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100127{
128 // Validate output
Manuel Bottini678d83a2019-01-07 16:05:36 +0000129 validate(Accessor(_target), _reference, tolerance_f16);
130}
131FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
Manuel Bottini21079dd2019-10-29 17:20:09 +0000132 framework::dataset::make("DataType", DataType::F16)),
Manuel Bottini678d83a2019-01-07 16:05:36 +0000133 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100134 framework::dataset::make("Axis", { 0 })))
Manuel Bottini678d83a2019-01-07 16:05:36 +0000135{
136 // Validate output
Manuel Bottini21079dd2019-10-29 17:20:09 +0000137 validate(Accessor(_target), _reference, tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100138}
giuros01efbf6c82018-09-03 09:53:53 +0100139FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
140 framework::dataset::make("DataType", DataType::F16)),
141 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100142 framework::dataset::make("Axis", { 0 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100143{
144 // Validate output
Manuel Bottini678d83a2019-01-07 16:05:36 +0000145 validate(Accessor(_target), _reference, tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100146}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000147TEST_SUITE_END() //FP16
148#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100149
150TEST_SUITE(FP32)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000151FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
152 framework::dataset::make("DataType", DataType::F32)),
153 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100154 framework::dataset::make("Axis", { 0 })))
Manuel Bottini678d83a2019-01-07 16:05:36 +0000155{
156 // Validate output
157 validate(Accessor(_target), _reference, tolerance_f32);
158}
159FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
160 framework::dataset::make("DataType", DataType::F32)),
161 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100162 framework::dataset::make("Axis", { 0 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100163{
164 // Validate output
165 validate(Accessor(_target), _reference, tolerance_f32);
166}
giuros01efbf6c82018-09-03 09:53:53 +0100167FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
168 framework::dataset::make("DataType", DataType::F32)),
169 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100170 framework::dataset::make("Axis", { 0 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100171{
172 // Validate output
173 validate(Accessor(_target), _reference, tolerance_f32);
174}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000175TEST_SUITE_END() //FP32
176TEST_SUITE_END() //Float
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100177
178template <typename T>
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000179using NESoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NESoftmaxLayer, T>;
180
181TEST_SUITE(Quantized)
182TEST_SUITE(QASYMM8)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000183FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
184 framework::dataset::make("DataType", DataType::QASYMM8)),
185 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
186 framework::dataset::make("Beta", { 1.0f, 2.f }))),
morgolock9c7fed82020-08-05 12:30:56 +0100187 framework::dataset::make("Axis", { 0 })))
Manuel Bottini678d83a2019-01-07 16:05:36 +0000188{
189 // Validate output
190 validate(Accessor(_target), _reference, tolerance_qasymm8);
191}
192FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(),
193 framework::dataset::make("DataType", DataType::QASYMM8)),
194 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
195 framework::dataset::make("Beta", { 1.0f, 2.f }))),
morgolock9c7fed82020-08-05 12:30:56 +0100196 framework::dataset::make("Axis", { 0 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000197{
198 // Validate output
199 validate(Accessor(_target), _reference, tolerance_qasymm8);
200}
giuros01efbf6c82018-09-03 09:53:53 +0100201FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000202 framework::dataset::make("DataType", DataType::QASYMM8)),
203 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
giuros01efbf6c82018-09-03 09:53:53 +0100204 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
morgolock9c7fed82020-08-05 12:30:56 +0100205 framework::dataset::make("Axis", { 0 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000206{
207 // Validate output
208 validate(Accessor(_target), _reference, tolerance_qasymm8);
209}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000210TEST_SUITE_END() //QASYMM8
Sang-Hoon Parkc3a74202019-11-22 16:05:46 +0000211
212TEST_SUITE(QASYMM8_SIGNED)
213FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
214 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
215 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
216 framework::dataset::make("Beta", { 1.0f, 2.f }))),
morgolock9c7fed82020-08-05 12:30:56 +0100217 framework::dataset::make("Axis", { 0 })))
Sang-Hoon Parkc3a74202019-11-22 16:05:46 +0000218{
219 // Validate output
220 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
221}
222FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(),
223 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
224 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
225 framework::dataset::make("Beta", { 1.0f, 2.f }))),
morgolock9c7fed82020-08-05 12:30:56 +0100226 framework::dataset::make("Axis", { 0 })))
Sang-Hoon Parkc3a74202019-11-22 16:05:46 +0000227{
228 // Validate output
229 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
230}
231TEST_SUITE_END() //QASYMM8_SIGNED
232
Manuel Bottini678d83a2019-01-07 16:05:36 +0000233TEST_SUITE_END() //Quantized
giuros01efbf6c82018-09-03 09:53:53 +0100234
Manuel Bottini678d83a2019-01-07 16:05:36 +0000235TEST_SUITE_END() //SoftmaxLayer
236TEST_SUITE_END() //NEON
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100237} // namespace validation
238} // namespace test
239} // namespace arm_compute