blob: 09a8f3fe399ea738304f028b0ec16500232d2fc9 [file] [log] [blame]
Ramy Elgammal404462a2022-11-08 02:14:46 +00001/*
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +00002 * Copyright (c) 2022-2023 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
Jakub Sujake57eea32023-09-04 16:53:37 +010025// TODO: Fix testing of CKW Elementwise Binary (COMPMID-6530)
26#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
27
Ramy Elgammal404462a2022-11-08 02:14:46 +000028#include "arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h"
29#include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuAdd.h"
30
31#include "tests/CL/CLAccessor.h"
32#include "tests/framework/Fixture.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36
37#include "tests/datasets/DynamicFusionDataset.h"
38#include "tests/datasets/ShapeDatasets.h"
39#include "tests/validation/fixtures/dynamic_fusion/gpu/cl/ElementwiseBinaryFixture.h"
Ramy Elgammal404462a2022-11-08 02:14:46 +000040
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
Jakub Sujak7359a872023-01-05 14:24:13 +000047/* Synced with tests/validation/CL/ArithmeticAddition.cpp from the standard interface.
48 *
Ramy Elgammalec320d92022-12-14 09:20:09 +000049 * Difference | Why the difference
Jakub Sujak7359a872023-01-05 14:24:13 +000050 * No quantized tests | Not supported yet
51 * No in place tests | Not supported yet
52 * No activation tests | Not needed in dynamic fusion interface
53 *
54 */
Ramy Elgammal404462a2022-11-08 02:14:46 +000055TEST_SUITE(CL)
56TEST_SUITE(DYNAMIC_FUSION)
57TEST_SUITE(ADD)
58
59// *INDENT-OFF*
60// clang-format off
Gunes Bayircc287732023-01-19 15:56:00 +000061DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
Jakub Sujak7359a872023-01-05 14:24:13 +000062 framework::dataset::make("LhsInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Ramy Elgammal404462a2022-11-08 02:14:46 +000063 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 Add
65 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // S32 is valid data type for Add
66 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +000067 TensorInfo(TensorShape(32U, 1U, 1U), 1, DataType::F32), // Broadcasting allowed for lhs
Jakub Sujak7359a872023-01-05 14:24:13 +000068 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Unsupported data type QASYMM8
69 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8_SIGNED), // Unsupported data type QASYMM8
Ramy Elgammal404462a2022-11-08 02:14:46 +000070 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +000071 TensorInfo(TensorShape(15U, 23U, 3U), 1, DataType::F32), // Broadcast Y dimension is not allowed
72 TensorInfo(TensorShape( 3U, 8U, 9U), 1, DataType::S16), // Broadcast Z dimension is not allowed
73 TensorInfo(TensorShape(32U, 13U, 2U, 2), 1, DataType::F32), // Batching is allowed
Ramy Elgammal404462a2022-11-08 02:14:46 +000074 }),
Jakub Sujak7359a872023-01-05 14:24:13 +000075 framework::dataset::make("RhsInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Ramy Elgammal404462a2022-11-08 02:14:46 +000076 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
79 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Jakub Sujak7359a872023-01-05 14:24:13 +000081 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Unsupported data type QASYMM8
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8_SIGNED), // Unsupported data type QASYMM8
Ramy Elgammal404462a2022-11-08 02:14:46 +000083 TensorInfo(TensorShape(32U, 1U, 1U), 1, DataType::F32), // Broadcasting allowed for rhs
Viet-Hoa Dob3077fb2023-01-03 17:59:14 +000084 TensorInfo(TensorShape(15U, 1U, 3U), 1, DataType::F32),
85 TensorInfo(TensorShape( 3U, 8U, 1U), 1, DataType::S16),
86 TensorInfo(TensorShape(32U, 13U, 2U, 2), 1, DataType::F32),
Ramy Elgammal404462a2022-11-08 02:14:46 +000087 })),
Jakub Sujak7359a872023-01-05 14:24:13 +000088 framework::dataset::make("Expected", { true, false, true, true, false, true, false, false, true, false, false, true})),
Ramy Elgammal404462a2022-11-08 02:14:46 +000089 input1_info, input2_info, expected)
90{
91 // Create a new workload sketch
92 auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010093 auto context = GpuWorkloadContext{ &cl_compile_ctx };
94 GpuWorkloadSketch sketch{ &context };
Ramy Elgammal404462a2022-11-08 02:14:46 +000095
Jakub Sujak7359a872023-01-05 14:24:13 +000096 // Validate Elementwise Add
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010097 auto lhs_info = context.create_tensor_info(input1_info);
98 auto rhs_info = context.create_tensor_info(input2_info);
Ramy Elgammal404462a2022-11-08 02:14:46 +000099
Gunes Bayircc287732023-01-19 15:56:00 +0000100 bool res = bool(GpuAdd::validate_op(sketch, &lhs_info, &rhs_info));
Ramy Elgammal404462a2022-11-08 02:14:46 +0000101 ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
102}
103// clang-format on
104// *INDENT-ON*
105
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000106constexpr AbsoluteTolerance<float> tolerance_f(0.0001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 and DataType::F16 */
Jakub Sujak7359a872023-01-05 14:24:13 +0000107constexpr float tolerance_num = 0.0001f; /**< Tolerance number */
Ramy Elgammal404462a2022-11-08 02:14:46 +0000108
109template <typename T>
Jakub Sujak7359a872023-01-05 14:24:13 +0000110using DynamicFusionCLAddFixture = DynamicFusionGpuElementwiseBinaryOneOpValidationFixture<CLTensor, CLAccessor, GpuAdd, T>;
Ramy Elgammal404462a2022-11-08 02:14:46 +0000111
112template <typename T>
Jakub Sujak7359a872023-01-05 14:24:13 +0000113using DynamicFusionCLAddBroadcastFixture = DynamicFusionGpuElementwiseBinaryBroadcastOneOpValidationFixture<CLTensor, CLAccessor, GpuAdd, T>;
Ramy Elgammal404462a2022-11-08 02:14:46 +0000114
115template <typename T>
Jakub Sujak7359a872023-01-05 14:24:13 +0000116using DynamicFusionCLAddTwoOpsFixture = 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,
122 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
123 datasets::SmallShapes()),
124 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,
133 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
134 datasets::LargeShapes()),
135 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,
144 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
145 datasets::TemporaryLimitedSmallShapesBroadcast()),
146 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,
156 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
157 datasets::TemporaryLimitedLargeShapesBroadcast()),
158 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}
Jakub Sujak7359a872023-01-05 14:24:13 +0000164FIXTURE_DATA_TEST_CASE(RunSmallTwoOps,
165 DynamicFusionCLAddTwoOpsFixture<float>,
166 framework::DatasetMode::PRECOMMIT,
167 combine(combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
168 datasets::DynamicFusionElementwiseBinaryTwoOpsSmallShapes()),
169 framework::dataset::make("DataType", { DataType::F32 })),
170 framework::dataset::make("InPlace", { false })),
171 framework::dataset::make("FuseTwoOps", { true })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000172{
173 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000174 validate(CLAccessor(_target), _reference, tolerance_f);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000175}
176TEST_SUITE_END() // FP32
177
178TEST_SUITE(FP16)
Jakub Sujak7359a872023-01-05 14:24:13 +0000179FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
180 DynamicFusionCLAddFixture<half>,
181 framework::DatasetMode::ALL,
182 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
183 datasets::SmallShapes()),
184 framework::dataset::make("DataType", { DataType::F16 })),
185 framework::dataset::make("InPlace", { false })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000186{
187 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000188 validate(CLAccessor(_target), _reference, tolerance_f, tolerance_num);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000189}
190
Jakub Sujak7359a872023-01-05 14:24:13 +0000191FIXTURE_DATA_TEST_CASE(RunSmallBroadcastOneOp,
192 DynamicFusionCLAddBroadcastFixture<half>,
193 framework::DatasetMode::ALL,
194 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
195 datasets::TemporaryLimitedSmallShapesBroadcast()),
196 framework::dataset::make("DataType", { DataType::F16 })),
197 framework::dataset::make("InPlace", { false })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000198{
199 // Validate output
Omar Al Khatib3c7c1fa2023-03-07 09:57:49 +0000200 validate(CLAccessor(_target), _reference, tolerance_f, tolerance_num);
Ramy Elgammal404462a2022-11-08 02:14:46 +0000201}
202
203TEST_SUITE_END() // FP16
204
205TEST_SUITE(S32)
Jakub Sujak7359a872023-01-05 14:24:13 +0000206FIXTURE_DATA_TEST_CASE(RunSmall,
207 DynamicFusionCLAddFixture<int32_t>,
208 framework::DatasetMode::PRECOMMIT,
209 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
210 datasets::SmallShapes()),
211 framework::dataset::make("DataType", { DataType::S32 })),
212 framework::dataset::make("InPlace", { false })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000213{
214 // Validate output
215 validate(CLAccessor(_target), _reference);
216}
217TEST_SUITE_END() // S32
218
219TEST_SUITE(S16)
Jakub Sujak7359a872023-01-05 14:24:13 +0000220FIXTURE_DATA_TEST_CASE(RunSmall,
221 DynamicFusionCLAddFixture<int16_t>,
222 framework::DatasetMode::PRECOMMIT,
223 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
224 datasets::SmallShapes()),
225 framework::dataset::make("DataType", { DataType::S16 })),
226 framework::dataset::make("InPlace", { false })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000227{
228 // Validate output
229 validate(CLAccessor(_target), _reference);
230}
Jakub Sujak7359a872023-01-05 14:24:13 +0000231FIXTURE_DATA_TEST_CASE(RunLarge,
232 DynamicFusionCLAddFixture<int16_t>,
233 framework::DatasetMode::NIGHTLY,
234 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
235 datasets::LargeShapes()),
236 framework::dataset::make("DataType", { DataType::S16 })),
237 framework::dataset::make("InPlace", { false })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000238{
239 // Validate output
240 validate(CLAccessor(_target), _reference);
241}
242TEST_SUITE_END() // S16
243
244TEST_SUITE(U8)
Jakub Sujak7359a872023-01-05 14:24:13 +0000245FIXTURE_DATA_TEST_CASE(RunSmall,
246 DynamicFusionCLAddFixture<uint8_t>,
247 framework::DatasetMode::PRECOMMIT,
248 combine(combine(combine(framework::dataset::make("ElementwiseOp", { ArithmeticOperation::ADD }),
249 datasets::SmallShapes()),
250 framework::dataset::make("DataType", { DataType::U8 })),
251 framework::dataset::make("InPlace", { false })))
Ramy Elgammal404462a2022-11-08 02:14:46 +0000252{
253 // Validate output
254 validate(CLAccessor(_target), _reference);
255}
256TEST_SUITE_END() // U8
257
258TEST_SUITE_END() // ADD
259TEST_SUITE_END() // DYNAMIC_FUSION
260TEST_SUITE_END() // CL
261} // namespace validation
262} // namespace test
263} // namespace arm_compute
Jakub Sujake57eea32023-09-04 16:53:37 +0100264#endif // ACL_INTERNAL_TEST_CKW_IN_DF