mirror of
https://github.com/opencv/opencv.git
synced 2026-11-20 08:15:26 -06:00
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