Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2023-2024 Arm Limited. |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 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/core/Types.h" |
| 26 | #include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuTanh.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 28 | |
| 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 32 | #include "tests/framework/datasets/Datasets.h" |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 33 | #include "tests/framework/Macros.h" |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 34 | #include "tests/validation/fixtures/dynamic_fusion/operators/ActivationFixture.h" |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 35 | #include "tests/validation/Validation.h" |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | constexpr AbsoluteTolerance<float> tolerance_f32(0.00001f); |
| 46 | constexpr AbsoluteTolerance<float> tolerance_f16(0.001f); |
| 47 | } // namespace |
| 48 | |
| 49 | TEST_SUITE(CL) |
| 50 | TEST_SUITE(DYNAMIC_FUSION) |
| 51 | TEST_SUITE(TANH) |
| 52 | // *INDENT-OFF* |
| 53 | // clang-format off |
| 54 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip( |
| 55 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 56 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16), |
| 57 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), // Unsupported data type |
| 58 | }), |
| 59 | framework::dataset::make("Expected", { true, true, false })), |
| 60 | input_info, expected) |
| 61 | { |
| 62 | // Create a new workload sketch |
| 63 | CLCompileContext cl_compile_ctx = CLKernelLibrary::get().get_compile_context(); |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 64 | GpuWorkloadContext context{ &cl_compile_ctx }; |
| 65 | GpuWorkloadSketch sketch{ &context }; |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 66 | |
| 67 | // Fuse tanh |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 68 | const ITensorInfo* src_info = context.create_tensor_info(input_info); |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 69 | |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 70 | const bool res = static_cast<bool>(GpuTanh::validate_op(sketch, src_info)); |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 71 | ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS); |
| 72 | } |
| 73 | // clang-format on |
| 74 | // *INDENT-ON* |
| 75 | |
| 76 | template <typename T> |
| 77 | using DynamicFusionTanhOpFixture = DynamicFusionTanhValidationFixture<CLTensor, CLAccessor, GpuTanh, T>; |
| 78 | |
| 79 | TEST_SUITE(Float) |
| 80 | TEST_SUITE(FP16) |
| 81 | FIXTURE_DATA_TEST_CASE(RunSmallOneOp, |
| 82 | DynamicFusionTanhOpFixture<half>, |
| 83 | framework::DatasetMode::ALL, |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 84 | combine(combine(datasets::SmallShapes(), framework::dataset::make("Fuse", {false})), |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 85 | framework::dataset::make("DataType", DataType::F16))) |
| 86 | { |
| 87 | // Validate output |
| 88 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 89 | } |
| 90 | |
| 91 | FIXTURE_DATA_TEST_CASE(RunSmall5dOneOp, |
| 92 | DynamicFusionTanhOpFixture<half>, |
| 93 | framework::DatasetMode::ALL, |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 94 | combine(combine(datasets::Small5dShapes(), framework::dataset::make("Fuse", {false})), |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 95 | framework::dataset::make("DataType", DataType::F16))) |
| 96 | { |
| 97 | // Validate output |
Adnan AlSinan | 4184e86 | 2023-07-10 15:20:44 +0100 | [diff] [blame] | 98 | ARM_COMPUTE_TEST_INFO("Currently 5D+ tensors are unsupported for this operation."); |
| 99 | framework::ARM_COMPUTE_PRINT_INFO(); |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | FIXTURE_DATA_TEST_CASE(RunSmallTwoOps, |
| 103 | DynamicFusionTanhOpFixture<half>, |
| 104 | framework::DatasetMode::ALL, |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 105 | combine(combine(datasets::SmallShapes(), framework::dataset::make("Fuse", {true})), |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 106 | framework::dataset::make("DataType", DataType::F16))) |
| 107 | { |
| 108 | // Validate output |
| 109 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 110 | } |
| 111 | |
| 112 | TEST_SUITE_END() // FP16 |
| 113 | |
| 114 | TEST_SUITE(FP32) |
| 115 | FIXTURE_DATA_TEST_CASE(RunSmallOneOp, |
| 116 | DynamicFusionTanhOpFixture<float>, |
| 117 | framework::DatasetMode::ALL, |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 118 | combine(combine(datasets::SmallShapes(), framework::dataset::make("Fuse", {false})), |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 119 | framework::dataset::make("DataType", DataType::F32))) |
| 120 | { |
| 121 | // Validate output |
| 122 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 123 | } |
| 124 | |
| 125 | FIXTURE_DATA_TEST_CASE(RunSmall5dOneOp, |
| 126 | DynamicFusionTanhOpFixture<float>, |
| 127 | framework::DatasetMode::ALL, |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 128 | combine(combine(datasets::Small5dShapes(), framework::dataset::make("Fuse", {false})), |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 129 | framework::dataset::make("DataType", DataType::F32))) |
| 130 | { |
| 131 | // Validate output |
Adnan AlSinan | 4184e86 | 2023-07-10 15:20:44 +0100 | [diff] [blame] | 132 | ARM_COMPUTE_TEST_INFO("Currently 5D+ tensors are unsupported for this operation."); |
| 133 | framework::ARM_COMPUTE_PRINT_INFO(); |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | FIXTURE_DATA_TEST_CASE(RunSmallTwoOps, |
| 137 | DynamicFusionTanhOpFixture<float>, |
| 138 | framework::DatasetMode::ALL, |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame^] | 139 | combine(combine(datasets::SmallShapes(), framework::dataset::make("Fuse", {true})), |
Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +0000 | [diff] [blame] | 140 | framework::dataset::make("DataType", DataType::F32))) |
| 141 | { |
| 142 | // Validate output |
| 143 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 144 | } |
| 145 | |
| 146 | TEST_SUITE_END() // FP32 |
| 147 | TEST_SUITE_END() // Float |
| 148 | |
| 149 | TEST_SUITE_END() // TANH |
| 150 | TEST_SUITE_END() // DYNAMIC_FUSION |
| 151 | TEST_SUITE_END() // CL |
| 152 | } // namespace validation |
| 153 | } // namespace test |
| 154 | } // namespace arm_compute |