blob: 148613c5f83a1202dee6088bc52e4ff5cd87e7ba [file] [log] [blame]
Sang-Hoon Park62eeb532019-10-29 13:13:19 +00001/*
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/CL/kernels/CLSoftmaxLayerKernel.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/CLTensorAllocator.h"
28#include "arm_compute/runtime/CL/functions/CLSoftmaxLayer.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/SoftmaxLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Tolerance for float operations */
47RelativeTolerance<half> tolerance_f16(half(0.2));
48RelativeTolerance<float> tolerance_f32(0.001f);
49
50/** Tolerance for quantized operations */
51constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
52
53/** CNN data types */
54const auto CNNDataTypes = framework::dataset::make("DataType",
55{
56 DataType::QASYMM8,
57 DataType::F16,
58 DataType::F32,
59});
60} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(LogSoftmaxLayer)
64
65template <typename T>
66using CLLogSoftmaxLayerFixture = SoftmaxValidationFixture<CLTensor, CLAccessor, CLLogSoftmaxLayer, T, true>;
67
68TEST_SUITE(Float)
69TEST_SUITE(FP16)
70FIXTURE_DATA_TEST_CASE(RunSmall, CLLogSoftmaxLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
71 framework::dataset::make("DataType", DataType::F16)),
72 framework::dataset::make("Beta", { 1.0f, 2.0f })),
73 framework::dataset::make("Axis", { 1, 2 })))
74{
75 // Validate output
76 validate(CLAccessor(_target), _reference, tolerance_f16);
77}
78FIXTURE_DATA_TEST_CASE(RunLarge, CLLogSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
79 framework::dataset::make("DataType", DataType::F16)),
80 framework::dataset::make("Beta", { 1.0f, 2.0f })),
81 framework::dataset::make("Axis", { 1, 2 })))
82{
83 // Validate output
84 validate(CLAccessor(_target), _reference, tolerance_f16);
85}
86FIXTURE_DATA_TEST_CASE(Run4D, CLLogSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
87 framework::dataset::make("DataType", DataType::F16)),
88 framework::dataset::make("Beta", { 1.0f, 2.0f })),
89 framework::dataset::make("Axis", { 1, 2, 3 })))
90{
91 // Validate output
92 validate(CLAccessor(_target), _reference, tolerance_f16);
93}
94TEST_SUITE_END()
95
96TEST_SUITE(FP32)
97FIXTURE_DATA_TEST_CASE(RunSmall, CLLogSoftmaxLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
98 framework::dataset::make("DataType", DataType::F32)),
99 framework::dataset::make("Beta", { 1.0f, 2.0f })),
100 framework::dataset::make("Axis", { 1, 2 })))
101{
102 // Validate output
103 validate(CLAccessor(_target), _reference, tolerance_f32);
104}
105FIXTURE_DATA_TEST_CASE(RunLarge, CLLogSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
106 framework::dataset::make("DataType", DataType::F32)),
107 framework::dataset::make("Beta", { 1.0f, 2.0f })),
108 framework::dataset::make("Axis", { 1, 2 })))
109{
110 // Validate output
111 validate(CLAccessor(_target), _reference, tolerance_f32);
112}
113FIXTURE_DATA_TEST_CASE(Run4D, CLLogSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
114 framework::dataset::make("DataType", DataType::F32)),
115 framework::dataset::make("Beta", { 1.0f, 2.0f })),
116 framework::dataset::make("Axis", { 1, 2, 3 })))
117{
118 // Validate output
119 validate(CLAccessor(_target), _reference, tolerance_f32);
120}
121TEST_SUITE_END()
122TEST_SUITE_END()
123
124template <typename T>
125using CLLogSoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<CLTensor, CLAccessor, CLLogSoftmaxLayer, T, true>;
126
127TEST_SUITE(Quantized)
128TEST_SUITE(QASYMM8)
129FIXTURE_DATA_TEST_CASE(RunSmall, CLLogSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
130 framework::dataset::make("DataType", DataType::QASYMM8)),
131 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
132 framework::dataset::make("Beta", { 1.0f, 2.f }))),
133 framework::dataset::make("Axis", { 1, 2 })))
134{
135 // Validate output
136 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
137}
138FIXTURE_DATA_TEST_CASE(RunLarge, CLLogSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
139 framework::dataset::make("DataType", DataType::QASYMM8)),
140 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
141 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
142 framework::dataset::make("Axis", { 1 })))
143{
144 // Validate output
145 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
146}
147FIXTURE_DATA_TEST_CASE(Run4D, CLLogSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
148 framework::dataset::make("DataType", DataType::QASYMM8)),
149 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
150 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
151 framework::dataset::make("Axis", { 1, 2, 3 })))
152{
153 // Validate output
154 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
155}
156
157TEST_SUITE_END()
158TEST_SUITE_END()
159
160TEST_SUITE_END()
161TEST_SUITE_END()
162} // namespace validation
163} // namespace test
164} // namespace arm_compute