mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
60858fce9e0c1a4dc3421e479b5633c140aa2191
The previous OpenCL implementation of UMat::diag() relied on a sequence of operations involving buffer initialization followed by copy/transpose on an aliased diag() view. Although these operations were enqueued on an in-order command queue, this implicitly assumed memory visibility between kernels operating on aliased regions of the same buffer. According to the OpenCL specification, in-order command queues only guarantee command scheduling order, while memory visibility between commands is only established through explicit command-level synchronization points (e.g. events, barriers, or clFinish).Under OpenCL’s relaxed memory model, such assumptions are not guaranteed without an explicit command-level synchronization point, and can lead to data races and incorrect results, especially for very small matrices (e.g. 1x1). The issue is more likely to be exposed on Mesa-based drivers when the GPU is running at lower frequencies (e.g. 500 MHz). This change introduces a dedicated OpenCL kernel to construct the diagonal matrix in a single kernel invocation, avoiding intermediate aliasing and eliminating the need for implicit ordering assumptions. If the OpenCL path is unavailable or unsupported, the implementation transparently falls back to the CPU path. Signed-off-by: jiajia Qian <jiajia.qian@nxp.com>
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/4.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.
Description
Languages
C++
87.6%
C
3.1%
Python
2.9%
CMake
2%
Java
1.5%
Other
2.7%