blob: 9bfdc961fe57bdb0e78736a8e4250e586f5e8a76 [file] [log] [blame]
Ramy Elgammal404462a2022-11-08 02:14:46 +00001/*
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +00002 * Copyright (c) 2022-2024 Arm Limited.
Ramy Elgammal404462a2022-11-08 02:14:46 +00003 *
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/GpuAdd.h"
27
28#include "tests/CL/CLAccessor.h"
Ramy Elgammal404462a2022-11-08 02:14:46 +000029#include "tests/datasets/DynamicFusionDataset.h"
30#include "tests/datasets/ShapeDatasets.h"
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000031#include "tests/framework/datasets/Datasets.h"
32#include "tests/framework/Fixture.h"
33#include "tests/framework/Macros.h"
Ramy Elgammal404462a2022-11-08 02:14:46 +000034#include "tests/validation/fixtures/dynamic_fusion/gpu/cl/ElementwiseBinaryFixture.h"
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000035#include "tests/validation/Validation.h"
Ramy Elgammal404462a2022-11-08 02:14:46 +000036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
Jakub Sujak7359a872023-01-05 14:24:13 +000043/* Synced with tests/validation/CL/ArithmeticAddition.cpp from the standard interface.
44 *
Ramy Elgammalec320d92022-12-14 09:20:09 +000045 * Difference | Why the difference
Jakub Sujak7359a872023-01-05 14:24:13 +000046 * No quantized tests | Not supported yet
47 * No in place tests | Not supported yet
48 * No activation tests | Not needed in dynamic fusion interface
49 *
50 */
Ramy Elgammal404462a2022-11-08 02:14:46 +000051TEST_SUITE(CL)
52TEST_SUITE(DYNAMIC_FUSION)
53TEST_SUITE(ADD)
54
55// *INDENT-OFF*
56// clang-format off
Gunes Bayircc287732023-01-19 15:56:00 +000057DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
Jakub Sujak7359a872023-01-05 14:24:13 +000058 framework::dataset::make("LhsInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Ramy Elgammal404462a2022-11-08 02:14:46 +000059 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid data type combination
60 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), // S16 is valid data type for Add
61 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // S32 is valid data type for Add
62 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +000063 TensorInfo(TensorShape(32U, 1U, 1U), 1, DataType::F32), // Broadcasting allowed for lhs
Jakub Sujak7359a872023-01-05 14:24:13 +000064 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Unsupported data type QASYMM8
65 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8_SIGNED), // Unsupported data type QASYMM8
Ramy Elgammal404462a2022-11-08 02:14:46 +000066 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +000067 TensorInfo(TensorShape(15U, 23U, 3U), 1, DataType::F32), // Broadcast Y dimension is not allowed
68 TensorInfo(TensorShape( 3U, 8U, 9U), 1, DataType::S16), // Broadcast Z dimension is not allowed
69 TensorInfo(TensorShape(32U, 13U, 2U, 2), 1, DataType::F32), // Batching is allowed
Ramy Elgammal404462a2022-11-08 02:14:46 +000070 }),
Jakub Sujak7359a872023-01-05 14:24:13 +000071 framework::dataset::make("RhsInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Ramy Elgammal404462a2022-11-08 02:14:46 +000072 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
75 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Jakub Sujak7359a872023-01-05 14:24:13 +000077 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Unsupported data type QASYMM8
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8_SIGNED), // Unsupported data type QASYMM8
Ramy Elgammal404462a2022-11-08 02:14:46 +000079 TensorInfo(TensorShape(32U, 1U, 1U), 1, DataType::F32), // Broadcasting allowed for rhs
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +000080 TensorInfo(TensorShape(15U, 1U, 3U), 1, DataType::F32),
81 TensorInfo(TensorShape( 3U, 8U, 1U), 1, DataType::S16),
82 TensorInfo(TensorShape(32U, 13U, 2U, 2), 1, DataType::F32),
Ramy Elgammal404462a2022-11-08 02:14:46 +000083 })),
Jakub Sujak7359a872023-01-05 14:24:13 +000084 framework::dataset::make("Expected", { true, false, true, true, false, true, false, false, true, false, false, true})),
Ramy Elgammal404462a2022-11-08 02:14:46 +000085 input1_info, input2_info, expected)
86{
87 // Create a new workload sketch
88 auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010089 auto context = GpuWorkloadContext{ &cl_compile_ctx };
90 GpuWorkloadSketch sketch{ &context };
Ramy Elgammal404462a2022-11-08 02:14:46 +000091
Jakub Sujak7359a872023-01-05 14:24:13 +000092 // Validate Elementwise Add
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010093 auto lhs_info = context.create_tensor_info(input1_info);
94 auto rhs_info = context.create_tensor_info(input2_info);
Ramy Elgammal404462a2022-11-08 02:14:46 +000095
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000096 bool res = bool(GpuAdd::validate_op(sketch, lhs_info, rhs_info));
Ramy Elgammal404462a2022-11-08 02:14:46 +000097 ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
98}
99// clang-format on
100// *INDENT-ON*
101
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000102constexpr AbsoluteTolerance<float> tolerance_f(
103 0.0001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 and DataType::F16 */
104constexpr float tolerance_num = 0.0001f; /**< Tolerance number */
Ramy Elgammal404462a2022-11-08 02:14:46 +0000105
106template <typename T>
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000107using DynamicFusionCLAddFixture =
108 DynamicFusionGpuElementwiseBinaryOneOpValidationFixture<CLTensor, CLAccessor, GpuAdd, T>;
Ramy Elgammal404462a2022-11-08 02:14:46 +0000109
110template <typename T>
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000111using DynamicFusionCLAddBroadcastFixture =
112 DynamicFusionGpuElementwiseBinaryBroadcastOneOpValidationFixture<CLTensor, CLAccessor, GpuAdd, T>;
Ramy Elgammal404462a2022-11-08 02:14:46 +0000113
114template <typename T>
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000115using DynamicFusionCLAddTwoOpsFixture =
116 DynamicFusionGpuElementwiseBinaryTwoOpsValidationFixture<CLTensor, CLAccessor, GpuAdd, T>;
Ramy Elgammal404462a2022-11-08 02:14:46 +0000117
118TEST_SUITE(FP32)
Jakub Sujak7359a872023-01-05 14:24:13 +0000119FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
120 DynamicFusionCLAddFixture<float>,
121 framework::DatasetMode::PRECOMMIT,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000122 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000123 datasets::SmallShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000124 framework::dataset::make("DataType", {DataType::F32})),
125 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000126{
127 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000128 validate(CLAccessor(_target), _reference, tolerance_f);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000129}
Jakub Sujak7359a872023-01-05 14:24:13 +0000130FIXTURE_DATA_TEST_CASE(RunLargeOneOp,
131 DynamicFusionCLAddFixture<float>,
132 framework::DatasetMode::NIGHTLY,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000133 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000134 datasets::LargeShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000135 framework::dataset::make("DataType", {DataType::F32})),
136 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000137{
138 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000139 validate(CLAccessor(_target), _reference, tolerance_f);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000140}
Jakub Sujak7359a872023-01-05 14:24:13 +0000141FIXTURE_DATA_TEST_CASE(RunSmallBroadcastOneOp,
142 DynamicFusionCLAddBroadcastFixture<float>,
143 framework::DatasetMode::PRECOMMIT,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000144 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000145 datasets::TemporaryLimitedSmallShapesBroadcast()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000146 framework::dataset::make("DataType", {DataType::F32})),
147 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000148{
149 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000150 validate(CLAccessor(_target), _reference, tolerance_f);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000151}
152
Jakub Sujak7359a872023-01-05 14:24:13 +0000153FIXTURE_DATA_TEST_CASE(RunLargeBroadcastOneOp,
154 DynamicFusionCLAddBroadcastFixture<float>,
155 framework::DatasetMode::NIGHTLY,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000156 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000157 datasets::TemporaryLimitedLargeShapesBroadcast()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000158 framework::dataset::make("DataType", {DataType::F32})),
159 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000160{
161 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000162 validate(CLAccessor(_target), _reference, tolerance_f);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000163}
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000164FIXTURE_DATA_TEST_CASE(
165 RunSmallTwoOps,
166 DynamicFusionCLAddTwoOpsFixture<float>,
167 framework::DatasetMode::PRECOMMIT,
168 combine(combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
169 datasets::DynamicFusionElementwiseBinaryTwoOpsSmallShapes()),
170 framework::dataset::make("DataType", {DataType::F32})),
171 framework::dataset::make("InPlace", {false})),
172 framework::dataset::make("FuseTwoOps", {true})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000173{
174 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000175 validate(CLAccessor(_target), _reference, tolerance_f);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000176}
177TEST_SUITE_END() // FP32
178
179TEST_SUITE(FP16)
Jakub Sujak7359a872023-01-05 14:24:13 +0000180FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
181 DynamicFusionCLAddFixture<half>,
182 framework::DatasetMode::ALL,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000183 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000184 datasets::SmallShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000185 framework::dataset::make("DataType", {DataType::F16})),
186 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000187{
188 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000189 validate(CLAccessor(_target), _reference, tolerance_f, tolerance_num);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000190}
191
Jakub Sujak7359a872023-01-05 14:24:13 +0000192FIXTURE_DATA_TEST_CASE(RunSmallBroadcastOneOp,
193 DynamicFusionCLAddBroadcastFixture<half>,
194 framework::DatasetMode::ALL,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000195 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000196 datasets::TemporaryLimitedSmallShapesBroadcast()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000197 framework::dataset::make("DataType", {DataType::F16})),
198 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000199{
200 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000201 validate(CLAccessor(_target), _reference, tolerance_f, tolerance_num);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000202}
203
204TEST_SUITE_END() // FP16
205
206TEST_SUITE(S32)
Jakub Sujak7359a872023-01-05 14:24:13 +0000207FIXTURE_DATA_TEST_CASE(RunSmall,
208 DynamicFusionCLAddFixture<int32_t>,
209 framework::DatasetMode::PRECOMMIT,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000210 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000211 datasets::SmallShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000212 framework::dataset::make("DataType", {DataType::S32})),
213 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000214{
215 // Validate output
216 validate(CLAccessor(_target), _reference);
217}
218TEST_SUITE_END() // S32
219
220TEST_SUITE(S16)
Jakub Sujak7359a872023-01-05 14:24:13 +0000221FIXTURE_DATA_TEST_CASE(RunSmall,
222 DynamicFusionCLAddFixture<int16_t>,
223 framework::DatasetMode::PRECOMMIT,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000224 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000225 datasets::SmallShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000226 framework::dataset::make("DataType", {DataType::S16})),
227 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000228{
229 // Validate output
230 validate(CLAccessor(_target), _reference);
231}
Jakub Sujak7359a872023-01-05 14:24:13 +0000232FIXTURE_DATA_TEST_CASE(RunLarge,
233 DynamicFusionCLAddFixture<int16_t>,
234 framework::DatasetMode::NIGHTLY,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000235 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000236 datasets::LargeShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000237 framework::dataset::make("DataType", {DataType::S16})),
238 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000239{
240 // Validate output
241 validate(CLAccessor(_target), _reference);
242}
243TEST_SUITE_END() // S16
244
245TEST_SUITE(U8)
Jakub Sujak7359a872023-01-05 14:24:13 +0000246FIXTURE_DATA_TEST_CASE(RunSmall,
247 DynamicFusionCLAddFixture<uint8_t>,
248 framework::DatasetMode::PRECOMMIT,
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000249 combine(combine(combine(framework::dataset::make("ElementwiseOp", {ArithmeticOperation::ADD}),
Jakub Sujak7359a872023-01-05 14:24:13 +0000250 datasets::SmallShapes()),
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000251 framework::dataset::make("DataType", {DataType::U8})),
252 framework::dataset::make("InPlace", {false})))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000253{
254 // Validate output
255 validate(CLAccessor(_target), _reference);
256}
257TEST_SUITE_END() // U8
258
259TEST_SUITE_END() // ADD
260TEST_SUITE_END() // DYNAMIC_FUSION
261TEST_SUITE_END() // CL
262} // namespace validation
263} // namespace test
264} // namespace arm_compute