Thomas Saison
Thomas Saison

Reputation: 127

Build OpenCV with CUDA 12, undefined identifiers cudaUnbindTexture, textureReference

I try to compile Opencv with cuda, but I have an error

Running with:

I don't know where it comes from...

[  7%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc.o
/home/totar/cv2/opencv-3.4.16/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(61): error: texture is not a template

/home/totar/cv2/opencv-3.4.16/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(83): error: identifier "cudaUnbindTexture" is undefined

/home/totar/cv2/opencv-3.4.16/modules/core/include/opencv2/core/cuda/common.hpp(99): error: identifier "textureReference" is undefined

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


modules/core/CMakeFiles/opencv_core.dir/build.make:63: recipe for target 'modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o' failed
make[2]: *** [modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o] Error 1
CMakeFiles/Makefile2:1889: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Output of nvcc --version

totar@totar:~/cv2/opencv-3.4.16/build$ nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Mon_Oct_24_19:12:58_PDT_2022
Cuda compilation tools, release 12.0, V12.0.76
Build cuda_12.0.r12.0/compiler.31968024_0

Has anyone ever had this problem?

Upvotes: 3

Views: 6377

Answers (2)

Nick Hockings
Nick Hockings

Reputation: 29

Following from Robert Crovella's answer, another solution (for many people) would be to build OpenCV-4x instead, where the backend uses OpenCL for GPU access, and the Cuda modules are optional (found in the separate https://github.com/opencv/opencv_contrib repository).

Obviously this depends on whether you have a lot of code using the Cuda gpuMat class, which you would need to migrate to the UMat class for the OpenCV-4 "Transparent API" (aka TAPI). This probably worth doing for code that you intend to keep using for the long term.

Upvotes: 0

Robert Crovella
Robert Crovella

Reputation: 152173

CUDA 12.0 dropped support for legacy texture references. Therefore, any code that uses legacy texture references can no longer be properly compiled with CUDA 12.0 or beyond.

Legacy texture reference usage has been deprecated for some time now.

As indicated in the comments, by reverting to CUDA 11.x where legacy texture references are still supported (albeit deprecated) you won't run into this issue.

The other option may happen some day when OpenCV converts usage of legacy texture references to texture object methods. In that case, it may then be possible to use CUDA 12.0 or a newer CUDA toolkit to compile OpenCV/CUDA functionality.

There is no work around to somehow allow texture reference usage to be compiled properly with CUDA 12.0 and beyond.

Likewise, this limitation is not unique or specific to OpenCV. Any CUDA code that uses texture references can no longer be compiled properly with CUDA 12.0 and beyond. The options are to refactor that code with texture object usage instead, or revert to a previous CUDA toolkit that still has the deprecated support for texture reference usage.

Upvotes: 7

Related Questions