blob: d04c10cee220d088a9102946b736df8bb79bd7cf [file] [log] [blame]
Giorgio Arenac6aa49b2018-08-07 11:53:30 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Giorgio Arenac6aa49b2018-08-07 11:53:30 +01003 *
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 */
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010024#include "arm_compute/core/Types.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010025#include "src/core/CL/kernels/CLWeightsReshapeKernel.h"
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010026#include "tests/CL/CLAccessor.h"
Sheri Zhang55c0c0c2020-04-14 21:58:37 +010027#include "tests/CL/Helper.h"
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010028#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
35namespace arm_compute
36{
37namespace test
38{
39namespace validation
40{
41TEST_SUITE(CL)
42TEST_SUITE(WeightsReshape)
43
44using CLWeightsReshape = CLSynthetizeFunction<CLWeightsReshapeKernel>;
45
Sheri Zhang55c0c0c2020-04-14 21:58:37 +010046/** 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 */
58DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
59 framework::dataset::make("InputInfo",
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010060{
Sheri Zhang55c0c0c2020-04-14 21:58:37 +010061 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}),
68framework::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})),
77framework::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})),
86framework::dataset::make("NumGroups", { 1, 1, 1, 2, 1, 2 })),
87framework::dataset::make("Expected", { false, false, false, false, false, false })),
88input_info, biases_info, output_info, num_groups, expected)
89{
90 bool status = bool(CLWeightsReshape::validate(&input_info, &biases_info, &output_info, num_groups));
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010091 ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
92}
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010093
94template <typename T>
95using CLWeightsReshapeFixture = WeightsReshapeValidationFixture<CLTensor, CLAccessor, CLWeightsReshape, T>;
96
97TEST_SUITE(Float)
Sheri Zhang55c0c0c2020-04-14 21:58:37 +010098FIXTURE_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 })))
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100102{
103 // Validate output
104 validate(CLAccessor(_target), _reference);
105}
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100106
Sheri Zhang55c0c0c2020-04-14 21:58:37 +0100107FIXTURE_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 })))
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100111{
112 // Validate output
113 validate(CLAccessor(_target), _reference);
114}
Sheri Zhang55c0c0c2020-04-14 21:58:37 +0100115
116FIXTURE_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 })))
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100120{
121 // Validate output
122 validate(CLAccessor(_target), _reference);
123}
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100124
125TEST_SUITE_END()
126
Sheri Zhang55c0c0c2020-04-14 21:58:37 +0100127TEST_SUITE(Quantized)
128FIXTURE_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 })))
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100132{
133 // Validate output
134 validate(CLAccessor(_target), _reference);
135}
Sheri Zhang55c0c0c2020-04-14 21:58:37 +0100136
137FIXTURE_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 })))
Giorgio Arenac6aa49b2018-08-07 11:53:30 +0100141{
142 // Validate output
143 validate(CLAccessor(_target), _reference);
144}
145TEST_SUITE_END()
146
147TEST_SUITE_END()
148TEST_SUITE_END()
149} // namespace validation
150} // namespace test
151} // namespace arm_compute