使用CUDA 12构建OpenCV,未定义标识符cudaUnbindTexture, texturerreference



我尝试用cuda编译Opencv,但我有一个错误

运行:

  • nvidia-driver-525.60.13
  • CUDA 12.0
  • OpenCV 3.4.16

我不知道它是从哪里来的…

[  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....

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

有人遇到过这个问题吗?

CUDA 12.0不再支持旧的纹理引用。因此,任何使用遗留纹理引用的代码都不能在CUDA 12.0或更高版本下正确编译。

旧的纹理引用已经被弃用一段时间了。

如评论所示,通过恢复到CUDA 11。X中仍然支持遗留纹理引用(尽管已弃用),您将不会遇到此问题。

当OpenCV将遗留纹理引用的使用转换为纹理对象方法时,另一个选项可能会在某一天发生。在这种情况下,可以使用CUDA 12.0或更新的CUDA工具包来编译OpenCV/CUDA功能。

没有办法允许纹理引用使用在CUDA 12.0或更高版本中正确编译。

同样,这个限制也不是OpenCV独有的或特定的。任何使用纹理引用的CUDA代码都不能在CUDA 12.0及以后的版本中正确编译。选项是用纹理对象的使用来重构代码,或者恢复到以前的CUDA工具包,该工具包仍然不支持纹理引用的使用。

根据Robert Crovella的回答,另一个解决方案(对许多人来说)将是构建OpenCV-4x,其中后端使用OpenCL进行GPU访问,Cuda模块是可选的(在单独的https://github.com/opencv/opencv_contrib存储库中找到)。

显然,这取决于你是否有很多使用Cuda gpuMat类的代码,你需要将其迁移到OpenCV-4"透明api"的UMat类。(又名TAPI)。对于您打算长期使用的代码,这可能值得这样做。

最新更新