blob: 340f5dc2a3e1df3fbdb3397ea1d34498500b3c50 [file] [log] [blame]
Ramy Elgammal002e6532023-01-11 18:48:04 +00001/*
2 * Copyright (c) 2023 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 */
SiCong Li23882a92023-06-28 09:49:45 +010024#ifndef ACL_INTERNAL_TEST_CKW_IN_DF // Do not include this test if ACL_INTERNAL_TEST_CKW_IN_DF and the op has not been ported to ckw
Ramy Elgammal002e6532023-01-11 18:48:04 +000025#include "arm_compute/core/Types.h"
26#include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuSoftmax.h"
27
28#include "tests/CL/CLAccessor.h"
29#include "tests/datasets/ShapeDatasets.h"
30#include "tests/framework/Asserts.h"
31#include "tests/framework/Fixture.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/dynamic_fusion/operators/SoftmaxFixture.h"
36
37using namespace arm_compute::experimental::dynamic_fusion;
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45/** Tolerance for float operations */
46RelativeTolerance<half> tolerance_f16(half(0.2));
47RelativeTolerance<float> tolerance_f32(0.001f);
48
49TEST_SUITE(CL)
50TEST_SUITE(DYNAMIC_FUSION)
51TEST_SUITE(SOFTMAX)
52
53// *INDENT-OFF*
54// clang-format off
55DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
56 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types
57 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes
58 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
59 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
60 TensorInfo(TensorShape(32U, 13U), 1, DataType::S32), // Unsupported data type
61 TensorInfo(TensorShape(32U, 13U), 1, DataType::F16),
62 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
63 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
64 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
65 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
66
67 }),
68 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16),
69 TensorInfo(TensorShape(27U, 11U), 1, DataType::F32),
70 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
71 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
72 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
73 TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM16), // Unsupported data type
74 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
75 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
76 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
77 TensorInfo(TensorShape(32U, 13U), 1, DataType::F32),
78
79 })),
80 framework::dataset::make("beta", { 1.0,
81 2.0,
82 2.0,
83 1.0,
84 1.0,
85 1.0,
86 1.0,
87 1.0,
88 1.0,
89 1.0,
90 })),
91 framework::dataset::make("axis", {
92 0,
93 0,
94 1, // Invalid as axis != 0
95 0,
96 0,
97 0,
98 -3, // Invalid as axis != 0
99 2, // Invalid as axis != 0
100 1, // Invalid as axis != 0
101 -1, // Invalid as axis != 0
102 })),
103 framework::dataset::make("Expected", { false, false, false, true, false, false, false, false, false, false})),
104 input_info, output_info, beta, axis, expected)
105{
106 // Create a new workload sketch
107 CLCompileContext cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +0100108 GpuWorkloadContext context = GpuWorkloadContext{ &cl_compile_ctx };
109 GpuWorkloadSketch sketch{ &context };
Ramy Elgammal002e6532023-01-11 18:48:04 +0000110
111 SoftmaxAttributes softmax_attr{};
112 softmax_attr.axis(axis).beta(beta).is_log_softmax(false);
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +0100113 TensorInfo src_info = context.create_tensor_info(input_info);
114 TensorInfo dst_info = context.create_tensor_info(output_info);
Ramy Elgammal002e6532023-01-11 18:48:04 +0000115 const bool res = static_cast<bool>(GpuSoftmax::validate_op(sketch, &src_info, &dst_info, softmax_attr));
116 ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
117}
118
119template <typename T>
120using DynamicFusionSoftmaxLayerFixture = DynamicFusionSoftmaxValidationFixture<CLTensor, CLAccessor, GpuSoftmax, T>;
121
122TEST_SUITE(FLOAT)
123TEST_SUITE(FP32)
124
125FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionSoftmaxLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
126 framework::dataset::make("DataType", DataType::F32)),
127 framework::dataset::make("Beta", { 1.0f, 2.0f })),
128 framework::dataset::make("Axis", { 0 })),
129 framework::dataset::make("is_log", {false, true})))
130{
131 // Validate output
132 validate(CLAccessor(_target), _reference, tolerance_f32);
133}
134
135
136FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
137 framework::dataset::make("DataType", DataType::F32)),
138 framework::dataset::make("Beta", { 1.0f, 2.0f })),
139 framework::dataset::make("Axis", { 0 })),
140 framework::dataset::make("is_log", {false, true})))
141{
142 // Validate output
143 validate(CLAccessor(_target), _reference, tolerance_f32);
144}
145
146
147FIXTURE_DATA_TEST_CASE(Run4D, DynamicFusionSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
148 framework::dataset::make("DataType", DataType::F32)),
149 framework::dataset::make("Beta", { 1.0f, 2.0f })),
150 framework::dataset::make("Axis", { 0 })),
151 framework::dataset::make("is_log", {false, true})))
152{
153 // Validate output
154 validate(CLAccessor(_target), _reference, tolerance_f32);
155}
156TEST_SUITE_END() // FP32
157TEST_SUITE(FP16)
158
159FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionSoftmaxLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SoftmaxLayerSmallShapes(),
160 framework::dataset::make("DataType", DataType::F16)),
161 framework::dataset::make("Beta", { 1.0f, 2.0f })),
162 framework::dataset::make("Axis", { 0 })),
163 framework::dataset::make("is_log", {false, true})))
164{
165 // Validate output
166 validate(CLAccessor(_target), _reference, tolerance_f16);
167}
168
169
170FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SoftmaxLayerLargeShapes(),
171 framework::dataset::make("DataType", DataType::F16)),
172 framework::dataset::make("Beta", { 1.0f, 2.0f })),
173 framework::dataset::make("Axis", { 0 })),
174 framework::dataset::make("is_log", {false, true})))
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_f16);
178}
179
180
181FIXTURE_DATA_TEST_CASE(Run4D, DynamicFusionSoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SoftmaxLayer4DShapes(),
182 framework::dataset::make("DataType", DataType::F16)),
183 framework::dataset::make("Beta", { 1.0f, 2.0f })),
184 framework::dataset::make("Axis", { 0 })),
185 framework::dataset::make("is_log", {false, true})))
186{
187 // Validate output
188 validate(CLAccessor(_target), _reference, tolerance_f16);
189}
190TEST_SUITE_END() // FP16
191TEST_SUITE_END() // FLOAT
192
193TEST_SUITE_END() // SOFTMAX
194TEST_SUITE_END() // DYNAMIC_FUSION
195TEST_SUITE_END() // CL
196
197} // namespace validation
198} // namespace test
199} // namespace arm_compute
SiCong Li23882a92023-06-28 09:49:45 +0100200
201#endif // ACL_INTERNAL_TEST_CKW_IN_DF