Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [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 | */ |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 24 | #include "src/core/NEON/kernels/NEHeightConcatenateLayerKernel.h" |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
| 28 | #include "arm_compute/core/IAccessWindow.h" |
| 29 | #include "arm_compute/core/ITensor.h" |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/TensorInfo.h" |
| 31 | #include "arm_compute/core/Utils.h" |
| 32 | #include "arm_compute/core/Validate.h" |
| 33 | #include "arm_compute/core/Window.h" |
Georgios Pinitas | ddb93bb | 2020-10-02 16:38:59 +0100 | [diff] [blame] | 34 | #include "src/core/NEON/NEAsymm.h" |
| 35 | #include "src/core/NEON/wrapper/wrapper.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 36 | #include "src/core/helpers/AutoConfiguration.h" |
| 37 | #include "src/core/helpers/WindowHelpers.h" |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 38 | |
| 39 | #include <cstdint> |
| 40 | |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 41 | namespace arm_compute |
| 42 | { |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 43 | namespace |
| 44 | { |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 45 | Status validate_arguments(const ITensorInfo *input, unsigned int height_offset, const ITensorInfo *output) |
| 46 | { |
| 47 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
| 48 | // Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input) is not needed here as this kernel doesn't use NEON FP16 instructions. |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON(input->data_type() == DataType::UNKNOWN); |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 50 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 51 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(Window::DimX) != output->dimension(Window::DimX)); |
| 52 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(Window::DimY) + height_offset > output->dimension(Window::DimY)); |
| 53 | for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i) |
| 54 | { |
| 55 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(i) != output->dimension(i)); |
| 56 | } |
| 57 | |
| 58 | return Status{}; |
| 59 | } |
| 60 | } // namespace |
| 61 | |
| 62 | NEHeightConcatenateLayerKernel::NEHeightConcatenateLayerKernel() |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 63 | : _height_offset(0) |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 64 | { |
| 65 | } |
| 66 | |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 67 | void NEHeightConcatenateLayerKernel::configure(const ITensorInfo *input, unsigned int height_offset, ITensorInfo *output) |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 68 | { |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 69 | ARM_COMPUTE_UNUSED(input); |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 70 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 71 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, height_offset, output)); |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 72 | |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 73 | _height_offset = height_offset; |
| 74 | |
| 75 | // Configure kernel window |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 76 | Window win = calculate_max_window(*output, Steps()); |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 77 | Coordinates coord; |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 78 | coord.set_num_dimensions(output->num_dimensions()); |
| 79 | output->set_valid_region(ValidRegion(coord, output->tensor_shape())); |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 80 | INEKernel::configure(win); |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | Status NEHeightConcatenateLayerKernel::validate(const ITensorInfo *input, unsigned int height_offset, const ITensorInfo *output) |
| 84 | { |
| 85 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, height_offset, output)); |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 86 | return Status{}; |
| 87 | } |
| 88 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 89 | void NEHeightConcatenateLayerKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 90 | { |
| 91 | ARM_COMPUTE_UNUSED(info); |
| 92 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 93 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 94 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 95 | const auto src = tensors.get_const_tensor(TensorType::ACL_SRC); |
| 96 | auto dst = tensors.get_tensor(TensorType::ACL_DST); |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 97 | |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 98 | // Offset output pointer to the correct position |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 99 | uint8_t *output_ptr = dst->buffer() + dst->info()->offset_first_element_in_bytes() + _height_offset * dst->info()->strides_in_bytes()[Window::DimY]; |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 100 | |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 101 | const auto window_start_x = static_cast<int>(window.x().start()); |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 102 | const auto window_end_x = static_cast<int>(window.x().end()) * static_cast<int>(dst->info()->element_size()); |
| 103 | const int window_step_x = 16; |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 104 | |
| 105 | Window win{ window }; |
| 106 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 107 | win.set(Window::DimY, Window::Dimension(0, src->info()->tensor_shape().y(), 1)); |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 108 | |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 109 | // Create iterators |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 110 | Iterator input(src, win); |
| 111 | Iterator output(dst, win); |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 112 | |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 113 | const DataType dt = src->info()->data_type(); |
| 114 | const UniformQuantizationInfo &input_qinfo = src->info()->quantization_info().uniform(); |
| 115 | const UniformQuantizationInfo &output_qinfo = dst->info()->quantization_info().uniform(); |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 116 | if(dt == DataType::QASYMM8 && input_qinfo != output_qinfo) |
| 117 | { |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 118 | execute_window_loop(win, [&](const Coordinates &) |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 119 | { |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 120 | int x = window_start_x; |
| 121 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 122 | { |
| 123 | vst1q_u8(output_ptr + output.offset() + x, vquantize(vdequantize(vld1q_u8(input.ptr() + x), input_qinfo), output_qinfo)); |
| 124 | } |
| 125 | |
| 126 | // Compute left-over elements |
| 127 | for(; x < window_end_x; ++x) |
| 128 | { |
| 129 | *(output_ptr + output.offset() + x) = quantize_qasymm8(dequantize_qasymm8(*(input.ptr() + x), input_qinfo), output_qinfo); |
| 130 | } |
| 131 | |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 132 | }, |
| 133 | input, output); |
| 134 | } |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 135 | else if(dt == DataType::QASYMM8_SIGNED && input_qinfo != output_qinfo) |
| 136 | { |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 137 | execute_window_loop(win, [&](const Coordinates &) |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 138 | { |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 139 | int x = window_start_x; |
| 140 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 141 | { |
| 142 | vst1q_s8(reinterpret_cast<int8_t *>(output_ptr + output.offset() + x), |
| 143 | vquantize_signed(vdequantize(vld1q_s8(reinterpret_cast<int8_t *>(input.ptr()) + x), input_qinfo), output_qinfo)); |
| 144 | } |
| 145 | |
| 146 | // Compute left-over elements |
| 147 | for(; x < window_end_x; ++x) |
| 148 | { |
| 149 | *(output_ptr + output.offset() + x) = quantize_qasymm8_signed(dequantize_qasymm8_signed(*(input.ptr() + x), input_qinfo), output_qinfo); |
| 150 | } |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 151 | }, |
| 152 | input, output); |
| 153 | } |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 154 | else |
| 155 | { |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 156 | execute_window_loop(win, [&](const Coordinates &) |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 157 | { |
| 158 | const auto in_ptr = input.ptr(); |
| 159 | const auto out_ptr = output_ptr + output.offset(); |
| 160 | |
Michalis Spyrou | 61b1708 | 2020-03-04 17:34:20 +0000 | [diff] [blame] | 161 | int x = window_start_x; |
| 162 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 163 | { |
| 164 | wrapper::vstore(out_ptr + x, wrapper::vloadq(in_ptr + x)); |
| 165 | } |
| 166 | |
| 167 | // Compute left-over elements |
| 168 | for(; x < window_end_x; ++x) |
| 169 | { |
| 170 | *(out_ptr + x) = *(in_ptr + x); |
| 171 | } |
Pablo Tello | 3dd5b68 | 2019-03-04 14:14:02 +0000 | [diff] [blame] | 172 | }, |
| 173 | input, output); |
| 174 | } |
| 175 | } |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 176 | } // namespace arm_compute |