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