Merge pull request #19385 from alalek:ocl_isOpenCLActivated_update

pull/19396/head^2
Alexander Alekhin 4 years ago
commit 857f339914
  1. 10
      modules/core/src/ocl.cpp

@ -830,13 +830,12 @@ public:
// true if we have initialized OpenCL subsystem with available platforms // true if we have initialized OpenCL subsystem with available platforms
static bool g_isOpenCVActivated = false; static bool g_isOpenCLInitialized = false;
static bool g_isOpenCLAvailable = false;
bool haveOpenCL() bool haveOpenCL()
{ {
CV_TRACE_FUNCTION(); CV_TRACE_FUNCTION();
static bool g_isOpenCLInitialized = false;
static bool g_isOpenCLAvailable = false;
if (!g_isOpenCLInitialized) if (!g_isOpenCLInitialized)
{ {
@ -855,7 +854,7 @@ bool haveOpenCL()
{ {
cl_uint n = 0; cl_uint n = 0;
g_isOpenCLAvailable = ::clGetPlatformIDs(0, NULL, &n) == CL_SUCCESS; g_isOpenCLAvailable = ::clGetPlatformIDs(0, NULL, &n) == CL_SUCCESS;
g_isOpenCVActivated = n > 0; g_isOpenCLAvailable &= n > 0;
} }
catch (...) catch (...)
{ {
@ -885,7 +884,7 @@ bool useOpenCL()
bool isOpenCLActivated() bool isOpenCLActivated()
{ {
if (!g_isOpenCVActivated) if (!g_isOpenCLAvailable)
return false; // prevent unnecessary OpenCL activation via useOpenCL()->haveOpenCL() calls return false; // prevent unnecessary OpenCL activation via useOpenCL()->haveOpenCL() calls
return useOpenCL(); return useOpenCL();
} }
@ -5783,7 +5782,6 @@ public:
static OpenCLAllocator* getOpenCLAllocator_() // call once guarantee static OpenCLAllocator* getOpenCLAllocator_() // call once guarantee
{ {
static OpenCLAllocator* g_allocator = new OpenCLAllocator(); // avoid destructor call (using of this object is too wide) static OpenCLAllocator* g_allocator = new OpenCLAllocator(); // avoid destructor call (using of this object is too wide)
g_isOpenCVActivated = true;
return g_allocator; return g_allocator;
} }
MatAllocator* getOpenCLAllocator() MatAllocator* getOpenCLAllocator()

Loading…
Cancel
Save