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