In OpenCV 4.5 or later and on all platforms…after any successful ocl::setUseOpenCL(true)
and use of that OpenCL computing device, the managed OpenCL resources (buffers, queues, etc.) are not released when ocl::setUseOpenCL(false)
. The setUseOpenCL(false
)` only sets a boolean flag. It doesn’t release resources or any refcount on them.
Goal → “OpenCV, please turn off OpenCL and release the used resources”.
I recommend the OpenCV API itself to be enhanced to somehow enable managed OpenCL resources to be released without requiring a new computing device. It is not possible to do alternatives like (pseudocode)
-
cv::ocl::OpenCLExecutionContext::getCurrentRef() = ocl::OpenCLExecutionContext()
exposes a bug. It leaves the opencv TLS with empty.oclExecutionContext
yet.execcontextinitialized=true
. -
ocl::OpenCLExecutionContext().bind()
asserts because there is no impl -
cv::ocl::OpenCLExecutionContext::getCurrentRef().release()
fails later due to unmatched refcount decrement -
cl_context = cv::ocl::Context::create("disabled"); cv::ocl::OpenCLExecutionContext::create(cl_context, cl_context.device(0)).bind();
asserts with no context or device
The only way to release managed OpenCL resources is to ocl::OpenCLExecutionContext.bind()
to another OpenCL computing device – the old devices resources are released, and new resources are eventually allocated on the new computing device. But that is not the goal…and there might not be a 2nd OpenCL compute device to bind(). Somewhat related to Refcounts for ocl::Context::Impl not decremented when UMats out of scope · Issue #18919 · opencv/opencv · GitHub
I am confident I can update the API itself code to achieve the goal. However, I am unclear the approach to take. I’ll probably decrement the refcount for the current OpenCLExecutionContext
. But…I’m not sure if I want to…
- create new static
cv::ocl::OpenCLExecutionContext::unbind()
- allow binding a blank
OpenCLExecutionContext
- allow assigning a blank to the current ref
- something else, etc…
Comments, ideas, alternatives?