Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEDepthConcatenateLayerKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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 | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/NEON/NEAsymm.h" |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/NEFixedPoint.h" |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/TensorInfo.h" |
| 34 | #include "arm_compute/core/Utils.h" |
| 35 | #include "arm_compute/core/Validate.h" |
| 36 | #include "arm_compute/core/Window.h" |
| 37 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 38 | #include <cstdint> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 42 | namespace |
| 43 | { |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 44 | template <typename T> |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 45 | void depth_concat(const ITensor *in, ITensor *out, unsigned int depth_offset, const Window &window) |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 46 | { |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 47 | // Offset input |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 48 | uint8_t *input_ptr = in->buffer() + in->info()->offset_first_element_in_bytes(); |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 49 | |
| 50 | // Offset output |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 51 | uint8_t *output_ptr = out->buffer() + out->info()->offset_first_element_in_bytes() + depth_offset * out->info()->strides_in_bytes()[2]; |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 52 | |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 53 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 54 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 55 | const int window_step_x = 16 / out->info()->element_size(); |
| 56 | |
| 57 | Window win{ window }; |
| 58 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 59 | win.set(Window::DimZ, Window::Dimension(0, in->info()->tensor_shape().z(), 1)); |
| 60 | |
| 61 | Iterator input(in, win); |
| 62 | Iterator output(out, win); |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 63 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 64 | const DataType dt = in->info()->data_type(); |
| 65 | const UniformQuantizationInfo input_qinfo = in->info()->quantization_info().uniform(); |
| 66 | const UniformQuantizationInfo output_qinfo = out->info()->quantization_info().uniform(); |
Pablo Tello | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 67 | if(dt == DataType::QASYMM8 && input_qinfo != output_qinfo) |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 68 | { |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 69 | execute_window_loop(win, [&](const Coordinates &) |
Pablo Tello | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 70 | { |
| 71 | const auto in_ptr = reinterpret_cast<const uint8_t *>(input_ptr + input.offset()); |
| 72 | const auto out_ptr = reinterpret_cast<uint8_t *>(output_ptr + output.offset()); |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 73 | int x = window_start_x; |
| 74 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 75 | { |
| 76 | wrapper::vstore(out_ptr + x, vquantize(vdequantize(wrapper::vloadq(in_ptr + x), input_qinfo), output_qinfo)); |
| 77 | } |
| 78 | |
| 79 | // Compute left-over elements |
| 80 | for(; x < window_end_x; ++x) |
| 81 | { |
| 82 | *(out_ptr + x) = quantize_qasymm8(dequantize_qasymm8(*(in_ptr + x), input_qinfo), output_qinfo); |
| 83 | } |
Pablo Tello | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 84 | }, |
| 85 | input, output); |
| 86 | } |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 87 | else if(dt == DataType::QASYMM8_SIGNED && input_qinfo != output_qinfo) |
| 88 | { |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 89 | execute_window_loop(win, [&](const Coordinates &) |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 90 | { |
| 91 | const auto in_ptr = reinterpret_cast<const int8_t *>(input_ptr + input.offset()); |
| 92 | const auto out_ptr = reinterpret_cast<int8_t *>(output_ptr + output.offset()); |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 93 | int x = window_start_x; |
| 94 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 95 | { |
| 96 | wrapper::vstore(out_ptr + x, vquantize_signed(vdequantize(wrapper::vloadq(in_ptr + x), input_qinfo), output_qinfo)); |
| 97 | } |
| 98 | |
| 99 | // Compute left-over elements |
| 100 | for(; x < window_end_x; ++x) |
| 101 | { |
| 102 | *(out_ptr + x) = quantize_qasymm8_signed(dequantize_qasymm8_signed(*(in_ptr + x), input_qinfo), output_qinfo); |
| 103 | } |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 104 | }, |
| 105 | input, output); |
| 106 | } |
Pablo Tello | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 107 | else |
| 108 | { |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 109 | execute_window_loop(win, [&](const Coordinates &) |
Pablo Tello | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 110 | { |
| 111 | const auto in_ptr = reinterpret_cast<const T *>(input_ptr + input.offset()); |
| 112 | const auto out_ptr = reinterpret_cast<T *>(output_ptr + output.offset()); |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 113 | int x = window_start_x; |
| 114 | for(; x <= (window_end_x - window_step_x); x += window_step_x) |
| 115 | { |
| 116 | wrapper::vstore(out_ptr + x, wrapper::vloadq(in_ptr + x)); |
| 117 | } |
| 118 | // Compute left-over elements |
| 119 | for(; x < window_end_x; ++x) |
| 120 | { |
| 121 | *(out_ptr + x) = *(in_ptr + x); |
| 122 | } |
Pablo Tello | 54e98d9 | 2019-02-05 16:16:19 +0000 | [diff] [blame] | 123 | }, |
| 124 | input, output); |
| 125 | } |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 126 | } |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 127 | |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 128 | Status validate_arguments(const ITensorInfo *input, unsigned int depth_offset, const ITensorInfo *output) |
| 129 | { |
| 130 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 131 | //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] | 132 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::F16, DataType::F32); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 133 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 134 | |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame] | 135 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(Window::DimX) != output->dimension(Window::DimX)); |
| 136 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(Window::DimY) != output->dimension(Window::DimY)); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 137 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(2) + depth_offset > output->dimension(2)); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 138 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(3, input, output); |
| 139 | |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 140 | return Status{}; |
| 141 | } |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 142 | } // namespace |
| 143 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 144 | NEDepthConcatenateLayerKernel::NEDepthConcatenateLayerKernel() |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 145 | : _func(nullptr), _depth_offset(0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 146 | { |
| 147 | } |
| 148 | |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 149 | void NEDepthConcatenateLayerKernel::configure(const ITensorInfo *input, unsigned int depth_offset, ITensorInfo *output) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 150 | { |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 151 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 152 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, depth_offset, output)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 153 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 154 | _func = nullptr; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 155 | _depth_offset = depth_offset; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 156 | |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 157 | switch(input->data_type()) |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 158 | { |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 159 | case DataType::QASYMM8: |
| 160 | _func = &depth_concat<uint8_t>; |
| 161 | break; |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 162 | case DataType::QASYMM8_SIGNED: |
| 163 | _func = &depth_concat<int8_t>; |
| 164 | break; |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 165 | case DataType::F16: |
| 166 | _func = &depth_concat<uint16_t>; |
| 167 | break; |
| 168 | case DataType::F32: |
| 169 | _func = &depth_concat<uint32_t>; |
| 170 | break; |
| 171 | default: |
| 172 | ARM_COMPUTE_ERROR("Unsupported data type."); |
| 173 | } |
| 174 | |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 175 | // Configure kernel window |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 176 | Window win = calculate_max_window(*output, Steps()); |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 177 | Coordinates coord; |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 178 | coord.set_num_dimensions(output->num_dimensions()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 179 | |
Georgios Pinitas | 4667ddd | 2020-07-13 21:21:33 +0100 | [diff] [blame] | 180 | output->set_valid_region(ValidRegion(coord, output->tensor_shape())); |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 181 | INEKernel::configure(win); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 182 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 184 | Status NEDepthConcatenateLayerKernel::validate(const arm_compute::ITensorInfo *input, |
| 185 | unsigned int depth_offset, |
| 186 | const arm_compute::ITensorInfo *output) |
| 187 | { |
| 188 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, depth_offset, output)); |
Georgios Pinitas | ae54e02 | 2018-07-16 15:41:27 +0100 | [diff] [blame] | 189 | return Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 192 | void NEDepthConcatenateLayerKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 193 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 194 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 195 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 196 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 197 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 198 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 199 | (*_func)(tensors.get_const_tensor(TensorType::ACL_SRC), |
| 200 | tensors.get_tensor(TensorType::ACL_DST), |
| 201 | _depth_offset, |
| 202 | window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 203 | } |
Michalis Spyrou | c28d428 | 2020-03-04 15:30:41 +0000 | [diff] [blame] | 204 | } // namespace arm_compute |