| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2025 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: Apache-2.0 | ||
| 4 | |||
| 5 | #ifndef KLEIDICV_MEDIAN_BLUR_SORTING_NETWORK_3X3_H | ||
| 6 | #define KLEIDICV_MEDIAN_BLUR_SORTING_NETWORK_3X3_H | ||
| 7 | |||
| 8 | #include <algorithm> | ||
| 9 | |||
| 10 | #include "kleidicv/kleidicv.h" | ||
| 11 | #include "kleidicv/traits.h" | ||
| 12 | |||
| 13 | namespace KLEIDICV_TARGET_NAMESPACE { | ||
| 14 | template <class Comparator, typename KernelWindowFunctor, typename T, | ||
| 15 | typename ContextType> | ||
| 16 | 7424 | void sorting_network3x3_single_row(KernelWindowFunctor& KernelWindow, | |
| 17 | T& output_vec, | ||
| 18 | ContextType& context) KLEIDICV_STREAMING { | ||
| 19 | // full sort row | ||
| 20 | 7424 | Comparator::compare_and_swap(KernelWindow(0, 0), KernelWindow(0, 2), context); | |
| 21 | 7424 | Comparator::compare_and_swap(KernelWindow(0, 0), KernelWindow(0, 1), context); | |
| 22 | 7424 | Comparator::compare_and_swap(KernelWindow(0, 1), KernelWindow(0, 2), context); | |
| 23 | 7424 | Comparator::compare_and_swap(KernelWindow(1, 0), KernelWindow(1, 2), context); | |
| 24 | 7424 | Comparator::compare_and_swap(KernelWindow(1, 0), KernelWindow(1, 1), context); | |
| 25 | 7424 | Comparator::compare_and_swap(KernelWindow(1, 1), KernelWindow(1, 2), context); | |
| 26 | 7424 | Comparator::compare_and_swap(KernelWindow(2, 0), KernelWindow(2, 2), context); | |
| 27 | 7424 | Comparator::compare_and_swap(KernelWindow(2, 0), KernelWindow(2, 1), context); | |
| 28 | 7424 | Comparator::compare_and_swap(KernelWindow(2, 1), KernelWindow(2, 2), context); | |
| 29 | // find max in col 0 | ||
| 30 | 14848 | T max_0_1_2 = | |
| 31 | 7424 | Comparator::get_max(KernelWindow(0, 0), KernelWindow(1, 0), context); | |
| 32 | 7424 | max_0_1_2 = Comparator::get_max(max_0_1_2, KernelWindow(2, 0), context); | |
| 33 | // find mid in col 1 | ||
| 34 | 7424 | T src_tmp_0 = KernelWindow(0, 1); | |
| 35 | 7424 | T mid_0_1_2 = KernelWindow(1, 1); | |
| 36 | 7424 | T src_tmp_2 = KernelWindow(2, 1); | |
| 37 | 7424 | Comparator::compare_and_swap(src_tmp_0, src_tmp_2, context); | |
| 38 | 7424 | Comparator::max(src_tmp_0, mid_0_1_2, context); | |
| 39 | 7424 | Comparator::min(mid_0_1_2, src_tmp_2, context); | |
| 40 | // find min in col 2 | ||
| 41 | 14848 | T min_0_1_2 = | |
| 42 | 7424 | Comparator::get_min(KernelWindow(0, 2), KernelWindow(1, 2), context); | |
| 43 | 7424 | min_0_1_2 = Comparator::get_min(min_0_1_2, KernelWindow(2, 2), context); | |
| 44 | // find median | ||
| 45 | 7424 | Comparator::compare_and_swap(min_0_1_2, max_0_1_2, context); | |
| 46 | 7424 | Comparator::max(min_0_1_2, mid_0_1_2, context); | |
| 47 | 7424 | Comparator::min(mid_0_1_2, max_0_1_2, context); | |
| 48 | 7424 | output_vec = mid_0_1_2; | |
| 49 | 7424 | } | |
| 50 | |||
| 51 | template <class Comparator, typename KernelWindowFunctor, typename T, | ||
| 52 | typename ContextType> | ||
| 53 | 36836 | void sorting_network3x3_dual_rows(KernelWindowFunctor& KernelWindow, | |
| 54 | T& output_vec_0, T& output_vec_1, | ||
| 55 | ContextType& context) KLEIDICV_STREAMING { | ||
| 56 | // full sort row | ||
| 57 | 36836 | Comparator::compare_and_swap(KernelWindow(0, 0), KernelWindow(0, 2), context); | |
| 58 | 36836 | Comparator::compare_and_swap(KernelWindow(0, 0), KernelWindow(0, 1), context); | |
| 59 | 36836 | Comparator::compare_and_swap(KernelWindow(0, 1), KernelWindow(0, 2), context); | |
| 60 | 36836 | Comparator::compare_and_swap(KernelWindow(1, 0), KernelWindow(1, 2), context); | |
| 61 | 36836 | Comparator::compare_and_swap(KernelWindow(1, 0), KernelWindow(1, 1), context); | |
| 62 | 36836 | Comparator::compare_and_swap(KernelWindow(1, 1), KernelWindow(1, 2), context); | |
| 63 | 36836 | Comparator::compare_and_swap(KernelWindow(2, 0), KernelWindow(2, 2), context); | |
| 64 | 36836 | Comparator::compare_and_swap(KernelWindow(2, 0), KernelWindow(2, 1), context); | |
| 65 | 36836 | Comparator::compare_and_swap(KernelWindow(2, 1), KernelWindow(2, 2), context); | |
| 66 | 36836 | Comparator::compare_and_swap(KernelWindow(3, 0), KernelWindow(3, 2), context); | |
| 67 | 36836 | Comparator::compare_and_swap(KernelWindow(3, 0), KernelWindow(3, 1), context); | |
| 68 | 36836 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(3, 2), context); | |
| 69 | // sort common element | ||
| 70 | 36836 | Comparator::compare_and_swap(KernelWindow(1, 0), KernelWindow(2, 0), context); | |
| 71 | 36836 | Comparator::compare_and_swap(KernelWindow(1, 2), KernelWindow(2, 2), context); | |
| 72 | 36836 | Comparator::compare_and_swap(KernelWindow(1, 1), KernelWindow(2, 1), context); | |
| 73 | // find first median | ||
| 74 | // find max in col 0 | ||
| 75 | 73672 | T max_0_1_2 = | |
| 76 | 36836 | Comparator::get_max(KernelWindow(0, 0), KernelWindow(2, 0), context); | |
| 77 | // find mid in col 1 | ||
| 78 | 73672 | T src_tmp_0 = | |
| 79 | 36836 | Comparator::get_min(KernelWindow(0, 1), KernelWindow(2, 1), context); | |
| 80 | 36836 | T mid_0_1_2 = Comparator::get_max(KernelWindow(1, 1), src_tmp_0, context); | |
| 81 | // find min in col 2 | ||
| 82 | 73672 | T min_0_1_2 = | |
| 83 | 36836 | Comparator::get_min(KernelWindow(0, 2), KernelWindow(1, 2), context); | |
| 84 | // find median | ||
| 85 | 36836 | Comparator::compare_and_swap(min_0_1_2, max_0_1_2, context); | |
| 86 | 36836 | Comparator::max(min_0_1_2, mid_0_1_2, context); | |
| 87 | 36836 | Comparator::min(mid_0_1_2, max_0_1_2, context); | |
| 88 | 36836 | output_vec_0 = mid_0_1_2; | |
| 89 | // find second median | ||
| 90 | // find max in col 0 | ||
| 91 | 36836 | max_0_1_2 = | |
| 92 | 36836 | Comparator::get_max(KernelWindow(2, 0), KernelWindow(3, 0), context); | |
| 93 | // find mid in col 1 | ||
| 94 | 36836 | src_tmp_0 = | |
| 95 | 36836 | Comparator::get_max(KernelWindow(1, 1), KernelWindow(3, 1), context); | |
| 96 | 36836 | mid_0_1_2 = Comparator::get_min(KernelWindow(2, 1), src_tmp_0, context); | |
| 97 | // find min in col 2 | ||
| 98 | 36836 | min_0_1_2 = | |
| 99 | 36836 | Comparator::get_min(KernelWindow(1, 2), KernelWindow(3, 2), context); | |
| 100 | // find median | ||
| 101 | 36836 | Comparator::compare_and_swap(min_0_1_2, max_0_1_2, context); | |
| 102 | 36836 | Comparator::max(min_0_1_2, mid_0_1_2, context); | |
| 103 | 36836 | Comparator::min(mid_0_1_2, max_0_1_2, context); | |
| 104 | 36836 | output_vec_1 = mid_0_1_2; | |
| 105 | 36836 | } | |
| 106 | |||
| 107 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
| 108 | |||
| 109 | #endif // KLEIDICV_MEDIAN_BLUR_SORTING_NETWORK_3X3_H | ||
| 110 |