-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
OpenCLExecutionContext::create() and getDevice() don't support multiple devices #18888
Description
System information (version)
- OpenCV => 4.5.0
- Operating System / Platform => Microsoft Windows [Version 10.0.19042.630]
- Compiler => Visual Studio Community 2019 v16.8.2
Detailed description
cv::ocl::OpenCLExecutionContext::getDevice() supports only one device. This is not in alignment with the sibling API
cv::ocl::Context::ndevices() and cv::ocl::Context::device(i) that support multiple devices in an opencl context.
🙂 Thanks for the effort into OpenCLExecutionContext. It adds programmatic control of opencl computation devices 👍
Steps to reproduce
This was found in code review. This is a design investigation rather than faulty code.
OpenCV before v4.5.0 might have difficulty in assigning multiple devices into a opencl context. It would likely be an advanced hardware platform and be the "default" context created. Still, the APIs like cv::ocl::Context::device(i) would allow probing for such multiple devices in a single opencl context.
The new OpenCLExecutionContext APIs available in v4.5.0+, there is no direct way to probe all devices in the default OpenCLExecutionContext. And OpenCLExecutionContext::getDevice() only provides for one -- which suggests that there is an underlying implementation limit of one device in an OpenCLExecutionContext while the older APIs support multiple devices in similar APIs.
Perhaps, OpenCV never supported multiple devices in a opencl context. Perhaps cv::ocl::Context::ndevices() could never return anything but 0 or 1. Though, I don't readily see such a limit in the code. This direction of thought then questions why cv::ocl::OpenCLExecutionContext::create(context, device) needs the device parameter. If OpenCV supports only one device in a cv::ocl::Context then what is the value of that 2nd param?
// pre 4.5.0
cv::ocl::Context cl_context = cv::ocl::Context::getDefault(true);
for (size_t i = 0; i < cl_context.ndevices(); ++i) { ... }
// new APIs in 4.5.0
const auto& exec_context = cv::ocl::OpenCLExecutionContext::getCurrentRef();
const auto& cl_device = exec_context.getDevice(); // not possible to get all devices
// workaround
const auto& exec_context = cv::ocl::OpenCLExecutionContext::getCurrentRef();
const auto &cl_context = exec_context.getContext();
for (size_t i = 0; i < cl_context.ndevices(); ++i) { ... }OpenCLExecutionContext::create() is also limited to a single device.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
answers.opencv.org, Stack Overflow, etc and have not found solution - I updated to latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc