blob: 396e274e0b301d4e7c9aa8bcd06895f0c22a5cb7 [file] [log] [blame]
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01003 *
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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLSoftmaxLayer.h"
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010028#include "tests/CL/CLAccessor.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 */
Georgios Pinitas583137c2017-08-31 18:12:42 +010046RelativeTolerance<half> tolerance_f16(half(0.2));
47RelativeTolerance<float> tolerance_f32(0.001f);
steniu013e05e4e2017-08-25 17:18:01 +010048
Chunosovf450caa2017-11-08 16:09:35 +070049/** Tolerance for quantized operations */
50constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
Sang-Hoon Park0779fec2019-11-13 17:08:12 +000051constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1);
52
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010053/** CNN data types */
54const auto CNNDataTypes = framework::dataset::make("DataType",
55{
Chunosovf450caa2017-11-08 16:09:35 +070056 DataType::QASYMM8,
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010057 DataType::F16,
58 DataType::F32,
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010059});
60} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(SoftmaxLayer)
64
Georgios Pinitas30902ed2017-11-14 15:32:57 +000065// *INDENT-OFF*
66// clang-format off
SiCong Lid004a7a2020-05-28 15:26:41 +010067DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +010068 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types
69 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
70 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, // Invalid output quantization info
Georgios Pinitas30902ed2017-11-14 15:32:57 +000071 QuantizationInfo(1.f/256, 12)),
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +010072 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
73 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
Georgios Pinitas30902ed2017-11-14 15:32:57 +000074 QuantizationInfo(1.f/256, 12)),
Sang-Hoon Park0779fec2019-11-13 17:08:12 +000075 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8_SIGNED,
SiCong Lid004a7a2020-05-28 15:26:41 +010076 QuantizationInfo(1.f/256, 12)),
77 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8_SIGNED, // Invalid axis high
78 QuantizationInfo(1.f/256, 12)),
79 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8_SIGNED, // Invalid axis low
Sang-Hoon Park0779fec2019-11-13 17:08:12 +000080 QuantizationInfo(1.f/256, 12))
Georgios Pinitas30902ed2017-11-14 15:32:57 +000081 }),
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +010082 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
83 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
84 TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8,
Georgios Pinitas30902ed2017-11-14 15:32:57 +000085 QuantizationInfo(1.f/256, 12)),
Georgios Pinitas17d6d3c2018-07-02 17:52:40 +010086 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
87 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8,
Georgios Pinitas30902ed2017-11-14 15:32:57 +000088 QuantizationInfo(1.f/256, 0)),
Sang-Hoon Park0779fec2019-11-13 17:08:12 +000089 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8_SIGNED,
90 QuantizationInfo(1.f/256, -128)),
SiCong Li96209c72020-08-21 12:28:30 +010091 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8_SIGNED,
SiCong Lid004a7a2020-05-28 15:26:41 +010092 QuantizationInfo(1.f/256, -128)),
SiCong Li96209c72020-08-21 12:28:30 +010093 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8_SIGNED,
SiCong Lid004a7a2020-05-28 15:26:41 +010094 QuantizationInfo(1.f/256, -128)),
Georgios Pinitas30902ed2017-11-14 15:32:57 +000095 })),
SiCong Lid004a7a2020-05-28 15:26:41 +010096 framework::dataset::make("beta", { 1.0,
97 2.0,
98 1.0,
99 2.0,
100 1.0,
101 2.0,
102 1.0,
103 2.0,
SiCong Lid004a7a2020-05-28 15:26:41 +0100104 })),
morgolock9c7fed82020-08-05 12:30:56 +0100105 framework::dataset::make("axis", {
SiCong Lid004a7a2020-05-28 15:26:41 +0100106 0,
107 0,
108 0,
SiCong Li96209c72020-08-21 12:28:30 +0100109 1,
morgolock9c7fed82020-08-05 12:30:56 +0100110 0,
SiCong Lid004a7a2020-05-28 15:26:41 +0100111 -1,
SiCong Li96209c72020-08-21 12:28:30 +0100112 2,
113 -3,
SiCong Lid004a7a2020-05-28 15:26:41 +0100114 })),
Giorgio Arena2d1a8352020-10-26 15:04:08 +0000115 framework::dataset::make("Expected", { false, false, false, true, true, true, false, false })),
morgolock9c7fed82020-08-05 12:30:56 +0100116 input_info, output_info, beta, axis, expected)
Georgios Pinitas30902ed2017-11-14 15:32:57 +0000117{
morgolock9c7fed82020-08-05 12:30:56 +0100118 ARM_COMPUTE_EXPECT(bool(CLSoftmaxLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), beta, axis)) == expected, framework::LogLevel::ERRORS);
Georgios Pinitas30902ed2017-11-14 15:32:57 +0000119}
120// clang-format on
121// *INDENT-ON*
122
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100123template <typename T>
124using CLSoftmaxLayerFixture = SoftmaxValidationFixture<CLTensor, CLAccessor, CLSoftmaxLayer, T>;
125
126TEST_SUITE(Float)
127TEST_SUITE(FP16)
giuros01efbf6c82018-09-03 09:53:53 +0100128FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
129 framework::dataset::make("DataType", DataType::F16)),
130 framework::dataset::make("Beta", { 1.0f, 2.0f })),
SiCong Li96209c72020-08-21 12:28:30 +0100131 framework::dataset::make("Axis", { 0, -1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100132{
133 // Validate output
134 validate(CLAccessor(_target), _reference, tolerance_f16);
135}
giuros01efbf6c82018-09-03 09:53:53 +0100136FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
137 framework::dataset::make("DataType", DataType::F16)),
138 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100139 framework::dataset::make("Axis", { 0 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100140{
141 // Validate output
142 validate(CLAccessor(_target), _reference, tolerance_f16);
143}
giuros01efbf6c82018-09-03 09:53:53 +0100144FIXTURE_DATA_TEST_CASE(Run4D, CLSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
145 framework::dataset::make("DataType", DataType::F16)),
146 framework::dataset::make("Beta", { 1.0f, 2.0f })),
SiCong Li96209c72020-08-21 12:28:30 +0100147 framework::dataset::make("Axis", { 0, -1, 2 })))
Giuseppe Rossini87e896a2018-08-24 10:24:12 +0100148{
149 // Validate output
150 validate(CLAccessor(_target), _reference, tolerance_f16);
151}
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100152TEST_SUITE_END()
153
154TEST_SUITE(FP32)
giuros01efbf6c82018-09-03 09:53:53 +0100155FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
156 framework::dataset::make("DataType", DataType::F32)),
157 framework::dataset::make("Beta", { 1.0f, 2.0f })),
SiCong Li96209c72020-08-21 12:28:30 +0100158 framework::dataset::make("Axis", { 0, 1 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100159{
160 // Validate output
161 validate(CLAccessor(_target), _reference, tolerance_f32);
162}
giuros01efbf6c82018-09-03 09:53:53 +0100163FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
164 framework::dataset::make("DataType", DataType::F32)),
165 framework::dataset::make("Beta", { 1.0f, 2.0f })),
morgolock9c7fed82020-08-05 12:30:56 +0100166 framework::dataset::make("Axis", { 0 })))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100167{
168 // Validate output
169 validate(CLAccessor(_target), _reference, tolerance_f32);
170}
giuros01efbf6c82018-09-03 09:53:53 +0100171FIXTURE_DATA_TEST_CASE(Run4D, CLSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
172 framework::dataset::make("DataType", DataType::F32)),
173 framework::dataset::make("Beta", { 1.0f, 2.0f })),
SiCong Li96209c72020-08-21 12:28:30 +0100174 framework::dataset::make("Axis", { 0, -2, 3 })))
Giuseppe Rossini87e896a2018-08-24 10:24:12 +0100175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_f32);
178}
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100179TEST_SUITE_END()
180TEST_SUITE_END()
181
182template <typename T>
Chunosovf450caa2017-11-08 16:09:35 +0700183using CLSoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<CLTensor, CLAccessor, CLSoftmaxLayer, T>;
184
185TEST_SUITE(Quantized)
186TEST_SUITE(QASYMM8)
giuros01efbf6c82018-09-03 09:53:53 +0100187FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100188 framework::dataset::make("DataType", DataType::QASYMM8)),
giuros01efbf6c82018-09-03 09:53:53 +0100189 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
190 framework::dataset::make("Beta", { 1.0f, 2.f }))),
SiCong Li96209c72020-08-21 12:28:30 +0100191 framework::dataset::make("Axis", { 0, 1 })))
Chunosovf450caa2017-11-08 16:09:35 +0700192{
193 // Validate output
194 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
195}
giuros01efbf6c82018-09-03 09:53:53 +0100196FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100197 framework::dataset::make("DataType", DataType::QASYMM8)),
198 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
giuros01efbf6c82018-09-03 09:53:53 +0100199 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
morgolock9c7fed82020-08-05 12:30:56 +0100200 framework::dataset::make("Axis", { 0 })))
Chunosovf450caa2017-11-08 16:09:35 +0700201{
202 // Validate output
203 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
204}
giuros01efbf6c82018-09-03 09:53:53 +0100205FIXTURE_DATA_TEST_CASE(Run4D, CLSoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
Giuseppe Rossini87e896a2018-08-24 10:24:12 +0100206 framework::dataset::make("DataType", DataType::QASYMM8)),
giuros01efbf6c82018-09-03 09:53:53 +0100207 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
208 framework::dataset::make("Beta", { 1.0f, 2.0f }))),
SiCong Li96209c72020-08-21 12:28:30 +0100209 framework::dataset::make("Axis", { 0, -4, 1 })))
Giuseppe Rossini87e896a2018-08-24 10:24:12 +0100210{
211 // Validate output
212 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
213}
214
Sang-Hoon Park0779fec2019-11-13 17:08:12 +0000215TEST_SUITE_END() // QASYMM8
Chunosovf450caa2017-11-08 16:09:35 +0700216
Sang-Hoon Park0779fec2019-11-13 17:08:12 +0000217TEST_SUITE(QASYMM8_SIGNED)
218
219FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
220 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
221 combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }),
222 framework::dataset::make("Beta", { 1.0f, 2.f }))),
SiCong Li96209c72020-08-21 12:28:30 +0100223 framework::dataset::make("Axis", { 0, 1 })))
Sang-Hoon Park0779fec2019-11-13 17:08:12 +0000224{
225 // Validate output
Sang-Hoon Park77d3d242020-08-10 22:50:17 +0100226 validate(CLAccessor(_target), _reference, tolerance_qasymm8_signed);
Sang-Hoon Park0779fec2019-11-13 17:08:12 +0000227}
228
229TEST_SUITE_END() // QASYMM8_SIGNED
230TEST_SUITE_END() // Quantized
231TEST_SUITE_END() // SoftmaxLayer
232TEST_SUITE_END() // CL
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100233} // namespace validation
234} // namespace test
235} // namespace arm_compute