xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/dynamic_fusion/gpu/cl/Sub.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
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  */
24 
25 #include "arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h"
26 #include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuSub.h"
27 
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/framework/Fixture.h"
30 #include "tests/framework/Macros.h"
31 #include "tests/framework/datasets/Datasets.h"
32 #include "tests/validation/Validation.h"
33 
34 #include "tests/datasets/DynamicFusionDataset.h"
35 #include "tests/datasets/ShapeDatasets.h"
36 #include "tests/validation/fixtures/dynamic_fusion/gpu/cl/ElementwiseBinaryFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 /* Synced with tests/validation/CL/ArithmeticSubtraction.cpp from the standard interface.
45  *
46  * Difference          | Why the difference
47  * No quantized tests  | Not supported yet
48  * No in place tests   | Not supported yet
49  * No activation tests | Not needed in dynamic fusion interface
50  *
51  */
52 TEST_SUITE(CL)
TEST_SUITE(DYNAMIC_FUSION)53 TEST_SUITE(DYNAMIC_FUSION)
54 TEST_SUITE(SUB)
55 
56 // *INDENT-OFF*
57 // clang-format off
58 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
59                framework::dataset::make("LhsInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
60                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U32),    // Unsupported data type U32
61                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),    // Unsupported data type QASYMM8
62                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8_SIGNED),    // Unsupported data type QASYMM8
63                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),    // Invalid data type combination
64                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),    // S16 is valid data type for Sub
65                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),    // S32 is valid data type for Sub
66                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),    // Mismatching shapes
67                                                         TensorInfo(TensorShape(32U,  1U, 1U), 1, DataType::F32),    // Broadcasting allowed for lhs
68                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69                                                         TensorInfo(TensorShape(15U, 23U, 3U), 1, DataType::F32),    // Broadcast Y dimension is not allowed
70                                                         TensorInfo(TensorShape( 3U,  8U, 9U), 1, DataType::S16),    // Broadcast Z dimension is not allowed
71                                                         TensorInfo(TensorShape(32U, 13U, 2U, 2), 1, DataType::F32), // Batching is allowed
72                                                       }),
73                framework::dataset::make("RhsInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
74                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U32),
75                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
76                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8_SIGNED),
77                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
78                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
79                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
80                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
81                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
82                                                        TensorInfo(TensorShape(32U,  1U, 1U), 1, DataType::F32),    // Broadcasting allowed for rhs
83                                                        TensorInfo(TensorShape(15U,  1U, 3U), 1, DataType::F32),
84                                                        TensorInfo(TensorShape( 3U,  8U, 1U), 1, DataType::S16),
85                                                        TensorInfo(TensorShape(32U, 13U, 2U, 2), 1, DataType::F32),
86                                                       })),
87                framework::dataset::make("Expected", { true, false, false, false, false, true, true, false, true, true, false, false, true })),
88                input1_info, input2_info, expected)
89 {
90     // Create a new workload sketch
91     auto              cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
92     auto              gpu_ctx        = GpuWorkloadContext{ &cl_compile_ctx };
93     GpuWorkloadSketch sketch{ &gpu_ctx };
94 
95     // Validate Elementwise Sub
96     auto          lhs_info         = sketch.create_tensor_info(input1_info);
97     auto          rhs_info         = sketch.create_tensor_info(input2_info);
98 
99     bool res = bool(GpuSub::validate_op(sketch, &lhs_info, &rhs_info));
100     ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
101 }
102 // clang-format on
103 // *INDENT-ON*
104 
105 template <typename T>
106 using DynamicFusionCLSubFixture = DynamicFusionGpuElementwiseBinaryOneOpValidationFixture<CLTensor, CLAccessor, GpuSub, T>;
107 
108 template <typename T>
109 using DynamicFusionCLSubBroadcastFixture = DynamicFusionGpuElementwiseBinaryBroadcastOneOpValidationFixture<CLTensor, CLAccessor, GpuSub, T>;
110 
111 template <typename T>
112 using DynamicFusionCLSubTwoOpsFixture = DynamicFusionGpuElementwiseBinaryTwoOpsValidationFixture<CLTensor, CLAccessor, GpuSub, T>;
113 
114 TEST_SUITE(FP32)
115 FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
116                        DynamicFusionCLSubFixture<float>,
117                        framework::DatasetMode::PRECOMMIT,
118                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
119                                                datasets::SmallShapes()),
120                                        framework::dataset::make("DataType", { DataType::F32 })),
121                                framework::dataset::make("InPlace", { false })))
122 {
123     // Validate output
124     validate(CLAccessor(_target), _reference);
125 }
126 FIXTURE_DATA_TEST_CASE(RunLargeOneOp,
127                        DynamicFusionCLSubFixture<float>,
128                        framework::DatasetMode::NIGHTLY,
129                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
130                                                datasets::LargeShapes()),
131                                        framework::dataset::make("DataType", { DataType::F32 })),
132                                framework::dataset::make("InPlace", { false })))
133 {
134     // Validate output
135     validate(CLAccessor(_target), _reference);
136 }
137 FIXTURE_DATA_TEST_CASE(RunSmallBroadcastOneOp,
138                        DynamicFusionCLSubBroadcastFixture<float>,
139                        framework::DatasetMode::PRECOMMIT,
140                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
141                                                datasets::TemporaryLimitedSmallShapesBroadcast()),
142                                        framework::dataset::make("DataType", { DataType::F32 })),
143                                framework::dataset::make("InPlace", { false })))
144 {
145     // Validate output
146     validate(CLAccessor(_target), _reference);
147 }
148 
149 FIXTURE_DATA_TEST_CASE(RunLargeBroadcastOneOp,
150                        DynamicFusionCLSubBroadcastFixture<float>,
151                        framework::DatasetMode::NIGHTLY,
152                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
153                                                datasets::TemporaryLimitedLargeShapesBroadcast()),
154                                        framework::dataset::make("DataType", { DataType::F32 })),
155                                framework::dataset::make("InPlace", { false })))
156 {
157     // Validate output
158     validate(CLAccessor(_target), _reference);
159 }
160 FIXTURE_DATA_TEST_CASE(RunSmallTwoOps,
161                        DynamicFusionCLSubTwoOpsFixture<float>,
162                        framework::DatasetMode::PRECOMMIT,
163                        combine(combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
164                                                        datasets::DynamicFusionElementwiseBinaryTwoOpsSmallShapes()),
165                                                framework::dataset::make("DataType", { DataType::F32 })),
166                                        framework::dataset::make("InPlace", { false })),
167                                framework::dataset::make("FuseTwoOps", { true })))
168 {
169     // Validate output
170     validate(CLAccessor(_target), _reference);
171 }
172 TEST_SUITE_END() // FP32
173 
TEST_SUITE(FP16)174 TEST_SUITE(FP16)
175 FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
176                        DynamicFusionCLSubFixture<half>,
177                        framework::DatasetMode::ALL,
178                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
179                                                datasets::SmallShapes()),
180                                        framework::dataset::make("DataType", { DataType::F16 })),
181                                framework::dataset::make("InPlace", { false })))
182 {
183     // Validate output
184     validate(CLAccessor(_target), _reference);
185 }
186 
187 FIXTURE_DATA_TEST_CASE(RunSmallBroadcastOneOp,
188                        DynamicFusionCLSubBroadcastFixture<half>,
189                        framework::DatasetMode::ALL,
190                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
191                                                datasets::TemporaryLimitedSmallShapesBroadcast()),
192                                        framework::dataset::make("DataType", { DataType::F16 })),
193                                framework::dataset::make("InPlace", { false })))
194 {
195     // Validate output
196     validate(CLAccessor(_target), _reference);
197 }
198 
199 TEST_SUITE_END() // FP16
200 
TEST_SUITE(S32)201 TEST_SUITE(S32)
202 FIXTURE_DATA_TEST_CASE(RunSmall,
203                        DynamicFusionCLSubFixture<int32_t>,
204                        framework::DatasetMode::PRECOMMIT,
205                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
206                                                datasets::SmallShapes()),
207                                        framework::dataset::make("DataType", { DataType::S32 })),
208                                framework::dataset::make("InPlace", { false })))
209 {
210     // Validate output
211     validate(CLAccessor(_target), _reference);
212 }
213 TEST_SUITE_END() // S32
214 
TEST_SUITE(S16)215 TEST_SUITE(S16)
216 FIXTURE_DATA_TEST_CASE(RunSmall,
217                        DynamicFusionCLSubFixture<int16_t>,
218                        framework::DatasetMode::PRECOMMIT,
219                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
220                                                datasets::SmallShapes()),
221                                        framework::dataset::make("DataType", { DataType::S16 })),
222                                framework::dataset::make("InPlace", { false })))
223 {
224     // Validate output
225     validate(CLAccessor(_target), _reference);
226 }
227 FIXTURE_DATA_TEST_CASE(RunLarge,
228                        DynamicFusionCLSubFixture<int16_t>,
229                        framework::DatasetMode::NIGHTLY,
230                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
231                                                datasets::LargeShapes()),
232                                        framework::dataset::make("DataType", { DataType::S16 })),
233                                framework::dataset::make("InPlace", { false })))
234 {
235     // Validate output
236     validate(CLAccessor(_target), _reference);
237 }
238 TEST_SUITE_END() // S16
239 
TEST_SUITE(U8)240 TEST_SUITE(U8)
241 FIXTURE_DATA_TEST_CASE(RunSmall,
242                        DynamicFusionCLSubFixture<uint8_t>,
243                        framework::DatasetMode::PRECOMMIT,
244                        combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::SUB }),
245                                                datasets::SmallShapes()),
246                                        framework::dataset::make("DataType", { DataType::U8 })),
247                                framework::dataset::make("InPlace", { false })))
248 {
249     // Validate output
250     validate(CLAccessor(_target), _reference);
251 }
252 TEST_SUITE_END() // U8
253 
254 TEST_SUITE_END() // SUB
255 TEST_SUITE_END() // DYNAMIC_FUSION
256 TEST_SUITE_END() // CL
257 } // namespace validation
258 } // namespace test
259 } // namespace arm_compute
260