Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +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 | */ |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 24 | #include "AssetsLibrary.h" |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 25 | #include "Globals.h" |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame^] | 26 | #include "NEON/Accessor.h" |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 27 | #include "TypePrinter.h" |
| 28 | #include "Utils.h" |
| 29 | #include "validation/Datasets.h" |
| 30 | #include "validation/ReferenceCPP.h" |
| 31 | #include "validation/Validation.h" |
| 32 | |
| 33 | #include "arm_compute/core/Helpers.h" |
| 34 | #include "arm_compute/core/NEON/NEFixedPoint.h" |
| 35 | #include "arm_compute/core/Types.h" |
| 36 | #include "arm_compute/runtime/Tensor.h" |
| 37 | #include "arm_compute/runtime/TensorAllocator.h" |
| 38 | |
| 39 | #include "boost_wrapper.h" |
| 40 | |
| 41 | #include <random> |
| 42 | #include <string> |
| 43 | |
| 44 | using namespace arm_compute; |
| 45 | using namespace arm_compute::test; |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 46 | using namespace arm_compute::test::validation; |
| 47 | |
| 48 | namespace |
| 49 | { |
| 50 | const float tolerance = 1.0f; /**< Tolerance value for comparing reference's output against implementation's output */ |
| 51 | |
| 52 | /** Compute Neon exponential function for signed 16 bit fixed point. |
| 53 | * |
| 54 | * @param[in] shape Shape of the input and output tensors. |
| 55 | * |
| 56 | * @return Computed output tensor. |
| 57 | */ |
| 58 | Tensor compute_exp_qs16(const TensorShape &shape, int fixed_point_position) |
| 59 | { |
| 60 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 61 | Tensor src = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); |
| 62 | Tensor dst = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 63 | |
| 64 | constexpr unsigned int num_elems_processed_per_iteration = 8; |
| 65 | Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); |
| 66 | AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); |
| 67 | AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); |
| 68 | |
| 69 | update_window_and_padding(window, input_access, output_access); |
| 70 | output_access.set_valid_region(window, src.info()->valid_region()); |
| 71 | |
| 72 | // Allocate tensors |
| 73 | src.allocator()->allocate(); |
| 74 | dst.allocator()->allocate(); |
| 75 | |
| 76 | BOOST_TEST(!src.info()->is_resizable()); |
| 77 | BOOST_TEST(!dst.info()->is_resizable()); |
| 78 | |
| 79 | // Fill tensors. Keep the range between [-1.0, 1.0) so the result won't |
| 80 | // overflow. |
| 81 | std::uniform_int_distribution<> distribution(-(1 << (fixed_point_position - 1)), (1 << (fixed_point_position - 1))); |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame^] | 82 | library->fill(Accessor(src), distribution, 0); |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 83 | |
| 84 | Iterator input(&src, window); |
| 85 | Iterator output(&dst, window); |
| 86 | |
| 87 | execute_window_loop(window, [&](const Coordinates & id) |
| 88 | { |
| 89 | qint16x8_t in = vld1q_qs16(reinterpret_cast<const qint16_t *>(input.ptr())); |
| 90 | // Use saturated exp |
| 91 | vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqexpq_qs16(in, fixed_point_position)); |
| 92 | }, |
| 93 | input, output); |
| 94 | |
| 95 | return dst; |
| 96 | } |
| 97 | } // namespace |
| 98 | |
| 99 | #ifndef DOXYGEN_SKIP_THIS |
| 100 | BOOST_AUTO_TEST_SUITE(NEON) |
| 101 | BOOST_AUTO_TEST_SUITE(FixedPoint) |
| 102 | BOOST_AUTO_TEST_SUITE(QS16) |
| 103 | BOOST_AUTO_TEST_SUITE(Exp) |
| 104 | |
| 105 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 106 | BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 15), shape, fixed_point_position) |
| 107 | { |
| 108 | // Compute function |
| 109 | Tensor dst = compute_exp_qs16(shape, fixed_point_position); |
| 110 | |
| 111 | // Compute reference |
| 112 | RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS16, DataType::QS16, FixedPointOp::EXP, fixed_point_position); |
| 113 | |
| 114 | // Validate output |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame^] | 115 | validate(Accessor(dst), ref_dst, tolerance, 0); |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | BOOST_AUTO_TEST_SUITE_END() |
| 119 | BOOST_AUTO_TEST_SUITE_END() |
| 120 | BOOST_AUTO_TEST_SUITE_END() |
| 121 | BOOST_AUTO_TEST_SUITE_END() |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 122 | #endif /* DOXYGEN_SKIP_THIS */ |