From 7fcfafff8bab4d24608d6897a5db137f380d7a4b Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 22 Apr 2026 13:05:39 +0300 Subject: [PATCH] Use fast math for dnn module. --- cmake/OpenCVUtils.cmake | 11 +++++++++++ modules/dnn/CMakeLists.txt | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 93e93c157c..880a72c9e1 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1519,6 +1519,17 @@ function(ocv_target_compile_definitions target) endif() endfunction() +function(ocv_target_compile_options target) + _ocv_fix_target(target) + if(NOT TARGET ${target}) + if(NOT DEFINED OPENCV_MODULE_${target}_LOCATION) + message(FATAL_ERROR "ocv_target_compile_definitions: invalid target: '${target}'") + endif() + set(OPENCV_MODULE_${target}_COMPILE_OPTIONS ${OPENCV_MODULE_${target}_COMPILE_OPTIONS} ${ARGN} CACHE INTERNAL "" FORCE) + else() + target_compile_options(${target} ${ARGN}) + endif() +endfunction() function(_ocv_append_target_includes target) if(DEFINED OCV_TARGET_INCLUDE_DIRS_${target}) diff --git a/modules/dnn/CMakeLists.txt b/modules/dnn/CMakeLists.txt index f1e8132daa..76f4515f9a 100644 --- a/modules/dnn/CMakeLists.txt +++ b/modules/dnn/CMakeLists.txt @@ -37,6 +37,13 @@ if(HAVE_CANN) ocv_target_compile_definitions(${the_module} PRIVATE "HAVE_CANN=1") endif() +if(MSVC) + ocv_target_compile_options(${the_module} PRIVATE "/fp:fast") +elseif(CV_GCC OR CV_CLANG) + ocv_target_compile_options(${the_module} PRIVATE -ffast-math) + ocv_target_compile_options(${the_module} PRIVATE -fno-finite-math-only) +endif() + ocv_option(OPENCV_DNN_CUDA "Build with CUDA support" HAVE_CUDA AND HAVE_CUBLAS