blob: cbf7729bc36e64e55e8cb1956b7adedf9a0c20c4 [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);
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
Manuel Bottini678d83a2019-01-07 16:05:36 +000066DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Medium2DShapes()), CNNDataTypes), shape, data_type)
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010067{
Manuel Bottini678d83a2019-01-07 16:05:36 +000068 const QuantizationInfo quantization_info = is_data_type_quantized_asymmetric(data_type) ? QuantizationInfo(1.f / 255.f, 0) : QuantizationInfo();
69
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010070 // Create tensors
Manuel Bottini678d83a2019-01-07 16:05:36 +000071 Tensor src = create_tensor<Tensor>(shape, data_type, 1, quantization_info);
72 Tensor dst = create_tensor<Tensor>(shape, data_type, 1, QuantizationInfo(1.f / 256.f, 0));
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010073
74 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
75 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
76
77 // Create and configure function
78 NESoftmaxLayer smx_layer;
79 smx_layer.configure(&src, &dst);
80
81 // Validate valid region
82 const ValidRegion valid_region = shape_to_valid_region(shape);
83 validate(src.info()->valid_region(), valid_region);
84 validate(dst.info()->valid_region(), valid_region);
85
Manuel Bottini678d83a2019-01-07 16:05:36 +000086 // NESoftmaxLayer configures the paddings only in the 2D case
87 if(shape.num_dimensions() <= 2)
88 {
89 // Validate padding
90 const int step = 16 / data_size_from_type(data_type);
91 const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding();
92 validate(src.info()->padding(), padding);
93 validate(dst.info()->padding(), PaddingSize());
94 }
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010095}
96
Michalis Spyrouafa5d812017-11-30 14:25:57 +000097// *INDENT-OFF*
98// clang-format off
Manuel Bottini678d83a2019-01-07 16:05:36 +000099DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
100 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types
101 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
102 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, // Invalid output quantization info
103 QuantizationInfo(1.f/256, 12)),
104 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Window shrink
105 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),// Invalid input dimensionality
106 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
107 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
108 QuantizationInfo(1.f/256, 12)),
109 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, //Invalid axis value
110 QuantizationInfo(1.f/256, 12)),
111 }),
112 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
113 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
114 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8,
115 QuantizationInfo(1.f/256, 12)),
116 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32),
117 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
118 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
119 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
120 QuantizationInfo(1.f/256, 0)),
121 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
122 QuantizationInfo(1.f/256, 0)),
123 })),
124 framework::dataset::make("beta", { 1.0,
125 2.0,
126 1.0,
127 2.0,
128 1.0,
129 2.0,
130 1.0,
131 2.0,
132 1.0,
133 })),
134 framework::dataset::make("axis", { 1,
135 1,
136 1,
137 1,
138 1,
139 1,
140 1,
141 0,
142 })),
143 framework::dataset::make("Expected", { false, false, false, false, false, true, true, false })),
144 input_info, output_info, beta, axis, expected)
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000145{
Manuel Bottini678d83a2019-01-07 16:05:36 +0000146 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 +0000147}
148// clang-format on
149// *INDENT-ON*
150
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100151template <typename T>
152using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>;
153
154TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000155#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100156TEST_SUITE(FP16)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000157FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100158 framework::dataset::make("DataType", DataType::F16)),
giuros01efbf6c82018-09-03 09:53:53 +0100159 framework::dataset::make("Beta", { 1.0f, 2.0f })),
160 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100161{
162 // Validate output
Manuel Bottini678d83a2019-01-07 16:05:36 +0000163 validate(Accessor(_target), _reference, tolerance_f16);
164}
165FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
Manuel Bottini21079dd2019-10-29 17:20:09 +0000166 framework::dataset::make("DataType", DataType::F16)),
Manuel Bottini678d83a2019-01-07 16:05:36 +0000167 framework::dataset::make("Beta", { 1.0f, 2.0f })),
168 framework::dataset::make("Axis", { 1, 2, 3 })))
169{
170 // Validate output
Manuel Bottini21079dd2019-10-29 17:20:09 +0000171 validate(Accessor(_target), _reference, tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100172}
giuros01efbf6c82018-09-03 09:53:53 +0100173FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
174 framework::dataset::make("DataType", DataType::F16)),
175 framework::dataset::make("Beta", { 1.0f, 2.0f })),
176 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100177{
178 // Validate output
Manuel Bottini678d83a2019-01-07 16:05:36 +0000179 validate(Accessor(_target), _reference, tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100180}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000181TEST_SUITE_END() //FP16
182#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100183
184TEST_SUITE(FP32)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000185FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
186 framework::dataset::make("DataType", DataType::F32)),
187 framework::dataset::make("Beta", { 1.0f, 2.0f })),
188 framework::dataset::make("Axis", { 1 })))
189{
190 // Validate output
191 validate(Accessor(_target), _reference, tolerance_f32);
192}
193FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
194 framework::dataset::make("DataType", DataType::F32)),
195 framework::dataset::make("Beta", { 1.0f, 2.0f })),
196 framework::dataset::make("Axis", { 1, 2, 3 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100197{
198 // Validate output
199 validate(Accessor(_target), _reference, tolerance_f32);
200}
giuros01efbf6c82018-09-03 09:53:53 +0100201FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
202 framework::dataset::make("DataType", DataType::F32)),
203 framework::dataset::make("Beta", { 1.0f, 2.0f })),
204 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100205{
206 // Validate output
207 validate(Accessor(_target), _reference, tolerance_f32);
208}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000209TEST_SUITE_END() //FP32
210TEST_SUITE_END() //Float
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100211
212template <typename T>
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000213using NESoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NESoftmaxLayer, T>;
214
215TEST_SUITE(Quantized)
216TEST_SUITE(QASYMM8)
Manuel Bottini678d83a2019-01-07 16:05:36 +0000217FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
218 framework::dataset::make("DataType", DataType::QASYMM8)),
219 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
220 framework::dataset::make("Beta", { 1.0f, 2.f }))),
221 framework::dataset::make("Axis", { 1 })))
222{
223 // Validate output
224 validate(Accessor(_target), _reference, tolerance_qasymm8);
225}
226FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(),
227 framework::dataset::make("DataType", DataType::QASYMM8)),
228 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
229 framework::dataset::make("Beta", { 1.0f, 2.f }))),
230 framework::dataset::make("Axis", { 1, 2, 3 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000231{
232 // Validate output
233 validate(Accessor(_target), _reference, tolerance_qasymm8);
234}
giuros01efbf6c82018-09-03 09:53:53 +0100235FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000236 framework::dataset::make("DataType", DataType::QASYMM8)),
237 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
giuros01efbf6c82018-09-03 09:53:53 +0100238 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
239 framework::dataset::make("Axis", { 1 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000240{
241 // Validate output
242 validate(Accessor(_target), _reference, tolerance_qasymm8);
243}
Manuel Bottini678d83a2019-01-07 16:05:36 +0000244TEST_SUITE_END() //QASYMM8
Sang-Hoon Parkc3a74202019-11-22 16:05:46 +0000245
246TEST_SUITE(QASYMM8_SIGNED)
247FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
248 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
249 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
250 framework::dataset::make("Beta", { 1.0f, 2.f }))),
251 framework::dataset::make("Axis", { 1 })))
252{
253 // Validate output
254 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
255}
256FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(),
257 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
258 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
259 framework::dataset::make("Beta", { 1.0f, 2.f }))),
260 framework::dataset::make("Axis", { 1, 2, 3 })))
261{
262 // Validate output
263 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
264}
265TEST_SUITE_END() //QASYMM8_SIGNED
266
Manuel Bottini678d83a2019-01-07 16:05:36 +0000267TEST_SUITE_END() //Quantized
giuros01efbf6c82018-09-03 09:53:53 +0100268
Manuel Bottini678d83a2019-01-07 16:05:36 +0000269TEST_SUITE_END() //SoftmaxLayer
270TEST_SUITE_END() //NEON
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100271} // namespace validation
272} // namespace test
273} // namespace arm_compute