Running detection on GPU using CUDA backend crashes JVM without error

I am trying to build openCV 460 from source with cuda support for java. I’ve run thru the build process a million times in the past week and have run out of bright ideas on how to ever get this running so I can start the intended development process;

  • Building on MS Windows 10
  • Configuring from CMake gui
  • Building from visual studio 2022
  • I’ve run into issues while configuring from a FAT32 partition where certain modules would not download, this seemed to be solved by building from an NTFS volume
  • Configured and build with 2 different jdk’s (11 coretto from intelij / 11 oracle from intelij / 11 coretto from windows / 11 oracle from windows, all to no avail.
  • jar’s and dll’s seem to have been build successfully no errors during configure or build stage.
  • building cuda arch 8.6 only for an RTX3060
  • cuda 11.7 installed as per manual, successfully detected during configure
  • latest cudnn installed as per manual. successfully detected during configure
  • building without tests
  • building without examples

The behavior I am observing is;
When executing on CPU without CUDA backend detection works as expected, application has been running stable on CPU for 2 days without interruptions, which leads to believe there are no obvious memory leaks in the code that might be magnified when running on GPU. When running on GPU with cuda backend, after a spike to 100% resource usage on the RTX3060 the process exits without any warning or error.

I’ve debugged the crash and it seems to come from an opencv java class;
Net.java: forward_4(nativeObj, outputBlobs_mat.nativeObj, outBlobNames);

I am quite new to OpenCV and the process exits without any warnings or errors before the first detection returns with results. My questions are;

  • first off what are my options for properly debugging what is going on with opencv under te hood? (I have tried setting the environment variable for opencv to INFO but no luck)
  • the application uses multiple threads 1 for Main 1 for capture 1 for detection and 1 for processing the result onto a frame with detections. Could this have anything to do with the behavior I am observing?

Configure logs;

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
Detected processor: AMD64
libjpeg-turbo: VERSION = 2.1.3, BUILD = opencv-4.6.0-dev-libjpeg-turbo
64-bit build (x86_64)
CMAKE_ASM_NASM_COMPILER = C:/Program Files/NASM/nasm.exe
CMAKE_ASM_NASM_OBJECT_FORMAT = win64
CMAKE_ASM_NASM_FLAGS =  -DWIN64 -D__x86_64__ 
SIMD extensions: x86_64 (WITH_SIMD = 1)
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.6.0-dev-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
at: C:/Build/opencv/build/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2020.0.0
at: C:/Build/opencv/build/3rdparty/ippicv/ippicv_win/iw
CUDA detected: 11.7
CUDA: Using CUDA_ARCH_BIN=8.6
CUDA NVCC target flags: -gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES
CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
LAPACK(OpenBLAS): LAPACK_LIBRARIES: J:/OpenBLAS-0.3.21-x64/lib/libopenblas.lib
LAPACK(OpenBLAS): Support is enabled.
Found apache ant: J:/apache-ant-1.10.12/bin/ant.bat (1.10.12)
Found JNI: C:/Program Files/Java/jdk-11.0.16/include  found components: AWT JVM 
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
freetype2:   NO
harfbuzz:    NO
Julia not found. Not compiling Julia Bindings. 
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Glog/Gflags
Tesseract:   NO
Allocator metrics storage type: 'long long'
Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/Build/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
highgui: using builtin backend: WIN32UI
Building with NVIDIA Optical Flow API 2.0
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
  CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
  directory
Call Stack (most recent call first):
  CMakeLists.txt:1050 (include)



General configuration for OpenCV 4.6.0-dev =====================================
  Version control:               4.6.0-343-g1646a21197

  Extra modules:
    Location (extra):            C:/Build/opencv_contrib/modules
    Version control (extra):     4.6.0-75-g74fce7f7

  Platform:
    Timestamp:                   2022-10-02T10:19:02Z
    Host:                        Windows 10.0.19044 AMD64
    CMake:                       3.24.2
    CMake generator:             Visual Studio 17 2022
    CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
    MSVC:                        1933
    Configuration:               Debug Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (16 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (32 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      NO
    C++ standard:                11
    C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe  (ver 19.33.31630.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP  /MT /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP  /MTd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MT /O2 /Ob2 /DNDEBUG 
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MTd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          J:/OpenBLAS-0.3.21-x64/lib/libopenblas.lib wsock32 comctl32 gdi32 ole32 setupapi ws2_32 cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib
    3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc ippiw ippicv

  OpenCV modules:
    To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    python3 python_bindings_generator python_tests world
    Disabled by dependency:      -
    Unavailable:                 cvv freetype hdf julia matlab ovis python2 sfm viz
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI:                           WIN32UI
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.12)
    JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
        SIMD Support Request:    YES
        SIMD Support:            YES
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/Build/opencv/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/Build/opencv/build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      YES (J:/OpenBLAS-0.3.21-x64/lib/libopenblas.lib)
    Eigen:                       YES (ver ..)
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)

  NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS)
    NVIDIA GPU arch:             86
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.5.0)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/Build/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            C:/Python27/python.exe

  Java:                          export all functions
    ant:                         J:/apache-ant-1.10.12/bin/ant.bat (ver 1.10.12)
    JNI:                         C:/Program Files/Java/jdk-11.0.16/include C:/Program Files/Java/jdk-11.0.16/include/win32 C:/Program Files/Java/jdk-11.0.16/include
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    C:/Program Files/opencv
-----------------------------------------------------------------

Configuring done
Generating done

Is there anybody on the forum that would be willing to help me along with this?

there are too many moving parts here.

you need to make the first steps. swap/exclude individual parts to narrow the problem space down. you know, standard problem solving.

I have no appreciable experience with java or CUDA, let alone both combined. do not expect further responses from me relating to this thread/problem.