Please check CUDA_ARCH_PTX or CUDA_ARCH_BIN in your build configuration错误解决

在RTX2060显卡的机器上,编译了cuda opencv4.4没有报错,但是使用gpu就报错,报错如下:

classes, confidences, boxes = net.detect(image, confThreshold, nmsThreshold)
cv2.error: OpenCV(4.4.0) /home/ycc/opencv-4.4.0/modules/dnn/src/dnn.cpp:2353: error: (-216:No CUDA support) OpenCV was not built to work with the selected device. Please check CUDA_ARCH_PTX or CUDA_ARCH_BIN in your build configuration. in function 'initCUDABackend'

cmake -DCMAKE_BUILD_TYPE=RELEASE \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules .. \
    -DWITH_CUDA=1 \
    -DENABLE_FAST_MATH=1 \
    -DCUDA_FAST_MATH=1 \
    -DWITH_CUBLAS=1 \
    -DOPENCV_GENERATE_PKGCONFIG=1 \
    -DCUDA_GENERATION=Pascal ..

在gtx1080下正常,在rtx2060下报错,说明和算力有关,如下图。

Please check CUDA_ARCH_PTX or CUDA_ARCH_BIN in your build configuration错误解决_第1张图片

解决办法:添加  -DCUDA_ARCH_BIN=7.5 \   即:

cmake -DCMAKE_BUILD_TYPE=RELEASE \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules .. \
    -DWITH_CUDA=1 \
    -DCUDA_ARCH_BIN=7.5 \
    -DENABLE_FAST_MATH=1 \
    -DCUDA_FAST_MATH=1 \
    -DWITH_CUBLAS=1 \
    -DOPENCV_GENERATE_PKGCONFIG=1 \
    -DCUDA_GENERATION=Pascal ..

但是还是不行,因为   -DCUDA_GENERATION=Pascal 还是会改为61;60 ,可以查看./cmake/OpenCVDetectCUDA.cmake:

set(_generations "Fermi" "Kepler" "Maxwell" "Pascal" "Volta" "Turing" "Ampere")
  set(_arch_fermi   "2.0")
  set(_arch_kepler  "3.0;3.5;3.7")
  set(_arch_maxwell "5.0;5.2")
  set(_arch_pascal  "6.0;6.1")
  set(_arch_volta   "7.0")
  set(_arch_turing  "7.5")
  set(_arch_ampere  "8.0")

最后修改:

cmake -DCMAKE_BUILD_TYPE=RELEASE \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules .. \
    -DWITH_CUDA=1 \
    -DCUDA_ARCH_BIN=7.5 \
    -DENABLE_FAST_MATH=1 \
    -DCUDA_FAST_MATH=1 \
    -DWITH_CUBLAS=1 \
    -DOPENCV_GENERATE_PKGCONFIG=1 \
    ..

 问题解决。

 

你可能感兴趣的:(opencv,opencv,cuda,编译)