Skip to content

Add RISC-V HAL implementation for cv::pyrDown and cv::pyrUp#26958

Merged
asmorkalov merged 7 commits intoopencv:4.xfrom
amane-ame:pyramids_hal_rvv
Mar 4, 2025
Merged

Add RISC-V HAL implementation for cv::pyrDown and cv::pyrUp#26958
asmorkalov merged 7 commits intoopencv:4.xfrom
amane-ame:pyramids_hal_rvv

Conversation

@amane-ame
Copy link
Copy Markdown
Contributor

This patch implements cv_hal_pyrdown/cv_hal_pyrup function in RVV_HAL using native intrinsics, optimizing the performance for cv::pyrDown, cv::pyrUp and cv::buildPyramids with data types {8U,16S,32F} x {C1,C2,C3,C4,Cn}.

Tested on MUSE-PI (Spacemit X60) for both gcc 14.2 and clang 20.0.

$ ./opencv_test_imgproc --gtest_filter="*pyr*:*Pyr*"
$ ./opencv_perf_imgproc --gtest_filter="*pyr*:*Pyr*" --perf_min_samples=300 --perf_force_samples=300
Untitled

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

amane-ame and others added 5 commits February 16, 2025 16:11
Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
@asmorkalov
Copy link
Copy Markdown
Contributor

Please rebase and fix conflicts.

@amane-ame amane-ame requested a review from mshabunin February 28, 2025 12:22
Co-authored-by: Liutong HAN <liutong2020@iscas.ac.cn>
@amane-ame amane-ame requested a review from mshabunin March 1, 2025 03:18
@asmorkalov
Copy link
Copy Markdown
Contributor

Perf numbers for Spacemit Muse Pi v 30 (GCC 14.2):

pyrDown::Size_MatType::(127x61, 8UC1) 	0.018 	0.018 	1.01
pyrDown::Size_MatType::(127x61, 16SC1) 	0.022 	0.018 	1.17
pyrDown::Size_MatType::(127x61, 32FC1) 	0.019 	0.019 	1.00
pyrDown::Size_MatType::(127x61, 8UC3) 	0.065 	0.031 	2.14
pyrDown::Size_MatType::(127x61, 16SC3) 	0.070 	0.032 	2.16
pyrDown::Size_MatType::(127x61, 32FC3) 	0.065 	0.035 	1.83
pyrDown::Size_MatType::(127x61, 8UC4) 	0.042 	0.036 	1.17
pyrDown::Size_MatType::(127x61, 16SC4) 	0.069 	0.040 	1.73
pyrDown::Size_MatType::(127x61, 32FC4) 	0.065 	0.042 	1.56
pyrDown::Size_MatType::(320x240, 8UC1) 	0.058 	0.051 	1.14
pyrDown::Size_MatType::(320x240, 16SC1) 	0.063 	0.055 	1.14
pyrDown::Size_MatType::(320x240, 32FC1) 	0.064 	0.064 	0.99
pyrDown::Size_MatType::(320x240, 8UC3) 	0.456 	0.138 	3.31
pyrDown::Size_MatType::(320x240, 16SC3) 	0.440 	0.156 	2.82
pyrDown::Size_MatType::(320x240, 32FC3) 	0.382 	0.166 	2.29
pyrDown::Size_MatType::(320x240, 8UC4) 	0.237 	0.185 	1.28
pyrDown::Size_MatType::(320x240, 16SC4) 	0.438 	0.202 	2.16
pyrDown::Size_MatType::(320x240, 32FC4) 	0.400 	0.265 	1.51
pyrDown::Size_MatType::(640x480, 8UC1) 	0.180 	0.156 	1.16
pyrDown::Size_MatType::(640x480, 16SC1) 	0.181 	0.162 	1.12
pyrDown::Size_MatType::(640x480, 32FC1) 	0.222 	0.225 	0.98
pyrDown::Size_MatType::(640x480, 8UC3) 	1.770 	0.558 	3.17
pyrDown::Size_MatType::(640x480, 16SC3) 	1.762 	0.721 	2.44
pyrDown::Size_MatType::(640x480, 32FC3) 	1.631 	1.021 	1.60
pyrDown::Size_MatType::(640x480, 8UC4) 	0.948 	0.824 	1.15
pyrDown::Size_MatType::(640x480, 16SC4) 	1.830 	0.996 	1.84
pyrDown::Size_MatType::(640x480, 32FC4) 	1.833 	1.413 	1.30
pyrDown::Size_MatType::(1280x720, 8UC1) 	0.495 	0.437 	1.13
pyrDown::Size_MatType::(1280x720, 16SC1) 	0.563 	0.497 	1.13
pyrDown::Size_MatType::(1280x720, 32FC1) 	0.829 	0.819 	1.01
pyrDown::Size_MatType::(1280x720, 8UC3) 	5.462 	1.609 	3.40
pyrDown::Size_MatType::(1280x720, 16SC3) 	5.252 	2.294 	2.29
pyrDown::Size_MatType::(1280x720, 32FC3) 	4.644 	3.274 	1.42
pyrDown::Size_MatType::(1280x720, 8UC4) 	2.970 	2.415 	1.23
pyrDown::Size_MatType::(1280x720, 16SC4) 	5.621 	3.238 	1.74
pyrDown::Size_MatType::(1280x720, 32FC4) 	6.236 	5.073 	1.23
pyrDown::Size_MatType::(1920x1080, 8UC1) 	2.271 	1.961 	1.16
pyrDown::Size_MatType::(1920x1080, 16SC1) 	1.466 	1.352 	1.08
pyrDown::Size_MatType::(1920x1080, 32FC1) 	2.026 	2.068 	0.98
pyrDown::Size_MatType::(1920x1080, 8UC3) 	13.350 	3.836 	3.48
pyrDown::Size_MatType::(1920x1080, 16SC3) 	12.742 	5.957 	2.14
pyrDown::Size_MatType::(1920x1080, 32FC3) 	10.460 	8.651 	1.21
pyrDown::Size_MatType::(1920x1080, 8UC4) 	8.920 	6.165 	1.45
pyrDown::Size_MatType::(1920x1080, 16SC4) 	14.579 	9.148 	1.59
pyrDown::Size_MatType::(1920x1080, 32FC4) 	16.442 	13.892 	1.18
pyrUp::Size_MatType::(127x61, 8UC1) 	0.124 	0.074 	1.68
pyrUp::Size_MatType::(127x61, 16SC1) 	0.119 	0.077 	1.55
pyrUp::Size_MatType::(127x61, 32FC1) 	0.134 	0.141 	0.95
pyrUp::Size_MatType::(127x61, 8UC3) 	0.363 	0.221 	1.64
pyrUp::Size_MatType::(127x61, 16SC3) 	0.362 	0.243 	1.49
pyrUp::Size_MatType::(127x61, 32FC3) 	0.519 	0.473 	1.10
pyrUp::Size_MatType::(127x61, 8UC4) 	0.493 	0.288 	1.71
pyrUp::Size_MatType::(127x61, 16SC4) 	0.506 	0.346 	1.46
pyrUp::Size_MatType::(127x61, 32FC4) 	0.934 	0.511 	1.83
pyrUp::Size_MatType::(320x240, 8UC1) 	1.109 	0.807 	1.37
pyrUp::Size_MatType::(320x240, 16SC1) 	1.013 	0.648 	1.56
pyrUp::Size_MatType::(320x240, 32FC1) 	1.093 	0.559 	1.96
pyrUp::Size_MatType::(320x240, 8UC3) 	3.553 	3.017 	1.18
pyrUp::Size_MatType::(320x240, 16SC3) 	3.342 	2.397 	1.39
pyrUp::Size_MatType::(320x240, 32FC3) 	3.911 	2.302 	1.70
pyrUp::Size_MatType::(320x240, 8UC4) 	5.381 	3.562 	1.51
pyrUp::Size_MatType::(320x240, 16SC4) 	4.493 	3.174 	1.42
pyrUp::Size_MatType::(320x240, 32FC4) 	5.149 	3.185 	1.62
pyrUp::Size_MatType::(640x480, 8UC1) 	4.442 	3.892 	1.14
pyrUp::Size_MatType::(640x480, 16SC1) 	4.107 	2.861 	1.44
pyrUp::Size_MatType::(640x480, 32FC1) 	4.654 	2.863 	1.63
pyrUp::Size_MatType::(640x480, 8UC3) 	15.506 	11.783 	1.32
pyrUp::Size_MatType::(640x480, 16SC3) 	13.772 	9.141 	1.51
pyrUp::Size_MatType::(640x480, 32FC3) 	15.384 	9.701 	1.59
pyrUp::Size_MatType::(640x480, 8UC4) 	20.438 	13.956 	1.46
pyrUp::Size_MatType::(640x480, 16SC4) 	19.403 	13.898 	1.40
pyrUp::Size_MatType::(640x480, 32FC4) 	22.509 	14.574 	1.54
pyrUp::Size_MatType::(1280x720, 8UC1) 	15.634 	11.194 	1.40
pyrUp::Size_MatType::(1280x720, 16SC1) 	13.798 	9.824 	1.40
pyrUp::Size_MatType::(1280x720, 32FC1) 	16.698 	10.182 	1.64
pyrUp::Size_MatType::(1280x720, 8UC3) 	45.080 	32.759 	1.38
pyrUp::Size_MatType::(1280x720, 16SC3) 	40.116 	29.394 	1.36
pyrUp::Size_MatType::(1280x720, 32FC3) 	45.339 	31.277 	1.45
pyrUp::Size_MatType::(1280x720, 8UC4) 	58.486 	41.172 	1.42
pyrUp::Size_MatType::(1280x720, 16SC4) 	58.284 	40.594 	1.44
pyrUp::Size_MatType::(1280x720, 32FC4) 	67.617 	41.300 	1.64 

@fengyuentau
Copy link
Copy Markdown
Member

My perf on K1 (clang) and RK3568:
pyrUp-pyrDown-perf.zip

@asmorkalov asmorkalov merged commit cbcfd77 into opencv:4.x Mar 4, 2025
27 of 28 checks passed
@asmorkalov asmorkalov mentioned this pull request Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants