From 79fc3a62037901606a43a58875bb2088474805d8 Mon Sep 17 00:00:00 2001 From: Konstantin Matskevich Date: Fri, 21 Mar 2014 16:56:12 +0400 Subject: [PATCH 1/2] added gpu type selection in OPENCV_OPENCL_DEVICE parser --- modules/core/src/ocl.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index c6e0c40398..736fd5f3ab 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2193,7 +2193,7 @@ static cl_device_id selectOpenCLDevice() for (size_t t = 0; t < deviceTypes.size(); t++) { int deviceType = 0; - if (deviceTypes[t] == "GPU") + if (deviceTypes[t] == "GPU" || deviceTypes[t] == "dGPU" || deviceTypes[t] == "iGPU") deviceType = Device::TYPE_GPU; else if (deviceTypes[t] == "CPU") deviceType = Device::TYPE_CPU; @@ -2229,7 +2229,14 @@ static cl_device_id selectOpenCLDevice() { std::string name; CV_OclDbgAssert(getStringInfo(clGetDeviceInfo, devices[i], CL_DEVICE_NAME, name) == CL_SUCCESS); - if (isID || name.find(deviceName) != std::string::npos) + cl_bool useGPU = true; + if(deviceTypes[t] == "dGPU" || deviceTypes[t] == "iGPU") + { + cl_bool isIGPU = CL_FALSE; + clGetDeviceInfo(devices[i], CL_DEVICE_HOST_UNIFIED_MEMORY, sizeof(isIGPU), &isIGPU, NULL); + useGPU = deviceTypes[t] == "dGPU" ? !isIGPU : isIGPU; + } + if ( (isID || name.find(deviceName) != std::string::npos) && useGPU) { // TODO check for OpenCL 1.1 return devices[i]; From c2355d3a12902eb5f2368f27b94802b335940f9d Mon Sep 17 00:00:00 2001 From: Konstantin Matskevich Date: Mon, 24 Mar 2014 15:20:00 +0400 Subject: [PATCH 2/2] case-insensitivity --- modules/core/src/ocl.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 736fd5f3ab..8d22ebe828 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2179,7 +2179,6 @@ static cl_device_id selectOpenCLDevice() goto not_found; } } - if (deviceTypes.size() == 0) { if (!isID) @@ -2193,13 +2192,16 @@ static cl_device_id selectOpenCLDevice() for (size_t t = 0; t < deviceTypes.size(); t++) { int deviceType = 0; - if (deviceTypes[t] == "GPU" || deviceTypes[t] == "dGPU" || deviceTypes[t] == "iGPU") + std::string tempStrDeviceType = deviceTypes[t]; + std::transform( tempStrDeviceType.begin(), tempStrDeviceType.end(), tempStrDeviceType.begin(), tolower ); + + if (tempStrDeviceType == "gpu" || tempStrDeviceType == "dgpu" || tempStrDeviceType == "igpu") deviceType = Device::TYPE_GPU; - else if (deviceTypes[t] == "CPU") + else if (tempStrDeviceType == "cpu") deviceType = Device::TYPE_CPU; - else if (deviceTypes[t] == "ACCELERATOR") + else if (tempStrDeviceType == "accelerator") deviceType = Device::TYPE_ACCELERATOR; - else if (deviceTypes[t] == "ALL") + else if (tempStrDeviceType == "all") deviceType = Device::TYPE_ALL; else { @@ -2230,11 +2232,11 @@ static cl_device_id selectOpenCLDevice() std::string name; CV_OclDbgAssert(getStringInfo(clGetDeviceInfo, devices[i], CL_DEVICE_NAME, name) == CL_SUCCESS); cl_bool useGPU = true; - if(deviceTypes[t] == "dGPU" || deviceTypes[t] == "iGPU") + if(tempStrDeviceType == "dgpu" || tempStrDeviceType == "igpu") { cl_bool isIGPU = CL_FALSE; clGetDeviceInfo(devices[i], CL_DEVICE_HOST_UNIFIED_MEMORY, sizeof(isIGPU), &isIGPU, NULL); - useGPU = deviceTypes[t] == "dGPU" ? !isIGPU : isIGPU; + useGPU = tempStrDeviceType == "dgpu" ? !isIGPU : isIGPU; } if ( (isID || name.find(deviceName) != std::string::npos) && useGPU) {