Fix OpenCL device detection when some OpenCL platform has no devices
It's not an error if some OpenCL platform has no devices. This makes
OpenCL device detection work correctly in the following scenario:
$ OPENCV_OPENCL_DEVICE=:GPU: ./opencv_test_dnn
OpenCV version: 4.1.2-dev
OpenCV VCS version: 4.1.2-80-g467748ee98-dirty
Build type: Debug
Compiler: /usr/bin/g++ (ver 7.4.0)
Parallel framework: pthreads
CPU features: SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?
Intel(R) IPP version: ippIP AVX2 (l9) 2019.0.0 Gold (-) Jul 24 2018
OpenCL Platforms:
AMD Accelerated Parallel Processing
Portable Computing Language
CPU: pthread-AMD Ryzen 7 2700X Eight-Core Processor (OpenCL 1.2 pocl HSTR: pthread-x86_64-pc-linux-gnu-znver1)
NVIDIA CUDA
dGPU: GeForce GTX 1080 (OpenCL 1.2 CUDA)
Current OpenCL device:
Type = dGPU
Name = GeForce GTX 1080
Version = OpenCL 1.2 CUDA
Driver version = 430.26
This commit is contained in:
parent
53139e6ebe
commit
cdbfdcc363
@ -2037,16 +2037,25 @@ struct Context::Impl
|
||||
0
|
||||
};
|
||||
|
||||
cl_uint i, nd0 = 0, nd = 0;
|
||||
cl_uint nd0 = 0;
|
||||
int dtype = dtype0 & 15;
|
||||
CV_OCL_DBG_CHECK(clGetDeviceIDs(pl, dtype, 0, 0, &nd0));
|
||||
cl_int status = clGetDeviceIDs(pl, dtype, 0, NULL, &nd0);
|
||||
if (status != CL_DEVICE_NOT_FOUND) // Not an error if platform has no devices
|
||||
{
|
||||
CV_OCL_DBG_CHECK_RESULT(status,
|
||||
cv::format("clGetDeviceIDs(platform=%p, device_type=%d, num_entries=0, devices=NULL, numDevices=%p)", pl, dtype, &nd0).c_str());
|
||||
}
|
||||
|
||||
if (nd0 == 0)
|
||||
return;
|
||||
|
||||
AutoBuffer<void*> dlistbuf(nd0*2+1);
|
||||
cl_device_id* dlist = (cl_device_id*)dlistbuf.data();
|
||||
cl_device_id* dlist_new = dlist + nd0;
|
||||
CV_OCL_DBG_CHECK(clGetDeviceIDs(pl, dtype, nd0, dlist, &nd0));
|
||||
String name0;
|
||||
|
||||
cl_uint i, nd = 0;
|
||||
String name0;
|
||||
for(i = 0; i < nd0; i++)
|
||||
{
|
||||
Device d(dlist[i]);
|
||||
@ -5944,7 +5953,12 @@ void convertFromImage(void* cl_mem_image, UMat& dst)
|
||||
static void getDevices(std::vector<cl_device_id>& devices, cl_platform_id platform)
|
||||
{
|
||||
cl_uint numDevices = 0;
|
||||
CV_OCL_DBG_CHECK(clGetDeviceIDs(platform, (cl_device_type)Device::TYPE_ALL, 0, NULL, &numDevices));
|
||||
cl_int status = clGetDeviceIDs(platform, (cl_device_type)Device::TYPE_ALL, 0, NULL, &numDevices);
|
||||
if (status != CL_DEVICE_NOT_FOUND) // Not an error if platform has no devices
|
||||
{
|
||||
CV_OCL_DBG_CHECK_RESULT(status,
|
||||
cv::format("clGetDeviceIDs(platform, Device::TYPE_ALL, num_entries=0, devices=NULL, numDevices=%p)", &numDevices).c_str());
|
||||
}
|
||||
|
||||
if (numDevices == 0)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user