Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CUDA texture bugs and replace all instances of CUDA texture references with texture objects #3378

Merged

Conversation

cudawarped
Copy link
Contributor

@cudawarped cudawarped commented Nov 16, 2022

CUDA texture objects replaced CUDA texture references in the 2012 (CUDA SDK 5.0 toolkit) and could be removed at any time from future SDK releases by Nvidia as they were depreciated in April 2021 (CUDA SDK 11.3).

This PR replaces all instances of texture references with texture objects using the existing updated cv::cudev::Texture class.

Additionaly it addresses the three bugs below related to incorrect texture usage:

  1. cv::cuda::resize - currently resize uses texture references if the default stream or no stream is passed. Under these circumstances global texture references are used when multiple threads call cv::cuda::resize which is unsafe.
  2. cv::cuda::demosaicing - returns incorrect results when passed image ROI's.
  3. cv::cuda::HoughSegmentDetector - passes the existing cv::cudev::Texture object whose destructor calls cudaDestroyTextureObject() to the CUDA kernel. This can cause the underlying cudaTextureObject_t to be destroyed on return from the copy to the stub function before the kernel is launched as described in the Nvidia docs.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • 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
force_builders=Custom
buildworker:Custom=linux-1
docker_image:Custom=ubuntu-cuda:16.04

@cudawarped cudawarped force-pushed the replace_texture_ref_with_texture_obj branch from d738c38 to 50c6568 Compare November 16, 2022 08:55
@cudawarped cudawarped changed the title Replace all instances of CUDA texture references with texture objects Fix CUDA texture bugs and replace all instances of CUDA texture references with texture objects Nov 22, 2022
@asmorkalov asmorkalov self-requested a review November 23, 2022 06:09
@alalek
Copy link
Member

alalek commented Nov 23, 2022

@asmorkalov How to run Ubuntu2004-x64-CUDA configuration on GitHub actions (GHA)?

modules/cudaimgproc/src/cuda/canny.cu Outdated Show resolved Hide resolved
modules/cudaimgproc/src/cuda/canny.cu Outdated Show resolved Hide resolved
modules/cudaimgproc/src/cuda/debayer.cu Outdated Show resolved Hide resolved
modules/cudaimgproc/src/cuda/hough_segments.cu Outdated Show resolved Hide resolved
modules/cudaimgproc/test/test_color.cpp Outdated Show resolved Hide resolved
@cudawarped cudawarped force-pushed the replace_texture_ref_with_texture_obj branch 2 times, most recently from 5f0ed82 to 2938ad7 Compare December 14, 2022 15:09
@asmorkalov asmorkalov self-assigned this Dec 14, 2022
@cudawarped
Copy link
Contributor Author

@asmorkalov I've just noticed I missed, lut.cu and left the main texture reference routine in the main repo which is causing issues with CUDA 12.0 (#3390). I'm addressing this now.

@asmorkalov
Copy link
Contributor

Combination of changes in core and contrib leads to build error. CUDA: 10.2, Ubuntu 18.04.

/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp: In member function ‘R cv::cudev::TexturePtr<T, R>::operator()(cv::cudev::TexturePtr<T, R>::index_type, cv::cudev::TexturePtr<T, R>::index_type) const’:
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:32:20: error: ‘tex2D’ was not declared in this scope
             return tex2D<R>(tex, x, y);
                    ^~~~~
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:32:20: note: suggested alternative: ‘tex’
             return tex2D<R>(tex, x, y);
                    ^~~~~
                    tex
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:32:27: error: expected primary-expression before ‘>’ token
             return tex2D<R>(tex, x, y);
                           ^
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp: In member function ‘R cv::cudev::TexturePtr<T, R>::operator()(cv::cudev::TexturePtr<T, R>::index_type) const’:
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:35:20: error: ‘tex1Dfetch’ was not declared in this scope
             return tex1Dfetch<R>(tex, x);
                    ^~~~~~~~~~
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:35:32: error: expected primary-expression before ‘>’ token
             return tex1Dfetch<R>(tex, x);
                                ^
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp: In member function ‘R cv::cudev::TexturePtr<long unsigned int, R>::operator()(cv::cudev::TexturePtr<long unsigned int, R>::index_type, cv::cudev::TexturePtr<long unsigned int, R>::index_type) const’:
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:48:34: error: ‘tex2D’ was not declared in this scope
             const uint2 retVal = tex2D<uint2>(tex, x, y);
                                  ^~~~~
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:48:34: note: suggested alternative: ‘tex’
             const uint2 retVal = tex2D<uint2>(tex, x, y);
                                  ^~~~~
                                  tex
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:48:45: error: expected primary-expression before ‘>’ token
             const uint2 retVal = tex2D<uint2>(tex, x, y);
                                             ^
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp: In member function ‘R cv::cudev::TexturePtr<long unsigned int, R>::operator()(cv::cudev::TexturePtr<long unsigned int, R>::index_type) const’:
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:52:34: error: ‘tex1Dfetch’ was not declared in this scope
             const uint2 retVal = tex1Dfetch<uint2>(tex, x);
                                  ^~~~~~~~~~
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:52:50: error: expected primary-expression before ‘>’ token
             const uint2 retVal = tex1Dfetch<uint2>(tex, x);
                                                  ^
In file included from /mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudaimgproc/src/precomp.hpp:62:0,
                 from /mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudaimgproc/src/bilateral_filter.cpp:43:
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp: In member function ‘R cv::cudev::TextureOffPtr<T, R>::operator()(cv::cudev::TextureOffPtr<T, R>::index_type, cv::cudev::TextureOffPtr<T, R>::index_type) const’:
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:65:20: error: ‘tex2D’ was not declared in this scope
             return tex2D<R>(tex, x + xoff, y + yoff);
                    ^~~~~
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:65:20: note: suggested alternative: ‘tex’
             return tex2D<R>(tex, x + xoff, y + yoff);
                    ^~~~~
                    tex
/mnt/projects/Projects/OpenCV/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:65:27: error: expected primary-expression before ‘>’ token
             return tex2D<R>(tex, x + xoff, y + yoff);

…cts using the existing updated cv::cudev::Texture class.

Fixes bugs in cv::cuda::demosaicing, cv::cuda::resize and cv::cuda::HoughSegmentDetector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants