Repository navigation
Fix empty patch match results on CUDA compute >= 100 (Blackwell GPUs) - #4161
Conversation
- `GpuMat<T>` contains `std::shared_ptr`, making it non-trivially copyable.
Passing it by value to CUDA kernels is undefined behavior per the
[CUDA spec](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-support.html).
On Blackwell GPUs (compute >= 100), this causes the compiler to misoptimize
the `depth_` loop in `SetSlice`/`GetSlice`, producing all-zero normal maps
and 0 fused points.
- Introduce `GpuMatView<T>`, a trivially-copyable POD struct with only the
fields needed on the device (`ptr`, `pitch`, `width`, `height`, `depth`)
and all device-side accessors (`Get`, `Set`, `GetSlice`, `SetSlice`, `GetRef`).
- All CUDA kernels now accept `GpuMatView<T>` instead of `GpuMat<T>`.
Launch sites use `->View()` instead of `*ptr`.
Fixes #3514
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a critical issue with CUDA compatibility on newer GPU architectures by introducing GpuMatView<T>. This new struct serves as a trivially-copyable view of GpuMat<T>, resolving the undefined behavior of passing non-trivially copyable objects to CUDA kernels. The implementation is clean, and the changes are consistently applied across all relevant kernels and launch sites. The approach is sound and aligns with best practices for CUDA programming. I have one minor suggestion to further improve code maintainability.
GpuMat<T>containsstd::shared_ptr, making it non-trivially copyable. Passing it by value to CUDA kernels is undefined behavior per the CUDA spec. On Blackwell GPUs (compute >= 100), this causes the compiler to misoptimize thedepth_loop inSetSlice/GetSlice, producing all-zero normal maps and 0 fused points.GpuMatView<T>, a trivially-copyable POD struct with only the fields needed on the device (ptr,pitch,width,height,depth) and all device-side accessors (Get,Set,GetSlice,SetSlice,GetRef).GpuMatView<T>instead ofGpuMat<T>. Launch sites use->View()instead of*ptr.Fixes #3514