Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 1 | /* |
Pablo Marquez Tello | 732c1b2 | 2023-03-29 11:42:30 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2023 Arm Limited. |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 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" |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 25 | #include "arm_compute/core/utils/misc/Traits.h" |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEActivationLayer.h" |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/RuntimeContext.h" |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/Tensor.h" |
| 29 | #include "arm_compute/runtime/TensorAllocator.h" |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 30 | #include "src/common/cpuinfo/CpuIsaInfo.h" |
| 31 | #include "src/cpu/kernels/CpuActivationKernel.h" |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 32 | #include "tests/NEON/Accessor.h" |
| 33 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 34 | #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 Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 41 | |
Georgios Pinitas | 4164814 | 2021-08-03 08:24:00 +0100 | [diff] [blame] | 42 | #include "arm_compute/Acl.hpp" |
Pablo Marquez Tello | 732c1b2 | 2023-03-29 11:42:30 +0100 | [diff] [blame] | 43 | #include "support/AclRequires.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 44 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 45 | namespace arm_compute |
| 46 | { |
| 47 | namespace test |
| 48 | { |
| 49 | namespace validation |
| 50 | { |
| 51 | namespace |
| 52 | { |
Manuel Bottini | 1d1bca7 | 2020-11-17 13:53:13 +0000 | [diff] [blame] | 53 | RelativeTolerance<float> tolerance_float_sqrt(0.0001f); |
Sang-Hoon Park | add8e81 | 2020-11-25 11:46:03 +0000 | [diff] [blame] | 54 | |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 55 | /** Define relative tolerance of the activation layer. |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 56 | * |
| 57 | * @param[in] data_type The data type used. |
| 58 | * @param[in] activation The activation function used. |
| 59 | * |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 60 | * @return Relative tolerance depending on the activation function. |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 61 | */ |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 62 | RelativeTolerance<float> relative_tolerance(DataType data_type, ActivationLayerInfo::ActivationFunction activation) |
| 63 | { |
| 64 | switch(activation) |
| 65 | { |
| 66 | case ActivationLayerInfo::ActivationFunction::LOGISTIC: |
Georgios Pinitas | fb0fdcd | 2019-08-22 17:10:04 +0100 | [diff] [blame] | 67 | case ActivationLayerInfo::ActivationFunction::ELU: |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 68 | case ActivationLayerInfo::ActivationFunction::SQRT: |
| 69 | case ActivationLayerInfo::ActivationFunction::TANH: |
SiCong Li | a32e2ae | 2020-06-08 17:30:51 +0100 | [diff] [blame] | 70 | case ActivationLayerInfo::ActivationFunction::HARD_SWISH: |
Jonathan Deakin | d6b8a71 | 2022-08-23 11:44:18 +0100 | [diff] [blame] | 71 | case ActivationLayerInfo::ActivationFunction::SWISH: |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 72 | case ActivationLayerInfo::ActivationFunction::GELU: |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 73 | switch(data_type) |
| 74 | { |
| 75 | case DataType::F16: |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 76 | #if defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 77 | return RelativeTolerance<float>(0.25f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 78 | #else // !defined(ENABLE_SVE) |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 79 | return RelativeTolerance<float>(0.1f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 80 | #endif // defined(ENABLE_SVE) |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 81 | default: |
| 82 | return RelativeTolerance<float>(0.05f); |
| 83 | } |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 84 | case ActivationLayerInfo::ActivationFunction::SOFT_RELU: |
| 85 | switch(data_type) |
| 86 | { |
| 87 | case DataType::F16: |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 88 | #if defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 89 | return RelativeTolerance<float>(0.9f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 90 | #else // !defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 91 | return RelativeTolerance<float>(0.01f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 92 | #endif // defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 93 | default: |
| 94 | return RelativeTolerance<float>(0.00001f); |
| 95 | } |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 96 | 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 | */ |
| 108 | AbsoluteTolerance<float> absolute_tolerance(DataType data_type, ActivationLayerInfo::ActivationFunction activation) |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 109 | { |
| 110 | switch(activation) |
| 111 | { |
| 112 | case ActivationLayerInfo::ActivationFunction::LOGISTIC: |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 113 | case ActivationLayerInfo::ActivationFunction::SQRT: |
| 114 | case ActivationLayerInfo::ActivationFunction::TANH: |
Jonathan Deakin | d6b8a71 | 2022-08-23 11:44:18 +0100 | [diff] [blame] | 115 | case ActivationLayerInfo::ActivationFunction::SWISH: |
SiCong Li | a32e2ae | 2020-06-08 17:30:51 +0100 | [diff] [blame] | 116 | case ActivationLayerInfo::ActivationFunction::HARD_SWISH: |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 117 | switch(data_type) |
| 118 | { |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 119 | case DataType::F16: |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 120 | #if defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 121 | return AbsoluteTolerance<float>(0.25f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 122 | #else // !defined(ENABLE_SVE) |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 123 | return AbsoluteTolerance<float>(0.01f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 124 | #endif // defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 125 | default: |
| 126 | return AbsoluteTolerance<float>(0.00001f); |
| 127 | } |
| 128 | case ActivationLayerInfo::ActivationFunction::SOFT_RELU: |
| 129 | switch(data_type) |
| 130 | { |
| 131 | case DataType::F16: |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 132 | #if defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 133 | return AbsoluteTolerance<float>(0.9f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 134 | #else // !defined(ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 135 | return AbsoluteTolerance<float>(0.01f); |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 136 | #endif // defined(ENABLE_SVE) |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 137 | default: |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 138 | return AbsoluteTolerance<float>(0.00001f); |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 139 | } |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 140 | default: |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 141 | return AbsoluteTolerance<float>(0.f); |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Michele Di Giorgio | 7e5a865 | 2021-01-12 13:49:07 +0000 | [diff] [blame] | 145 | /** 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 | */ |
| 151 | AbsoluteTolerance<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 Pinitas | 151fa87 | 2019-06-06 14:44:44 +0100 | [diff] [blame] | 166 | |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 167 | constexpr AbsoluteTolerance<int16_t> tolerance_qsymm16(1); |
| 168 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 169 | /** CNN data types */ |
| 170 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 171 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 172 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 173 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 174 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 175 | DataType::F32, |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 176 | }); |
| 177 | |
Jonathan Deakin | d6b8a71 | 2022-08-23 11:44:18 +0100 | [diff] [blame] | 178 | const auto NeonActivationFunctionsDataset = concat(datasets::ActivationFunctions(), |
Pablo Marquez Tello | d158609 | 2022-06-10 14:37:10 +0100 | [diff] [blame] | 179 | framework::dataset::make("ActivationFunction", { ActivationLayerInfo::ActivationFunction::HARD_SWISH, ActivationLayerInfo::ActivationFunction::SWISH })); |
morgolock | 07df3d4 | 2020-02-27 11:46:28 +0000 | [diff] [blame] | 180 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 181 | /** Input data sets. */ |
morgolock | 07df3d4 | 2020-02-27 11:46:28 +0000 | [diff] [blame] | 182 | const auto ActivationDataset = combine(combine(framework::dataset::make("InPlace", { false, true }), NeonActivationFunctionsDataset), framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 183 | |
Giorgio Arena | c5a6139 | 2021-01-06 15:13:08 +0000 | [diff] [blame] | 184 | template <typename T, ARM_COMPUTE_REQUIRES_TA(arm_compute::utils::traits::is_floating_point<T>::value)> |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 185 | void 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 Bottini | 1d1bca7 | 2020-11-17 13:53:13 +0000 | [diff] [blame] | 218 | validate(Accessor(src), reference_dst, tolerance_float_sqrt); |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 219 | } |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 220 | } // namespace |
| 221 | |
| 222 | TEST_SUITE(NEON) |
| 223 | TEST_SUITE(ActivationLayer) |
| 224 | |
Georgios Pinitas | 4164814 | 2021-08-03 08:24:00 +0100 | [diff] [blame] | 225 | /** 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 | */ |
| 232 | TEST_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 Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 267 | // *INDENT-OFF* |
| 268 | // clang-format off |
| 269 | DATA_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 Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 273 | }), |
| 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 Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 277 | })), |
| 278 | framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 279 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 280 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 281 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 282 | framework::dataset::make("Expected", { false, true, false})), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 283 | 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 Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 288 | |
| 289 | DATA_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 Tello | d158609 | 2022-06-10 14:37:10 +0100 | [diff] [blame] | 316 | const auto *selected_impl = CpuActivationKernel::get_implementation(ActivationDataTypeISASelectorData{data_type, CPUModel::GENERIC, cpu_isa,ActivationLayerInfo::ActivationFunction::BOUNDED_RELU}, cpu::KernelSelectionType::Preferred); |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 317 | |
| 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 Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 325 | // clang-format on |
| 326 | // *INDENT-ON* |
| 327 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 328 | template <typename T> |
| 329 | using NEActivationLayerFixture = ActivationValidationFixture<Tensor, Accessor, NEActivationLayer, T>; |
| 330 | |
| 331 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 332 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 333 | TEST_SUITE(FP16) |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 334 | TEST_CASE(SqrtBoundaryValue, framework::DatasetMode::ALL) |
| 335 | { |
| 336 | test_float_sqrt_boundary_value<half>(); |
| 337 | } |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 338 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ActivationDataset), |
| 339 | framework::dataset::make("DataType", |
| 340 | DataType::F16))) |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 341 | { |
| 342 | // Validate output |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 343 | validate(Accessor(_target), _reference, relative_tolerance(_data_type, _function), 0.f, absolute_tolerance(_data_type, _function)); |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 344 | } |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 345 | TEST_SUITE_END() // FP16 |
| 346 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 347 | |
| 348 | TEST_SUITE(FP32) |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 349 | TEST_CASE(SqrtBoundaryValue, framework::DatasetMode::ALL) |
| 350 | { |
| 351 | test_float_sqrt_boundary_value<float>(); |
| 352 | } |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 353 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ActivationDataset), framework::dataset::make("DataType", |
| 354 | DataType::F32))) |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 355 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 356 | { |
| 357 | // Validate output |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 358 | validate(Accessor(_target), _reference, relative_tolerance(_data_type, _function), 0.f, absolute_tolerance(_data_type, _function)); |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 359 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 360 | TEST_SUITE_END() // FP32 |
| 361 | TEST_SUITE_END() // Float |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 362 | |
| 363 | template <typename T> |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 364 | using NEActivationLayerQuantizedFixture = ActivationValidationQuantizedFixture<Tensor, Accessor, NEActivationLayer, T>; |
| 365 | |
| 366 | /** Input data sets. */ |
Sang-Hoon Park | add8e81 | 2020-11-25 11:46:03 +0000 | [diff] [blame] | 367 | const 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 | }); |
morgolock | aa85cdf | 2020-02-28 15:38:28 +0000 | [diff] [blame] | 376 | |
| 377 | const auto QuantizedActivationDataset = combine(combine(framework::dataset::make("InPlace", { false }), |
| 378 | concat(QuantizedActivationFunctionsDataset, framework::dataset::make("ActivationFunction", ActivationLayerInfo::ActivationFunction::HARD_SWISH))), |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 379 | framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
| 380 | |
| 381 | TEST_SUITE(Quantized) |
| 382 | TEST_SUITE(QASYMM8) |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 383 | FIXTURE_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 Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 387 | { |
| 388 | // Validate output |
Michele Di Giorgio | 7e5a865 | 2021-01-12 13:49:07 +0000 | [diff] [blame] | 389 | validate(Accessor(_target), _reference, tolerance_qasymm8(_function)); |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 390 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 391 | TEST_SUITE_END() // QASYMM8 |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 392 | |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 393 | TEST_SUITE(QASYMM8_SIGNED) |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 394 | FIXTURE_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 Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 398 | { |
| 399 | // Validate output |
Michele Di Giorgio | 7e5a865 | 2021-01-12 13:49:07 +0000 | [diff] [blame] | 400 | validate(Accessor(_target), _reference, tolerance_qasymm8(_function)); |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 401 | } |
| 402 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 403 | |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 404 | /** Input data sets. */ |
Pablo Marquez Tello | f55cca5 | 2022-04-06 14:31:25 +0100 | [diff] [blame] | 405 | const auto Int16QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationFunction", |
| 406 | { |
| 407 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 408 | ActivationLayerInfo::ActivationFunction::TANH, |
| 409 | ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, |
| 410 | }); |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 411 | const auto Int16QuantizedActivationDataset = combine(combine(framework::dataset::make("InPlace", { false }), Int16QuantizedActivationFunctionsDataset), |
| 412 | framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
| 413 | |
| 414 | TEST_SUITE(QSYMM16) |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 415 | FIXTURE_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) }))) |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 419 | { |
| 420 | // Validate output |
| 421 | validate(Accessor(_target), _reference, tolerance_qsymm16); |
| 422 | } |
| 423 | TEST_SUITE_END() // QSYMM16 |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 424 | TEST_SUITE_END() // Quantized |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 425 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 426 | TEST_SUITE_END() // ActivationLayer |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 427 | TEST_SUITE_END() // Neon |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 428 | } // namespace validation |
| 429 | } // namespace test |
| 430 | } // namespace arm_compute |