1 /*
2 * Copyright (c) 2019-2020 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
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 namespace
44 {
45 /** Tolerance for float operations */
46 constexpr RelativeTolerance<float> tolerance_f32(0.00001f);
47 RelativeTolerance<half> tolerance_f16(half(0.2));
48
49 /** Tolerance for quantized operations */
50 constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
51
52 /** CNN data types */
53 const 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
62 TEST_SUITE(NEON)
63 TEST_SUITE(LogSoftmaxLayer)
64
65 template <typename T>
66 using NELogSoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NELogSoftmaxLayer, T, true>;
67
68 TEST_SUITE(Float)
69 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
TEST_SUITE(FP16)70 TEST_SUITE(FP16)
71 FIXTURE_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", { 0, -1 })))
75 {
76 // Validate output
77 validate(Accessor(_target), _reference, tolerance_f16);
78 }
79 FIXTURE_DATA_TEST_CASE(RunSmall4D, NELogSoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(),
80 framework::dataset::make("DataType", DataType::F16)),
81 framework::dataset::make("Beta", { 1.0f, 2.0f })),
82 framework::dataset::make("Axis", { 0, -3, 2 })))
83 {
84 // Validate output
85 validate(Accessor(_target), _reference, tolerance_f16);
86 }
87 FIXTURE_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", { 0 })))
91 {
92 // Validate output
93 validate(Accessor(_target), _reference, tolerance_f16);
94 }
95 TEST_SUITE_END() //FP16
96 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
97
TEST_SUITE(FP32)98 TEST_SUITE(FP32)
99 FIXTURE_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", { 0, 1 })))
103 {
104 // Validate output
105 validate(Accessor(_target), _reference, tolerance_f32);
106 }
107 FIXTURE_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", { 0, 2, -1 })))
111 {
112 // Validate output
113 validate(Accessor(_target), _reference, tolerance_f32);
114 }
115 FIXTURE_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", { 0 })))
119 {
120 // Validate output
121 validate(Accessor(_target), _reference, tolerance_f32);
122 }
123 TEST_SUITE_END() //FP32
124 TEST_SUITE_END() //Float
125
126 template <typename T>
127 using NELogSoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NELogSoftmaxLayer, T, true>;
128
129 TEST_SUITE(Quantized)
TEST_SUITE(QASYMM8)130 TEST_SUITE(QASYMM8)
131 FIXTURE_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", { 0, 1 })))
136 {
137 // Validate output
138 validate(Accessor(_target), _reference, tolerance_qasymm8);
139 }
140 FIXTURE_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", { 0, -1, 1 })))
145 {
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_qasymm8);
148 }
149 FIXTURE_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", { 0 })))
154 {
155 // Validate output
156 validate(Accessor(_target), _reference, tolerance_qasymm8);
157 }
158 TEST_SUITE_END() //QASYMM8
159 TEST_SUITE_END() //Quantized
160
161 TEST_SUITE_END() //LogSoftmaxLayer
162 TEST_SUITE_END() //NEON
163 } // namespace validation
164 } // namespace test
165 } // namespace arm_compute
166