@ -1,17 +1,15 @@
if ( WIN32 AND NOT MSVC )
if ( ( WIN32 AND NOT MSVC ) OR OPENCV_CMAKE_FORCE_CUDA )
message ( STATUS "CUDA compilation is disabled (due to only Visual Studio compiler supported on your platform)." )
return ( )
endif ( )
if ( NOT UNIX AND CV_CLANG )
if ( ( NOT UNIX AND CV_CLANG ) OR OPENCV_CMAKE_FORCE_CUDA )
message ( STATUS "CUDA compilation is disabled (due to Clang unsupported on your platform)." )
return ( )
endif ( )
if ( CUDA_HOST_COMPILER )
# r e s p e c t t h e C U D A _ H O S T _ C O M P I L E R i f s p e c i f i e d m a n u a l l y
set ( PREFERRED_CUDA_HOST_COMPILER "${CUDA_HOST_COMPILER}" )
endif ( )
# set ( OPENCV_CMAKE_CUDA_DEBUG 1 )
if ( ( ( NOT CMAKE_VERSION VERSION_LESS "3.9.0" ) # requires https://gitlab.kitware.com/cmake/cmake/merge_requests/663
O R O P E N C V _ C U D A _ F O R C E _ E X T E R N A L _ C M A K E _ M O D U L E )
A N D N O T O P E N C V _ C U D A _ F O R C E _ B U I L T I N _ C M A K E _ M O D U L E )
@ -56,7 +54,7 @@ if(CUDA_FOUND)
endif ( )
if ( WITH_NVCUVID )
macro ( SEARCH_NVCUVID_HEADER _filename _result )
macro ( ocv_cuda_ SEARCH_NVCUVID_HEADER _filename _result )
# p l a c e h e a d e r f i l e u n d e r C U D A _ T O O L K I T _ T A R G E T _ D I R o r C U D A _ T O O L K I T _ R O O T _ D I R
find_path ( _header_result
$ { _ f i l e n a m e }
@ -73,8 +71,8 @@ if(CUDA_FOUND)
endif ( )
unset ( _header_result CACHE )
endmacro ( )
SEARCH_NVCUVID_HEADER ( "nvcuvid.h" HAVE_NVCUVID_HEADER )
SEARCH_NVCUVID_HEADER ( "dynlink_nvcuvid.h" HAVE_DYNLINK_NVCUVID_HEADER )
ocv_cuda_ SEARCH_NVCUVID_HEADER( "nvcuvid.h" HAVE_NVCUVID_HEADER )
ocv_cuda_ SEARCH_NVCUVID_HEADER( "dynlink_nvcuvid.h" HAVE_DYNLINK_NVCUVID_HEADER )
find_cuda_helper_libs ( nvcuvid )
if ( WIN32 )
find_cuda_helper_libs ( nvcuvenc )
@ -115,44 +113,89 @@ if(CUDA_FOUND)
unset ( CUDA_ARCH_PTX CACHE )
endif ( )
if ( PREFERRED_CUDA_HOST_COMPILER )
LIST ( APPEND CUDA_NVCC_FLAGS -ccbin "${PREFERRED_CUDA_HOST_COMPILER}" )
else ( )
if ( WIN32 AND CMAKE_LINKER ) # W o r k a r o u n d f o r V S c l . e x e n o t b e i n g i n t h e e n v . p a t h
if ( OPENCV_CUDA_DETECTION_NVCC_FLAGS MATCHES "-ccbin" )
# a l r e a d y s p e c i f i e d b y u s e r
elseif ( CUDA_HOST_COMPILER AND EXISTS "${CUDA_HOST_COMPILER}" )
LIST ( APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}" )
elseif ( WIN32 AND CMAKE_LINKER ) # W o r k a r o u n d f o r V S c l . e x e n o t b e i n g i n t h e e n v . p a t h
get_filename_component ( host_compiler_bindir ${ CMAKE_LINKER } DIRECTORY )
LIST ( APPEND CUDA_NVCC_FLAGS -ccbin ${ host_compiler_bindir } )
LIST ( APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${host_compiler_bindir}" )
else ( )
if ( CUDA_HOST_COMPILER )
message ( STATUS "CUDA: CUDA_HOST_COMPILER='${CUDA_HOST_COMPILER}' is not valid, autodetection may not work. Specify OPENCV_CUDA_DETECTION_NVCC_FLAGS with -ccbin option for fix that" )
endif ( )
endif ( )
SET ( DETECT_ARCHS_COMMAND "${CUDA_NVCC_EXECUTABLE}" ${ CUDA_NVCC_FLAGS } "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run" )
macro ( ocv_filter_available_architecture result_list )
if ( DEFINED CUDA_SUPPORTED_CC )
set ( ${ result_list } "${CUDA_SUPPORTED_CC}" )
set ( __cache_key_check "${ARGN} : ${CUDA_NVCC_EXECUTABLE} ${OPENCV_CUDA_DETECTION_NVCC_FLAGS}" )
if ( DEFINED OPENCV_CACHE_CUDA_SUPPORTED_CC AND OPENCV_CACHE_CUDA_SUPPORTED_CC_check STREQUAL __cache_key_check )
set ( ${ result_list } "${OPENCV_CACHE_CUDA_SUPPORTED_CC}" )
else ( )
set ( CC_LIST ${ ARGN } )
foreach ( target_arch ${ CC_LIST } )
string ( REPLACE "." "" target_arch_short "${target_arch}" )
set ( NVCC_OPTION "-gencode;arch=compute_${target_arch_short},code=sm_${target_arch_short}" )
execute_process ( COMMAND "${CUDA_NVCC_EXECUTABLE}" ${ NVCC_OPTION } "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu"
set ( _cmd "${CUDA_NVCC_EXECUTABLE}" ${ OPENCV_CUDA_DETECTION_NVCC_FLAGS } ${ NVCC_OPTION } "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" --compile )
execute_process (
C O M M A N D $ { _ c m d }
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } $ { C M A K E _ F I L E S _ D I R E C T O R Y } / C M a k e T m p / "
R E S U L T _ V A R I A B L E _ n v c c _ r e s O U T P U T _ V A R I A B L E _ n v c c _ o u t
E R R O R _ Q U I E T O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
R E S U L T _ V A R I A B L E _ n v c c _ r e s
O U T P U T _ V A R I A B L E _ n v c c _ o u t
E R R O R _ V A R I A B L E _ n v c c _ e r r
# E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
if ( OPENCV_CMAKE_CUDA_DEBUG )
message ( WARNING "COMMAND: ${_cmd}" )
message ( STATUS "Result: ${_nvcc_res}" )
message ( STATUS "Out: ${_nvcc_out}" )
message ( STATUS "Err: ${_nvcc_err}" )
endif ( )
if ( _nvcc_res EQUAL 0 )
set ( ${ result_list } "${${result_list}} ${target_arch}" )
LIST ( APPEND ${ result_list } "${target_arch}" )
endif ( )
endforeach ( )
string ( STRIP "${${result_list}}" ${ result_list } )
set ( CUDA_SUPPORTED_CC ${ ${result_list } } CACHE INTERNAL "List of supported compute capability" )
if ( " ${${result_list}}" STREQUAL " " )
message ( WARNING "CUDA: Autodetection arch list is empty. Please enable OPENCV_CMAKE_CUDA_DEBUG=1 and check/specify OPENCV_CUDA_DETECTION_NVCC_FLAGS variable" )
endif ( )
# c a c h e d e t e c t e d v a l u e s
set ( OPENCV_CACHE_CUDA_SUPPORTED_CC ${ ${result_list } } CACHE INTERNAL "" )
set ( OPENCV_CACHE_CUDA_SUPPORTED_CC_check "${__cache_key_check}" CACHE INTERNAL "" )
endif ( )
endmacro ( )
macro ( ocv_detect_native_cuda_arch status output )
execute_process ( COMMAND ${ DETECT_ARCHS_COMMAND }
set ( OPENCV_CUDA_DETECT_ARCHS_COMMAND "${CUDA_NVCC_EXECUTABLE}" ${ OPENCV_CUDA_DETECTION_NVCC_FLAGS } "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run" )
set ( __cache_key_check "${OPENCV_CUDA_DETECT_ARCHS_COMMAND}" )
if ( DEFINED OPENCV_CACHE_CUDA_ACTIVE_CC AND OPENCV_CACHE_CUDA_ACTIVE_CC_check STREQUAL __cache_key_check )
set ( ${ output } "${OPENCV_CACHE_CUDA_ACTIVE_CC}" )
set ( ${ status } 0 )
else ( )
execute_process (
C O M M A N D $ { O P E N C V _ C U D A _ D E T E C T _ A R C H S _ C O M M A N D }
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } $ { C M A K E _ F I L E S _ D I R E C T O R Y } / C M a k e T m p / "
R E S U L T _ V A R I A B L E $ { s t a t u s } O U T P U T _ V A R I A B L E _ n v c c _ o u t
E R R O R _ Q U I E T O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
R E S U L T _ V A R I A B L E $ { s t a t u s }
O U T P U T _ V A R I A B L E _ n v c c _ o u t
E R R O R _ V A R I A B L E _ n v c c _ e r r
E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
if ( OPENCV_CMAKE_CUDA_DEBUG )
message ( WARNING "COMMAND: ${OPENCV_CUDA_DETECT_ARCHS_COMMAND}" )
message ( STATUS "Result: ${${status}}" )
message ( STATUS "Out: ${_nvcc_out}" )
message ( STATUS "Err: ${_nvcc_err}" )
endif ( )
string ( REGEX REPLACE ".*\n" "" ${ output } "${_nvcc_out}" ) # S t r i p l e a d i n g w a r n i n g m e s s a g e s , i f a n y
if ( ${ status } EQUAL 0 )
# c a c h e d e t e c t e d v a l u e s
set ( OPENCV_CACHE_CUDA_ACTIVE_CC ${ ${result_list } } CACHE INTERNAL "" )
set ( OPENCV_CACHE_CUDA_ACTIVE_CC_check "${__cache_key_check}" CACHE INTERNAL "" )
endif ( )
endif ( )
endmacro ( )
macro ( ocv_wipeout_deprecated _arch_bin_list )
@ -181,6 +224,9 @@ if(CUDA_FOUND)
else ( )
string ( REGEX MATCHALL "[0-9]+\\.[0-9]" __cuda_arch_bin "${_nvcc_out}" )
endif ( )
elseif ( CUDA_ARCH_BIN )
message ( STATUS "CUDA: Using CUDA_ARCH_BIN=${CUDA_ARCH_BIN}" )
set ( __cuda_arch_bin ${ CUDA_ARCH_BIN } )
endif ( )
if ( NOT DEFINED __cuda_arch_bin )
@ -188,7 +234,11 @@ if(CUDA_FOUND)
set ( __cuda_arch_bin "3.2" )
set ( __cuda_arch_ptx "" )
elseif ( AARCH64 )
if ( NOT CMAKE_CROSSCOMPILING )
ocv_detect_native_cuda_arch ( _nvcc_res _nvcc_out )
else ( )
set ( _nvcc_res -1 ) # e m u l a t e e r r o r , s e e b e l o w
endif ( )
if ( NOT _nvcc_res EQUAL 0 )
message ( STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures." )
# TX1 ( 5.3 ) TX2 ( 6.2 ) Xavier ( 7.2 ) V100 ( 7.0 )
@ -222,11 +272,9 @@ if(CUDA_FOUND)
string ( REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}" )
string ( REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}" )
# C k e c k i f u s e r s p e c i f i e d 1 . 0 c o m p u t e c a p a b i l i t y : w e d o n ' t s u p p o r t i t
string ( REGEX MATCH "1.0" HAS_ARCH_10 "${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}" )
set ( CUDA_ARCH_BIN_OR_PTX_10 0 )
if ( NOT ${ HAS_ARCH_10 } STREQUAL "" )
set ( CUDA_ARCH_BIN_OR_PTX_10 1 )
# C h e c k i f u s e r s p e c i f i e d 1 . 0 c o m p u t e c a p a b i l i t y : w e d o n ' t s u p p o r t i t
if ( " ${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}" MATCHES " 1.0" )
message ( SEND_ERROR "CUDA: 1.0 compute capability is not supported - exclude it from ARCH/PTX list are re-run CMake" )
endif ( )
# N V C C f l a g s t o b e s e t
@ -421,7 +469,7 @@ if(HAVE_CUDA)
if ( CMAKE_GENERATOR MATCHES "Visual Studio"
A N D N O T O P E N C V _ S K I P _ C U D A _ C M A K E _ S U P P R E S S _ R E G E N E R A T I O N
)
message ( WARNING "CUDA with MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.")
message ( STATUS "CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.")
set ( CMAKE_SUPPRESS_REGENERATION ON )
endif ( )
endif ( )