Line | Branch | Exec | Source |
---|---|---|---|
1 | // SPDX-FileCopyrightText: 2023 - 2025 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
2 | // | ||
3 | // SPDX-License-Identifier: Apache-2.0 | ||
4 | |||
5 | #ifndef KLEIDICV_SEPARABLE_FILTER_3X3_SC_H | ||
6 | #define KLEIDICV_SEPARABLE_FILTER_3X3_SC_H | ||
7 | |||
8 | #include "kleidicv/sve2.h" | ||
9 | #include "kleidicv/workspace/border_3x3.h" | ||
10 | |||
11 | // It is used by SVE2 and SME, the actual namespace will reflect it. | ||
12 | namespace KLEIDICV_TARGET_NAMESPACE { | ||
13 | |||
14 | // Template for drivers of separable NxM filters. | ||
15 | template <typename FilterType, const size_t S> | ||
16 | class SeparableFilter; | ||
17 | |||
18 | // Driver for a separable 3x3 filter. | ||
19 | template <typename FilterType> | ||
20 | class SeparableFilter<FilterType, 3UL> { | ||
21 | public: | ||
22 | using SourceType = typename FilterType::SourceType; | ||
23 | using BufferType = typename FilterType::BufferType; | ||
24 | using DestinationType = typename FilterType::DestinationType; | ||
25 | using SourceVecTraits = | ||
26 | typename ::KLEIDICV_TARGET_NAMESPACE::VecTraits<SourceType>; | ||
27 | using SourceVectorType = typename SourceVecTraits::VectorType; | ||
28 | using BufferVecTraits = | ||
29 | typename ::KLEIDICV_TARGET_NAMESPACE::VecTraits<BufferType>; | ||
30 | using BufferVectorType = typename BufferVecTraits::VectorType; | ||
31 | using BorderInfoType = | ||
32 | typename ::KLEIDICV_TARGET_NAMESPACE::FixedBorderInfo3x3<SourceType>; | ||
33 | using BorderType = FixedBorderType; | ||
34 | using BorderOffsets = typename BorderInfoType::Offsets; | ||
35 | |||
36 | 460 | explicit SeparableFilter(FilterType filter) KLEIDICV_STREAMING | |
37 | 460 | : filter_{filter} {} | |
38 | |||
39 | static constexpr size_t margin = 1UL; | ||
40 | |||
41 | 8224 | void process_vertical(size_t width, Rows<const SourceType> src_rows, | |
42 | Rows<BufferType> dst_rows, | ||
43 | BorderOffsets border_offsets) const KLEIDICV_STREAMING { | ||
44 | 8224 | LoopUnroll2 loop{width * src_rows.channels(), SourceVecTraits::num_lanes()}; | |
45 | |||
46 | 10772 | loop.unroll_once([&](size_t index) KLEIDICV_STREAMING { | |
47 | 2548 | svbool_t pg_all = SourceVecTraits::svptrue(); | |
48 | 2548 | vertical_vector_path(pg_all, src_rows, dst_rows, border_offsets, index); | |
49 | 2548 | }); | |
50 | |||
51 | 16448 | loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING { | |
52 | 8224 | svbool_t pg = SourceVecTraits::svwhilelt(index, length); | |
53 | 8224 | vertical_vector_path(pg, src_rows, dst_rows, border_offsets, index); | |
54 | 8224 | }); | |
55 | 8224 | } | |
56 | |||
57 | 8224 | void process_horizontal(size_t width, Rows<const BufferType> src_rows, | |
58 | Rows<DestinationType> dst_rows, | ||
59 | BorderOffsets border_offsets) const | ||
60 | KLEIDICV_STREAMING { | ||
61 | 8224 | svbool_t pg_all = BufferVecTraits::svptrue(); | |
62 | 8224 | LoopUnroll2 loop{width * src_rows.channels(), BufferVecTraits::num_lanes()}; | |
63 | |||
64 | 10144 | loop.unroll_twice([&](size_t index) KLEIDICV_STREAMING { | |
65 | 3840 | horizontal_vector_path_2x(pg_all, src_rows, dst_rows, border_offsets, | |
66 | 1920 | index); | |
67 | 1920 | }); | |
68 | |||
69 | 9440 | loop.unroll_once([&](size_t index) KLEIDICV_STREAMING { | |
70 | 1216 | horizontal_vector_path(pg_all, src_rows, dst_rows, border_offsets, index); | |
71 | 1216 | }); | |
72 | |||
73 | 12568 | loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING { | |
74 | 4344 | svbool_t pg = BufferVecTraits::svwhilelt(index, length); | |
75 | 4344 | horizontal_vector_path(pg, src_rows, dst_rows, border_offsets, index); | |
76 | 4344 | }); | |
77 | 8224 | } | |
78 | |||
79 | // Processing of horizontal borders is always scalar because border offsets | ||
80 | // change for each and every element in the border. | ||
81 | 16448 | void process_horizontal_borders( | |
82 | Rows<const BufferType> src_rows, Rows<DestinationType> dst_rows, | ||
83 | BorderOffsets border_offsets) const KLEIDICV_STREAMING { | ||
84 |
4/4✓ Branch 0 taken 8512 times.
✓ Branch 1 taken 16304 times.
✓ Branch 2 taken 7936 times.
✓ Branch 3 taken 15544 times.
|
48296 | for (size_t index = 0; index < src_rows.channels(); ++index) { |
85 | 31848 | disable_loop_vectorization(); | |
86 | 31848 | process_horizontal_border(src_rows, dst_rows, border_offsets, index); | |
87 | 31848 | } | |
88 | 16448 | } | |
89 | |||
90 | private: | ||
91 | 10772 | void vertical_vector_path(svbool_t pg, Rows<const SourceType> src_rows, | |
92 | Rows<BufferType> dst_rows, | ||
93 | BorderOffsets border_offsets, | ||
94 | size_t index) const KLEIDICV_STREAMING { | ||
95 | 21544 | SourceVectorType src_0 = | |
96 | 10772 | svld1(pg, &src_rows.at(border_offsets.c0())[index]); | |
97 | 21544 | SourceVectorType src_1 = | |
98 | 10772 | svld1(pg, &src_rows.at(border_offsets.c1())[index]); | |
99 | 21544 | SourceVectorType src_2 = | |
100 | 10772 | svld1(pg, &src_rows.at(border_offsets.c2())[index]); | |
101 | 10772 | std::reference_wrapper<SourceVectorType> sources[3] = {src_0, src_1, src_2}; | |
102 | 10772 | filter_.vertical_vector_path(pg, sources, &dst_rows[index]); | |
103 | 10772 | } | |
104 | |||
105 | 1920 | void horizontal_vector_path_2x(svbool_t pg, Rows<const BufferType> src_rows, | |
106 | Rows<DestinationType> dst_rows, | ||
107 | BorderOffsets border_offsets, | ||
108 | size_t index) const KLEIDICV_STREAMING { | ||
109 | 1920 | auto src_0 = &src_rows.at(0, border_offsets.c0())[index]; | |
110 | 1920 | auto src_1 = &src_rows.at(0, border_offsets.c1())[index]; | |
111 | 1920 | auto src_2 = &src_rows.at(0, border_offsets.c2())[index]; | |
112 | |||
113 | 1920 | BufferVectorType src_0_0 = svld1(pg, &src_0[0]); | |
114 | 1920 | BufferVectorType src_1_0 = svld1_vnum(pg, &src_0[0], 1); | |
115 | 1920 | BufferVectorType src_0_1 = svld1(pg, &src_1[0]); | |
116 | 1920 | BufferVectorType src_1_1 = svld1_vnum(pg, &src_1[0], 1); | |
117 | 1920 | BufferVectorType src_0_2 = svld1(pg, &src_2[0]); | |
118 | 1920 | BufferVectorType src_1_2 = svld1_vnum(pg, &src_2[0], 1); | |
119 | |||
120 | 1920 | std::reference_wrapper<BufferVectorType> sources_0[3] = {src_0_0, src_0_1, | |
121 | 1920 | src_0_2}; | |
122 | 1920 | filter_.horizontal_vector_path(pg, sources_0, &dst_rows[index]); | |
123 | 1920 | std::reference_wrapper<BufferVectorType> sources_1[3] = {src_1_0, src_1_1, | |
124 | 1920 | src_1_2}; | |
125 | 1936 | filter_.horizontal_vector_path( | |
126 | 1920 | pg, sources_1, &dst_rows[index + BufferVecTraits::num_lanes()]); | |
127 | 1920 | } | |
128 | |||
129 | 5560 | void horizontal_vector_path(svbool_t pg, Rows<const BufferType> src_rows, | |
130 | Rows<DestinationType> dst_rows, | ||
131 | BorderOffsets border_offsets, | ||
132 | size_t index) const KLEIDICV_STREAMING { | ||
133 | 11120 | BufferVectorType src_0 = | |
134 | 5560 | svld1(pg, &src_rows.at(0, border_offsets.c0())[index]); | |
135 | 11120 | BufferVectorType src_1 = | |
136 | 5560 | svld1(pg, &src_rows.at(0, border_offsets.c1())[index]); | |
137 | 11120 | BufferVectorType src_2 = | |
138 | 5560 | svld1(pg, &src_rows.at(0, border_offsets.c2())[index]); | |
139 | |||
140 | 5560 | std::reference_wrapper<BufferVectorType> sources[3] = {src_0, src_1, src_2}; | |
141 | 5560 | filter_.horizontal_vector_path(pg, sources, &dst_rows[index]); | |
142 | 5560 | } | |
143 | |||
144 | 31848 | void process_horizontal_border(Rows<const BufferType> src_rows, | |
145 | Rows<DestinationType> dst_rows, | ||
146 | BorderOffsets border_offsets, | ||
147 | size_t index) const KLEIDICV_STREAMING { | ||
148 | 31848 | BufferType src[3]; | |
149 | 31848 | src[0] = src_rows.at(0, border_offsets.c0())[index]; | |
150 | 31848 | src[1] = src_rows.at(0, border_offsets.c1())[index]; | |
151 | 31848 | src[2] = src_rows.at(0, border_offsets.c2())[index]; | |
152 | 31848 | filter_.horizontal_scalar_path(src, &dst_rows[index]); | |
153 | 31848 | } | |
154 | |||
155 | FilterType filter_; | ||
156 | }; // end of class SeparableFilter<FilterType, 3UL> | ||
157 | |||
158 | // Shorthand for 3x3 separable filters driver type. | ||
159 | template <class FilterType> | ||
160 | using SeparableFilter3x3 = SeparableFilter<FilterType, 3UL>; | ||
161 | |||
162 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
163 | |||
164 | #endif // KLEIDICV_SEPARABLE_FILTER_3X3_SC_H | ||
165 |