From d8c2f0bcdfdfdfe28db96e6f422e19ee3bd867e5 Mon Sep 17 00:00:00 2001 From: lve-gh <160332675+lve-gh@users.noreply.github.com> Date: Tue, 11 Feb 2025 17:57:05 +0300 Subject: [PATCH] Merge pull request #26884 from lve-gh:split8u_rvv_hal [HAL] split8u RVV 1.0 #26884 ### Pull Request Readiness Checklist * Banana Pi BF3 (SpacemiT K1) * Compiler: Syntacore Clang 18.1.4 (build 2024.12) ``` Geometric mean (ms) Name of Test baseline hal hal ui vs baseline ui (x-factor) split::Size_Depth_Channels::(127x61, 8UC1, 2) 0.012 0.004 3.12 split::Size_Depth_Channels::(127x61, 8UC1, 3) 0.019 0.006 2.91 split::Size_Depth_Channels::(127x61, 8UC1, 4) 0.028 0.011 2.64 split::Size_Depth_Channels::(127x61, 8UC1, 5) 0.067 0.033 2.02 split::Size_Depth_Channels::(127x61, 8UC1, 6) 0.084 0.040 2.11 split::Size_Depth_Channels::(127x61, 8UC1, 7) 0.103 0.055 1.88 split::Size_Depth_Channels::(127x61, 8UC1, 8) 0.113 0.032 3.50 split::Size_Depth_Channels::(640x480, 8UC1, 2) 0.454 0.179 2.54 split::Size_Depth_Channels::(640x480, 8UC1, 3) 0.677 0.298 2.27 split::Size_Depth_Channels::(640x480, 8UC1, 4) 0.901 0.410 2.20 split::Size_Depth_Channels::(640x480, 8UC1, 5) 3.781 3.010 1.26 split::Size_Depth_Channels::(640x480, 8UC1, 6) 4.886 4.009 1.22 split::Size_Depth_Channels::(640x480, 8UC1, 7) 5.777 4.770 1.21 split::Size_Depth_Channels::(640x480, 8UC1, 8) 4.596 1.330 3.46 split::Size_Depth_Channels::(1280x720, 8UC1, 2) 1.377 0.709 1.94 split::Size_Depth_Channels::(1280x720, 8UC1, 3) 2.091 1.034 2.02 split::Size_Depth_Channels::(1280x720, 8UC1, 4) 2.744 1.573 1.74 split::Size_Depth_Channels::(1280x720, 8UC1, 5) 9.542 6.284 1.52 split::Size_Depth_Channels::(1280x720, 8UC1, 6) 11.114 7.850 1.42 split::Size_Depth_Channels::(1280x720, 8UC1, 7) 14.083 11.879 1.19 split::Size_Depth_Channels::(1280x720, 8UC1, 8) 13.524 3.865 3.50 split::Size_Depth_Channels::(1920x1080, 8UC1, 2) 3.108 1.395 2.23 split::Size_Depth_Channels::(1920x1080, 8UC1, 3) 4.659 2.128 2.19 split::Size_Depth_Channels::(1920x1080, 8UC1, 4) 6.127 2.818 2.17 split::Size_Depth_Channels::(1920x1080, 8UC1, 5) 26.733 16.625 1.61 split::Size_Depth_Channels::(1920x1080, 8UC1, 6) 31.242 22.414 1.39 split::Size_Depth_Channels::(1920x1080, 8UC1, 7) 35.968 27.658 1.30 split::Size_Depth_Channels::(1920x1080, 8UC1, 8) 29.997 8.655 3.47 ``` See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- 3rdparty/hal_rvv/hal_rvv.hpp | 1 + 3rdparty/hal_rvv/hal_rvv_1p0/split.hpp | 93 ++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 3rdparty/hal_rvv/hal_rvv_1p0/split.hpp diff --git a/3rdparty/hal_rvv/hal_rvv.hpp b/3rdparty/hal_rvv/hal_rvv.hpp index 0ff9c3530e..6f62d8471a 100644 --- a/3rdparty/hal_rvv/hal_rvv.hpp +++ b/3rdparty/hal_rvv/hal_rvv.hpp @@ -27,6 +27,7 @@ #include "hal_rvv_1p0/convert_scale.hpp" // core #include "hal_rvv_1p0/minmax.hpp" // core #include "hal_rvv_1p0/atan.hpp" // core +#include "hal_rvv_1p0/split.hpp" // core #endif #endif diff --git a/3rdparty/hal_rvv/hal_rvv_1p0/split.hpp b/3rdparty/hal_rvv/hal_rvv_1p0/split.hpp new file mode 100644 index 0000000000..9646fd9f67 --- /dev/null +++ b/3rdparty/hal_rvv/hal_rvv_1p0/split.hpp @@ -0,0 +1,93 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#ifndef OPENCV_HAL_RVV_SPLIT_HPP_INCLUDED +#define OPENCV_HAL_RVV_SPLIT_HPP_INCLUDED + +#include + +namespace cv { namespace cv_hal_rvv { + +#undef cv_hal_split8u +#define cv_hal_split8u cv::cv_hal_rvv::split8u + +inline int split8u(const uchar* src, uchar** dst, int len, int cn) +{ + int vl = 0; + if (cn == 1) + { + uchar* dst0 = dst[0]; + for (int i = 0; i < len; i += vl) + { + vl = __riscv_vsetvl_e8m8(len - i); + __riscv_vse8_v_u8m8(dst0 + i, __riscv_vle8_v_u8m8(src + i, vl), vl); + } + } + else if (cn == 2) + { + uchar *dst0 = dst[0], *dst1 = dst[1]; + for (int i = 0; i < len; i += vl) + { + vl = __riscv_vsetvl_e8m4(len - i); + vuint8m4x2_t seg = __riscv_vlseg2e8_v_u8m4x2(src + i * cn, vl); + __riscv_vse8_v_u8m4(dst0 + i, __riscv_vget_v_u8m4x2_u8m4(seg, 0), vl); + __riscv_vse8_v_u8m4(dst1 + i, __riscv_vget_v_u8m4x2_u8m4(seg, 1), vl); + } + } + else if (cn == 3) + { + uchar *dst0 = dst[0], *dst1 = dst[1], *dst2 = dst[2]; + for (int i = 0; i < len; i += vl) + { + vl = __riscv_vsetvl_e8m2(len - i); + vuint8m2x3_t seg = __riscv_vlseg3e8_v_u8m2x3(src + i * cn, vl); + __riscv_vse8_v_u8m2(dst0 + i, __riscv_vget_v_u8m2x3_u8m2(seg, 0), vl); + __riscv_vse8_v_u8m2(dst1 + i, __riscv_vget_v_u8m2x3_u8m2(seg, 1), vl); + __riscv_vse8_v_u8m2(dst2 + i, __riscv_vget_v_u8m2x3_u8m2(seg, 2), vl); + } + } + else if (cn == 4) + { + uchar *dst0 = dst[0], *dst1 = dst[1], *dst2 = dst[2], *dst3 = dst[3]; + for (int i = 0; i < len; i += vl) + { + vl = __riscv_vsetvl_e8m2(len - i); + vuint8m2x4_t seg = __riscv_vlseg4e8_v_u8m2x4(src + i * cn, vl); + __riscv_vse8_v_u8m2(dst0 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 0), vl); + __riscv_vse8_v_u8m2(dst1 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 1), vl); + __riscv_vse8_v_u8m2(dst2 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 2), vl); + __riscv_vse8_v_u8m2(dst3 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 3), vl); + } + } + else + { + int k = 0; + for (; k <= cn - 4; k += 4) + { + uchar *dst0 = dst[k], *dst1 = dst[k + 1], *dst2 = dst[k + 2], *dst3 = dst[k + 3]; + for (int i = 0; i < len; i += vl) + { + vl = __riscv_vsetvl_e8m2(len - i); + vuint8m2x4_t seg = __riscv_vlsseg4e8_v_u8m2x4(src + k + i * cn, cn, vl); + __riscv_vse8_v_u8m2(dst0 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 0), vl); + __riscv_vse8_v_u8m2(dst1 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 1), vl); + __riscv_vse8_v_u8m2(dst2 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 2), vl); + __riscv_vse8_v_u8m2(dst3 + i, __riscv_vget_v_u8m2x4_u8m2(seg, 3), vl); + } + } + for (; k < cn; ++k) + { + uchar* dstK = dst[k]; + for (int i = 0; i < len; i += vl) + { + vl = __riscv_vsetvl_e8m2(len - i); + vuint8m2_t seg = __riscv_vlse8_v_u8m2(src + k + i * cn, cn, vl); + __riscv_vse8_v_u8m2(dstK + i, seg, vl); + } + } + } + return CV_HAL_ERROR_OK; +} + +}} +#endif