blob: 5ede321db1269a82aebb9233fafe0b5433e1d640 [file] [log] [blame]
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010047#ifdef ARM_COMPUTE_ENABLE_FP16
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010048constexpr AbsoluteTolerance<float> tolerance_f16(0.0001f);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010049#endif /* ARM_COMPUTE_ENABLE_FP16*/
50/** Tolerance for fixed point operations */
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +010051constexpr AbsoluteTolerance<int16_t> tolerance_fixed_point(2);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010052
53/** CNN data types */
54const auto CNNDataTypes = framework::dataset::make("DataType",
55{
56#ifdef ARM_COMPUTE_ENABLE_FP16
57 DataType::F16,
58#endif /* ARM_COMPUTE_ENABLE_FP16 */
59 DataType::F32,
60 DataType::QS8,
61 DataType::QS16,
62});
63} // namespace
64
65TEST_SUITE(NEON)
66TEST_SUITE(SoftmaxLayer)
67
68DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), CNNDataTypes), shape, data_type)
69{
70 // Set fixed point position data type allowed
71 const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
72
73 // Create tensors
74 Tensor src = create_tensor<Tensor>(shape, data_type, 1, fixed_point_position);
75 Tensor dst = create_tensor<Tensor>(shape, data_type, 1, fixed_point_position);
76
77 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
79
80 // Create and configure function
81 NESoftmaxLayer smx_layer;
82 smx_layer.configure(&src, &dst);
83
84 // Validate valid region
85 const ValidRegion valid_region = shape_to_valid_region(shape);
86 validate(src.info()->valid_region(), valid_region);
87 validate(dst.info()->valid_region(), valid_region);
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(), padding);
94}
95
96template <typename T>
97using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>;
98
99TEST_SUITE(Float)
100#ifdef ARM_COMPUTE_ENABLE_FP16
101TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100102FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100103{
104 // Validate output
105 validate(Accessor(_target), _reference, tolerance_f16);
106}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100107FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100108{
109 // Validate output
110 validate(Accessor(_target), _reference, tolerance_f16);
111}
112TEST_SUITE_END()
113#endif /* ARM_COMPUTE_ENABLE_FP16 */
114
115TEST_SUITE(FP32)
116FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
117{
118 // Validate output
119 validate(Accessor(_target), _reference, tolerance_f32);
120}
121FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)))
122{
123 // Validate output
124 validate(Accessor(_target), _reference, tolerance_f32);
125}
126TEST_SUITE_END()
127TEST_SUITE_END()
128
129template <typename T>
130using NESoftmaxLayerFixedPointFixture = SoftmaxValidationFixedPointFixture<Tensor, Accessor, NESoftmaxLayer, T>;
131
132TEST_SUITE(Quantized)
133TEST_SUITE(QS8)
134// Testing for fixed point position [1,6) as reciprocal limits the maximum fixed point position to 5
135FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
136 DataType::QS8)),
137 framework::dataset::make("FractionalBits", 1, 6)))
138{
139 // Validate output
140 validate(Accessor(_target), _reference, tolerance_fixed_point);
141}
142FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
143 DataType::QS8)),
144 framework::dataset::make("FractionalBits", 1, 6)))
145{
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_fixed_point);
148}
149TEST_SUITE_END()
150
151TEST_SUITE(QS16)
152// Testing for fixed point position [1,14) as reciprocal limits the maximum fixed point position to 14
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100153FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(),
154 framework::dataset::make("DataType",
155 DataType::QS16)),
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100156 framework::dataset::make("FractionalBits", 1, 14)))
157{
158 // Validate output
159 validate(Accessor(_target), _reference, tolerance_fixed_point);
160}
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100161FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(),
162 framework::dataset::make("DataType",
163 DataType::QS16)),
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100164 framework::dataset::make("FractionalBits", 1, 14)))
165{
166 // Validate output
167 validate(Accessor(_target), _reference, tolerance_fixed_point);
168}
169TEST_SUITE_END()
170TEST_SUITE_END()
171
172TEST_SUITE_END()
173TEST_SUITE_END()
174} // namespace validation
175} // namespace test
176} // namespace arm_compute