blob: 871143bc19e2e8d9a1ed76ff363426fcd16080a3 [file] [log] [blame]
Abe Mbise4bd2cb82017-09-27 18:39:19 +01001/*
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
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46constexpr AbsoluteTolerance<float> tolerance_exp_qs8(0.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential) for DataType::QS8 */
47constexpr AbsoluteTolerance<float> tolerance_exp_qs16(1.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential) for DataType::QS16 */
48constexpr AbsoluteTolerance<float> tolerance_invsqrt_qs8(4.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) for DataType::QS8 */
49constexpr AbsoluteTolerance<float> tolerance_invsqrt_qs16(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) for DataType::QS16 */
50constexpr AbsoluteTolerance<float> tolerance_log_qs8(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) for DataType::QS8 */
51constexpr AbsoluteTolerance<float> tolerance_log_qs16(7.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) for DataType::QS16 */
52constexpr AbsoluteTolerance<float> tolerance_reciprocal_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output (reciprocal) for DataType::QS8 */
53constexpr 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
56TEST_SUITE(NEON)
57TEST_SUITE(FixedPoint)
58template <typename T>
59using NEFixedPointFixture = FixedPointValidationFixture<Tensor, Accessor, T>;
60
61TEST_SUITE(QS8)
62TEST_SUITE(Exp)
63
Gian Marco5420b282017-11-29 10:41:38 +000064FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +010065 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}
72TEST_SUITE_END()
73
74TEST_SUITE(Invsqrt)
Gian Marco5420b282017-11-29 10:41:38 +000075FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +010076 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}
83TEST_SUITE_END()
84
85TEST_SUITE(Log)
Gian Marco5420b282017-11-29 10:41:38 +000086FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +010087 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}
94TEST_SUITE_END()
95
96TEST_SUITE(Reciprocal)
Gian Marco5420b282017-11-29 10:41:38 +000097FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +010098 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}
105TEST_SUITE_END()
106TEST_SUITE_END()
107
108TEST_SUITE(QS16)
109TEST_SUITE(Exp)
Gian Marco5420b282017-11-29 10:41:38 +0000110FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +0100111 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}
118TEST_SUITE_END()
119
120TEST_SUITE(Invsqrt)
121FIXTURE_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}
130TEST_SUITE_END()
131
132TEST_SUITE(Log)
Gian Marco5420b282017-11-29 10:41:38 +0000133FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +0100134 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}
141TEST_SUITE_END()
142
143TEST_SUITE(Reciprocal)
Gian Marco5420b282017-11-29 10:41:38 +0000144FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShapes(), framework::dataset::make("DataType",
Abe Mbise4bd2cb82017-09-27 18:39:19 +0100145 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}
152TEST_SUITE_END()
153TEST_SUITE_END()
154
155TEST_SUITE_END()
156TEST_SUITE_END()
157} // namespace validation
158} // namespace test
159} // namespace arm_compute