Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib module CUDEV uses c++ exceptions but not enabled on Windows #19728

Open
3 tasks done
diablodale opened this issue Mar 14, 2021 · 0 comments
Open
3 tasks done

contrib module CUDEV uses c++ exceptions but not enabled on Windows #19728

diablodale opened this issue Mar 14, 2021 · 0 comments

Comments

@diablodale
Copy link
Contributor

OpenCV compile that includes contrib module CUDEV, the cmake infrastructure disables C++ exceptions but this module's code needs exceptions. Because of this, the code will behave unpredictably if an exception occurs.

System information (version)

  • OpenCV => 4.5.1 at master b19f860
  • Operating System / Platform => Microsoft Windows [Version 10.0.19042.867]
  • Compiler => VS2019 v16.9.0 64-bit compile

Repro

  1. Setup as above.
  2. Enable features related to contrib modulke CUDEV
  3. Compile debug

Result

This warning is issued during compile:

[build] [1645/2349  69% :: 538.614] Building CXX object modules\cudev\test\CMakeFiles\opencv_test_cudev.dir\test_main.cpp.obj
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\ostream(411): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\ostream(404): note: while compiling class template member function 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(double)'
[build] C:\repos-nobackup\opencv\modules\core\include\opencv2/core/utility.hpp(400): note: see reference to function template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(double)' being compiled
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\ostream(641): note: see reference to class template instantiation 'std::basic_ostream<char,std::char_traits<char>>' being compiled

Expected

Clean compile, no warnings, and predictable code execution.

Likely cause

compile_commands.json created by cmake on Windows shows exceptions are not enabled for cudev/test/test_main.cpp

{
  "directory": "C:/repos-nobackup/opencv/build",
  "command": "C:\\PROGRA~2\\MICROS~2\\2019\\COMMUN~1\\VC\\Tools\\MSVC\\1428~1.299\\bin\\Hostx64\\x64\\cl.exe  /nologo /TP -D_USE_MATH_DEFINES -D_VARIADIC_MAX=10 -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I. -IC:\\repos-nobackup\\opencv_contrib\\modules\\cudev\\src -IC:\\repos-nobackup\\opencv_contrib\\modules\\cudev\\include -Imodules\\cudev -IC:\\repos-nobackup\\opencv\\modules\\core\\include -Imodules\\cudev\\test -IC:\\repos-nobackup\\opencv\\modules\\imgproc\\include -IC:\\repos-nobackup\\opencv\\modules\\imgcodecs\\include -IC:\\repos-nobackup\\opencv\\modules\\videoio\\include -IC:\\repos-nobackup\\opencv\\modules\\highgui\\include -IC:\\repos-nobackup\\opencv\\modules\\ts\\include -I\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\include\" -I\"C:\\Program Files (x86)\\Intel\\oneAPI\\ipp\\2021.1.1\\include\"  -DGLOG_NO_ABBREVIATED_SEVERITIES -DWINVER=0x0A00 -D_WIN32_WINNT=0x0A00 -DNTDDI_VERSION=0x0A000005 /arch:AVX  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS         /arch:AVX  /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4189 /wd4505  /MD /O2 /Ob2 /DNDEBUG  /GL /Fomodules\\cudev\\test\\CMakeFiles\\opencv_test_cudev.dir\\test_main.cpp.obj /FdTARGET_COMPILE_PDB /FS -c C:\\repos-nobackup\\opencv_contrib\\modules\\cudev\\test\\test_main.cpp",
  "file": "C:\\repos-nobackup\\opencv_contrib\\modules\\cudev\\test\\test_main.cpp"
},

There are only two cpp files in the CUDEV module. The compile command for cudev/src/stub.cpp correctly includes /EHa. A suspicious difference in the two compile commands for each. Notice the two spaces between AVX and /wd4127. This suggests that somewhere is placement for the missing /EHa and cmake chose to not place it yet the surrounding spaces remain.

      below is test_main.cpp
/Gy /bigobj /Oi  /fp:precise /FS         /arch:AVX  /wd4127 /wd4251 /wd4324
/Gy /bigobj /Oi  /fp:precise /FS         /arch:AVX /EHa /wd4127 /wd4251 /wd4324
      above is stub.cpp

I suspect the missing flag is due to the following

macro(ocv_cuda_filter_options)
foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
set(${var}_backup_in_cuda_compile_ "${${var}}")
if (CV_CLANG)
# we remove -Winconsistent-missing-override and -Qunused-arguments
# just in case we are compiling CUDA with gcc but OpenCV with clang
string(REPLACE "-Winconsistent-missing-override" "" ${var} "${${var}}")
string(REPLACE "-Qunused-arguments" "" ${var} "${${var}}")
endif()
# we remove /EHa as it generates warnings under windows
string(REPLACE "/EHa" "" ${var} "${${var}}")

If the test code needs exceptions (as this warning declares), then the /EHa needs to be used on the compile command. In contrast, if the test code removes its use of exceptions, then exception support is not needed. It is possible to ignore warning 4530, but the test code would still be unpredictable and it might provide invalid test results.

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants