Application built with OpenCV 4.3 and openCL 1.2 failed to exit at the end

My company has a Windows application that uses Deep Neural Network and computer vision for image segmentation. The application employs OpenCV and OpenCL and has been running fine until recently we upgrade our OpenCV to version 4.3 from the older version 3.1. We now run into the issue that at the end, the application just fails to quit properly. This issue only happens to AMD GPU devices when using with OpenCL. Intel’s devices and AMD CPU (not running OpenCL) do not have this problem. The application seems just hang at the very last statement (without returning back the prompt to the Windows’s command prompt). I’ve been doing some intensive search but could not find a good solution. One closest hit is like this thread Opencl ReleaseCommandQueue hangs - AMD Community . Posted more messages in AMD developer forum but I also try here to see if anyone can help with a couple questions here:

  1. if anyone has run into similar problem and has ideas what could be the issue and/or where to troubleshoot?
  2. Why it happens to OpenCV 4.3 but not 3.1?
  3. Or do we need to have more updated version of OpenCL to work with OpenCV 4.3?

The application is mainly C++ and built with VS 2017 and the issue happens for both 32 and 64 bit.

Thanks in advance for all the helps.

same issue here, Win10 using ocv 4.8.1 + VS2022 OpenCL target with Intel iGPU, 11900k
The dnn runs are significantly faster than the CPU target, no deadlock w RTX 4070Ti

It looks a deadlock here:

opencv_world481d.dll!cv::ocl::Program::Impl::~Impl() Line 4756 C++
opencv_world481d.dll!cv::ocl::Program::Impl::`scalar deleting destructor’(unsigned int) C++
opencv_world481d.dll!cv::ocl::Program::Impl::release() Line 4342 C++
> opencv_world481d.dll!cv::ocl::Program::~Program() Line 4818 C++

you both might want to approach the OpenCV developers with a bug report on this.

bug report should come with MRE and description of the environment. you should make sure to reproduce this on the latest release. also check existing issues for mentions of your issue.

Vanilla build of 4.8.1 on a 11900k w/o dGPU, Win10

  1. CMake -G “Visual Studio 17 2022” -A “x64” -S …\opencv-4.8.1 -B . -DBUILD_opencv_world=ON
  2. msbuild OpenCV.sln /m /low -t:Build -p:Configuration=Release;Platform=x64
  3. pMyNet->Handle.setPreferableBackend(DNN_BACKEND_DEFAULT);
    pMyNet->Handle.setPreferableTarget(DNN_TARGET_OPENCL);
  4. more workflow?

result:

  • Deadlock at unloading opencv_world481.dll (dtor cv::ocl::Program::Impl::~Impl()) on intel 11900k and same on 8750H.
  • I had same issue w 4.3.0 two years ago
  • No deadlock on a 13700k PC w dGPU 4070Ti same target (opencl) and backend selection. (Looks like it depends on Intel driver software.)
  • The DLL load and unload happen in the same thread.
  • Inference utilises the iGPU and the results are OK, but the dtor has this issue