• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2021 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 "arm_compute/core/Types.h"
25 #include "src/gpu/cl/kernels/ClWeightsReshapeKernel.h"
26 #include "tests/CL/CLAccessor.h"
27 #include "tests/CL/Helper.h"
28 #include "tests/datasets/ShapeDatasets.h"
29 #include "tests/framework/Asserts.h"
30 #include "tests/framework/Macros.h"
31 #include "tests/framework/datasets/Datasets.h"
32 #include "tests/validation/Validation.h"
33 #include "tests/validation/fixtures/WeightsReshapeFixture.h"
34 
35 namespace arm_compute
36 {
37 namespace test
38 {
39 namespace validation
40 {
41 TEST_SUITE(CL)
42 TEST_SUITE(WeightsReshape)
43 
44 using ClWeightsReshape = ClSynthetizeOperatorWithBorder<opencl::kernels::ClWeightsReshapeKernel>;
45 
46 /** Validate tests
47  *
48  * A series of validation tests on configurations which according to the API specification
49  * the function should fail against.
50  *
51  * Checks performed in order:
52  *     - Mismachting data type: bias need to has same data type as input
53  *     - Mismachting data type: output need to has same data type as input
54  *     - Bias only supports FP32/FP16
55  *     - num_groups != 1 is only supported for NCHW data layout
56  *     - Bias' shape need to match input's shape.
57  */
58 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
59                                                                       framework::dataset::make("InputInfo",
60 {
61     TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32),                   // Mismatching data type
62     TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32),                   // Mismatching data type
63     TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::QASYMM8),               // Bias only supports FP32/FP16
64     TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, DataLayout::NHWC), // num_groups != 1 is only supported for NCHW data layout
65     TensorInfo(TensorShape(3U, 3U, 2U, 4U, 4U), 1, DataType::F32),               // Bias' shape need to match input's shape
66     TensorInfo(TensorShape(3U, 3U, 2U, 4U, 4U), 1, DataType::F32),               // Bias' shape need to match input's shape
67 }),
68 framework::dataset::make("BiasesInfo",
69 {
70     TensorInfo(TensorShape(4U), 1, DataType::F16),
71     TensorInfo(TensorShape(4U), 1, DataType::F32),
72     TensorInfo(TensorShape(4U), 1, DataType::QASYMM8),
73     TensorInfo(TensorShape(4U), 1, DataType::F32),
74     TensorInfo(TensorShape(4U, 3U), 1, DataType::F32),
75     TensorInfo(TensorShape(3U, 4U), 1, DataType::F32),
76 })),
77 framework::dataset::make("OutputInfo",
78 {
79     TensorInfo(TensorShape(4U, 19U), 1, DataType::F32),
80     TensorInfo(TensorShape(4U, 19U), 1, DataType::F16),
81     TensorInfo(TensorShape(4U, 19U), 1, DataType::QASYMM8),
82     TensorInfo(TensorShape(4U, 19U), 1, DataType::F32),
83     TensorInfo(TensorShape(4U, 19U), 1, DataType::F32),
84     TensorInfo(TensorShape(4U, 19U), 1, DataType::F32),
85 })),
86 framework::dataset::make("NumGroups", { 1, 1, 1, 2, 1, 2 })),
87 framework::dataset::make("Expected", { false, false, false, false, false, false })),
88 input_info, biases_info, output_info, num_groups, expected)
89 {
90     bool status = bool(opencl::kernels::ClWeightsReshapeKernel::validate(&input_info, &biases_info, &output_info, num_groups));
91     ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
92 }
93 
94 template <typename T>
95 using ClWeightsReshapeFixture = WeightsReshapeOpValidationFixture<CLTensor, CLAccessor, ClWeightsReshape, T>;
96 
97 TEST_SUITE(Float)
98 FIXTURE_DATA_TEST_CASE(FP32, ClWeightsReshapeFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("InputShape", { TensorShape(3U, 3U, 48U, 120U) }),
99                                                                                                                   framework::dataset::make("DataType", DataType::F32)),
100                                                                                                           framework::dataset::make("HasBias", { true, false })),
101                                                                                                   framework::dataset::make("NumGroups", { 1, 2 })))
102 {
103     // Validate output
104     validate(CLAccessor(_target), _reference);
105 }
106 
107 FIXTURE_DATA_TEST_CASE(FP16, ClWeightsReshapeFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("InputShape", { TensorShape(13U, 13U, 96U, 240U) }),
108                                                                                                                  framework::dataset::make("DataType", DataType::F16)),
109                                                                                                          framework::dataset::make("HasBias", { true, false })),
110                                                                                                  framework::dataset::make("NumGroups", { 3, 4 })))
111 {
112     // Validate output
113     validate(CLAccessor(_target), _reference);
114 }
115 
116 FIXTURE_DATA_TEST_CASE(BFloat16, ClWeightsReshapeFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("InputShape", { TensorShape(9U, 9U, 96U, 240U) }),
117                                                                                                                      framework::dataset::make("DataType", DataType::BFLOAT16)),
118                                                                                                              framework::dataset::make("HasBias", { false })),
119                                                                                                      framework::dataset::make("NumGroups", { 3, 4 })))
120 {
121     // Validate output
122     validate(CLAccessor(_target), _reference);
123 }
124 
125 TEST_SUITE_END()
126 
TEST_SUITE(Quantized)127 TEST_SUITE(Quantized)
128 FIXTURE_DATA_TEST_CASE(QASYMM8, ClWeightsReshapeFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("InputShape", { TensorShape(5U, 5U, 48U, 120U) }),
129                                                                                                                        framework::dataset::make("DataType", DataType::QASYMM8)),
130                                                                                                                framework::dataset::make("HasBias", { false })),
131                                                                                                        framework::dataset::make("NumGroups", { 1, 2 })))
132 {
133     // Validate output
134     validate(CLAccessor(_target), _reference);
135 }
136 
137 FIXTURE_DATA_TEST_CASE(QASYMM8_SIGNED, ClWeightsReshapeFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("InputShape", { TensorShape(5U, 5U, 48U, 120U) }),
138                                                                                                                       framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
139                                                                                                                       framework::dataset::make("HasBias", { false })),
140                                                                                                               framework::dataset::make("NumGroups", { 1, 2 })))
141 {
142     // Validate output
143     validate(CLAccessor(_target), _reference);
144 }
145 TEST_SUITE_END()
146 
147 TEST_SUITE_END()
148 TEST_SUITE_END()
149 } // namespace validation
150 } // namespace test
151 } // namespace arm_compute
152