• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019-2020 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 "arm_compute/runtime/CL/CLTensor.h"
26 #include "arm_compute/runtime/CL/CLTensorAllocator.h"
27 #include "arm_compute/runtime/CL/functions/CLPReluLayer.h"
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/ConvertPolicyDataset.h"
31 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Asserts.h"
33 #include "tests/framework/Macros.h"
34 #include "tests/framework/datasets/Datasets.h"
35 #include "tests/validation/Validation.h"
36 #include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 RelativeTolerance<float> tolerance_fp32(0.000001f);
47 RelativeTolerance<float> tolerance_fp16(0.001f);
48 
49 /** Input data sets **/
50 const auto PReluLayerU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
51                                          framework::dataset::make("DataType",
52                                                                   DataType::U8));
53 const auto PReluLayerQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
54                                               framework::dataset::make("DataType",
55                                                                        DataType::QASYMM8));
56 const auto PReluLayerQASYMM8SIGNEDDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
57                                                     framework::dataset::make("DataType",
58                                                                              DataType::QASYMM8_SIGNED));
59 const auto PReluLayerS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
60                                           framework::dataset::make("DataType", DataType::S16));
61 const auto PReluLayerFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
62                                            framework::dataset::make("DataType", DataType::F16));
63 const auto PReluLayerFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
64                                            framework::dataset::make("DataType", DataType::F32));
65 } // namespace
66 
67 TEST_SUITE(CL)
TEST_SUITE(PReluLayer)68 TEST_SUITE(PReluLayer)
69 
70 // *INDENT-OFF*
71 // clang-format off
72 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
73                framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
74                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
75                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),      // Invalid data type combination
76                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),     // Mismatching shapes
77                                                       }),
78                framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
79                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
80                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
81                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
82                                                      })),
83                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
84                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
85                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
86                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
87                                                      })),
88                framework::dataset::make("Expected", { true, true, false, false})),
89                input1_info, input2_info, output_info, expected)
90 {
91     ARM_COMPUTE_EXPECT(bool(CLPReluLayer::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
92 }
93 // clang-format on
94 // *INDENT-ON*
95 
96 template <typename T>
97 using CLPReluLayerFixture = PReluLayerValidationFixture<CLTensor, CLAccessor, CLPReluLayer, T>;
98 
99 TEST_SUITE(U8)
FIXTURE_DATA_TEST_CASE(RunSmall,CLPReluLayerFixture<uint8_t>,framework::DatasetMode::PRECOMMIT,combine (datasets::SmallShapes (),PReluLayerU8Dataset))100 FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), PReluLayerU8Dataset))
101 {
102     // Validate output
103     validate(CLAccessor(_target), _reference);
104 }
105 TEST_SUITE_END()
106 
107 template <typename T>
108 using CLPReluLayerQuantizedFixture = PReluLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPReluLayer, T>;
109 
110 TEST_SUITE(Quantized)
TEST_SUITE(QASYMM8)111 TEST_SUITE(QASYMM8)
112 FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
113                                                                                                                    PReluLayerQASYMM8Dataset),
114                                                                                                                    framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
115                                                                                                                    framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
116                                                                                                                    framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
117 
118                       )
119 {
120     // Validate output
121     validate(CLAccessor(_target), _reference);
122 }
123 TEST_SUITE_END()
124 
TEST_SUITE(QASYMM8_SIGNED)125 TEST_SUITE(QASYMM8_SIGNED)
126 FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
127                                                                                                                   PReluLayerQASYMM8SIGNEDDataset),
128                                                                                                                   framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 127.f, 20) })),
129                                                                                                                   framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 127.f, 10) })),
130                                                                                                                   framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 127.f, 5) }))
131 
132                       )
133 {
134     // Validate output
135     validate(CLAccessor(_target), _reference);
136 }
137 TEST_SUITE_END()
TEST_SUITE_END()138 TEST_SUITE_END()
139 
140 TEST_SUITE(S16)
141 FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerS16Dataset))
142 {
143     // Validate output
144     validate(CLAccessor(_target), _reference);
145 }
146 TEST_SUITE_END()
147 
TEST_SUITE(Float)148 TEST_SUITE(Float)
149 TEST_SUITE(FP16)
150 FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP16Dataset))
151 {
152     // Validate output
153     validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
154 }
155 TEST_SUITE_END()
156 
TEST_SUITE(FP32)157 TEST_SUITE(FP32)
158 FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP32Dataset))
159 {
160     // Validate output
161     validate(CLAccessor(_target), _reference, tolerance_fp32);
162 }
163 template <typename T>
164 using CLPReluLayerBroadcastFixture = PReluLayerBroadcastValidationFixture<CLTensor, CLAccessor, CLPReluLayer, T>;
165 
FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,CLPReluLayerBroadcastFixture<float>,framework::DatasetMode::ALL,combine (datasets::SmallShapesBroadcast (),PReluLayerFP32Dataset))166 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLPReluLayerBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
167                                                                                                                     PReluLayerFP32Dataset))
168 {
169     // Validate output
170     validate(CLAccessor(_target), _reference, tolerance_fp32);
171 }
172 TEST_SUITE_END()
173 TEST_SUITE_END()
174 
175 TEST_SUITE_END()
176 TEST_SUITE_END()
177 } // namespace validation
178 } // namespace test
179 } // namespace arm_compute
180