From eebf92ba58f68a7fc0f05c6e37d6e4fb111de151 Mon Sep 17 00:00:00 2001 From: Konstantin Matskevich Date: Tue, 18 Mar 2014 13:19:41 +0400 Subject: [PATCH] fix for incorrect opencl device selection --- modules/core/src/ocl.cpp | 5 +++-- modules/core/src/umatrix.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 7c4f8de9e0..b8f9db5fb4 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -1410,7 +1410,7 @@ bool useOpenCL() { CoreTLSData* data = coreTlsData.get(); if( data->useOpenCL < 0 ) - data->useOpenCL = (int)haveOpenCL(); + data->useOpenCL = (int)haveOpenCL() && Device::getDefault().ptr() != NULL; return data->useOpenCL > 0; } @@ -1419,7 +1419,7 @@ void setUseOpenCL(bool flag) if( haveOpenCL() ) { CoreTLSData* data = coreTlsData.get(); - data->useOpenCL = flag ? 1 : 0; + data->useOpenCL = (flag && Device::getDefault().ptr() != NULL) ? 1 : 0; } } @@ -2245,6 +2245,7 @@ not_found: std::cerr << deviceTypes[t] << " "; std::cerr << std::endl << " Device name: " << (deviceName.length() == 0 ? "any" : deviceName) << std::endl; + throw cv::Exception(); return NULL; } diff --git a/modules/core/src/umatrix.cpp b/modules/core/src/umatrix.cpp index 44cb3f44b5..d88dda2730 100644 --- a/modules/core/src/umatrix.cpp +++ b/modules/core/src/umatrix.cpp @@ -88,7 +88,7 @@ void UMatData::unlock() MatAllocator* UMat::getStdAllocator() { - if( ocl::haveOpenCL() ) + if( ocl::haveOpenCL() && ocl::useOpenCL() ) return ocl::getOpenCLAllocator(); return Mat::getStdAllocator(); }