blob: e35c8fd8a228428cc8acd8e71714096a7d7b3acd [file] [log] [blame]
Sang-Hoon Parkd24affe2019-10-08 18:07:23 +01001/*
2 * Copyright (c) 2019 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"
28#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
30#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"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45/** Tolerance for float operations */
46constexpr RelativeTolerance<float> tolerance_f32(0.00001f);
47RelativeTolerance<half> tolerance_f16(half(0.2));
48
49/** Tolerance for quantized operations */
50constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
51
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
55#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
56 DataType::F16,
57#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
58 DataType::F32,
59});
60} // namespace
61
62TEST_SUITE(NEON)
63TEST_SUITE(LogSoftmaxLayer)
64
65template <typename T>
66using NELogSoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NELogSoftmaxLayer, T, true>;
67
68TEST_SUITE(Float)
69#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
70TEST_SUITE(FP16)
71FIXTURE_DATA_TEST_CASE(RunSmall, NELogSoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
72 framework::dataset::make("DataType", DataType::F16)),
73 framework::dataset::make("Beta", { 1.0f, 2.0f })),
74 framework::dataset::make("Axis", { 1 })))
75{
76 // Validate output
77 validate(Accessor(_target), _reference, tolerance_f16);
78}
79FIXTURE_DATA_TEST_CASE(RunSmall4D, NELogSoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
80 framework::dataset::make("DataType", DataType::F32)),
81 framework::dataset::make("Beta", { 1.0f, 2.0f })),
82 framework::dataset::make("Axis", { 1, 2, 3 })))
83{
84 // Validate output
85 validate(Accessor(_target), _reference, tolerance_f32);
86}
87FIXTURE_DATA_TEST_CASE(RunLarge, NELogSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
88 framework::dataset::make("DataType", DataType::F16)),
89 framework::dataset::make("Beta", { 1.0f, 2.0f })),
90 framework::dataset::make("Axis", { 1 })))
91{
92 // Validate output
93 validate(Accessor(_target), _reference, tolerance_f16);
94}
95TEST_SUITE_END() //FP16
96#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
97
98TEST_SUITE(FP32)
99FIXTURE_DATA_TEST_CASE(RunSmall2D, NELogSoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
100 framework::dataset::make("DataType", DataType::F32)),
101 framework::dataset::make("Beta", { 1.0f, 2.0f })),
102 framework::dataset::make("Axis", { 1 })))
103{
104 // Validate output
105 validate(Accessor(_target), _reference, tolerance_f32);
106}
107FIXTURE_DATA_TEST_CASE(RunSmall4D, NELogSoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
108 framework::dataset::make("DataType", DataType::F32)),
109 framework::dataset::make("Beta", { 1.0f, 2.0f })),
110 framework::dataset::make("Axis", { 1, 2, 3 })))
111{
112 // Validate output
113 validate(Accessor(_target), _reference, tolerance_f32);
114}
115FIXTURE_DATA_TEST_CASE(RunLarge, NELogSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
116 framework::dataset::make("DataType", DataType::F32)),
117 framework::dataset::make("Beta", { 1.0f, 2.0f })),
118 framework::dataset::make("Axis", { 1 })))
119{
120 // Validate output
121 validate(Accessor(_target), _reference, tolerance_f32);
122}
123TEST_SUITE_END() //FP32
124TEST_SUITE_END() //Float
125
126template <typename T>
127using NELogSoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NELogSoftmaxLayer, T, true>;
128
129TEST_SUITE(Quantized)
130TEST_SUITE(QASYMM8)
131FIXTURE_DATA_TEST_CASE(RunSmall2D, NELogSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
132 framework::dataset::make("DataType", DataType::QASYMM8)),
133 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
134 framework::dataset::make("Beta", { 1.0f, 2.f }))),
135 framework::dataset::make("Axis", { 1 })))
136{
137 // Validate output
138 validate(Accessor(_target), _reference, tolerance_qasymm8);
139}
140FIXTURE_DATA_TEST_CASE(RunSmall4D, NELogSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(),
141 framework::dataset::make("DataType", DataType::QASYMM8)),
142 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
143 framework::dataset::make("Beta", { 1.0f, 2.f }))),
144 framework::dataset::make("Axis", { 1, 2, 3 })))
145{
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_qasymm8);
148}
149FIXTURE_DATA_TEST_CASE(RunLarge, NELogSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
150 framework::dataset::make("DataType", DataType::QASYMM8)),
151 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
152 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
153 framework::dataset::make("Axis", { 1 })))
154{
155 // Validate output
156 validate(Accessor(_target), _reference, tolerance_qasymm8);
157}
158TEST_SUITE_END() //QASYMM8
159TEST_SUITE_END() //Quantized
160
161TEST_SUITE_END() //LogSoftmaxLayer
162TEST_SUITE_END() //NEON
163} // namespace validation
164} // namespace test
165} // namespace arm_compute