blob: 6789ec72647c7a06ffdbd0eaecc7cd97a2423fb4 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 "Globals.h"
25#include "NEON/Helper.h"
26#include "NEON/NEAccessor.h"
27#include "TensorLibrary.h"
28#include "TypePrinter.h"
29#include "Utils.h"
30#include "validation/Datasets.h"
31#include "validation/ReferenceCPP.h"
32#include "validation/Validation.h"
33
34#include "arm_compute/core/Helpers.h"
35#include "arm_compute/core/NEON/NEFixedPoint.h"
36#include "arm_compute/core/Types.h"
37#include "arm_compute/runtime/Tensor.h"
38#include "arm_compute/runtime/TensorAllocator.h"
39
40#include "boost_wrapper.h"
41
42#include <random>
43#include <string>
44
45using namespace arm_compute;
46using namespace arm_compute::test;
47using namespace arm_compute::test::neon;
48using namespace arm_compute::test::validation;
49
50namespace
51{
52const float tolerance = 5; /**< Tolerance value for comparing reference's output against implementation's output */
53
54/** Compute Neon logarithm function for signed 8bit fixed point.
55 *
56 * @param[in] shape Shape of the input and output tensors.
57 *
58 * @return Computed output tensor.
59 */
60Tensor compute_log_qs8(const TensorShape &shape, int fixed_point_position)
61{
62 // Create tensors
63 Tensor src = create_tensor(shape, DataType::QS8, 1, fixed_point_position);
64 Tensor dst = create_tensor(shape, DataType::QS8, 1, fixed_point_position);
65
66 constexpr unsigned int num_elems_processed_per_iteration = 16;
67 Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration));
68 AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration);
69 AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration);
70
71 update_window_and_padding(window, input_access, output_access);
72 output_access.set_valid_region(window, src.info()->valid_region());
73
74 // Allocate tensors
75 src.allocator()->allocate();
76 dst.allocator()->allocate();
77
78 BOOST_TEST(!src.info()->is_resizable());
79 BOOST_TEST(!dst.info()->is_resizable());
80
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010081 // Fill tensors. Keep the range between [(1 << (fixed_point_position - 1), 63) so the result won't
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082 // overflow. E.g. for Q2.5 ln(0.001) = -6.9, which cannot be represented.
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010083 std::uniform_int_distribution<> distribution((1 << (fixed_point_position - 1)), 0x3F);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084 library->fill(NEAccessor(src), distribution, 0);
85
86 Iterator input(&src, window);
87 Iterator output(&dst, window);
88
89 execute_window_loop(window, [&](const Coordinates & id)
90 {
91 qint8x16_t in = vld1q_s8(reinterpret_cast<const qint8_t *>(input.ptr()));
92 vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vlogq_qs8(in, fixed_point_position));
93 },
94 input, output);
95
96 return dst;
97}
98} // namespace
99
100#ifndef DOXYGEN_SKIP_THIS
101BOOST_AUTO_TEST_SUITE(NEON)
102BOOST_AUTO_TEST_SUITE(FixedPoint)
103BOOST_AUTO_TEST_SUITE(QS8)
104BOOST_AUTO_TEST_SUITE(Log)
105
106BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
107BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(3, 6), shape, fixed_point_position)
108{
109 // Compute function
110 Tensor dst = compute_log_qs8(shape, fixed_point_position);
111
112 // Compute reference
113 RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::LOG, fixed_point_position);
114
115 // Validate output
116 validate(NEAccessor(dst), ref_dst, tolerance, 0);
117}
118
119BOOST_AUTO_TEST_SUITE_END()
120BOOST_AUTO_TEST_SUITE_END()
121BOOST_AUTO_TEST_SUITE_END()
122BOOST_AUTO_TEST_SUITE_END()
123#endif