Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 1 | /* |
Giorgio Arena | c5a6139 | 2021-01-06 15:13:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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" |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 30 | #include "tests/NEON/Accessor.h" |
| 31 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 32 | #include "tests/datasets/ActivationFunctionsDataset.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/ActivationLayerFixture.h" |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 39 | |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 40 | #include "support/Requires.h" |
| 41 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 42 | namespace arm_compute |
| 43 | { |
| 44 | namespace test |
| 45 | { |
| 46 | namespace validation |
| 47 | { |
| 48 | namespace |
| 49 | { |
Manuel Bottini | 1d1bca7 | 2020-11-17 13:53:13 +0000 | [diff] [blame] | 50 | RelativeTolerance<float> tolerance_float_sqrt(0.0001f); |
Sang-Hoon Park | add8e81 | 2020-11-25 11:46:03 +0000 | [diff] [blame] | 51 | |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 52 | /** Define relative tolerance of the activation layer. |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 53 | * |
| 54 | * @param[in] data_type The data type used. |
| 55 | * @param[in] activation The activation function used. |
| 56 | * |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 57 | * @return Relative tolerance depending on the activation function. |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 58 | */ |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 59 | RelativeTolerance<float> relative_tolerance(DataType data_type, ActivationLayerInfo::ActivationFunction activation) |
| 60 | { |
| 61 | switch(activation) |
| 62 | { |
| 63 | case ActivationLayerInfo::ActivationFunction::LOGISTIC: |
Georgios Pinitas | fb0fdcd | 2019-08-22 17:10:04 +0100 | [diff] [blame] | 64 | case ActivationLayerInfo::ActivationFunction::ELU: |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 65 | case ActivationLayerInfo::ActivationFunction::SQRT: |
| 66 | case ActivationLayerInfo::ActivationFunction::TANH: |
SiCong Li | a32e2ae | 2020-06-08 17:30:51 +0100 | [diff] [blame] | 67 | case ActivationLayerInfo::ActivationFunction::HARD_SWISH: |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 68 | switch(data_type) |
| 69 | { |
| 70 | case DataType::F16: |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 71 | #if defined(__ARM_FEATURE_SVE) |
| 72 | return RelativeTolerance<float>(0.25f); |
| 73 | #else // !defined(__ARM_FEATURE_SVE) |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 74 | return RelativeTolerance<float>(0.1f); |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 75 | #endif // defined(__ARM_FEATURE_SVE) |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 76 | default: |
| 77 | return RelativeTolerance<float>(0.05f); |
| 78 | } |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 79 | case ActivationLayerInfo::ActivationFunction::SOFT_RELU: |
| 80 | switch(data_type) |
| 81 | { |
| 82 | case DataType::F16: |
| 83 | #if defined(__ARM_FEATURE_SVE) |
| 84 | return RelativeTolerance<float>(0.9f); |
| 85 | #else // !defined(__ARM_FEATURE_SVE) |
| 86 | return RelativeTolerance<float>(0.01f); |
| 87 | #endif // defined(__ARM_FEATURE_SVE) |
| 88 | default: |
| 89 | return RelativeTolerance<float>(0.00001f); |
| 90 | } |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 91 | default: |
| 92 | return RelativeTolerance<float>(0.f); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** Define absolute tolerance of the activation layer. |
| 97 | * |
| 98 | * @param[in] data_type The data type used. |
| 99 | * @param[in] activation The activation function used. |
| 100 | * |
| 101 | * @return Absolute tolerance depending on the activation function. |
| 102 | */ |
| 103 | AbsoluteTolerance<float> absolute_tolerance(DataType data_type, ActivationLayerInfo::ActivationFunction activation) |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 104 | { |
| 105 | switch(activation) |
| 106 | { |
| 107 | case ActivationLayerInfo::ActivationFunction::LOGISTIC: |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 108 | case ActivationLayerInfo::ActivationFunction::SQRT: |
| 109 | case ActivationLayerInfo::ActivationFunction::TANH: |
SiCong Li | a32e2ae | 2020-06-08 17:30:51 +0100 | [diff] [blame] | 110 | case ActivationLayerInfo::ActivationFunction::HARD_SWISH: |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 111 | switch(data_type) |
| 112 | { |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 113 | case DataType::F16: |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 114 | #if defined(__ARM_FEATURE_SVE) |
| 115 | return AbsoluteTolerance<float>(0.25f); |
| 116 | #else // !defined(__ARM_FEATURE_SVE) |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 117 | return AbsoluteTolerance<float>(0.01f); |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 118 | #endif // defined(__ARM_FEATURE_SVE) |
| 119 | default: |
| 120 | return AbsoluteTolerance<float>(0.00001f); |
| 121 | } |
| 122 | case ActivationLayerInfo::ActivationFunction::SOFT_RELU: |
| 123 | switch(data_type) |
| 124 | { |
| 125 | case DataType::F16: |
| 126 | #if defined(__ARM_FEATURE_SVE) |
| 127 | return AbsoluteTolerance<float>(0.9f); |
| 128 | #else // !defined(__ARM_FEATURE_SVE) |
| 129 | return AbsoluteTolerance<float>(0.01f); |
| 130 | #endif // defined(__ARM_FEATURE_SVE) |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 131 | default: |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 132 | return AbsoluteTolerance<float>(0.00001f); |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 133 | } |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 134 | default: |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 135 | return AbsoluteTolerance<float>(0.f); |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Michele Di Giorgio | 7e5a865 | 2021-01-12 13:49:07 +0000 | [diff] [blame] | 139 | /** Define absolute tolerance of the activation layer for qasymm8. |
| 140 | * |
| 141 | * @param[in] activation The activation function used. |
| 142 | * |
| 143 | * @return Absolute tolerance depending on the activation function. |
| 144 | */ |
| 145 | AbsoluteTolerance<uint8_t> tolerance_qasymm8(ActivationLayerInfo::ActivationFunction activation) |
| 146 | { |
| 147 | switch(activation) |
| 148 | { |
| 149 | case ActivationLayerInfo::ActivationFunction::LOGISTIC: |
| 150 | case ActivationLayerInfo::ActivationFunction::SQRT: |
| 151 | case ActivationLayerInfo::ActivationFunction::TANH: |
| 152 | case ActivationLayerInfo::ActivationFunction::HARD_SWISH: |
| 153 | case ActivationLayerInfo::ActivationFunction::SOFT_RELU: |
| 154 | case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: |
| 155 | return AbsoluteTolerance<uint8_t>(1); |
| 156 | default: |
| 157 | return AbsoluteTolerance<uint8_t>(0); |
| 158 | } |
| 159 | } |
Georgios Pinitas | 151fa87 | 2019-06-06 14:44:44 +0100 | [diff] [blame] | 160 | |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 161 | constexpr AbsoluteTolerance<int16_t> tolerance_qsymm16(1); |
| 162 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 163 | /** CNN data types */ |
| 164 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 165 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 166 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 167 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 168 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 169 | DataType::F32, |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 170 | }); |
| 171 | |
morgolock | aa85cdf | 2020-02-28 15:38:28 +0000 | [diff] [blame] | 172 | const auto NeonActivationFunctionsDataset = concat(datasets::ActivationFunctions(), framework::dataset::make("ActivationFunction", ActivationLayerInfo::ActivationFunction::HARD_SWISH)); |
morgolock | 07df3d4 | 2020-02-27 11:46:28 +0000 | [diff] [blame] | 173 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 174 | /** Input data sets. */ |
morgolock | 07df3d4 | 2020-02-27 11:46:28 +0000 | [diff] [blame] | 175 | 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] | 176 | |
Giorgio Arena | c5a6139 | 2021-01-06 15:13:08 +0000 | [diff] [blame] | 177 | 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] | 178 | void test_float_sqrt_boundary_value() |
| 179 | { |
| 180 | constexpr auto vector_size = uint32_t{ 16 }; |
| 181 | |
| 182 | auto data_type = DataType::F32; |
| 183 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 184 | data_type = std::is_same<T, half>::value ? DataType::F16 : data_type; |
| 185 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 186 | |
| 187 | const auto boundary_value_vector = std::vector<T> |
| 188 | { |
| 189 | std::numeric_limits<T>::min(), |
| 190 | T(0), |
| 191 | std::numeric_limits<T>::epsilon(), |
| 192 | std::numeric_limits<T>::max(), |
| 193 | }; |
| 194 | |
| 195 | // the following size ensures that the whole logic (vector + left-over) to be tested |
| 196 | // using all boundary values iff boundary_value_vecotr.size() is smaller than vector_size. |
| 197 | auto shape = TensorShape{ vector_size + boundary_value_vector.size() }; |
| 198 | auto info = ActivationLayerInfo{ ActivationLayerInfo::ActivationFunction::SQRT }; |
| 199 | auto src = create_tensor<Tensor>(shape, data_type); |
| 200 | |
| 201 | auto act = NEActivationLayer{}; |
| 202 | act.configure(&src, nullptr, info); |
| 203 | src.allocator()->allocate(); |
| 204 | library->fill_static_values(Accessor(src), boundary_value_vector); |
| 205 | act.run(); |
| 206 | |
| 207 | auto reference_src = SimpleTensor<T> { shape, data_type }; |
| 208 | library->fill_static_values(reference_src, boundary_value_vector); |
| 209 | auto reference_dst = reference::activation_layer<T>(reference_src, info); |
| 210 | |
Manuel Bottini | 1d1bca7 | 2020-11-17 13:53:13 +0000 | [diff] [blame] | 211 | validate(Accessor(src), reference_dst, tolerance_float_sqrt); |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 212 | } |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 213 | } // namespace |
| 214 | |
| 215 | TEST_SUITE(NEON) |
| 216 | TEST_SUITE(ActivationLayer) |
| 217 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 218 | // *INDENT-OFF* |
| 219 | // clang-format off |
| 220 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 221 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data types |
| 222 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 223 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 224 | }), |
| 225 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), |
| 226 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 227 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 228 | })), |
| 229 | framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 230 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 231 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 232 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 233 | framework::dataset::make("Expected", { false, true, false})), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 234 | input_info, output_info, act_info, expected) |
| 235 | { |
| 236 | bool is_valid = bool(NEActivationLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), act_info)); |
| 237 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 238 | } |
| 239 | // clang-format on |
| 240 | // *INDENT-ON* |
| 241 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 242 | template <typename T> |
| 243 | using NEActivationLayerFixture = ActivationValidationFixture<Tensor, Accessor, NEActivationLayer, T>; |
| 244 | |
| 245 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 246 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 247 | TEST_SUITE(FP16) |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 248 | TEST_CASE(SqrtBoundaryValue, framework::DatasetMode::ALL) |
| 249 | { |
| 250 | test_float_sqrt_boundary_value<half>(); |
| 251 | } |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 252 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ActivationDataset), |
| 253 | framework::dataset::make("DataType", |
| 254 | DataType::F16))) |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 255 | { |
| 256 | // Validate output |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 257 | 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] | 258 | } |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 259 | TEST_SUITE_END() // FP16 |
| 260 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 261 | |
| 262 | TEST_SUITE(FP32) |
Sang-Hoon Park | e728058 | 2020-10-13 23:34:09 +0100 | [diff] [blame] | 263 | TEST_CASE(SqrtBoundaryValue, framework::DatasetMode::ALL) |
| 264 | { |
| 265 | test_float_sqrt_boundary_value<float>(); |
| 266 | } |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 267 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ActivationDataset), framework::dataset::make("DataType", |
| 268 | DataType::F32))) |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 269 | |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 270 | { |
| 271 | // Validate output |
Georgios Pinitas | 3463a8b | 2018-08-23 13:11:53 +0100 | [diff] [blame] | 272 | 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] | 273 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 274 | TEST_SUITE_END() // FP32 |
| 275 | TEST_SUITE_END() // Float |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 276 | |
| 277 | template <typename T> |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 278 | using NEActivationLayerQuantizedFixture = ActivationValidationQuantizedFixture<Tensor, Accessor, NEActivationLayer, T>; |
| 279 | |
| 280 | /** Input data sets. */ |
Sang-Hoon Park | add8e81 | 2020-11-25 11:46:03 +0000 | [diff] [blame] | 281 | const auto QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationFunction", |
| 282 | { |
| 283 | ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, |
| 284 | ActivationLayerInfo::ActivationFunction::RELU, |
| 285 | ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, |
| 286 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 287 | ActivationLayerInfo::ActivationFunction::TANH, |
| 288 | ActivationLayerInfo::ActivationFunction::LEAKY_RELU, |
| 289 | }); |
morgolock | aa85cdf | 2020-02-28 15:38:28 +0000 | [diff] [blame] | 290 | |
| 291 | const auto QuantizedActivationDataset = combine(combine(framework::dataset::make("InPlace", { false }), |
| 292 | concat(QuantizedActivationFunctionsDataset, framework::dataset::make("ActivationFunction", ActivationLayerInfo::ActivationFunction::HARD_SWISH))), |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 293 | framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
| 294 | |
| 295 | TEST_SUITE(Quantized) |
| 296 | TEST_SUITE(QASYMM8) |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 297 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), QuantizedActivationDataset), |
| 298 | framework::dataset::make("DataType", |
| 299 | DataType::QASYMM8)), |
| 300 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1f, 128.0f) }))) |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 301 | { |
| 302 | // Validate output |
Michele Di Giorgio | 7e5a865 | 2021-01-12 13:49:07 +0000 | [diff] [blame] | 303 | validate(Accessor(_target), _reference, tolerance_qasymm8(_function)); |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 304 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 305 | TEST_SUITE_END() // QASYMM8 |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 306 | |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 307 | TEST_SUITE(QASYMM8_SIGNED) |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 308 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), QuantizedActivationDataset), |
| 309 | framework::dataset::make("DataType", |
| 310 | DataType::QASYMM8_SIGNED)), |
| 311 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10.0f) }))) |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 312 | { |
| 313 | // Validate output |
Michele Di Giorgio | 7e5a865 | 2021-01-12 13:49:07 +0000 | [diff] [blame] | 314 | validate(Accessor(_target), _reference, tolerance_qasymm8(_function)); |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 315 | } |
| 316 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 317 | |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 318 | /** Input data sets. */ |
| 319 | const auto Int16QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationFunction", { ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 320 | ActivationLayerInfo::ActivationFunction::TANH |
| 321 | }); |
| 322 | const auto Int16QuantizedActivationDataset = combine(combine(framework::dataset::make("InPlace", { false }), Int16QuantizedActivationFunctionsDataset), |
| 323 | framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
| 324 | |
| 325 | TEST_SUITE(QSYMM16) |
Sang-Hoon Park | a8a7c1d | 2020-05-12 22:01:23 +0100 | [diff] [blame] | 326 | FIXTURE_DATA_TEST_CASE(RunSmall, NEActivationLayerQuantizedFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), Int16QuantizedActivationDataset), |
| 327 | framework::dataset::make("DataType", |
| 328 | DataType::QSYMM16)), |
| 329 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 32768.f, 0.f) }))) |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 330 | { |
| 331 | // Validate output |
| 332 | validate(Accessor(_target), _reference, tolerance_qsymm16); |
| 333 | } |
| 334 | TEST_SUITE_END() // QSYMM16 |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 335 | TEST_SUITE_END() // Quantized |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 336 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 337 | TEST_SUITE_END() // ActivationLayer |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 338 | TEST_SUITE_END() // Neon |
Moritz Pflanzer | 572ade7 | 2017-07-21 17:36:33 +0100 | [diff] [blame] | 339 | } // namespace validation |
| 340 | } // namespace test |
| 341 | } // namespace arm_compute |