blob: 3b557173725b05cff882a9894b70bced23d7a4a7 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +01002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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/GLES_COMPUTE/GCTensor.h"
26#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h"
27#include "arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h"
28#include "tests/GLES_COMPUTE/GCAccessor.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
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45/** Tolerance for float operations */
46RelativeTolerance<half> tolerance_f16(half(0.2));
47RelativeTolerance<float> tolerance_f32(0.001f);
48
49/** CNN data types */
50const auto CNNDataTypes = framework::dataset::make("DataType",
51{
52 DataType::F16,
53 DataType::F32,
54});
55} // namespace
56
57TEST_SUITE(GC)
58TEST_SUITE(SoftmaxLayer)
59
Pablo Palmiera2b89ca2017-10-05 15:01:34 +010060DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::SoftmaxLayerSmallShapes(), datasets::SoftmaxLayerLargeShapes()), CNNDataTypes), shape, data_type)
Anthony Barbier7068f992017-10-26 15:23:08 +010061{
Anthony Barbier7068f992017-10-26 15:23:08 +010062 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010063 GCTensor src = create_tensor<GCTensor>(shape, data_type, 1);
64 GCTensor dst = create_tensor<GCTensor>(shape, data_type, 1);
Anthony Barbier7068f992017-10-26 15:23:08 +010065
66 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
67 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
68
69 // Create and configure function
70 GCSoftmaxLayer smx_layer;
71 smx_layer.configure(&src, &dst);
72
73 // Validate valid region
74 const ValidRegion valid_region = shape_to_valid_region(shape);
75 validate(src.info()->valid_region(), valid_region);
76 validate(dst.info()->valid_region(), valid_region);
77
78 // Validate padding
Joel Liang07c37f92017-11-17 11:34:19 +080079 const PaddingSize padding = PaddingCalculator(shape.x(), 8).required_padding();
Anthony Barbier7068f992017-10-26 15:23:08 +010080 validate(src.info()->padding(), padding);
81 validate(dst.info()->padding(), padding);
82}
83
84template <typename T>
85using GCSoftmaxLayerFixture = SoftmaxValidationFixture<GCTensor, GCAccessor, GCSoftmaxLayer, T>;
86
87TEST_SUITE(Float)
88TEST_SUITE(FP16)
giuros01efbf6c82018-09-03 09:53:53 +010089FIXTURE_DATA_TEST_CASE(RunSmall, GCSoftmaxLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +010090 framework::dataset::make("DataType", DataType::F16)),
giuros01efbf6c82018-09-03 09:53:53 +010091 framework::dataset::make("Beta", 1.0f)),
92 framework::dataset::make("Axis", 1)))
Anthony Barbier7068f992017-10-26 15:23:08 +010093{
94 // Validate output
95 validate(GCAccessor(_target), _reference, tolerance_f16);
96}
giuros01efbf6c82018-09-03 09:53:53 +010097FIXTURE_DATA_TEST_CASE(RunLarge, GCSoftmaxLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +010098 framework::dataset::make("DataType", DataType::F16)),
giuros01efbf6c82018-09-03 09:53:53 +010099 framework::dataset::make("Beta", 1.0f)),
100 framework::dataset::make("Axis", 1)))
Anthony Barbier7068f992017-10-26 15:23:08 +0100101{
102 // Validate output
103 validate(GCAccessor(_target), _reference, tolerance_f16);
104}
105TEST_SUITE_END()
106
107TEST_SUITE(FP32)
giuros01efbf6c82018-09-03 09:53:53 +0100108FIXTURE_DATA_TEST_CASE(RunSmall, GCSoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
Pablo Palmiera2b89ca2017-10-05 15:01:34 +0100109 framework::dataset::make("DataType", DataType::F32)),
giuros01efbf6c82018-09-03 09:53:53 +0100110 framework::dataset::make("Beta", 1.0f)),
111 framework::dataset::make("Axis", 1)))
Anthony Barbier7068f992017-10-26 15:23:08 +0100112{
113 // Validate output
114 validate(GCAccessor(_target), _reference, tolerance_f32);
115}
giuros01efbf6c82018-09-03 09:53:53 +0100116FIXTURE_DATA_TEST_CASE(RunLarge, GCSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
117 framework::dataset::make("DataType", DataType::F32)),
118 framework::dataset::make("Beta", 1.0f)),
119 framework::dataset::make("Axis", 1)))
Anthony Barbier7068f992017-10-26 15:23:08 +0100120{
121 // Validate output
122 validate(GCAccessor(_target), _reference, tolerance_f32);
123}
124TEST_SUITE_END()
125TEST_SUITE_END()
126
127TEST_SUITE_END()
128TEST_SUITE_END()
129} // namespace validation
130} // namespace test
131} // namespace arm_compute