Skip to content

Commit

Permalink
Android OpenCL support
Browse files Browse the repository at this point in the history
  • Loading branch information
komakai authored and Sajjad Ali committed Mar 27, 2023
1 parent 917dd36 commit 9fed0b3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
51 changes: 51 additions & 0 deletions modules/core/src/opencl/runtime/opencl_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,55 @@ static void *GetHandle(const char *file)
return handle;
}

#ifdef __ANDROID__

static const char *defaultAndroidPaths[] = {
"libOpenCL.so",
"/system/lib64/libOpenCL.so",
"/system/vendor/lib64/libOpenCL.so",
"/system/vendor/lib64/egl/libGLES_mali.so",
"/system/vendor/lib64/libPVROCL.so",
"/data/data/org.pocl.libs/files/lib64/libpocl.so",
"/system/lib/libOpenCL.so",
"/system/vendor/lib/libOpenCL.so",
"/system/vendor/lib/egl/libGLES_mali.so",
"/system/vendor/lib/libPVROCL.so",
"/data/data/org.pocl.libs/files/lib/libpocl.so"
};

static void* GetProcAddress(const char* name)
{
static bool initialized = false;
static void* handle = NULL;
if (!handle && !initialized)
{
cv::AutoLock lock(cv::getInitializationMutex());
if (!initialized)
{
bool foundOpenCL = false;
for (unsigned int i = 0; i < (sizeof(defaultAndroidPaths)/sizeof(char*)); i++)
{
const char* path = (i==0) ? getRuntimePath(defaultAndroidPaths[i]) : defaultAndroidPaths[i];
if (path) {
handle = GetHandle(path);
if (handle) {
foundOpenCL = true;
break;
}
}
}
initialized = true;
if (!foundOpenCL)
fprintf(stderr, ERROR_MSG_CANT_LOAD);
}
}
if (!handle)
return NULL;
return dlsym(handle, name);
}

#else // NOT __ANDROID__

static void* GetProcAddress(const char* name)
{
static bool initialized = false;
Expand Down Expand Up @@ -206,6 +255,8 @@ static void* GetProcAddress(const char* name)
return NULL;
return dlsym(handle, name);
}
#endif // __ANDROID__

#define CV_CL_GET_PROC_ADDRESS(name) GetProcAddress(name)
#endif

Expand Down
2 changes: 2 additions & 0 deletions platforms/android/build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def __init__(self, workdir, opencvdir, config):
self.debug = True if config.debug else False
self.debug_info = True if config.debug_info else False
self.no_samples_build = True if config.no_samples_build else False
self.opencl = True if config.opencl else False

def get_cmake(self):
if not self.config.use_android_buildtools and check_executable(['cmake', '--version']):
Expand Down Expand Up @@ -423,6 +424,7 @@ def get_ndk_dir():
parser.add_argument('--debug', action="store_true", help="Build 'Debug' binaries (CMAKE_BUILD_TYPE=Debug)")
parser.add_argument('--debug_info', action="store_true", help="Build with debug information (useful for Release mode: BUILD_WITH_DEBUG_INFO=ON)")
parser.add_argument('--no_samples_build', action="store_true", help="Do not build samples (speeds up build)")
parser.add_argument('--opencl', action="store_true", help="Enable OpenCL support")
args = parser.parse_args()

log.basicConfig(format='%(message)s', level=log.DEBUG)
Expand Down

0 comments on commit 9fed0b3

Please sign in to comment.