blob: c469b8acd8ba326bcfe2c78f2393a43913a13f44 [file] [log] [blame]
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +01001/*
2 * Copyright (c) 2017 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/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
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010049/** Tolerance for fixed point operations */
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +010050constexpr AbsoluteTolerance<int16_t> tolerance_fixed_point(2);
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010051
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
55 DataType::F16,
56 DataType::F32,
57 DataType::QS8,
58 DataType::QS16,
59});
60} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(SoftmaxLayer)
64
65DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), CNNDataTypes), shape, data_type)
66{
67 // Set fixed point position data type allowed
68 const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
69
70 // Create tensors
71 CLTensor src = create_tensor<CLTensor>(shape, data_type, 1, fixed_point_position);
72 CLTensor dst = create_tensor<CLTensor>(shape, data_type, 1, fixed_point_position);
73
74 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
75 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
76
77 // Create and configure function
78 CLSoftmaxLayer smx_layer;
79 smx_layer.configure(&src, &dst);
80
81 // Validate valid region
82 const ValidRegion valid_region = shape_to_valid_region(shape);
83 validate(src.info()->valid_region(), valid_region);
84 validate(dst.info()->valid_region(), valid_region);
85
86 // Validate padding
87 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
88 validate(src.info()->padding(), padding);
89 validate(dst.info()->padding(), padding);
90}
91
92template <typename T>
93using CLSoftmaxLayerFixture = SoftmaxValidationFixture<CLTensor, CLAccessor, CLSoftmaxLayer, T>;
94
95TEST_SUITE(Float)
96TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +010097FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +010098{
99 // Validate output
100 validate(CLAccessor(_target), _reference, tolerance_f16);
101}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100102FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100103{
104 // Validate output
105 validate(CLAccessor(_target), _reference, tolerance_f16);
106}
107TEST_SUITE_END()
108
109TEST_SUITE(FP32)
110FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
111{
112 // Validate output
113 validate(CLAccessor(_target), _reference, tolerance_f32);
114}
115FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)))
116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance_f32);
119}
120TEST_SUITE_END()
121TEST_SUITE_END()
122
123template <typename T>
124using CLSoftmaxLayerFixedPointFixture = SoftmaxValidationFixedPointFixture<CLTensor, CLAccessor, CLSoftmaxLayer, T>;
125
126TEST_SUITE(Quantized)
127TEST_SUITE(QS8)
128// Testing for fixed point position [1,6) as reciprocal limits the maximum fixed point position to 5
129FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
130 DataType::QS8)),
131 framework::dataset::make("FractionalBits", 1, 6)))
132{
133 // Validate output
134 validate(CLAccessor(_target), _reference, tolerance_fixed_point);
135}
136FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
137 DataType::QS8)),
138 framework::dataset::make("FractionalBits", 1, 6)))
139{
140 // Validate output
141 validate(CLAccessor(_target), _reference, tolerance_fixed_point);
142}
143TEST_SUITE_END()
144
145TEST_SUITE(QS16)
146// Testing for fixed point position [1,14) as reciprocal limits the maximum fixed point position to 14
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100147FIXTURE_DATA_TEST_CASE(RunSmall, CLSoftmaxLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(),
148 framework::dataset::make("DataType",
149 DataType::QS16)),
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100150 framework::dataset::make("FractionalBits", 1, 14)))
151{
152 // Validate output
153 validate(CLAccessor(_target), _reference, tolerance_fixed_point);
154}
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100155FIXTURE_DATA_TEST_CASE(RunLarge, CLSoftmaxLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(),
156 framework::dataset::make("DataType",
157 DataType::QS16)),
Moritz Pflanzerf6ad98a2017-07-21 17:19:58 +0100158 framework::dataset::make("FractionalBits", 1, 14)))
159{
160 // Validate output
161 validate(CLAccessor(_target), _reference, tolerance_fixed_point);
162}
163TEST_SUITE_END()
164TEST_SUITE_END()
165
166TEST_SUITE_END()
167TEST_SUITE_END()
168} // namespace validation
169} // namespace test
170} // namespace arm_compute