blob: e99551117103a8a3af3017aef0f79656b42a6c0c [file] [log] [blame]
Viet-Hoa Do98aca0f2023-03-02 17:43:45 +00001/*
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/GpuSigmoid.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
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45constexpr AbsoluteTolerance<float> tolerance_f32(1e-6f);
46constexpr AbsoluteTolerance<float> tolerance_f16(0.001f);
47} // namespace
48
49TEST_SUITE(CL)
50TEST_SUITE(DYNAMIC_FUSION)
51TEST_SUITE(SIGMOID)
52// *INDENT-OFF*
53// clang-format off
54DATA_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 Do3fcf3dc2023-05-17 15:17:48 +010064 GpuWorkloadContext context{ &cl_compile_ctx };
65 GpuWorkloadSketch sketch{ &context };
Viet-Hoa Do98aca0f2023-03-02 17:43:45 +000066
67 // Fuse sigmoid
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010068 const TensorInfo src_info = context.create_tensor_info(input_info);
Viet-Hoa Do98aca0f2023-03-02 17:43:45 +000069
70 const bool res = static_cast<bool>(GpuSigmoid::validate_op(sketch, &src_info));
71 ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
72}
73// clang-format on
74// *INDENT-ON*
75
76template <typename T>
77using DynamicFusionSigmoidOpFixture = DynamicFusionSigmoidValidationFixture<CLTensor, CLAccessor, GpuSigmoid, T>;
78
79TEST_SUITE(Float)
80TEST_SUITE(FP16)
81FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
82 DynamicFusionSigmoidOpFixture<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
92FIXTURE_DATA_TEST_CASE(RunSmall5dOneOp,
93 DynamicFusionSigmoidOpFixture<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
Adnan AlSinan4184e862023-07-10 15:20:44 +0100100 ARM_COMPUTE_TEST_INFO("Currently 5D+ tensors are unsupported for this operation.");
101 framework::ARM_COMPUTE_PRINT_INFO();
Viet-Hoa Do98aca0f2023-03-02 17:43:45 +0000102}
103
104FIXTURE_DATA_TEST_CASE(RunSmallTwoOps,
105 DynamicFusionSigmoidOpFixture<half>,
106 framework::DatasetMode::ALL,
107 combine(combine(datasets::SmallShapes(),
108 framework::dataset::make("Fuse", { true })),
109 framework::dataset::make("DataType", DataType::F16)))
110{
111 // Validate output
112 validate(CLAccessor(_target), _reference, tolerance_f16);
113}
114
115TEST_SUITE_END() // FP16
116
117TEST_SUITE(FP32)
118FIXTURE_DATA_TEST_CASE(RunSmallOneOp,
119 DynamicFusionSigmoidOpFixture<float>,
120 framework::DatasetMode::ALL,
121 combine(combine(datasets::SmallShapes(),
122 framework::dataset::make("Fuse", { false })),
123 framework::dataset::make("DataType", DataType::F32)))
124{
125 // Validate output
126 validate(CLAccessor(_target), _reference, tolerance_f32);
127}
128
129FIXTURE_DATA_TEST_CASE(RunSmall5dOneOp,
130 DynamicFusionSigmoidOpFixture<float>,
131 framework::DatasetMode::ALL,
132 combine(combine(datasets::Small5dShapes(),
133 framework::dataset::make("Fuse", { false })),
134 framework::dataset::make("DataType", DataType::F32)))
135{
136 // Validate output
Adnan AlSinan4184e862023-07-10 15:20:44 +0100137 ARM_COMPUTE_TEST_INFO("Currently 5D+ tensors are unsupported for this operation.");
138 framework::ARM_COMPUTE_PRINT_INFO();
Viet-Hoa Do98aca0f2023-03-02 17:43:45 +0000139}
140
141FIXTURE_DATA_TEST_CASE(RunSmallTwoOps,
142 DynamicFusionSigmoidOpFixture<float>,
143 framework::DatasetMode::ALL,
144 combine(combine(datasets::SmallShapes(),
145 framework::dataset::make("Fuse", { true })),
146 framework::dataset::make("DataType", DataType::F32)))
147{
148 // Validate output
149 validate(CLAccessor(_target), _reference, tolerance_f32);
150}
151
152TEST_SUITE_END() // FP32
153TEST_SUITE_END() // Float
154
155TEST_SUITE_END() // SIGMOID
156TEST_SUITE_END() // DYNAMIC_FUSION
157TEST_SUITE_END() // CL
158} // namespace validation
159} // namespace test
160} // namespace arm_compute