Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 2dc7e40 | 2020-02-28 14:41:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 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); |
Sang-Hoon Park | c3a7420 | 2019-11-22 16:05:46 +0000 | [diff] [blame] | 51 | constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1); |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 52 | |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 53 | /** CNN data types */ |
| 54 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 55 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 56 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 57 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 58 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 59 | DataType::F32, |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 60 | }); |
| 61 | } // namespace |
| 62 | |
| 63 | TEST_SUITE(NEON) |
| 64 | TEST_SUITE(SoftmaxLayer) |
| 65 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 66 | // *INDENT-OFF* |
| 67 | // clang-format off |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 68 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 69 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching data types |
| 70 | TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), // Mismatching shapes |
| 71 | TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, // Invalid output quantization info |
| 72 | QuantizationInfo(1.f/256, 12)), |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 73 | TensorInfo(TensorShape(32U, 13U), 1, DataType::F32), |
| 74 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, |
| 75 | QuantizationInfo(1.f/256, 12)), |
| 76 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, //Invalid axis value |
| 77 | QuantizationInfo(1.f/256, 12)), |
| 78 | }), |
| 79 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U), 1, DataType::F16), |
| 80 | TensorInfo(TensorShape(27U, 11U), 1, DataType::F32), |
| 81 | TensorInfo(TensorShape(27U, 13U), 1, DataType::QASYMM8, |
| 82 | QuantizationInfo(1.f/256, 12)), |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 83 | TensorInfo(TensorShape(32U, 13U), 1, DataType::F32), |
| 84 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, |
| 85 | QuantizationInfo(1.f/256, 0)), |
| 86 | TensorInfo(TensorShape(32U, 13U), 1, DataType::QASYMM8, |
| 87 | QuantizationInfo(1.f/256, 0)), |
| 88 | })), |
| 89 | framework::dataset::make("beta", { 1.0, |
| 90 | 2.0, |
| 91 | 1.0, |
| 92 | 2.0, |
| 93 | 1.0, |
| 94 | 2.0, |
| 95 | 1.0, |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 96 | })), |
| 97 | framework::dataset::make("axis", { 1, |
| 98 | 1, |
| 99 | 1, |
| 100 | 1, |
| 101 | 1, |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 102 | 0, |
| 103 | })), |
Michalis Spyrou | 2dc7e40 | 2020-02-28 14:41:35 +0000 | [diff] [blame] | 104 | framework::dataset::make("Expected", { false, false, false, true, true, false })), |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 105 | input_info, output_info, beta, axis, expected) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 106 | { |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 107 | 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] | 108 | } |
| 109 | // clang-format on |
| 110 | // *INDENT-ON* |
| 111 | |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 112 | template <typename T> |
| 113 | using NESoftmaxLayerFixture = SoftmaxValidationFixture<Tensor, Accessor, NESoftmaxLayer, T>; |
| 114 | |
| 115 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 116 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 117 | TEST_SUITE(FP16) |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 118 | 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] | 119 | framework::dataset::make("DataType", DataType::F16)), |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 120 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 121 | framework::dataset::make("Axis", { 1 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 122 | { |
| 123 | // Validate output |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 124 | validate(Accessor(_target), _reference, tolerance_f16); |
| 125 | } |
| 126 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(), |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 127 | framework::dataset::make("DataType", DataType::F16)), |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 128 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 129 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
| 130 | { |
| 131 | // Validate output |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 132 | validate(Accessor(_target), _reference, tolerance_f16); |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 133 | } |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 134 | FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(), |
| 135 | framework::dataset::make("DataType", DataType::F16)), |
| 136 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 137 | framework::dataset::make("Axis", { 1 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 138 | { |
| 139 | // Validate output |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 140 | validate(Accessor(_target), _reference, tolerance_f16); |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 141 | } |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 142 | TEST_SUITE_END() //FP16 |
| 143 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 144 | |
| 145 | TEST_SUITE(FP32) |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 146 | FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 147 | framework::dataset::make("DataType", DataType::F32)), |
| 148 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 149 | framework::dataset::make("Axis", { 1 }))) |
| 150 | { |
| 151 | // Validate output |
| 152 | validate(Accessor(_target), _reference, tolerance_f32); |
| 153 | } |
| 154 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small4DShapes(), |
| 155 | framework::dataset::make("DataType", DataType::F32)), |
| 156 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 157 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 158 | { |
| 159 | // Validate output |
| 160 | validate(Accessor(_target), _reference, tolerance_f32); |
| 161 | } |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 162 | FIXTURE_DATA_TEST_CASE(RunLarge, NESoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SoftmaxLayerLargeShapes(), |
| 163 | framework::dataset::make("DataType", DataType::F32)), |
| 164 | framework::dataset::make("Beta", { 1.0f, 2.0f })), |
| 165 | framework::dataset::make("Axis", { 1 }))) |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 166 | { |
| 167 | // Validate output |
| 168 | validate(Accessor(_target), _reference, tolerance_f32); |
| 169 | } |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 170 | TEST_SUITE_END() //FP32 |
| 171 | TEST_SUITE_END() //Float |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 172 | |
| 173 | template <typename T> |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 174 | using NESoftmaxLayerQuantizedFixture = SoftmaxValidationQuantizedFixture<Tensor, Accessor, NESoftmaxLayer, T>; |
| 175 | |
| 176 | TEST_SUITE(Quantized) |
| 177 | TEST_SUITE(QASYMM8) |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 178 | FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 179 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 180 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
| 181 | framework::dataset::make("Beta", { 1.0f, 2.f }))), |
| 182 | framework::dataset::make("Axis", { 1 }))) |
| 183 | { |
| 184 | // Validate output |
| 185 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 186 | } |
| 187 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(), |
| 188 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 189 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
| 190 | framework::dataset::make("Beta", { 1.0f, 2.f }))), |
| 191 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 192 | { |
| 193 | // Validate output |
| 194 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 195 | } |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 196 | 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] | 197 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 198 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 199 | framework::dataset::make("Beta", { 1.0f, 2.0f }))), |
| 200 | framework::dataset::make("Axis", { 1 }))) |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 201 | { |
| 202 | // Validate output |
| 203 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 204 | } |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 205 | TEST_SUITE_END() //QASYMM8 |
Sang-Hoon Park | c3a7420 | 2019-11-22 16:05:46 +0000 | [diff] [blame] | 206 | |
| 207 | TEST_SUITE(QASYMM8_SIGNED) |
| 208 | FIXTURE_DATA_TEST_CASE(RunSmall2D, NESoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 209 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 210 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
| 211 | framework::dataset::make("Beta", { 1.0f, 2.f }))), |
| 212 | framework::dataset::make("Axis", { 1 }))) |
| 213 | { |
| 214 | // Validate output |
| 215 | validate(Accessor(_target), _reference, tolerance_qasymm8_signed); |
| 216 | } |
| 217 | FIXTURE_DATA_TEST_CASE(RunSmall4D, NESoftmaxLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small4DShapes(), |
| 218 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 219 | combine(framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -10) }), |
| 220 | framework::dataset::make("Beta", { 1.0f, 2.f }))), |
| 221 | framework::dataset::make("Axis", { 1, 2, 3 }))) |
| 222 | { |
| 223 | // Validate output |
| 224 | validate(Accessor(_target), _reference, tolerance_qasymm8_signed); |
| 225 | } |
| 226 | TEST_SUITE_END() //QASYMM8_SIGNED |
| 227 | |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 228 | TEST_SUITE_END() //Quantized |
giuros01 | efbf6c8 | 2018-09-03 09:53:53 +0100 | [diff] [blame] | 229 | |
Manuel Bottini | 678d83a | 2019-01-07 16:05:36 +0000 | [diff] [blame] | 230 | TEST_SUITE_END() //SoftmaxLayer |
| 231 | TEST_SUITE_END() //NEON |
Moritz Pflanzer | f6ad98a | 2017-07-21 17:19:58 +0100 | [diff] [blame] | 232 | } // namespace validation |
| 233 | } // namespace test |
| 234 | } // namespace arm_compute |