Commit 7f554f3c authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #10155 from alalek:ocl_update_loader

parents 91c1d769 c38620e9
...@@ -63,6 +63,20 @@ CV_SUPPRESS_DEPRECATED_END ...@@ -63,6 +63,20 @@ CV_SUPPRESS_DEPRECATED_END
#define ERROR_MSG_CANT_LOAD "Failed to load OpenCL runtime\n" #define ERROR_MSG_CANT_LOAD "Failed to load OpenCL runtime\n"
#define ERROR_MSG_INVALID_VERSION "Failed to load OpenCL runtime (expected version 1.1+)\n" #define ERROR_MSG_INVALID_VERSION "Failed to load OpenCL runtime (expected version 1.1+)\n"
static const char* getRuntimePath(const char* defaultPath)
{
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME");
if (envPath)
{
static const char disabled_str[] = "disabled";
if ((strlen(envPath) == sizeof(disabled_str) - 1) &&
(memcmp(envPath, disabled_str, sizeof(disabled_str) - 1) == 0))
return NULL;
return envPath;
}
return defaultPath;
}
#if defined(__APPLE__) #if defined(__APPLE__)
#include <dlfcn.h> #include <dlfcn.h>
...@@ -75,14 +89,13 @@ static void* AppleCLGetProcAddress(const char* name) ...@@ -75,14 +89,13 @@ static void* AppleCLGetProcAddress(const char* name)
cv::AutoLock lock(cv::getInitializationMutex()); cv::AutoLock lock(cv::getInitializationMutex());
if (!initialized) if (!initialized)
{ {
const char* path = "/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL"; const char* defaultPath = "/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL";
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); const char* path = getRuntimePath(defaultPath);
if (envPath) if (path)
path = envPath; handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
handle = dlopen(oclpath, RTLD_LAZY | RTLD_GLOBAL);
if (handle == NULL) if (handle == NULL)
{ {
if (envPath) if (path != NULL && path != defaultPath)
fprintf(stderr, ERROR_MSG_CANT_LOAD); fprintf(stderr, ERROR_MSG_CANT_LOAD);
} }
else if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL) else if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL)
...@@ -115,14 +128,13 @@ static void* WinGetProcAddress(const char* name) ...@@ -115,14 +128,13 @@ static void* WinGetProcAddress(const char* name)
handle = GetModuleHandleA("OpenCL.dll"); handle = GetModuleHandleA("OpenCL.dll");
if (!handle) if (!handle)
{ {
const char* path = "OpenCL.dll"; const char* defaultPath = "OpenCL.dll";
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); const char* path = getRuntimePath(defaultPath);
if (envPath) if (path)
path = envPath; handle = LoadLibraryA(path);
handle = LoadLibraryA(path);
if (!handle) if (!handle)
{ {
if (envPath) if (path != NULL && path != defaultPath)
fprintf(stderr, ERROR_MSG_CANT_LOAD); fprintf(stderr, ERROR_MSG_CANT_LOAD);
} }
else if (GetProcAddress(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL) else if (GetProcAddress(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL)
...@@ -173,18 +185,18 @@ static void* GetProcAddress(const char* name) ...@@ -173,18 +185,18 @@ static void* GetProcAddress(const char* name)
cv::AutoLock lock(cv::getInitializationMutex()); cv::AutoLock lock(cv::getInitializationMutex());
if (!initialized) if (!initialized)
{ {
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); const char* defaultPath = "libOpenCL.so";
if (envPath) const char* path = getRuntimePath(defaultPath);
{ if (path)
handle = GetHandle(envPath);
if (!handle)
fprintf(stderr, ERROR_MSG_CANT_LOAD);
}
else
{ {
handle = GetHandle("libOpenCL.so"); handle = GetHandle(path);
if (!handle) if (!handle)
handle = GetHandle("libOpenCL.so.1"); {
if (path == defaultPath)
handle = GetHandle("libOpenCL.so.1");
else
fprintf(stderr, ERROR_MSG_CANT_LOAD);
}
} }
initialized = true; initialized = true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment