Viet-Hoa Do | 98aca0f | 2023-03-02 17:43:45 +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 | |
| 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" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/dynamic_fusion/operators/ActivationFixture.h" |
| 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(); |
| 64 | GpuWorkloadContext gpu_ctx{ &cl_compile_ctx }; |
| 65 | GpuWorkloadSketch sketch{ &gpu_ctx }; |
| 66 | |
| 67 | // Fuse tanh |
| 68 | const TensorInfo src_info = sketch.create_tensor_info(input_info); |
| 69 | |
| 70 | const bool res = static_cast<bool>(GpuTanh::validate_op(sketch, &src_info)); |
| 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, |
| 84 | combine(combine(datasets::SmallShapes(), |
| 85 | framework::dataset::make("Fuse", { false })), |
| 86 | framework::dataset::make("DataType", DataType::F16))) |
| 87 | { |
| 88 | // Validate output |
| 89 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 90 | } |
| 91 | |
| 92 | FIXTURE_DATA_TEST_CASE(RunSmall5dOneOp, |
| 93 | DynamicFusionTanhOpFixture<half>, |
| 94 | framework::DatasetMode::ALL, |
| 95 | combine(combine(datasets::Small5dShapes(), |
| 96 | framework::dataset::make("Fuse", { false })), |
| 97 | framework::dataset::make("DataType", DataType::F16))) |
| 98 | { |
| 99 | // Validate output |
| 100 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 101 | } |
| 102 | |
| 103 | FIXTURE_DATA_TEST_CASE(RunSmallTwoOps, |
| 104 | DynamicFusionTanhOpFixture<half>, |
| 105 | framework::DatasetMode::ALL, |
| 106 | combine(combine(datasets::SmallShapes(), |
| 107 | framework::dataset::make("Fuse", { true })), |
| 108 | framework::dataset::make("DataType", DataType::F16))) |
| 109 | { |
| 110 | // Validate output |
| 111 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 112 | } |
| 113 | |
| 114 | TEST_SUITE_END() // FP16 |
| 115 | |
| 116 | TEST_SUITE(FP32) |
| 117 | FIXTURE_DATA_TEST_CASE(RunSmallOneOp, |
| 118 | DynamicFusionTanhOpFixture<float>, |
| 119 | framework::DatasetMode::ALL, |
| 120 | combine(combine(datasets::SmallShapes(), |
| 121 | framework::dataset::make("Fuse", { false })), |
| 122 | framework::dataset::make("DataType", DataType::F32))) |
| 123 | { |
| 124 | // Validate output |
| 125 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 126 | } |
| 127 | |
| 128 | FIXTURE_DATA_TEST_CASE(RunSmall5dOneOp, |
| 129 | DynamicFusionTanhOpFixture<float>, |
| 130 | framework::DatasetMode::ALL, |
| 131 | combine(combine(datasets::Small5dShapes(), |
| 132 | framework::dataset::make("Fuse", { false })), |
| 133 | framework::dataset::make("DataType", DataType::F32))) |
| 134 | { |
| 135 | // Validate output |
| 136 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 137 | } |
| 138 | |
| 139 | FIXTURE_DATA_TEST_CASE(RunSmallTwoOps, |
| 140 | DynamicFusionTanhOpFixture<float>, |
| 141 | framework::DatasetMode::ALL, |
| 142 | combine(combine(datasets::SmallShapes(), |
| 143 | framework::dataset::make("Fuse", { true })), |
| 144 | framework::dataset::make("DataType", DataType::F32))) |
| 145 | { |
| 146 | // Validate output |
| 147 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 148 | } |
| 149 | |
| 150 | TEST_SUITE_END() // FP32 |
| 151 | TEST_SUITE_END() // Float |
| 152 | |
| 153 | TEST_SUITE_END() // TANH |
| 154 | TEST_SUITE_END() // DYNAMIC_FUSION |
| 155 | TEST_SUITE_END() // CL |
| 156 | } // namespace validation |
| 157 | } // namespace test |
| 158 | } // namespace arm_compute |