Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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 "FixedPointTarget.h" |
| 25 | |
| 26 | #include "arm_compute/core/Types.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
| 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/FixedPointFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | constexpr AbsoluteTolerance<float> tolerance_exp_qs8(0.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential) for DataType::QS8 */ |
| 47 | constexpr AbsoluteTolerance<float> tolerance_exp_qs16(1.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential) for DataType::QS16 */ |
| 48 | constexpr AbsoluteTolerance<float> tolerance_invsqrt_qs8(4.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) for DataType::QS8 */ |
| 49 | constexpr AbsoluteTolerance<float> tolerance_invsqrt_qs16(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) for DataType::QS16 */ |
| 50 | constexpr AbsoluteTolerance<float> tolerance_log_qs8(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) for DataType::QS8 */ |
| 51 | constexpr AbsoluteTolerance<float> tolerance_log_qs16(7.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) for DataType::QS16 */ |
| 52 | constexpr AbsoluteTolerance<float> tolerance_reciprocal_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output (reciprocal) for DataType::QS8 */ |
| 53 | constexpr AbsoluteTolerance<float> tolerance_reciprocal_qs16(11.0f); /**< Tolerance value for comparing reference's output against implementation's output (reciprocal) for DataType::QS16 */ |
| 54 | } // namespace |
| 55 | |
| 56 | TEST_SUITE(NEON) |
| 57 | TEST_SUITE(FixedPoint) |
| 58 | template <typename T> |
| 59 | using NEFixedPointFixture = FixedPointValidationFixture<Tensor, Accessor, T>; |
| 60 | |
| 61 | TEST_SUITE(QS8) |
| 62 | TEST_SUITE(Exp) |
| 63 | |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 64 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 65 | DataType::QS8)), |
| 66 | framework::dataset::make("FixedPointOp", FixedPointOp::EXP)), |
| 67 | framework::dataset::make("FractionalBits", 1, 7))) |
| 68 | { |
| 69 | // Validate output |
| 70 | validate(Accessor(_target), _reference, tolerance_exp_qs8, 0); |
| 71 | } |
| 72 | TEST_SUITE_END() |
| 73 | |
| 74 | TEST_SUITE(Invsqrt) |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 75 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 76 | DataType::QS8)), |
| 77 | framework::dataset::make("FixedPointOp", FixedPointOp::INV_SQRT)), |
| 78 | framework::dataset::make("FractionalBits", 1, 6))) |
| 79 | { |
| 80 | // Validate output |
| 81 | validate(Accessor(_target), _reference, tolerance_invsqrt_qs8, 0); |
| 82 | } |
| 83 | TEST_SUITE_END() |
| 84 | |
| 85 | TEST_SUITE(Log) |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 86 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 87 | DataType::QS8)), |
| 88 | framework::dataset::make("FixedPointOp", FixedPointOp::LOG)), |
| 89 | framework::dataset::make("FractionalBits", 3, 6))) |
| 90 | { |
| 91 | // Validate output |
| 92 | validate(Accessor(_target), _reference, tolerance_log_qs8, 0); |
| 93 | } |
| 94 | TEST_SUITE_END() |
| 95 | |
| 96 | TEST_SUITE(Reciprocal) |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 97 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 98 | DataType::QS8)), |
| 99 | framework::dataset::make("FixedPointOp", FixedPointOp::RECIPROCAL)), |
| 100 | framework::dataset::make("FractionalBits", 1, 6))) |
| 101 | { |
| 102 | // Validate output |
| 103 | validate(Accessor(_target), _reference, tolerance_reciprocal_qs8, 0); |
| 104 | } |
| 105 | TEST_SUITE_END() |
| 106 | TEST_SUITE_END() |
| 107 | |
| 108 | TEST_SUITE(QS16) |
| 109 | TEST_SUITE(Exp) |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 110 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 111 | DataType::QS16)), |
| 112 | framework::dataset::make("FixedPointOp", FixedPointOp::EXP)), |
| 113 | framework::dataset::make("FractionalBits", 1, 15))) |
| 114 | { |
| 115 | // Validate output |
| 116 | validate(Accessor(_target), _reference, tolerance_exp_qs16, 0); |
| 117 | } |
| 118 | TEST_SUITE_END() |
| 119 | |
| 120 | TEST_SUITE(Invsqrt) |
| 121 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("Shape", TensorShape(8192U)), |
| 122 | framework::dataset::make("DataType", |
| 123 | DataType::QS16)), |
| 124 | framework::dataset::make("FixedPointOp", FixedPointOp::INV_SQRT)), |
| 125 | framework::dataset::make("FractionalBits", 1, 14))) |
| 126 | { |
| 127 | // Validate output |
| 128 | validate(Accessor(_target), _reference, tolerance_invsqrt_qs16, 0); |
| 129 | } |
| 130 | TEST_SUITE_END() |
| 131 | |
| 132 | TEST_SUITE(Log) |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 133 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 134 | DataType::QS16)), |
| 135 | framework::dataset::make("FixedPointOp", FixedPointOp::LOG)), |
| 136 | framework::dataset::make("FractionalBits", 4, 14))) |
| 137 | { |
| 138 | // Validate output |
| 139 | validate(Accessor(_target), _reference, tolerance_log_qs16, 0); |
| 140 | } |
| 141 | TEST_SUITE_END() |
| 142 | |
| 143 | TEST_SUITE(Reciprocal) |
Gian Marco | 5420b28 | 2017-11-29 10:41:38 +0000 | [diff] [blame] | 144 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType", |
Abe Mbise | 4bd2cb8 | 2017-09-27 18:39:19 +0100 | [diff] [blame] | 145 | DataType::QS16)), |
| 146 | framework::dataset::make("FixedPointOp", FixedPointOp::RECIPROCAL)), |
| 147 | framework::dataset::make("FractionalBits", 1, 14))) |
| 148 | { |
| 149 | // Validate output |
| 150 | validate(Accessor(_target), _reference, tolerance_reciprocal_qs16, 0); |
| 151 | } |
| 152 | TEST_SUITE_END() |
| 153 | TEST_SUITE_END() |
| 154 | |
| 155 | TEST_SUITE_END() |
| 156 | TEST_SUITE_END() |
| 157 | } // namespace validation |
| 158 | } // namespace test |
| 159 | } // namespace arm_compute |