@@ -63,6 +63,20 @@ CV_SUPPRESS_DEPRECATED_END
63
63
#define ERROR_MSG_CANT_LOAD " Failed to load OpenCL runtime\n "
64
64
#define ERROR_MSG_INVALID_VERSION " Failed to load OpenCL runtime (expected version 1.1+)\n "
65
65
66
+ static const char * getRuntimePath (const char * defaultPath)
67
+ {
68
+ const char * envPath = getenv (" OPENCV_OPENCL_RUNTIME" );
69
+ if (envPath)
70
+ {
71
+ static const char disabled_str[] = " disabled" ;
72
+ if ((strlen (envPath) == sizeof (disabled_str) - 1 ) &&
73
+ (memcmp (envPath, disabled_str, sizeof (disabled_str) - 1 ) == 0 ))
74
+ return NULL ;
75
+ return envPath;
76
+ }
77
+ return defaultPath;
78
+ }
79
+
66
80
#if defined(__APPLE__)
67
81
#include < dlfcn.h>
68
82
@@ -75,14 +89,13 @@ static void* AppleCLGetProcAddress(const char* name)
75
89
cv::AutoLock lock (cv::getInitializationMutex ());
76
90
if (!initialized)
77
91
{
78
- const char * path = " /System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL" ;
79
- const char * envPath = getenv (" OPENCV_OPENCL_RUNTIME" );
80
- if (envPath)
81
- path = envPath;
82
- handle = dlopen (oclpath, RTLD_LAZY | RTLD_GLOBAL);
92
+ const char * defaultPath = " /System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL" ;
93
+ const char * path = getRuntimePath (defaultPath);
94
+ if (path)
95
+ handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL);
83
96
if (handle == NULL )
84
97
{
85
- if (envPath )
98
+ if (path != NULL && path != defaultPath )
86
99
fprintf (stderr, ERROR_MSG_CANT_LOAD);
87
100
}
88
101
else if (dlsym (handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL )
@@ -115,14 +128,13 @@ static void* WinGetProcAddress(const char* name)
115
128
handle = GetModuleHandleA (" OpenCL.dll" );
116
129
if (!handle)
117
130
{
118
- const char * path = " OpenCL.dll" ;
119
- const char * envPath = getenv (" OPENCV_OPENCL_RUNTIME" );
120
- if (envPath)
121
- path = envPath;
122
- handle = LoadLibraryA (path);
131
+ const char * defaultPath = " OpenCL.dll" ;
132
+ const char * path = getRuntimePath (defaultPath);
133
+ if (path)
134
+ handle = LoadLibraryA (path);
123
135
if (!handle)
124
136
{
125
- if (envPath )
137
+ if (path != NULL && path != defaultPath )
126
138
fprintf (stderr, ERROR_MSG_CANT_LOAD);
127
139
}
128
140
else if (GetProcAddress (handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL )
@@ -173,18 +185,18 @@ static void* GetProcAddress(const char* name)
173
185
cv::AutoLock lock (cv::getInitializationMutex ());
174
186
if (!initialized)
175
187
{
176
- const char * envPath = getenv (" OPENCV_OPENCL_RUNTIME" );
177
- if (envPath)
178
- {
179
- handle = GetHandle (envPath);
180
- if (!handle)
181
- fprintf (stderr, ERROR_MSG_CANT_LOAD);
182
- }
183
- else
188
+ const char * defaultPath = " libOpenCL.so" ;
189
+ const char * path = getRuntimePath (defaultPath);
190
+ if (path)
184
191
{
185
- handle = GetHandle (" libOpenCL.so " );
192
+ handle = GetHandle (path );
186
193
if (!handle)
187
- handle = GetHandle (" libOpenCL.so.1" );
194
+ {
195
+ if (path == defaultPath)
196
+ handle = GetHandle (" libOpenCL.so.1" );
197
+ else
198
+ fprintf (stderr, ERROR_MSG_CANT_LOAD);
199
+ }
188
200
}
189
201
initialized = true ;
190
202
}
0 commit comments