Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 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 | */ |
| 24 | #include "arm_compute/core/NEON/kernels/NEDilateKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/ITensor.h" |
| 28 | #include "arm_compute/core/NEON/INEKernel.h" |
| 29 | #include "arm_compute/core/TensorInfo.h" |
| 30 | #include "arm_compute/core/Validate.h" |
| 31 | |
| 32 | #include <arm_neon.h> |
| 33 | #include <cstddef> |
| 34 | #include <cstdint> |
| 35 | |
| 36 | using namespace arm_compute; |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | class Coordinates; |
| 41 | } // namespace arm_compute |
| 42 | |
| 43 | BorderSize NEDilateKernel::border_size() const |
| 44 | { |
| 45 | return BorderSize(1); |
| 46 | } |
| 47 | |
| 48 | void NEDilateKernel::configure(const ITensor *input, ITensor *output, bool border_undefined) |
| 49 | { |
| 50 | _input = input; |
| 51 | _output = output; |
| 52 | |
| 53 | constexpr unsigned int num_elems_processed_per_iteration = 8; |
| 54 | constexpr unsigned int num_elems_read_per_iteration = 16; |
| 55 | constexpr unsigned int num_elems_written_per_iteration = 8; |
| 56 | constexpr unsigned int num_rows_read_per_iteration = 3; |
| 57 | |
| 58 | // Configure kernel window |
| 59 | Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size()); |
| 60 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration); |
| 61 | AccessWindowRectangle input_access(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration); |
| 62 | |
| 63 | update_window_and_padding(win, input_access, output_access); |
| 64 | |
| 65 | output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size()); |
| 66 | |
| 67 | INEKernel::configure(win); |
| 68 | } |
| 69 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 70 | void NEDilateKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 71 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 72 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 74 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INESimpleKernel::window(), window); |
| 75 | |
| 76 | Iterator in(_input, window); |
| 77 | Iterator out(_output, window); |
| 78 | |
| 79 | const size_t in_stride = _input->info()->strides_in_bytes()[1]; |
| 80 | |
| 81 | execute_window_loop(window, [&](const Coordinates &) |
| 82 | { |
| 83 | uint8_t *in_ptr = in.ptr() - 1; |
| 84 | const uint8x16_t top_data = vld1q_u8(in_ptr - in_stride); |
| 85 | const uint8x16_t mid_data = vld1q_u8(in_ptr); |
| 86 | const uint8x16_t bot_data = vld1q_u8(in_ptr + in_stride); |
| 87 | |
| 88 | uint8x8_t top_high_data = vget_high_u8(top_data); |
| 89 | uint8x8_t top_low_data = vget_low_u8(top_data); |
| 90 | |
| 91 | uint8x8_t mid_high_data = vget_high_u8(mid_data); |
| 92 | uint8x8_t mid_low_data = vget_low_u8(mid_data); |
| 93 | |
| 94 | uint8x8_t bot_high_data = vget_high_u8(bot_data); |
| 95 | uint8x8_t bot_low_data = vget_low_u8(bot_data); |
| 96 | |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 97 | uint8x8_t p0; |
| 98 | uint8x8_t p1; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 99 | |
| 100 | p0 = top_low_data; |
| 101 | p1 = vext_u8(top_low_data, top_high_data, 1); |
| 102 | p0 = vmax_u8(p0, p1); |
| 103 | |
| 104 | p1 = vext_u8(top_low_data, top_high_data, 2); |
| 105 | p0 = vmax_u8(p0, p1); |
| 106 | |
| 107 | p1 = mid_low_data; |
| 108 | p0 = vmax_u8(p0, p1); |
| 109 | |
| 110 | p1 = vext_u8(mid_low_data, mid_high_data, 1); |
| 111 | p0 = vmax_u8(p0, p1); |
| 112 | |
| 113 | p1 = vext_u8(mid_low_data, mid_high_data, 2); |
| 114 | p0 = vmax_u8(p0, p1); |
| 115 | |
| 116 | p1 = bot_low_data; |
| 117 | p0 = vmax_u8(p0, p1); |
| 118 | |
| 119 | p1 = vext_u8(bot_low_data, bot_high_data, 1); |
| 120 | p0 = vmax_u8(p0, p1); |
| 121 | |
| 122 | p1 = vext_u8(bot_low_data, bot_high_data, 2); |
| 123 | p0 = vmax_u8(p0, p1); |
| 124 | |
| 125 | vst1_u8(out.ptr(), p0); |
| 126 | }, |
| 127 | in, out); |
| 128 | } |