Skip to content

Add size() to CUDA PtrStepSz#26042

Merged
asmorkalov merged 5 commits intoopencv:4.xfrom
pasbi:add-PtrStepSz_size
Sep 9, 2024
Merged

Add size() to CUDA PtrStepSz#26042
asmorkalov merged 5 commits intoopencv:4.xfrom
pasbi:add-PtrStepSz_size

Conversation

@pasbi
Copy link
Copy Markdown
Contributor

@pasbi pasbi commented Aug 18, 2024

According to cppreference.com compiler support table, nvcc supports [[nodiscard]] from version 11.

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

Related: #25659

@pasbi pasbi force-pushed the add-PtrStepSz_size branch from 9b677d9 to 4fe0913 Compare August 18, 2024 20:24
@asmorkalov asmorkalov added the category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib label Aug 19, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Aug 19, 2024
@asmorkalov asmorkalov self-requested a review August 19, 2024 16:44
@asmorkalov asmorkalov self-assigned this Aug 19, 2024
@asmorkalov
Copy link
Copy Markdown
Contributor

CUDA build:

[187/928] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat_nd.cu.o
FAILED: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat_nd.cu.o 
cd /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda && /usr/bin/cmake -E make_directory /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/. && /usr/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat_nd.cu.o -D generated_cubin_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat_nd.cu.o.cubin.txt -P /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat_nd.cu.o.Release.cmake
/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(128): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(129): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(130): error: attribute does not apply to any entity

3 errors detected in the compilation of "/home/ci/opencv/modules/core/src/cuda/gpu_mat_nd.cu".
CMake Error at cuda_compile_1_generated_gpu_mat_nd.cu.o.Release.cmake:280 (message):
  Error generating file
  /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat_nd.cu.o


[188/928] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o
FAILED: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o 
cd /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda && /usr/bin/cmake -E make_directory /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/. && /usr/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o -D generated_cubin_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o.cubin.txt -P /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake
/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(128): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(129): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(130): error: attribute does not apply to any entity

3 errors detected in the compilation of "/home/ci/opencv/modules/core/src/cuda/gpu_mat.cu".
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake:280 (message):
  Error generating file
  /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o

@pasbi
Copy link
Copy Markdown
Contributor Author

pasbi commented Aug 21, 2024

Seems like an older nvcc doesn't like [[nodiscard]].
We have two options:

  1. introduce a conditional [[nodiscard]] macro proxy (I haven't found one in OpenCV)
  2. remove [[nodiscard]]

Which one do you prefer? Since the other functions in this file don't have [[nodiscard]], I guess (2)?

There's another failing job PR:4.x / Android-Test / BuildAndTest (pull_request), I cannot see its build logs.

@asmorkalov
Copy link
Copy Markdown
Contributor

@pasbi
Copy link
Copy Markdown
Contributor Author

pasbi commented Aug 21, 2024

Sorry, maybe my comment was misleading.
The PR already has CV_NODISCARD_STD, but apparently it decays to [[nodiscard]] on old NVCC even though it's not supported (?).
Maybe we need to add an extra clause considering __NVCC__ in cvdef.h?

@asmorkalov
Copy link
Copy Markdown
Contributor

cvdef.h is not designed for GPU code. I propose to add local macro with NVCC check.

@asmorkalov
Copy link
Copy Markdown
Contributor

The PR was discussed on the Core Team meeting. The team proposes to extend cvdef.h and re-use CV_NODISCARD_STD macro everywhre, including CUDA code. So, please add extra branch for CV_NODISCARD_STD with NVCC.

@pasbi
Copy link
Copy Markdown
Contributor Author

pasbi commented Aug 31, 2024

According to cppreference.com compiler support table, nvcc supports [[nodiscard]] from version 11.
I cannot test that. I have only nvcc >12 at hand and [[nodiscard]] works there as expected.

I have added the requested changes, please have a look.

@asmorkalov
Copy link
Copy Markdown
Contributor

CUDA 11.7 on CI:

AILED: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat_nd.cu.o 
cd /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda && /usr/bin/cmake -E make_directory /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/. && /usr/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat_nd.cu.o -D generated_cubin_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat_nd.cu.o.cubin.txt -P /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat_nd.cu.o.Release.cmake
/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(130): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(131): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(132): error: attribute does not apply to any entity

3 errors detected in the compilation of "/home/ci/opencv/modules/core/src/cuda/gpu_mat_nd.cu".
CMake Error at cuda_compile_1_generated_gpu_mat_nd.cu.o.Release.cmake:280 (message):
  Error generating file
  /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat_nd.cu.o


[188/928] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o
FAILED: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o 
cd /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda && /usr/bin/cmake -E make_directory /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/. && /usr/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o -D generated_cubin_file:STRING=/home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o.cubin.txt -P /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake
/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(130): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(131): error: attribute does not apply to any entity

/home/ci/opencv/modules/core/include/opencv2/core/cuda_types.hpp(132): error: attribute does not apply to any entity

3 errors detected in the compilation of "/home/ci/opencv/modules/core/src/cuda/gpu_mat.cu".
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake:280 (message):
  Error generating file
  /home/ci/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o

@pasbi pasbi force-pushed the add-PtrStepSz_size branch from 6a57044 to ac0fe55 Compare September 4, 2024 10:37
@asmorkalov
Copy link
Copy Markdown
Contributor

CUDA 12.5:

/home/alexander/opencv/modules/core/include/opencv2/core/cuda_types.hpp(130): error: attribute does not apply to any entity
              __attribute__((host)) __attribute__((device)) __inline__ __attribute__((always_inline)) [[nodiscard]] Size size() const { return {cols, rows}; }
                                                                       ^

/home/alexander/opencv/modules/core/include/opencv2/core/cuda_types.hpp(131): error: attribute does not apply to any entity
              __attribute__((host)) __attribute__((device)) __inline__ __attribute__((always_inline)) [[nodiscard]] T& operator ()(const Point &pos) { return (*this)(pos.y, pos.x); }
                                                                       ^

/home/alexander/opencv/modules/core/include/opencv2/core/cuda_types.hpp(132): error: attribute does not apply to any entity
              __attribute__((host)) __attribute__((device)) __inline__ __attribute__((always_inline)) [[nodiscard]] const T& operator ()(const Point &pos) const { return (*this)(pos.y, pos.x); }
                                                                       ^

/home/alexander/opencv/modules/core/include/opencv2/core/cuda_types.hpp(130): error: attribute does not apply to any entity
              __attribute__((host)) __attribute__((device)) __inline__ __attribute__((always_inline)) [[nodiscard]] Size size() const { return {cols, rows}; }
                                                                       ^

/home/alexander/opencv/modules/core/include/opencv2/core/cuda_types.hpp(131): error: attribute does not apply to any entity
              __attribute__((host)) __attribute__((device)) __inline__ __attribute__((always_inline)) [[nodiscard]] T& operator ()(const Point &pos) { return (*this)(pos.y, pos.x); }
                                                                       ^

/home/alexander/opencv/modules/core/include/opencv2/core/cuda_types.hpp(132): error: attribute does not apply to any entity
              __attribute__((host)) __attribute__((device)) __inline__ __attribute__((always_inline)) [[nodiscard]] const T& operator ()(const Point &pos) const { return (*this)(pos.y, pos.x); }

@asmorkalov asmorkalov self-requested a review September 4, 2024 14:33
@pasbi pasbi force-pushed the add-PtrStepSz_size branch from ac0fe55 to 5425a52 Compare September 8, 2024 17:00
@asmorkalov asmorkalov changed the title Add ptr step sz size Add size() to CUDA PtrStepSz Sep 9, 2024
@asmorkalov asmorkalov merged commit 79faf85 into opencv:4.x Sep 9, 2024
@pasbi pasbi deleted the add-PtrStepSz_size branch September 10, 2024 07:10
@asmorkalov asmorkalov mentioned this pull request Sep 10, 2024
thewoz pushed a commit to CobbsLab/OPENCV that referenced this pull request Feb 13, 2025
Add size() to CUDA PtrStepSz opencv#26042

According to [cppreference.com compiler support table](https://en.cppreference.com/w/cpp/compiler_support/17), `nvcc` supports `[[nodiscard]]` from version 11.

### 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
- [ ] 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

Related: opencv#25659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants