mirror of
https://github.com/opencv/opencv.git
synced 2026-09-25 04:09:57 +03:00
fb96a94a037c8d6bbb60e971e865dd89a052c031
core: optimize float REDUCE_SUM2 with RVV - #29930 ### Summary Add an RVV 1.0 kernel for `cv::reduce` with `dim=0` and `CV_32F` input/output through the CPU dispatch mechanism. The optimized path targets the floating-point `REDUCE_SUM2` operation. ### Implementation Process four source rows per vector iteration to reduce intermediate buffer traffic while preserving source-row accumulation order. The RVV kernel uses LMUL=4 and dynamic vector lengths for tail handling. Output writes are deferred until all input rows have been read. This preserves correct behavior when the source and destination matrices overlap. The implementation is VLEN-agnostic. ### Functional Testing The Reduce tests were run with: ```bash ./bin/opencv_test_core \ --gtest_filter='*Reduce*:*reduce*' \ --test_threads=1 ``` ### Performance Testing Performance was measured with: ```bash ./bin/opencv_perf_core \ --gtest_filter='*reduceR*' \ --perf_threads=1 ``` Test environment: - SpacemiT K3 - VLEN = 256 - GCC 14.3.0 - Release build - Single thread - 10 samples per case Results were compared against an unmodified `5.x` baseline. `CV_32FC1 REDUCE_SUM2` median execution time (ms): | Size | Baseline | Patched | Speedup | | --- | ---: | ---: | ---: | | 640x480 | 0.20 | 0.08 | 2.50x | | 1280x720 | 0.64 | 0.29 | 2.21x | | 1920x1080 | 1.33 | 1.05 | 1.27x | Speedups are approximate and calculated from the rounded benchmark output. ### Co-authors - Yang Wang <yangwang@iscas.ac.cn> - Yuansheng <yuansheng@isrc.iscas.ac.cn> ### Pull Request Readiness Checklist - [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 - [ ] 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. - [ ] The feature is well documented and sample code can be built with the project CMake
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/5.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): http://answers.opencv.org
- Issue tracking: https://github.com/opencv/opencv/issues
- Additional OpenCV functionality: https://github.com/opencv/opencv_contrib
- Donate to OpenCV: https://opencv.org/support/
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.
Additional Resources
- Submit your OpenCV-based project for inclusion in Community Friday on opencv.org
- Subscribe to the OpenCV YouTube Channel featuring OpenCV Live, an hour-long streaming show
- Follow OpenCV on LinkedIn for daily posts showing the state-of-the-art in computer vision & AI
- Apply to be an OpenCV Volunteer to help organize events and online campaigns as well as amplify them
- Follow OpenCV on Mastodon in the Fediverse
- Follow OpenCV on Twitter
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Languages
C++
86%
Python
4.1%
C
2.9%
CMake
2.2%
Java
1.6%
Other
3.1%