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