安装OpenCV时遇到问题:nvcc fatal : Unsupported gpu architecture 'compute_30'

安装OpenCV时遇到问题:nvcc fatal : Unsupported gpu architecture 'compute_30' ,bug如下:

[ 19%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o
nvcc fatal   : Unsupported gpu architecture 'compute_30'
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake:220 (message):
  Error generating
  /home/yyx/packages/opencv-4.1.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:4193: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

我找到文件cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake ,里面设置NVCC_FLAGS的部分是这样的:

set(CUDA_NVCC_FLAGS -gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-D_FORCE_INLINES;-Xcompiler;-DCVAPI_EXPORTS;-Xcompiler;-fPIC;--std=c++11 ;; ) 

然后我把-gencode;arch=compute_30,code=sm_30;删掉了,重新make。
但是重新make还是报一样的错。

我又检查了cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake文件,
发现重新make以后-gencode;arch=compute_30,code=sm_30;设置又回来了!恢复原状!
改也改不掉,我没办法了,各位有什么经验吗,谢谢大家

根据您提供的信息,您在安装OpenCV时遇到了一个关于GPU架构不支持的错误。这个问题可能是由于您的GPU架构与编译器内置的默认架构不兼容造成的。

为了解决这个问题,您可以尝试以下几个步骤:

  1. 确保您的GPU架构与OpenCV版本的要求相符。首先确定您的GPU型号,并查找其计算能力(Compute Capability)。可以在NVIDIA官方网站或其他资源上找到与您的GPU型号对应的计算能力。

  2. 在编译OpenCV之前,在CMake配置时指定GPU架构。打开CMake配置界面,找到CUDA相关的选项,并将CUDA_ARCH_BIN设置为与您的GPU计算能力相对应的架构。例如,如果您的计算能力为3.0(对应compute_30),则将该选项设置为"3.0"。

  3. 如果在使用CMake进行配置时未看到CUDA相关的选项,请确保您已正确安装了CUDA Toolkit,并配置了相应的环境变量。

  4. 完成CMake配置后,重新运行make命令以编译OpenCV。