opencv 编译cuda版本 error: “cudaUnbindTexture“ is undefined cuda_compile_1_generated_gpu_mat.cu.o

文章讲述了在OpenCV4.5.0与不同CUDA版本(11.x和12.x)配合时遇到的编译错误,主要原因是CUDA12.0弃用了旧版纹理引用。给出了针对不同CUDA版本的解决方案:对CUDA11.x添加编译标志或降级/升级OpenCV版本以适应新工具包。
摘要由CSDN通过智能技术生成

完整报错

/var/docker/opencv-4.5.0/opencv_contrib-4.5.0/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(61): error: texture is not a template

/var/docker/opencv-4.5.0/opencv_contrib-4.5.0/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(83): error: identifier "cudaUnbindTexture" is undefined

/var/docker/opencv-4.5.0/modules/core/include/opencv2/core/cuda/common.hpp(99): error: identifier "textureReference" is undefined

[ 15%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dsp/upsampling_sse41.c.o
3 errors detected in the compilation of "/var/docker/opencv-4.5.0/modules/core/src/cuda/gpu_mat.cu".
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.RELEASE.cmake:282 (message):
  Error generating file
  /var/docker/opencv-4.5.0/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o

make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/build.make:77: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4078: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

问题根因

这是由于cuda的版本问题造成的,下面介绍方案

解决方案1 

 如果你的cuda版本是11.x,在opencv 4.5.0的项目根目录的CMakelists.txt的开头加一句

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")

参考:Ubuntu16.05+CUDA8下编译OpenCV错误 [...cuda_compile_generated_gpu_mat.cu.o] Error 1

没有验证过,如果有同学验证过,并成功了。希望在评论区积极反馈

解决方案2 

如果你的cuda版本是12.x,提供两个选择

  1. 要么选择降级cuda为11.x,而继续编译opencv4.5.0
  2. 要么选择升级opencv为4.8.0版本(亲测有效),而继续使用cuda12.x

参考:Build OpenCV with CUDA 12, undefined identifiers cudaUnbindTexture, textureReference

源文划重点:

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.

 源文重点处翻译

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 工具包,该工具包仍然具有对纹理引用使用的已弃用支持

希望各位同学,能在评论区多多交流,相互避坑。

关于在编译opencv的其它问题,多是一些文件下载问题,网上有很多可以参考的地方,在此处就不再赘述。

  • 23
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值