blob: 21c77e7059ffea3bae206e1519eea9ed58fe7cf9 [file] [log] [blame]
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01001/*
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +00002 * Copyright (c) 2017-2018 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);
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000047#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitas31fa0d62018-08-23 13:38:59 +010048constexpr RelativeTolerance<float> rel_tolerance_f16(0.1f);
49constexpr AbsoluteTolerance<float> abs_tolerance_f16(0.01f);
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000050#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC*/
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010051
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +000052/** Tolerance for quantized operations */
53constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
54
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010055/** CNN data types */
56const auto CNNDataTypes = framework::dataset::make("DataType",
57{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000058#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010059 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000060#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010061 DataType::F32,
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010062});
63} // namespace
64
65TEST_SUITE(NEON)
66TEST_SUITE(SoftmaxLayer)
67
Pablo Palmiera2b89ca2017-10-05 15:01:34 +010068DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::SoftmaxLayerSmallShapes(), datasets::SoftmaxLayerLargeShapes()), CNNDataTypes), shape, data_type)
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010069{
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010070 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010071 Tensor src = create_tensor<Tensor>(shape, data_type, 1);
72 Tensor dst = create_tensor<Tensor>(shape, data_type, 1);
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
86 // Validate padding
87 const int step = 16 / data_size_from_type(data_type);
88 const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding();
89 validate(src.info()->padding(), padding);
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +000090 validate(dst.info()->padding(), PaddingSize());
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010091}
92
Michalis Spyrouafa5d812017-11-30 14:25:57 +000093// *INDENT-OFF*
94// clang-format off
95DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +010096 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types
97 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
98 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Invalid input dimensionality
99 TensorInfo(TensorShape(32U, 16U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000100 }),
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +0100101 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
102 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
103 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
104 TensorInfo(TensorShape(32U, 16U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000105 })),
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +0100106 framework::dataset::make("Expected", { false, false, false, true })),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000107 input_info, output_info, expected)
108{
109 bool is_valid = bool(NESoftmaxLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false)));
110 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
111}
112// clang-format on
113// *INDENT-ON*
114
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100115template <typename T>
116using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>;
117
118TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000119#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100120TEST_SUITE(FP16)
giuros01efbf6c82018-09-03 09:53:53 +0100121FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100122 framework::dataset::make("DataType", DataType::F16)),
giuros01efbf6c82018-09-03 09:53:53 +0100123 framework::dataset::make("Beta", { 1.0f, 2.0f })),
124 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100125{
126 // Validate output
Georgios Pinitas31fa0d62018-08-23 13:38:59 +0100127 validate(Accessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100128}
giuros01efbf6c82018-09-03 09:53:53 +0100129FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
130 framework::dataset::make("DataType", DataType::F16)),
131 framework::dataset::make("Beta", { 1.0f, 2.0f })),
132 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100133{
134 // Validate output
Georgios Pinitas31fa0d62018-08-23 13:38:59 +0100135 validate(Accessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100136}
137TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000138#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100139
140TEST_SUITE(FP32)
giuros01efbf6c82018-09-03 09:53:53 +0100141FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100142 framework::dataset::make("DataType", DataType::F32)),
giuros01efbf6c82018-09-03 09:53:53 +0100143 framework::dataset::make("Beta", { 1.0f, 2.0f })),
144 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100145{
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_f32);
148}
giuros01efbf6c82018-09-03 09:53:53 +0100149FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
150 framework::dataset::make("DataType", DataType::F32)),
151 framework::dataset::make("Beta", { 1.0f, 2.0f })),
152 framework::dataset::make("Axis", { 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100153{
154 // Validate output
155 validate(Accessor(_target), _reference, tolerance_f32);
156}
157TEST_SUITE_END()
158TEST_SUITE_END()
159
160template <typename T>
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000161using NESoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NESoftmaxLayer, T>;
162
163TEST_SUITE(Quantized)
164TEST_SUITE(QASYMM8)
giuros01efbf6c82018-09-03 09:53:53 +0100165FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000166 framework::dataset::make("DataType", DataType::QASYMM8)),
giuros01efbf6c82018-09-03 09:53:53 +0100167 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
168 framework::dataset::make("Beta", { 1.0f, 2.f }))),
169 framework::dataset::make("Axis", { 1 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000170{
171 // Validate output
172 validate(Accessor(_target), _reference, tolerance_qasymm8);
173}
giuros01efbf6c82018-09-03 09:53:53 +0100174FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000175 framework::dataset::make("DataType", DataType::QASYMM8)),
176 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
giuros01efbf6c82018-09-03 09:53:53 +0100177 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
178 framework::dataset::make("Axis", { 1 })))
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000179{
180 // Validate output
181 validate(Accessor(_target), _reference, tolerance_qasymm8);
182}
giuros01efbf6c82018-09-03 09:53:53 +0100183
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000184TEST_SUITE_END()
185TEST_SUITE_END()
186
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100187TEST_SUITE_END()
188TEST_SUITE_END()
189} // namespace validation
190} // namespace test
191} // namespace arm_compute