blob: d64945ab31c7aad24829ad0034eb55ba6bc1e932 [file] [log] [blame]
Moritz Pflanzer572ade72017-07-21 17:36:33 +01001/*
Pablo Marquez Tello732c1b22023-03-29 11:42:30 +01002 * Copyright (c) 2017-2023 Arm Limited.
Moritz Pflanzer572ade72017-07-21 17:36:33 +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 */
24#include "arm_compute/core/Types.h"
Sang-Hoon Parke7280582020-10-13 23:34:09 +010025#include "arm_compute/core/utils/misc/Traits.h"
Moritz Pflanzer572ade72017-07-21 17:36:33 +010026#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h"
Georgios Pinitas12833d02019-07-25 13:31:10 +010027#include "arm_compute/runtime/RuntimeContext.h"
Moritz Pflanzer572ade72017-07-21 17:36:33 +010028#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
Giorgio Arena5ae8d802021-11-18 18:02:13 +000030#include "src/common/cpuinfo/CpuIsaInfo.h"
31#include "src/cpu/kernels/CpuActivationKernel.h"
Moritz Pflanzer572ade72017-07-21 17:36:33 +010032#include "tests/NEON/Accessor.h"
33#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/datasets/ActivationFunctionsDataset.h"
35#include "tests/datasets/ShapeDatasets.h"
36#include "tests/framework/Asserts.h"
37#include "tests/framework/Macros.h"
38#include "tests/framework/datasets/Datasets.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/ActivationLayerFixture.h"
Moritz Pflanzer572ade72017-07-21 17:36:33 +010041
Georgios Pinitas41648142021-08-03 08:24:00 +010042#include "arm_compute/Acl.hpp"
Pablo Marquez Tello732c1b22023-03-29 11:42:30 +010043#include "support/AclRequires.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010044
Moritz Pflanzer572ade72017-07-21 17:36:33 +010045namespace arm_compute
46{
47namespace test
48{
49namespace validation
50{
51namespace
52{
Manuel Bottini1d1bca72020-11-17 13:53:13 +000053RelativeTolerance<float> tolerance_float_sqrt(0.0001f);
Sang-Hoon Parkadd8e812020-11-25 11:46:03 +000054
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010055/** Define relative tolerance of the activation layer.
Moritz Pflanzer572ade72017-07-21 17:36:33 +010056 *
57 * @param[in] data_type The data type used.
58 * @param[in] activation The activation function used.
59 *
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010060 * @return Relative tolerance depending on the activation function.
Moritz Pflanzer572ade72017-07-21 17:36:33 +010061 */
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010062RelativeTolerance<float> relative_tolerance(DataType data_type, ActivationLayerInfo::ActivationFunction activation)
63{
64 switch(activation)
65 {
66 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
Georgios Pinitasfb0fdcd2019-08-22 17:10:04 +010067 case ActivationLayerInfo::ActivationFunction::ELU:
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010068 case ActivationLayerInfo::ActivationFunction::SQRT:
69 case ActivationLayerInfo::ActivationFunction::TANH:
SiCong Lia32e2ae2020-06-08 17:30:51 +010070 case ActivationLayerInfo::ActivationFunction::HARD_SWISH:
Jonathan Deakind6b8a712022-08-23 11:44:18 +010071 case ActivationLayerInfo::ActivationFunction::SWISH:
Murray Kornelsen926f5022022-07-13 21:22:39 -040072 case ActivationLayerInfo::ActivationFunction::GELU:
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010073 switch(data_type)
74 {
75 case DataType::F16:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010076#if defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000077 return RelativeTolerance<float>(0.25f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010078#else // !defined(ENABLE_SVE)
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010079 return RelativeTolerance<float>(0.1f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010080#endif // defined(ENABLE_SVE)
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010081 default:
82 return RelativeTolerance<float>(0.05f);
83 }
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000084 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
85 switch(data_type)
86 {
87 case DataType::F16:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010088#if defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000089 return RelativeTolerance<float>(0.9f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010090#else // !defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000091 return RelativeTolerance<float>(0.01f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010092#endif // defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000093 default:
94 return RelativeTolerance<float>(0.00001f);
95 }
Georgios Pinitas3463a8b2018-08-23 13:11:53 +010096 default:
97 return RelativeTolerance<float>(0.f);
98 }
99}
100
101/** Define absolute tolerance of the activation layer.
102 *
103 * @param[in] data_type The data type used.
104 * @param[in] activation The activation function used.
105 *
106 * @return Absolute tolerance depending on the activation function.
107 */
108AbsoluteTolerance<float> absolute_tolerance(DataType data_type, ActivationLayerInfo::ActivationFunction activation)
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100109{
110 switch(activation)
111 {
112 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100113 case ActivationLayerInfo::ActivationFunction::SQRT:
114 case ActivationLayerInfo::ActivationFunction::TANH:
Jonathan Deakind6b8a712022-08-23 11:44:18 +0100115 case ActivationLayerInfo::ActivationFunction::SWISH:
SiCong Lia32e2ae2020-06-08 17:30:51 +0100116 case ActivationLayerInfo::ActivationFunction::HARD_SWISH:
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100117 switch(data_type)
118 {
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100119 case DataType::F16:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100120#if defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +0000121 return AbsoluteTolerance<float>(0.25f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100122#else // !defined(ENABLE_SVE)
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +0100123 return AbsoluteTolerance<float>(0.01f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100124#endif // defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +0000125 default:
126 return AbsoluteTolerance<float>(0.00001f);
127 }
128 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
129 switch(data_type)
130 {
131 case DataType::F16:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100132#if defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +0000133 return AbsoluteTolerance<float>(0.9f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100134#else // !defined(ENABLE_SVE)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +0000135 return AbsoluteTolerance<float>(0.01f);
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100136#endif // defined(ENABLE_SVE)
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100137 default:
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +0100138 return AbsoluteTolerance<float>(0.00001f);
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100139 }
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100140 default:
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +0100141 return AbsoluteTolerance<float>(0.f);
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100142 }
143}
144
Michele Di Giorgio7e5a8652021-01-12 13:49:07 +0000145/** Define absolute tolerance of the activation layer for qasymm8.
146 *
147 * @param[in] activation The activation function used.
148 *
149 * @return Absolute tolerance depending on the activation function.
150 */
151AbsoluteTolerance<uint8_t> tolerance_qasymm8(ActivationLayerInfo::ActivationFunction activation)
152{
153 switch(activation)
154 {
155 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
156 case ActivationLayerInfo::ActivationFunction::SQRT:
157 case ActivationLayerInfo::ActivationFunction::TANH:
158 case ActivationLayerInfo::ActivationFunction::HARD_SWISH:
159 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
160 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
161 return AbsoluteTolerance<uint8_t>(1);
162 default:
163 return AbsoluteTolerance<uint8_t>(0);
164 }
165}
Georgios Pinitas151fa872019-06-06 14:44:44 +0100166
giuros01c9573f32019-06-20 10:30:17 +0100167constexpr AbsoluteTolerance<int16_t> tolerance_qsymm16(1);
168
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100169/** CNN data types */
170const auto CNNDataTypes = framework::dataset::make("DataType",
171{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000172#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100173 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000174#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100175 DataType::F32,
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100176});
177
Jonathan Deakind6b8a712022-08-23 11:44:18 +0100178const auto NeonActivationFunctionsDataset = concat(datasets::ActivationFunctions(),
Pablo Marquez Tellod1586092022-06-10 14:37:10 +0100179 framework::dataset::make("ActivationFunction", { ActivationLayerInfo::ActivationFunction::HARD_SWISH, ActivationLayerInfo::ActivationFunction::SWISH }));
morgolock07df3d42020-02-27 11:46:28 +0000180
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100181/** Input data sets. */
morgolock07df3d42020-02-27 11:46:28 +0000182const auto ActivationDataset = combine(combine(framework::dataset::make("InPlace", { false, true }), NeonActivationFunctionsDataset), framework::dataset::make("AlphaBeta", { 0.5f, 1.f }));
Sang-Hoon Parke7280582020-10-13 23:34:09 +0100183
Giorgio Arenac5a61392021-01-06 15:13:08 +0000184template <typename T, ARM_COMPUTE_REQUIRES_TA(arm_compute::utils::traits::is_floating_point<T>::value)>
Sang-Hoon Parke7280582020-10-13 23:34:09 +0100185void test_float_sqrt_boundary_value()
186{
187 constexpr auto vector_size = uint32_t{ 16 };
188
189 auto data_type = DataType::F32;
190#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
191 data_type = std::is_same<T, half>::value ? DataType::F16 : data_type;
192#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
193
194 const auto boundary_value_vector = std::vector<T>
195 {
196 std::numeric_limits<T>::min(),
197 T(0),
198 std::numeric_limits<T>::epsilon(),
199 std::numeric_limits<T>::max(),
200 };
201
202 // the following size ensures that the whole logic (vector + left-over) to be tested
203 // using all boundary values iff boundary_value_vecotr.size() is smaller than vector_size.
204 auto shape = TensorShape{ vector_size + boundary_value_vector.size() };
205 auto info = ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::SQRT };
206 auto src = create_tensor<Tensor>(shape, data_type);
207
208 auto act = NEActivationLayer{};
209 act.configure(&src, nullptr, info);
210 src.allocator()->allocate();
211 library->fill_static_values(Accessor(src), boundary_value_vector);
212 act.run();
213
214 auto reference_src = SimpleTensor<T> { shape, data_type };
215 library->fill_static_values(reference_src, boundary_value_vector);
216 auto reference_dst = reference::activation_layer<T>(reference_src, info);
217
Manuel Bottini1d1bca72020-11-17 13:53:13 +0000218 validate(Accessor(src), reference_dst, tolerance_float_sqrt);
Sang-Hoon Parke7280582020-10-13 23:34:09 +0100219}
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100220} // namespace
221
222TEST_SUITE(NEON)
223TEST_SUITE(ActivationLayer)
224
Georgios Pinitas41648142021-08-03 08:24:00 +0100225/** Test case for memory injection in @ref cpu::CpuWinogradConv2d.
226 *
227 * Configure the operator once and inject memory at run-time in multiple executions.
228 *
229 * Checks performed in order:
230 * - Both runs compute the same output
231 */
232TEST_CASE(ActivationAPI, framework::DatasetMode::ALL)
233{
234 acl::StatusCode err = acl::StatusCode::Success;
235
236 // Create context & Queue
237 acl::Context ctx(acl::Target::Cpu, &err);
238 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
239
240 acl::Queue queue(ctx, &err);
241 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
242
243 // Create activation operator
244 acl::TensorDescriptor src_info({ 2, 3 }, acl::DataType::Float32);
245 acl::TensorDescriptor dst_info({ 2, 3 }, acl::DataType::Float32);
246 acl::ActivationDesc desc{ AclRelu, 6.f, 0.f, false };
247
248 acl::Activation act(ctx, src_info, dst_info, desc, &err);
249 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
250
251 // Create tensors and feed
252 acl::Tensor src(ctx, src_info, &err);
253 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
254 acl::Tensor dst(ctx, dst_info, &err);
255 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
256
257 acl::TensorPack pack(ctx);
258 err = pack.add(src, ACL_SRC);
259 err = pack.add(dst, ACL_DST);
260 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
261
262 // Execute operator
263 err = act.run(queue, pack);
264 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
265}
266
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000267// *INDENT-OFF*
268// clang-format off
269DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
270 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data types
271 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
272 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000273 }),
274 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
275 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
276 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000277 })),
278 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
279 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
280 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000281 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +0100282 framework::dataset::make("Expected", { false, true, false})),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000283 input_info, output_info, act_info, expected)
284{
285 bool is_valid = bool(NEActivationLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), act_info));
286 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
287}
Giorgio Arena5ae8d802021-11-18 18:02:13 +0000288
289DATA_TEST_CASE(KernelSelection, framework::DatasetMode::ALL, concat(concat(
290 combine(framework::dataset::make("CpuExt", std::string("NEON")),
291 framework::dataset::make("DataType", { DataType::F32,
292 DataType::F16,
293 DataType::QASYMM8,
294 DataType::QASYMM8_SIGNED,
295 DataType::QSYMM16
296 })),
297 combine(framework::dataset::make("CpuExt", std::string("SVE")),
298 framework::dataset::make("DataType", { DataType::F32,
299 DataType::F16,
300 }))),
301 combine(framework::dataset::make("CpuExt", std::string("SVE2")),
302 framework::dataset::make("DataType", { DataType::QASYMM8,
303 DataType::QASYMM8_SIGNED,
304 DataType::QSYMM16
305 }))),
306 cpu_ext, data_type)
307{
308 using namespace cpu::kernels;
309
310 cpuinfo::CpuIsaInfo cpu_isa{};
311 cpu_isa.neon = (cpu_ext == "NEON");
312 cpu_isa.sve = (cpu_ext == "SVE");
313 cpu_isa.sve2 = (cpu_ext == "SVE2");
314 cpu_isa.fp16 = (data_type == DataType::F16);
315
Pablo Marquez Tellod1586092022-06-10 14:37:10 +0100316 const auto *selected_impl = CpuActivationKernel::get_implementation(ActivationDataTypeISASelectorData{data_type, CPUModel::GENERIC, cpu_isa,ActivationLayerInfo::ActivationFunction::BOUNDED_RELU}, cpu::KernelSelectionType::Preferred);
Giorgio Arena5ae8d802021-11-18 18:02:13 +0000317
318 ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl);
319
320 std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_activation";
321 std::string actual = selected_impl->name;
322
323 ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS);
324}
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000325// clang-format on
326// *INDENT-ON*
327
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100328template <typename T>
329using NEActivationLayerFixture = ActivationValidationFixture<Tensor, Accessor, NEActivationLayer, T>;
330
331TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000332#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100333TEST_SUITE(FP16)
Sang-Hoon Parke7280582020-10-13 23:34:09 +0100334TEST_CASE(SqrtBoundaryValue, framework::DatasetMode::ALL)
335{
336 test_float_sqrt_boundary_value<half>();
337}
Sang-Hoon Parka8a7c1d2020-05-12 22:01:23 +0100338FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ActivationDataset),
339 framework::dataset::make("DataType",
340 DataType::F16)))
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100341{
342 // Validate output
Georgios Pinitas3463a8b2018-08-23 13:11:53 +0100343 validate(Accessor(_target), _reference, relative_tolerance(_data_type, _function), 0.f, absolute_tolerance(_data_type, _function));
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100344}
Sang-Hoon Parke7280582020-10-13 23:34:09 +0100345TEST_SUITE_END() // FP16
346#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100347
348TEST_SUITE(FP32)
Sang-Hoon Parke7280582020-10-13 23:34:09 +0100349TEST_CASE(SqrtBoundaryValue, framework::DatasetMode::ALL)
350{
351 test_float_sqrt_boundary_value<float>();
352}
Sang-Hoon Parka8a7c1d2020-05-12 22:01:23 +0100353FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ActivationDataset), framework::dataset::make("DataType",
354 DataType::F32)))
Pablo Tello7282d562018-06-14 15:35:49 +0100355
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100356{
357 // Validate output
Georgios Pinitas3463a8b2018-08-23 13:11:53 +0100358 validate(Accessor(_target), _reference, relative_tolerance(_data_type, _function), 0.f, absolute_tolerance(_data_type, _function));
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100359}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000360TEST_SUITE_END() // FP32
361TEST_SUITE_END() // Float
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100362
363template <typename T>
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000364using NEActivationLayerQuantizedFixture = ActivationValidationQuantizedFixture<Tensor, Accessor, NEActivationLayer, T>;
365
366/** Input data sets. */
Sang-Hoon Parkadd8e812020-11-25 11:46:03 +0000367const auto QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationFunction",
368{
369 ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
370 ActivationLayerInfo::ActivationFunction::RELU,
371 ActivationLayerInfo::ActivationFunction::BOUNDED_RELU,
372 ActivationLayerInfo::ActivationFunction::LOGISTIC,
373 ActivationLayerInfo::ActivationFunction::TANH,
374 ActivationLayerInfo::ActivationFunction::LEAKY_RELU,
375});
morgolockaa85cdf2020-02-28 15:38:28 +0000376
377const auto QuantizedActivationDataset = combine(combine(framework::dataset::make("InPlace", { false }),
378 concat(QuantizedActivationFunctionsDataset, framework::dataset::make("ActivationFunction", ActivationLayerInfo::ActivationFunction::HARD_SWISH))),
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000379 framework::dataset::make("AlphaBeta", { 0.5f, 1.f }));
380
381TEST_SUITE(Quantized)
382TEST_SUITE(QASYMM8)
Sang-Hoon Parka8a7c1d2020-05-12 22:01:23 +0100383FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), QuantizedActivationDataset),
384 framework::dataset::make("DataType",
385 DataType::QASYMM8)),
386 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1f, 128.0f) })))
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000387{
388 // Validate output
Michele Di Giorgio7e5a8652021-01-12 13:49:07 +0000389 validate(Accessor(_target), _reference, tolerance_qasymm8(_function));
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000390}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000391TEST_SUITE_END() // QASYMM8
giuros01c9573f32019-06-20 10:30:17 +0100392
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +0000393TEST_SUITE(QASYMM8_SIGNED)
Sang-Hoon Parka8a7c1d2020-05-12 22:01:23 +0100394FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), QuantizedActivationDataset),
395 framework::dataset::make("DataType",
396 DataType::QASYMM8_SIGNED)),
397 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10.0f) })))
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +0000398{
399 // Validate output
Michele Di Giorgio7e5a8652021-01-12 13:49:07 +0000400 validate(Accessor(_target), _reference, tolerance_qasymm8(_function));
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +0000401}
402TEST_SUITE_END() // QASYMM8_SIGNED
403
giuros01c9573f32019-06-20 10:30:17 +0100404/** Input data sets. */
Pablo Marquez Tellof55cca52022-04-06 14:31:25 +0100405const auto Int16QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationFunction",
406{
407 ActivationLayerInfo::ActivationFunction::LOGISTIC,
408 ActivationLayerInfo::ActivationFunction::TANH,
409 ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
410});
giuros01c9573f32019-06-20 10:30:17 +0100411const auto Int16QuantizedActivationDataset = combine(combine(framework::dataset::make("InPlace", { false }), Int16QuantizedActivationFunctionsDataset),
412 framework::dataset::make("AlphaBeta", { 0.5f, 1.f }));
413
414TEST_SUITE(QSYMM16)
Sang-Hoon Parka8a7c1d2020-05-12 22:01:23 +0100415FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerQuantizedFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), Int16QuantizedActivationDataset),
416 framework::dataset::make("DataType",
417 DataType::QSYMM16)),
418 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 32768.f, 0.f) })))
giuros01c9573f32019-06-20 10:30:17 +0100419{
420 // Validate output
421 validate(Accessor(_target), _reference, tolerance_qsymm16);
422}
423TEST_SUITE_END() // QSYMM16
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000424TEST_SUITE_END() // Quantized
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000425
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000426TEST_SUITE_END() // ActivationLayer
Sheri Zhangac6499a2021-02-10 15:32:38 +0000427TEST_SUITE_END() // Neon
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100428} // namespace validation
429} // namespace test
430} // namespace arm_compute