Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +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" |
| 25 | #include "arm_compute/runtime/NEON/functions/NESoftmaxLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/SoftmaxLayerFixture.h" |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | /** Tolerance for float operations */ |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 46 | constexpr AbsoluteTolerance<float> tolerance_f32(0.000001f); |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 47 | RelativeTolerance<half> tolerance_f16(half(0.2)); |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 48 | |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 49 | /** Tolerance for quantized operations */ |
| 50 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); |
| 51 | |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 52 | /** CNN data types */ |
| 53 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 54 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 55 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 56 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 57 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 58 | DataType::F32, |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 59 | }); |
| 60 | } // namespace |
| 61 | |
| 62 | TEST_SUITE(NEON) |
| 63 | TEST_SUITE(SoftmaxLayer) |
| 64 | |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 65 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Medium2DShapes()), CNNDataTypes), shape, data_type) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 66 | { |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 67 | const QuantizationInfo quantization_info = is_data_type_quantized_asymmetric(data_type) ? QuantizationInfo(1.f / 255.f, 0) : QuantizationInfo(); |
| 68 | |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 69 | // Create tensors |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 70 | Tensor src = create_tensor<Tensor>(shape, data_type, 1, quantization_info); |
| 71 | Tensor dst = create_tensor<Tensor>(shape, data_type, 1, QuantizationInfo(1.f / 256.f, 0)); |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 72 | |
| 73 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 74 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 75 | |
| 76 | // Create and configure function |
| 77 | NESoftmaxLayer smx_layer; |
| 78 | smx_layer.configure(&src, &dst); |
| 79 | |
| 80 | // Validate valid region |
| 81 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 82 | validate(src.info()->valid_region(), valid_region); |
| 83 | validate(dst.info()->valid_region(), valid_region); |
| 84 | |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 85 | // NESoftmaxLayer configures the paddings only in the 2D case |
| 86 | if(shape.num_dimensions() <= 2) |
| 87 | { |
| 88 | // Validate padding |
| 89 | const int step = 16 / data_size_from_type(data_type); |
| 90 | const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); |
| 91 | validate(src.info()->padding(), padding); |
| 92 | validate(dst.info()->padding(), PaddingSize()); |
| 93 | } |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 96 | // *INDENT-OFF* |
| 97 | // clang-format off |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 98 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 99 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types |
| 100 | TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes |
| 101 | TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, // Invalid output quantization info |
| 102 | QuantizationInfo(1.f/256, 12)), |
| 103 | TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Window shrink |
| 104 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),// Invalid input dimensionality |
| 105 | TensorInfo(TensorShape(32U, 13U), 1, DataType::F32), |
| 106 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, |
| 107 | QuantizationInfo(1.f/256, 12)), |
| 108 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, //Invalid axis value |
| 109 | QuantizationInfo(1.f/256, 12)), |
| 110 | }), |
| 111 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16), |
| 112 | TensorInfo(TensorShape(27U, 11U), 1, DataType::F32), |
| 113 | TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, |
| 114 | QuantizationInfo(1.f/256, 12)), |
| 115 | TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), |
| 116 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 117 | TensorInfo(TensorShape(32U, 13U), 1, DataType::F32), |
| 118 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, |
| 119 | QuantizationInfo(1.f/256, 0)), |
| 120 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, |
| 121 | QuantizationInfo(1.f/256, 0)), |
| 122 | })), |
| 123 | framework::dataset::make("beta", { 1.0, |
| 124 | 2.0, |
| 125 | 1.0, |
| 126 | 2.0, |
| 127 | 1.0, |
| 128 | 2.0, |
| 129 | 1.0, |
| 130 | 2.0, |
| 131 | 1.0, |
| 132 | })), |
| 133 | framework::dataset::make("axis", { 1, |
| 134 | 1, |
| 135 | 1, |
| 136 | 1, |
| 137 | 1, |
| 138 | 1, |
| 139 | 1, |
| 140 | 0, |
| 141 | })), |
| 142 | framework::dataset::make("Expected", { false, false, false, false, false, true, true, false })), |
| 143 | input_info, output_info, beta, axis, expected) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 144 | { |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 145 | ARM_COMPUTE_EXPECT(bool(NESoftmaxLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), beta, axis)) == expected, framework::LogLevel::ERRORS); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 146 | } |
| 147 | // clang-format on |
| 148 | // *INDENT-ON* |
| 149 | |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 150 | template <typename T> |
| 151 | using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>; |
| 152 | |
| 153 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 154 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 155 | TEST_SUITE(FP16) |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 156 | FIXTURE_DATA_TEST_CASE(RunSmall, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(), |
Pablo Palmier | a2b89ca | 2017-10-05 15:01:34 +0100 | [diff] [blame] | 157 | framework::dataset::make("DataType", DataType::F16)), |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 158 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 159 | framework::dataset::make("Axis", { 1 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 160 | { |
| 161 | // Validate output |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 162 | validate(Accessor(_target), _reference, tolerance_f16); |
| 163 | } |
| 164 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(), |
| 165 | framework::dataset::make("DataType", DataType::F32)), |
| 166 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 167 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
| 168 | { |
| 169 | // Validate output |
| 170 | validate(Accessor(_target), _reference, tolerance_f32); |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 171 | } |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 172 | FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(), |
| 173 | framework::dataset::make("DataType", DataType::F16)), |
| 174 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 175 | framework::dataset::make("Axis", { 1 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 176 | { |
| 177 | // Validate output |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 178 | validate(Accessor(_target), _reference, tolerance_f16); |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 179 | } |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 180 | TEST_SUITE_END() //FP16 |
| 181 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 182 | |
| 183 | TEST_SUITE(FP32) |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 184 | FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 185 | framework::dataset::make("DataType", DataType::F32)), |
| 186 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 187 | framework::dataset::make("Axis", { 1 }))) |
| 188 | { |
| 189 | // Validate output |
| 190 | validate(Accessor(_target), _reference, tolerance_f32); |
| 191 | } |
| 192 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(), |
| 193 | framework::dataset::make("DataType", DataType::F32)), |
| 194 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 195 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 196 | { |
| 197 | // Validate output |
| 198 | validate(Accessor(_target), _reference, tolerance_f32); |
| 199 | } |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 200 | FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(), |
| 201 | framework::dataset::make("DataType", DataType::F32)), |
| 202 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 203 | framework::dataset::make("Axis", { 1 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 204 | { |
| 205 | // Validate output |
| 206 | validate(Accessor(_target), _reference, tolerance_f32); |
| 207 | } |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 208 | TEST_SUITE_END() //FP32 |
| 209 | TEST_SUITE_END() //Float |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 210 | |
| 211 | template <typename T> |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 212 | using NESoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NESoftmaxLayer, T>; |
| 213 | |
| 214 | TEST_SUITE(Quantized) |
| 215 | TEST_SUITE(QASYMM8) |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 216 | FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 217 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 218 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
| 219 | framework::dataset::make("Beta", { 1.0f, 2.f }))), |
| 220 | framework::dataset::make("Axis", { 1 }))) |
| 221 | { |
| 222 | // Validate output |
| 223 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 224 | } |
| 225 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(), |
| 226 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 227 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
| 228 | framework::dataset::make("Beta", { 1.0f, 2.f }))), |
| 229 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 230 | { |
| 231 | // Validate output |
| 232 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 233 | } |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 234 | FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(), |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 235 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 236 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 237 | framework::dataset::make("Beta", { 1.0f, 2.0f }))), |
| 238 | framework::dataset::make("Axis", { 1 }))) |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 239 | { |
| 240 | // Validate output |
| 241 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 242 | } |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 243 | TEST_SUITE_END() //QASYMM8 |
| 244 | TEST_SUITE_END() //Quantized |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 245 | |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame^] | 246 | TEST_SUITE_END() //SoftmaxLayer |
| 247 | TEST_SUITE_END() //NEON |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 248 | } // namespace validation |
| 249 | } // namespace test |
| 250 | } // namespace arm_compute |