xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/dynamic_fusion/gpu/cl/Reshape.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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 #include "tests/CL/CLAccessor.h"
25 #include "tests/datasets/ReshapeLayerDataset.h"
26 #include "tests/framework/Macros.h"
27 #include "tests/framework/datasets/Datasets.h"
28 #include "tests/validation/Validation.h"
29 #include "tests/validation/fixtures/dynamic_fusion/operators/ReshapeFixture.h"
30 
31 namespace arm_compute
32 {
33 namespace test
34 {
35 namespace validation
36 {
37 TEST_SUITE(CL)
TEST_SUITE(DYNAMIC_FUSION)38 TEST_SUITE(DYNAMIC_FUSION)
39 TEST_SUITE(RESHAPE)
40 
41 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
42                                                               framework::dataset::make("InputInfo",
43 {
44     TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F32),
45     TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32),
46     TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32), // mismatching dimensions
47 }),
48 framework::dataset::make("OutputShape",
49 {
50     TensorShape(9U, 5U, 21U),
51     TensorShape(8U, 24U, 4U),
52     TensorShape(192U, 192U),
53 })),
54 framework::dataset::make("Expected", { true, true, false })),
55 input_info, output_shape, expected)
56 {
57     // Create a new workload sketch
58     auto              cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
59     auto              gpu_ctx        = GpuWorkloadContext{ &cl_compile_ctx };
60     GpuWorkloadSketch sketch{ &gpu_ctx };
61 
62     // Create sketch tensors
63     TensorShape input_shape = input_info.tensor_shape();
64     TensorInfo  src_info    = sketch.create_tensor_info(input_info);
65 
66     ReshapeAttributes attributes;
67     attributes.shape(output_shape);
68     Status status = GpuReshape::validate_op(sketch, &src_info, attributes);
69     ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
70 }
71 
72 template <typename T>
73 using DynamicFusionGpuReshapeLayerFixture = DynamicFusionGpuReshapeLayerValidationFixture<CLTensor, CLAccessor, GpuReshape, T>;
74 
75 TEST_SUITE(F32)
76 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuReshapeLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallReshapeLayerDataset(), framework::dataset::make("DataType",
77                                                                                                                   DataType::F32)))
78 {
79     // Validate output
80     validate(CLAccessor(_target), _reference);
81 }
82 TEST_SUITE_END() // F32
83 
TEST_SUITE(F16)84 TEST_SUITE(F16)
85 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuReshapeLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallReshapeLayerDataset(), framework::dataset::make("DataType",
86                                                                                                                  DataType::F16)))
87 {
88     // Validate output
89     validate(CLAccessor(_target), _reference);
90 }
91 TEST_SUITE_END() // F16
92 
TEST_SUITE(U8)93 TEST_SUITE(U8)
94 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuReshapeLayerFixture<uint8_t>, framework::DatasetMode::ALL, combine(datasets::SmallReshapeLayerDataset(), framework::dataset::make("DataType",
95                                                                                                                     DataType::U8)))
96 {
97     // Validate output
98     validate(CLAccessor(_target), _reference);
99 }
100 TEST_SUITE_END() // U8
101 
TEST_SUITE(S8)102 TEST_SUITE(S8)
103 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuReshapeLayerFixture<int8_t>, framework::DatasetMode::ALL, combine(datasets::SmallReshapeLayerDataset(), framework::dataset::make("DataType",
104                                                                                                                    DataType::S8)))
105 {
106     // Validate output
107     validate(CLAccessor(_target), _reference);
108 }
109 TEST_SUITE_END() // S8
110 
TEST_SUITE(S16)111 TEST_SUITE(S16)
112 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuReshapeLayerFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallReshapeLayerDataset(), framework::dataset::make("DataType",
113                                                                                                                     DataType::S16)))
114 {
115     // Validate output
116     validate(CLAccessor(_target), _reference);
117 }
118 TEST_SUITE_END() // S16
119 
120 TEST_SUITE_END() // RESHAPE
121 TEST_SUITE_END() // DYNAMIC_FUSION
122 TEST_SUITE_END() // CL
123 } // namespace validation
124 } // namespace test
125 } // namespace arm_compute
126