Home > Blockchain >  Build OpenCV with CUDA 12, undefined identifiers cudaUnbindTexture, textureReference
Build OpenCV with CUDA 12, undefined identifiers cudaUnbindTexture, textureReference

Time:12-18

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

Running with:

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

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?

CodePudding user response:

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.

  • Related