blob: 8f91b51d9a2c477f0174a8375800c4a975862097 [file] [log] [blame]
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01001/*
Manuel Bottini678d83a2019-01-07 16:05:36 +00002 * Copyright (c) 2017-2019 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);
51
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010052/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000055#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010056 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000057#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010058 DataType::F32,
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010059});
60} // namespace
61
62TEST_SUITE(NEON)
63TEST_SUITE(SoftmaxLayer)
64
Manuel Bottini678d83a2019-01-07 16:05:36 +000065DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Medium2DShapes()), CNNDataTypes), shape, data_type)
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010066{
Manuel Bottini678d83a2019-01-07 16:05:36 +000067 const QuantizationInfo quantization_info = is_data_type_quantized_asymmetric(data_type) ? QuantizationInfo(1.f / 255.f, 0) : QuantizationInfo();
68
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010069 // Create tensors
Manuel Bottini678d83a2019-01-07 16:05:36 +000070 Tensor src = create_tensor<Tensor>(shape, data_type, 1, quantization_info);
71 Tensor dst = create_tensor<Tensor>(shape, data_type, 1, QuantizationInfo(1.f / 256.f, 0));
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010072
73 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
74 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
75
76 // Create and configure function
77 NESoftmaxLayer smx_layer;
78 smx_layer.configure(&src, &dst);
79
80 // Validate valid region
81 const ValidRegion valid_region = shape_to_valid_region(shape);
82 validate(src.info()->valid_region(), valid_region);
83 validate(dst.info()->valid_region(), valid_region);
84
Manuel Bottini678d83a2019-01-07 16:05:36 +000085 // NESoftmaxLayer configures the paddings only in the 2D case
86 if(shape.num_dimensions() <= 2)
87 {
88 // Validate padding
89 const int step = 16 / data_size_from_type(data_type);
90 const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding();
91 validate(src.info()->padding(), padding);
92 validate(dst.info()->padding(), PaddingSize());
93 }
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010094}
95
Michalis Spyrouafa5d812017-11-30 14:25:57 +000096// *INDENT-OFF*
97// clang-format off
Manuel Bottini678d83a2019-01-07 16:05:36 +000098DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
99 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types
100 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
101 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, // Invalid output quantization info
102 QuantizationInfo(1.f/256, 12)),
103 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Window shrink
104 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),// Invalid input dimensionality
105 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
106 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
107 QuantizationInfo(1.f/256, 12)),
108 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, //Invalid axis value
109 QuantizationInfo(1.f/256, 12)),
110 }),
111 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
112 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
113 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8,
114 QuantizationInfo(1.f/256, 12)),
115 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32),
116 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
117 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
118 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
119 QuantizationInfo(1.f/256, 0)),
120 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
121 QuantizationInfo(1.f/256, 0)),
122 })),
123 framework::dataset::make("beta", { 1.0,
124 2.0,
125 1.0,
126 2.0,
127 1.0,
128 2.0,
129 1.0,
130 2.0,
131 1.0,
132 })),
133 framework::dataset::make("axis", { 1,
134 1,
135 1,
136 1,
137 1,
138 1,
139 1,
140 0,
141 })),
142 framework::dataset::make("Expected", { false, false, false, false, false, true, true, false })),
143 input_info, output_info, beta, axis, expected)
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000144{
Manuel Bottini678d83a2019-01-07 16:05:36 +0000145 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 +0000146}
147// clang-format on
148// *INDENT-ON*
149
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100150template <typename T>
151using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>;
152
153TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000154#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100155TEST_SUITE(FP16)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000156FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100157 framework::dataset::make("DataType", DataType::F16)),
giuros01efbf6c82018-09-03 09:53:53 +0100158 framework::dataset::make("Beta", { 1.0f, 2.0f })),
159 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100160{
161 // Validate output
Manuel Bottini678d83a2019-01-07 16:05:36 +0000162 validate(Accessor(_target), _reference, tolerance_f16);
163}
164FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
165 framework::dataset::make("DataType", DataType::F32)),
166 framework::dataset::make("Beta", { 1.0f, 2.0f })),
167 framework::dataset::make("Axis", { 1, 2, 3 })))
168{
169 // Validate output
170 validate(Accessor(_target), _reference, tolerance_f32);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100171}
giuros01efbf6c82018-09-03 09:53:53 +0100172FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
173 framework::dataset::make("DataType", DataType::F16)),
174 framework::dataset::make("Beta", { 1.0f, 2.0f })),
175 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100176{
177 // Validate output
Manuel Bottini678d83a2019-01-07 16:05:36 +0000178 validate(Accessor(_target), _reference, tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100179}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000180TEST_SUITE_END() //FP16
181#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100182
183TEST_SUITE(FP32)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000184FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
185 framework::dataset::make("DataType", DataType::F32)),
186 framework::dataset::make("Beta", { 1.0f, 2.0f })),
187 framework::dataset::make("Axis", { 1 })))
188{
189 // Validate output
190 validate(Accessor(_target), _reference, tolerance_f32);
191}
192FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
193 framework::dataset::make("DataType", DataType::F32)),
194 framework::dataset::make("Beta", { 1.0f, 2.0f })),
195 framework::dataset::make("Axis", { 1, 2, 3 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100196{
197 // Validate output
198 validate(Accessor(_target), _reference, tolerance_f32);
199}
giuros01efbf6c82018-09-03 09:53:53 +0100200FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
201 framework::dataset::make("DataType", DataType::F32)),
202 framework::dataset::make("Beta", { 1.0f, 2.0f })),
203 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100204{
205 // Validate output
206 validate(Accessor(_target), _reference, tolerance_f32);
207}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000208TEST_SUITE_END() //FP32
209TEST_SUITE_END() //Float
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100210
211template <typename T>
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000212using NESoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NESoftmaxLayer, T>;
213
214TEST_SUITE(Quantized)
215TEST_SUITE(QASYMM8)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000216FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
217 framework::dataset::make("DataType", DataType::QASYMM8)),
218 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
219 framework::dataset::make("Beta", { 1.0f, 2.f }))),
220 framework::dataset::make("Axis", { 1 })))
221{
222 // Validate output
223 validate(Accessor(_target), _reference, tolerance_qasymm8);
224}
225FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(),
226 framework::dataset::make("DataType", DataType::QASYMM8)),
227 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
228 framework::dataset::make("Beta", { 1.0f, 2.f }))),
229 framework::dataset::make("Axis", { 1, 2, 3 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000230{
231 // Validate output
232 validate(Accessor(_target), _reference, tolerance_qasymm8);
233}
giuros01efbf6c82018-09-03 09:53:53 +0100234FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000235 framework::dataset::make("DataType", DataType::QASYMM8)),
236 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
giuros01efbf6c82018-09-03 09:53:53 +0100237 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
238 framework::dataset::make("Axis", { 1 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000239{
240 // Validate output
241 validate(Accessor(_target), _reference, tolerance_qasymm8);
242}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000243TEST_SUITE_END() //QASYMM8
244TEST_SUITE_END() //Quantized
giuros01efbf6c82018-09-03 09:53:53 +0100245
Manuel Bottini678d83a2019-01-07 16:05:36 +0000246TEST_SUITE_END() //SoftmaxLayer
247TEST_SUITE_END() //NEON
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100248} // namespace validation
249} // namespace test
250} // namespace arm_compute