Compute Library
 22.05
LogSoftmaxLayer.cpp
Go to the documentation of this file.
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"
28 #include "tests/NEON/Accessor.h"
30 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Macros.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
57 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
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
70 TEST_SUITE(FP16)
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 }
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 }
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 
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 }
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 }
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)
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(),
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(),
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
RelativeTolerance< float > tolerance_f32(0.001f)
F32 Tolerance value for comparing reference&#39;s output against implementation&#39;s output for floating poi...
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
Quantization information.
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
validate(CLAccessor(output_state), expected_output)
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
RelativeTolerance< half_float::half > tolerance_f16(half(0.2))
F16 Tolerance value for comparing reference&#39;s output against implementation&#39;s output for floating poi...
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
SoftmaxValidationFixture< Tensor, Accessor, NELogSoftmaxLayer, T, true > NELogSoftmaxLayerFixture