Build OpenCV with CUDA support

匿名 (未验证) 提交于 2019-12-03 02:16:02

问题:

Im use CMake to generate visual studio 2013 solution. Next im try to build it, but get follow error:

Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/Debug/cuda_compile_generated_gpu_mat.cu.obj

nvcc fatal : Unsupported gpu architecture 'compute_11'

Im try version 2.10 and 3.0 with cuda 6.5 and 7.0. CUDA_ARCH_BIN set to : 1.1 1.2 1.3 2.0 2.1(2.0) 3.0 3.5

回答1:

Another option. Ubuntu 14.04, GTX Titan X, opencv-2.4.10

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D CUDA_GENERATION=Auto -D BUILD_NEW_PYTHON_SUPPORT=ON  ..  

I also applied the patch, but I'm not sure whether it ended up being needed. I had tried with and withoutCUDA_GENERATION=Maxwell but Maxwell isn't detected. I did not try CUDA_GENERATION=Auto prior to the patch, that's why I don't know for sure.



回答2:

When using cmake to do configurations, set the option CUDA_GENERATION to specific your GPU architecture. I ran across the same error and tried this to work out the problem.



回答3:

Following up on Yun's answer (could not leave comment), this worked for me and shows a possible value for CUDA_GENERATION:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler .. 

(Ubuntu 12.04 and 14.04, GTX Titan, and OpenCV 2.4.11 and 3.0.0.)



回答4:

Thank you,

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler .. 

This let me install opencv-2.4.9.

If you want to know more detaills check this link.



回答5:

This is because of your gpu type is mismatching.

You have to define CUDA_GENERATION explicitly.

In my side, I could find 3 types of CUDA_GENERATION; Auto, Kepler, Fermi.

When I set CUDA_GENERATION as Kepler, compute_11 changed to compute_30 and build successful.



回答6:

You can use CUDA_GENERATION to specify the corresponding generation code name for your GPU architecture.

Here's the relevant opencv cmake code that parses the CUDA_GENERATION value:

  set(__cuda_arch_ptx "")   if(CUDA_GENERATION STREQUAL "Fermi")     set(__cuda_arch_bin "2.0")   elseif(CUDA_GENERATION STREQUAL "Kepler")     set(__cuda_arch_bin "3.0 3.5 3.7")   elseif(CUDA_GENERATION STREQUAL "Maxwell")     set(__cuda_arch_bin "5.0 5.2")   elseif(CUDA_GENERATION STREQUAL "Pascal")     set(__cuda_arch_bin "6.0 6.1")   elseif(CUDA_GENERATION STREQUAL "Volta")     set(__cuda_arch_bin "7.0")   elseif(CUDA_GENERATION STREQUAL "Auto")     execute_process( COMMAND "${CUDA_NVCC_EXECUTABLE}" ${CUDA_NVCC_FLAGS} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run"                      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"                      RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out                      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)     if(NOT _nvcc_res EQUAL 0)       message(STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures.")     else()       set(__cuda_arch_bin "${_nvcc_out}")       string(REPLACE "2.1" "2.1(2.0)" __cuda_arch_bin "${__cuda_arch_bin}")     endif() endif() 

And the wikipedia CUDA page has a nice table for mapping your video card to the right microarchitecture code name (sorry, it's too large to reproduce here):

https://en.wikipedia.org/wiki/CUDA#GPUs_supported

For example, my middling-2012 Macbook Pro has an antique GeForce GT 650M, which the wikipedia table indicates uses the Kepler microarchitecture. Therefore, I use this in my cmake command line:

cmake -D CUDA_GENERATION="Kepler" ...

and the opencv script converts that to "3.0 3.5 3.7" when it displays the config summary, and passes on the corresponding flags to nvcc.

In my case, before setting this properly, I was getting errors about compute_70 not supported. Apparently, there is still an open issue in the opencv tracker as of today (2017-10-07) about auto-detection not working properly.



回答7:

You should set with cmake these entries CUDA_ARCH_BIN = 3.2 and CUDA_ARCH_PTX = 3.2

Hope it helps.

Regards



回答8:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D CUDA_GENERATION=Kepler -D BUILD_NEW_PYTHON_SUPPORT=ON ..

worked for me for OpenCV 2.4.11



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!