mirror of
https://github.com/opencv/opencv.git
synced 2025-07-22 20:39:41 +08:00
Merge pull request #10155 from alalek:ocl_update_loader
This commit is contained in:
commit
7f554f3cc4
@ -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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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);
|
handle = GetHandle(path);
|
||||||
if (!handle)
|
if (!handle)
|
||||||
fprintf(stderr, ERROR_MSG_CANT_LOAD);
|
{
|
||||||
}
|
if (path == defaultPath)
|
||||||
else
|
handle = GetHandle("libOpenCL.so.1");
|
||||||
{
|
else
|
||||||
handle = GetHandle("libOpenCL.so");
|
fprintf(stderr, ERROR_MSG_CANT_LOAD);
|
||||||
if (!handle)
|
}
|
||||||
handle = GetHandle("libOpenCL.so.1");
|
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user