mirror of
https://github.com/opencv/opencv.git
synced 2026-09-25 04:09:57 +03:00
5866bbd9ff1a3ed264cc9c88a0412233fcf2cecd
dnn: add Winograd F(6,3) RVV implementation for RISC-V (VLEN≥256) #29411 ### Summary Adds a RISC-V Vector (RVV) backend for the Winograd F(6,3) convolution path in the DNN module, targeting VLEN≥256 processors (tested on SpacemiT K1, rv64gcv). ### Background The Winograd F(6,3) path was already gated on `useSIMD128 || useAVX || useAVX2 || useNEON` at runtime, and protected by the same set of compile-time macros. RVV was simply missing from both guards, so it always fell through to generic convolution even when the hardware supports it. A second issue: `conv_winograd_f63` was registered with `ocv_add_dispatched_file`, which skips ISA variants not present in the host toolchain during cross-compilation. Changing to `ocv_add_dispatched_file_force_all` forces the `.rvv.cpp` translation unit to be generated unconditionally, matching how every other RVV-enabled kernel in the DNN module is registered. ### Implementation notes **Atom width.** `vsetvlmax_e32m1()` returns 8 on VLEN=256, so `winoAtomF32=8` is chosen, matching the AVX2 atom width. The `impl_accum_F32` and transform functions are structured identically to the AVX2 path (4 output channels × 6 input tiles per atom). **Input/output transform.** AVX2 uses `_mm256_unpacklo/hi_ps` + `permute2f128` for an in-register 8×8 transpose. RVV has no equivalent cross-lane shuffle at this width without `vrgather`, which adds index-vector overhead for a non-bottleneck step. Instead the 8×8 intermediate matrix is transposed scalar-in-memory between the two `wino_bt8x8_rvv` / `wino_at8x6_rvv` passes. This keeps the transform code simple and correct; the GEMM in `impl_accum_F32` dominates runtime. **VLEN guard.** `getWinofunc_F32` checks `vsetvlmax_e32m1() >= 8` at runtime and returns an empty functor on narrower implementations, so the code is safe on VLEN=128 targets without a separate code path. ### Testing **Correctness:** `ConvolutionWinograd.Accuracy` passes on the K1 board (9 ms). **Performance:** `opencv_perf_dnn`, SpacemiT K1 (rv64gcv, VLEN=256), GCC 13, `-O2 -march=rv64gcv`. Reported times are per-iteration medians from `[ PERFSTAT ]` output (`--perf_min_samples=5`). "Generic" is the same build with Winograd disabled via `OPENCV_DNN_DISABLE_WINOGRAD=1`. | Input → Output C | Winograd (ms) | Generic (ms) | Speedup | |--------------------------|--------------|-------------|---------| | {1,128,52,52} → 256 | 35.97 | 62.86 | 1.75× | | {1,512,13,13} → 1024 | 65.18 | 112.50 | 1.73× | | {1,256,75,75} → 256 | 159.75 | 271.65 | 1.70× | | {1,64,300,300} → 64 | 174.21 | 295.32 | 1.69× | | {1,1152,16,16} → 1152 | 176.12 | 245.33 | 1.39× | ### Pull Request Readiness Checklist 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 - [ ] 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%